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
StreepeyeStreepeye 

SessionId in Header, how to set value in java?

 

I want to set the sessionId value in the header of the Upsert operation

with the value i just got from the Login operation.

 

I am new in java, i don't know how to get the value to set it again in the header  

 

 

 

this is the my generated java code:

 

/**
 * SalesForceAgent_EnterpriceService.java
 *
 * This file was generated by LANSA Integrator SOAP Agent Wizard
 */
package com.marktselect.service.soap ;

public class SalesForceAgent_EnterpriceService implements com.lansa.jsm.service.SOAPAgentHandler
{

    /*
        Operation - login
    */

    public final void setOperation_LOGIN ()
    {
    }

    /*
        Operation Request - login
    */

    public final void prepareRequest_LOGIN ( com.lansa.jsm.service.SOAPAgentRequest request ) throws Exception
    {
        request.prepareParameter ( "USERNAME", java.lang.String.class, false, false ) ;
        request.prepareParameter ( "PASSWORD", java.lang.String.class, false, false ) ;
    }

    /*
        Operation Parameter - login
    */

    public final void setParameter_LOGIN_USERNAME ( com.lansa.jsm.service.SOAPAgentParameter parameter, com.lansa.jsm.service.SOAPAgentBind bind ) throws Exception
    {
        parameter.setEntity ( bind.getFieldValue ( "MSLOGUSR" ), null, null ) ;
    }

    /*
        Operation Parameter - login
    */

    public final void setParameter_LOGIN_PASSWORD ( com.lansa.jsm.service.SOAPAgentParameter parameter, com.lansa.jsm.service.SOAPAgentBind bind ) throws Exception
    {
        parameter.setEntity ( bind.getFieldValue ( "MSLOGPWD" ), null, null ) ;
    }

    /*
        Operation Response - login
    */

    public final void prepareResponse_LOGIN ( com.lansa.jsm.service.SOAPAgentResponse response ) throws Exception
    {
        response.prepareFragment ( new String[] { "LOGIN" }, com.sforce.soap.enterprise.LoginResult.class, false, true, null ) ;
        response.prepareFragment ( new String[] { "LOGIN", "USERINFO" }, com.sforce.soap.enterprise.GetUserInfoResult.class, false, true, "getUserInfo" ) ;
    }

    /*
        Operation Fragment - login
    */

    public final void getFragment_LOGIN_LOGIN ( com.lansa.jsm.service.SOAPAgentResponseFragment fragment, com.lansa.jsm.service.SOAPAgentBind bind ) throws Exception
    {
        bind.setFieldValue ( "URLSERVER", fragment.getEntity ( "metadataServerUrl", null ) ) ;
        bind.setFieldValue ( "PWEXPIRED", fragment.getEntity ( "passwordExpired", null ) ) ;
        bind.setFieldValue ( "SANDBOX", fragment.getEntity ( "sandbox", null ) ) ;
        bind.setFieldValue ( "SERVERURL", fragment.getEntity ( "serverUrl", null ) ) ;
        bind.setFieldValue ( "SESSIONID", fragment.getEntity ( "sessionId", null ) ) ;
        bind.setFieldValue ( "USERID", fragment.getEntity ( "userId", null ) ) ;
    }

    /*
        Operation Fragment - login
    */

