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
BlandgerBlandger 

How to create correct SoapBindingStub using 'Session Id as string' only w/o making 'login'?

Hi all.

I need create SoapBindingStub object w/o calling

LoginResult lr = binding.login(userName, password);

I need to avoid the 'full scenario':

SoapBindingStub binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
LoginResult lr = binding.login(userName, password);
binding = (SoapBindingStub) new SforceServiceLocator().getSoap(new URL(lr.getServerUrl()));
_SessionHeader sh = new _SessionHeader();
sh.setSessionId(lr.getSessionId());
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);


The main idea is:
I want to recieve session ID value from the web-link then I want to create correct/working SoapBindingStub object WITHOUT invocation binding.login(userName, password) method.

is is possible to do? How is better accomplish it?

Now I'm trying something like that:

SforceServiceLocator locator = new SforceServiceLocator();
System.out.println("----- service URL is = " + locator.getSoapAddress()); // URL is correct !
binding = (SoapBindingStub) locator.getSoap();

// I can try to make a dummy call but it doesn't help
// binding.describeGlobal();

_SessionHeader sh = new _SessionHeader();
sh.setSessionId(sessionId);
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);

I'm getting error (on the dummy binding.describeGlobal() or on the real subseqWS call):

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server
faultSubcode:
faultString: Destination URL not reset. The URL returned from login must be set in the SforceService
faultActor:
faultNode:
faultDetail:
{urn:fault.enterprise.soap.sforce.com}fault: UNKNOWN_EXCEPTIONtionCode> Destination URL not reset. The URL returned from login must be set in the SforceService
Destination URL not reset. The URL returned from login must be set in th
e SforceService
DevAngelDevAngel

Hi Blandger,

You're almost there.  You still need to reset the url from the default.  When you ran wsdl2java the www endpoint from the wsdl was designated as you default endpoint in SforceServiceLocator.

To change the endpoint you need to add one line of code after

binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);

binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, serverUrl);

The serverUrl parameter is from the Web link.  You include it the same way you do the sessionId.  The merge field for the serverUrl is {!API_Enterprise_Server_URL_50} for the enterprise wsdl and {!API_Partner_Server_URL_50} for the partner wsdl.  These values are from the API Fields field type.

 

ndoshindoshi
Is it okay in terms of best practices to update the api session & url right before the soap call?
Also, I am thinking about putting that in a synchronized block to make sure if I get a request from a different user at the same time it doesn't make the soap call with the wrong user.

We are a pretty small company with a small userbase (about 15 people) so I think that would work for now.
If we need to scale it, it should be pretty easy to implement a pooling system or use a factory of some sort.
The app that makes the soap call is using Spring so we could probably make something work with that.

If anyone has a good idea for a quick solution to that, let me know.

Otherwise, I am mostly interested in my first question.

Thanks!

-nd
saachinahujaaovsaachinahujaaov

Following is the code snippet which we are using to connect with the sales force stubs:

 

 

package com.webaccommodate.enfinity.LSS.pipelet;

import com.intershop.beehive.core.capi.pipeline.Pipelet;

import com.intershop.beehive.core.capi.pipeline.PipelineDictionary;

import com.intershop.beehive.core.capi.pipeline.PipeletExecutionException;

import com.sforce.soap.enterprise.LoginResult;

import com.sforce.soap.enterprise.SaveResult;

import com.sforce.soap.enterprise.SessionHeader;

import com.sforce.soap.enterprise.SforceServiceLocator;

import com.sforce.soap.enterprise.Soap;

import com.sforce.soap.enterprise.SoapBindingStub;

import com.sforce.soap.enterprise.sobject.Account;

import com.sforce.soap.enterprise.sobject.Contact;

import com.sforce.soap.enterprise.sobject.SObject;

import javax.xml.rpc.ServiceException;

import java.net.URL;

import java.rmi.RemoteException;

/**

* Login to the Salesforce.com SOAP Api

 

*/

public class LoginNew extends Pipelet {

 

public int execute(PipelineDictionary dict) throws PipeletExecutionException {

String nextLoginTime;

String sessionId;

String serverUrl;

// lookup 'password' in pipeline dictionary

String password = "saachin1q6tWQri8eU0A37Ykz7SgwTddT";

// lookup 'username' in pipeline dictionary

String username = "saachinahuja@gmail.com";

try {Soap service = (

new SforceServiceLocator()).getSoap();

 

SoapBindingStub binding = (SoapBindingStub) new SforceServiceLocator().getSoap();

binding.setTimeout(6000000);

LoginResult loginResult = binding.login(username, password);

System.out.println("serviceResult....." + loginResult.getServerUrl());

System.out.println("USERID::: " + loginResult.getUserId());

// Create a new session header object and set the

// session id to that returned by the login

binding._setProperty(

SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY,

loginResult.getServerUrl());

// Create a new session header object and set the session id to that

// returned by the login

SessionHeader sh = new SessionHeader();

String sessID = loginResult.getSessionId();

System.out.println("Seesion ID: " + sessID);System.out.println("Service name:" + new SforceServiceLocator().getServiceName());

sh.setSessionId(sessID);

binding.setHeader(

new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader",

sh);

System.out.println("SH SESS ID: " + sh.getSessionId());

//*****************************************************************

Contact contact;

SObject[] cons = new Contact[2];

for (int j = 0; j < 2; j++) {contact =

new Contact();

System.out.println("In loop...");contact.setAssistantName(

"Jane");

contact.setAssistantPhone("777.777.7777");contact.setDepartment(

"Purchasing");

contact.setDescription("International IT Purchaser");contact.setEmail(

"joeblow@isp.com");

contact.setFax("555.555.5555");contact.setMailingCity(

"San Mateo");

contact.setMailingCountry("US");contact.setMailingState(

"CA");

contact.setMailingStreet("1129 B Street");contact.setMailingPostalCode(

"94105");

contact.setMobilePhone("888.888.8888");contact.setFirstName(

"Joe");

contact.setLastName("Blow");contact.setSalutation(

"Mr.");

contact.setPhone("999.999.9999");contact.setTitle(

"Purchasing Director");

cons[j] = contact;

}

System.out.println("Cons length: " + cons.length);

 

SaveResult[] sr = binding.create(cons);

for (int j = 0; j < sr.length; j++) {

if (sr[j].isSuccess()) {System.out.println(

"A contact was created with an id of: " + sr[j].getId());

}

}

//*****************************************************************

dict.put("sessionID", loginResult.getSessionId());

// store 'Result' in pipeline dictionary

dict.put("loginResult", loginResult);

dict.put("binding", binding);}

catch (ServiceException e) {

throw new PipeletExecutionException(

"Could not bind to service com.webaccommodate.enfinity.LSS.Sforce.Soap.",

e);

} catch (RemoteException e) {

throw new PipeletExecutionException(

"An exception occured invoking service login().",

e);

} catch (Exception e) {

throw new PipeletExecutionException(

"An exception occured invoking service login().",

e);

}

return PIPELET_NEXT;

}

}

 

 

Regards,

 

saachin ahuja