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
meister.edermeister.eder 

Apache CXF: INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

hey guys,

 

i have the following problem:

 

 

private Soap salesforceClient;
	private SessionHeader sh;
	private HashSet<Login> loginSet;


	public void init() {
		try {
			if(salesforceClient == null){
			SforceService ss = new SforceService(new URL("link/to/enterprise.wsdl"), new QName("urn:enterprise.soap.sforce.com", "SforceService"));
			salesforceClient = ss.getSoap();
	        LoginResult loginResult = salesforceClient.login("LOGIN", "PASSWORD+TOKEN");
	        ((BindingProvider) salesforceClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
			//ss.addPort(portName, loginResult.getSessionId(), loginResult.getMetadataServerUrl())
			
	        //Create a new session header object and set the session id to that returned by the login
	        sh = new SessionHeader();
	        sh.setSessionId(loginResult.getSessionId());
	        
	        
	        }	
			
		} catch (InvalidIdFault_Exception e) {
			logger.debug(e.toString());
		} catch (LoginFault_Exception e) {
			logger.debug(e.toString());
		} catch (UnexpectedErrorFault_Exception e) {
			logger.debug(e.toString());
		} catch (MalformedURLException e) {
			logger.debug(e.toString());
			e.printStackTrace();
		}
	}

 

 

I get the   UnexpectedErrorFault_Exception INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

 

 

dkadordkador

You've logged in, created the SessionHeader, set the sessionId to the SessionHeader, but you never set the SessionHeader back to the SforceService.  Do that.

dolu23dolu23

Ok, but can you explain how to set the SessionHeader back to the sf service ?

gbuttgbutt

This question is answered in the CXF FAQ.

 

Another method is to use the -exsh true argument when running wsdl2java. This flag will add all binding inputs to your port stub. For example, instead of calling portStub.query(soql), you would have a method such as portStub.query(sessionHeader, soql)