    public final void getFragment_LOGIN_USERINFO ( com.lansa.jsm.service.SOAPAgentResponseFragment fragment, com.lansa.jsm.service.SOAPAgentBind bind ) throws Exception
    {
        bind.setFieldValue ( "ACCMODE", fragment.getEntity ( "accessibilityMode", null ) ) ;
        bind.setFieldValue ( "CURSYMBOL", fragment.getEntity ( "currencySymbol", null ) ) ;
        bind.setFieldValue ( "ORGISOCOD", fragment.getEntity ( "orgDefaultCurrencyIsoCode", null ) ) ;
        bind.setFieldValue ( "PERSACC", fragment.getEntity ( "orgHasPersonAccounts", null ) ) ;
        bind.setFieldValue ( "ORGID", fragment.getEntity ( "organizationId", null ) ) ;
        bind.setFieldValue ( "ORGMLTCUR", fragment.getEntity ( "organizationMultiCurrency", null ) ) ;
        bind.setFieldValue ( "MSBEDRNM", fragment.getEntity ( "organizationName", null ) ) ;
        bind.setFieldValue ( "MSPROFILE", fragment.getEntity ( "profileId", null ) ) ;
        bind.setFieldValue ( "ROLEID", fragment.getEntity ( "roleId", null ) ) ;
        bind.setFieldValue ( "DEFCURCOD", fragment.getEntity ( "userDefaultCurrencyIsoCode", null ) ) ;
        bind.setFieldValue ( "MSEMAIL", fragment.getEntity ( "userEmail", null ) ) ;
        bind.setFieldValue ( "MSFULLNM", fragment.getEntity ( "userFullName", null ) ) ;
        bind.setFieldValue ( "MSUSRID", fragment.getEntity ( "userId", null ) ) ;
        bind.setFieldValue ( "USERLANG", fragment.getEntity ( "userLanguage", null ) ) ;
        bind.setFieldValue ( "USERLOCAL", fragment.getEntity ( "userLocale", null ) ) ;
        bind.setFieldValue ( "USRNAME", fragment.getEntity ( "userName", null ) ) ;
        bind.setFieldValue ( "TIMEZONE", fragment.getEntity ( "userTimeZone", null ) ) ;
        bind.setFieldValue ( "MSUSRTYPE", fragment.getEntity ( "userType", null ) ) ;
        bind.setFieldValue ( "UISKIN", fragment.getEntity ( "userUiSkin", null ) ) ;
    }

    /*
        Operation Return - login
    */

    public final void getReturnParameter_LOGIN ( com.lansa.jsm.service.SOAPAgentResponse response, com.lansa.jsm.service.SOAPAgentBind bind ) throws Exception
    {
    }

    /*
        Operation Call - login
    */

    public final com.lansa.jsm.service.SOAPAgentResponse callOperation_LOGIN ( com.lansa.jsm.service.SOAPAgentRequest request, String user, String password, String url ) throws Exception
    {
        com.sforce.soap.enterprise.SforceServiceLocator locator = new com.sforce.soap.enterprise.SforceServiceLocator () ;

        String endPoint = locator.getSoapAddress () ;

        if ( url != null )
        {
            endPoint = url ;
        }

        com.sforce.soap.enterprise.SoapBindingStub stub = (com.sforce.soap.enterprise.SoapBindingStub)locator.getSoap ( new java.net.URL ( endPoint ) ) ;

        if ( user != null && password != null )
        {
            stub.setUsername ( user ) ;

            stub.setPassword ( password ) ;
        }

/*

    Add SOAP header

*/


org.apache.axis.message.SOAPHeaderElement elementHead = new org.apache.axis.message.SOAPHeaderElement ("", "SessionHeader");
 

javax.xml.soap.SOAPElement elementsessionId = elementHead.addChildElement ( "sessionId" ) ;

elementsessionId.addTextNode ( "HOW DO I GET THE SESSIONID IN HERE?" );

stub.setHeader ( elementHead ) ;

 

/*

   End SOAP header
*/

        request.traceStub ( stub ) ;

        return new com.lansa.jsm.service.SOAPAgentResponse ( stub.login( request.getParameterValueString ( "USERNAME" ), request.getParameterValueString ( "PASSWORD" ) ) ) ;
    }

    /*
        Operation - upsert
    */

    public final void setOperation_UPSERT ()
    {
    }

    /*
        Operation Request - upsert
    */

    public final void prepareRequest_UPSERT ( com.lansa.jsm.service.SOAPAgentRequest request ) throws Exception
    {
        request.prepareParameter ( "EXTERNALIDFIELDNAME", java.lang.String.class, false, false ) ;
        request.prepareParameter ( "SOBJECTS", com.sforce.soap.enterprise.sobject.SObject.class, true, true ) ;
        request.prepareFragment ( "SOBJECTS", new String[] { "UPSERTOBJ" }, com.sforce.soap.enterprise.sobject.SObject.class, true, true, null ) ;
        request.prepareList ( "SOBJECTS", new String[] { "UPSERTOBJ", "OBJNAME" }, java.lang.String.class, true, false, "setFieldsToNull" ) ;
    }

