cancel
Showing results for 
Search instead for 
Did you mean: 

How to get SESSION ID

Former Member
0 Kudos

Hi Experts,

Could please me help me on this scenario as below.

ECC-- SAP PI -- 3rd Party

Sender is a Proxy, Receiver is a SOAP

1. Login into 3rd Party and need to get the SESSION ID with valid user name and password

2. Need to pass the SESSION ID as SOAP Header with actual payload.

I came to know that this can be done at mapping level using UDF to get the Session ID.

I have gone through the Bhavesh Kantilal Blog.


Could you please provide help on this.

Thank you in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

bhavesh_kantilal
Active Contributor
0 Kudos
Former Member
0 Kudos

Thanks for the reply Bhavesh.

As this can be done without JAVA mapping also, i am looking for the UDF for the same

bhavesh_kantilal
Active Contributor
0 Kudos
  • UDF to get sessionID, I assume this is for SalesForce. Takes username and password as inputs and returns sessionID.
  • Has the Business Service and Channel Name Hardcoded. This can be made dynamic as required,
  • This code is taken from the exact links i had shared before. Even though it is java mapping, the logic remains the same.

/* method is to login to SFDC with the username and password to get the sessionId from the response*/

private void getSessionIdFromSFDC(String username, String password)

{

String sessionId ="";

try

{

Channel channel = LookupService.getChannel("BC_SFDC","CC_Login");

SystemAccessor accessor = null;

accessor = LookupService.getSystemAccessor(channel);

String loginxml = "<login xmlns=\"urn:enterprise.soap.sforce.com\"> <username>"

+ username

+ "</username> <password>"

+ password

+ "</password> </login>";

InputStream inputStream = new ByteArrayInputStream(loginxml.getBytes());

Payload payload = LookupService.getXmlPayload(inputStream);

Payload SOAPOutPayload = null;

SOAPOutPayload = accessor.call(payload);

InputStream inp = SOAPOutPayload.getContent();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document document = builder.parse(inp);

NodeList sessionId1 = document.getElementsByTagName("sessionId");

Node node = sessionId1.item(0);

if (node != null)

{

node = node.getFirstChild();

if (node != null)

{

sessionId = node.getNodeValue();

}

}

}

catch(Exception e)

{e.printStackTrace();

}

return sessionId;

}

  • To create the SOAP header manually, you would either need to use a SOAP Axis, or Java Mapping or XSLT Mapping. A SCN Search for this will lead to multiple responses that should all help!

Regards,

Bhavesh

Former Member
0 Kudos

Hi Bhavesh,

thanks for the reply, let me implement this and will let you know