function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HaroldHHaroldH 

Login with SessionId and Server URL via Java

I'm trying to re-implement the following C# code in Java, and it is not working for reasons that are almost obvious.

Using WebSphere 5.12 and the IBM WebSphere V5 Web service runtime (SOAP stack).

First, the C# code, followed by the nearly equivalent (but not quite working) Java code.

C#:
private SforceService loginWithSession(string sessionId, string serverUrl) {

SforceService sfdc = new SforceService();
sfdc.SessionHeaderValue = new SessionHeader();
sfdc.SessionHeaderValue.sessionId = sessionId;
sfdc.Url = serverUrl;
return sfdc;

}

Java:
private SoapBindingStub loginWithSession(String sessionId, String serverUrl) throws ServiceException, MalformedURLException {

SoapBindingStub soapBindingStub = (SoapBindingStub) new SforceServiceLocator().getSoap(new java.net.URL(serverUrl));

SessionHeader sessionHeader = new SessionHeader();
sessionHeader.setSessionId(sessionId);

soapBindingStub._setProperty("SessionHeader", sessionHeader);
return soapBindingStub;
}


Question 1: The "INVALID_SESSION_ID" exception is raised by the sforce service.

Question 2: I see no way to reset the endpoint URL. No Url property, and no setUrl() method in the SoapBindingStub class. Is this a problem?

I'm certain that I'm using a valid sessionId string. I am, however, running through a proxy.

I would appreciate any suggestions.
SuperfellSuperfell
You should be calling setHeader not setProperty to set the SOAP Session Header.

You can create a new stub instance to handle the server redirect, or (in axis at least) there is a property you can set to change the endpoint URL, i don't remember the property name off the top of my head, but i think there's a java sample in the sforce docs that shows it.
DevAngelDevAngel

Hi HaroldH,

The problem is that the websphere soap stack does not enable the setting of headers.  We have developed a toolkit that is aimed at Websphere to handle this.  When you install the toolkit it creates an sforce nature that runs in the Web perspective.  When this nature is added to your web project it will cause a handler to be included in your project that will add the session header when an http request is made to the salesforce web services endpoint.

The toolkit also modifies at build time the login method of the generated proxy to handle the resetting of the endpoint for you.  A sample application is included in the toolkit that demonstrates how to use it.

Sforce 2.0 Toolkit for IBM WebSphere (API 5.0)

Cheers

HaroldHHaroldH

Hi Dave,

I've gone through the Websphere Toolkit documentation and instructions for implementing the sample (ProductConfigurator) application. 

It doesn't seem to work quite as expected.

For example, each time I try to generate a client from my enterprise WSDL, the only thing that gets generated is a package called "com.example" (this contains a set of *Element.java, *ResponseElement.java, and *Result.java classes).

The class files that are supposed to map to the custom objects in my org are not being regenerated.  So perhaps something is missing. 

Also, the weblink described in the documentation that accompanies the Websphere Toolkit is missing a parameter (oppname), causing the sample application to fail.  This is not critical, and is easy enough to figure out, but I wonder if perhaps there is a later version in the works that works a bit better. 

The real issue is that so far I seem to be missing the trick to generate a client from the WSDL file in WSAD 5.1.2. 

Any pointers?

Message Edited by HaroldH on 01-13-2005 05:04 PM

elieli
I see in the sForce Web Services Developer's Guide (in the login call described page) what you're talking about when you mention using the setHeader method. However, the setHeader method does not exist on the SoapBindingStub object that gets generated from the recommended WSDL to Java process. With any experience, you will surely say, "oh yes it does."

The problem appears to originiate with the sForce WebSphere Toolkit and the example for performing the WSDL to Java process that comes with that. When following the instructions in the sample provided in that toolkit (version 2.0 - installed with setup.exe dated 11/12/2004 into WSAD v5.1.2), the SOAPBindingStub object does NOT have a setHeader method. Maybe there is a quick solution or workaround, but I have to put on the brakes right there. This issue makes the validity of this example code as a reference for "how it's meant to be done" very much in doubt. Consequently, it is not clear if the sForce WebSphere Toolkit has a significant bug. (It does not regenerate any of the com.sforce.* packages when you follow the instructions to convert a WSDL to Java.)

I'm currently stuck wondering if I should continue to try to use the WSAD Toolkit or abandon it? I have just tried using the Eclipse WSDL2Java Plugin (http://prdownloads.sourceforge.net/sforce/com.myspotter.wsdl2java_1.2.0.zip?download) referenced here: http://sforce.sourceforge.net/. However, it does not generate that nice SOAPProxy class that the OrderConfigurator example in the sForce WebSphere Toolkit uses. So again, which way is the currently preferred approach? Furthermore I'm left questioning: if I abandon the sForce WebSphere Toolkit and use another plug-in, will I be missing some "best practice" that is preferred when running an sForce web service client from a WebSphere server.

Needless to say uncertainty reigns. Any insight you can share would be greatly appreciated.

Thanks,
Eli
DevAngelDevAngel

Hi eli,

There is a major bug with the toolkit.  But the bug is in the documentation.  In the documentation for generating the wsdl to java code, you should NOT choose IBM Soap.  Instead, you should choose IBM Websphere V5.

This will generate the expected proxy.  The method for logging in is still login(username, password), but you need not do anything explicit to have the session id included in subsequent calls.  The sforce nature modifies the login call in the SoapProxy class to save the session id in a property that is used by an HTTP handler that is added and configured when the project is built.  The handler looks for several possible properties that indicate that the soap headers for those properties should be added to the message.

 

A simple jsp that will run using the toolkit is :

<HTML>

<HEAD>

<%@ page

language="java"

contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"

%>

<% com.sforce.soap.enterprise.SoapProxy binding = new com.sforce.soap.enterprise.SoapProxy();

binding.login("username", "password");

com.sforce.soap.enterprise.DescribeGlobalResult dgr = binding.describeGlobal();

%>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<META name="GENERATOR" content="IBM WebSphere Studio">

<META http-equiv="Content-Style-Type" content="text/css">

<LINK href="theme/Master.css" rel="stylesheet"

type="text/css">

<TITLE>test.jsp</TITLE>

</HEAD>

<BODY>

<P>Place content here.</P>

<P>

<% for (int i=0;i<dgr.getTypes().length;i++) {

out.print(dgr.getTypes(i) + "<BR>");

}

%>

</P>

</BODY>

</HTML>

Message Edited by DevAngel on 01-18-2005 12:02 PM

bbpbbp

Hi Is there an updated version of the toolkit, as I'm hitting this problem of setting the session header in Rational v6 for Websphere v6?

 

Many Thanks.

 

Pete