    /*
        Operation Parameter - upsert
    */

    public final void setParameter_UPSERT_EXTERNALIDFIELDNAME ( com.lansa.jsm.service.SOAPAgentParameter parameter,

 

    etc... 

 

 

 

 

this is the my generated message i sent:

 

 

<?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Header>
- <SessionHeader soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0">
  <sessionId>HOW DO I GET THE SESSIONID IN HERE?</sessionId>
  </SessionHeader>
  </soapenv:Header>
- <soapenv:Body>
- <upsert xmlns="urn:enterprise.soap.sforce.com">
  <externalIDFieldName>mskey__c</externalIDFieldName>
- <sObjects>
  <ns1:fieldsToNull xmlns:ns1="urn:sobject.enterprise.soap.sforce.com">34</ns1:fieldsToNull>
  <ns2:Id xmlns:ns2="urn:sobject.enterprise.soap.sforce.com">11111</ns2:Id>
  </sObjects>
  </upsert>
  </soapenv:Body>
  </soapenv:Envelope>

Best Answer chosen by Admin (Salesforce Developers) 
StreepieStreepie

Lansa users says: The SalesForce.com Web Service API (WSDL) uses non-industry standard methods for defining the parameters for their web service operations

they mean the headers....

 

 

But as i know .. with almost  every language you can define and set the headerfields you want.... but NOT with LANSA Integrator ......

 

So this is really MY problem with which you can not help me.... 

 

Our  temp. solution is to GET upsert data from the external webservice instead of POSTING upsertdata to salesforce, this way i don't have to set any headerfield whatsoever...

 

Until the world changes...best regards!

All Answers

werewolfwerewolf

It says it fairly in black and white in the Java sample included in the login call docs:

 

  binding._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());

// Create a new session header object
// add the session ID returned from the login
_SessionHeader sh = new _SessionHeader();
sh.setSessionId(loginResult.getSessionId());
// Set the session header for subsequent call authentication
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),
"SessionHeader", sh);

 

StreepieStreepie

when i use that code i get an error saying:

 

cannot resolve symbol : class _SessionHeader

 

 

!?

werewolfwerewolf
When you generated the classes from the WSDL, did you get anything that looks like that at least?  You should have some kind of class that looks like SessionHeader into which you put the sessionId.
StreepieStreepie

 

I can not see that information... i am using the Integrator from Lansa ....

 

I think you don't know that program language...

 

I am busy contacting them so ... let this question rest.. until later ....sorry

SuperfellSuperfell
the SessionId is returned from the Login call 9 (as part of the LoginResult structure), you'll need to ask the Lansa folks how you access that.
StreepieStreepie

Lansa users says: The SalesForce.com Web Service API (WSDL) uses non-industry standard methods for defining the parameters for their web service operations

they mean the headers....

 

 

But as i know .. with almost  every language you can define and set the headerfields you want.... but NOT with LANSA Integrator ......

 

So this is really MY problem with which you can not help me.... 

 

Our  temp. solution is to GET upsert data from the external webservice instead of POSTING upsertdata to salesforce, this way i don't have to set any headerfield whatsoever...

 

Until the world changes...best regards!

This was selected as the best answer
angel fekhangel fekh
I have the same error , but I have not the class " SoapBindingStub " because I use the salesforce version of " Partner" . here is my code

SforceService service = new SforceService();
        LoginResult lr = service.getSoap().login(tLogin(),Password() + Token());
        String sessionId = lr.getSessionId();
        WS_Service ws_Service = new WS_Service();
        WS_ManagementPortType ws_Management = ws_Service.getWS005OpportunityManagement();
        com.sforce.soap.schemas._.SessionHeader sessionHeader = new com.sforce.soap.schemas._..SessionHeader();
        sessionHeader.setSessionId(sessionId);
        result =  ws_Management.manageClosure(dataObject, sessionHeader, null, null);

any Solution ?