Skip to Content
avatar image
Former Member

Connecting from SAP PI To Salesforce

Hi Folks,

I'm doing a scenario based the document from Prasanna Vittal "Salesforce.com Integration Using SAP PI: A Case Study" I followed the document end to end..and tried to implement the same scenario in PI 7.3 also did a service pack upgrade for the SOAP lookup. Once the service pack upgrade was done..I'm getting the sessionId when I triggered the message from RWB. But, In the response structure I'm getting a internal server 500 error.

SOAP: response message contains an error XIAdapter/HTTP/ADAPTER.HTTP_EXCEPTION - HTTP 500 Internal Server Error

As suggested by some of the folks I have made sure my receiving message matches with SOAPUI message:

Here is the request message from SOAP UI:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">

   <soapenv:Header>

      <urn:SessionHeader>

         <urn:sessionId>00DL00000000soj!ARoAQKQaBOVhchb_RT4uex4jm8c39PkURvyz93vFY2xHfLj1zU0b.KGNeLAUtPNDlX7ooNl2dZpHo2IkHLfDYpcg1CgI6RnO</urn:sessionId>

    

</urn:SessionHeader>

   </soapenv:Header>

   <soapenv:Body>

      <urn:getServerTimestamp/>

   </soapenv:Body>

</soapenv:Envelope>

and  Request message from PI:

<?xml version="1.0" encoding="UTF-8" ?> 

- < soapenv:Envelope xmlns:soapenv =" http://schemas.xmlsoap.org/soap/envelope/ " xmlns:urn =" urn:enterprise.soap.sforce.com " >

- < soapenv:Header >

- < urn:SessionHeader >

< urn:sessionId > 00DL00000000soj!ARoAQKQaBOVhchb_RT4uex4jm8c39PkURvyz93vFY2xHfLj1zU0b.KGNeLAUtPNDlX7ooNl2dZpHo2IkHLfDYpcg1CgI6RnO </ urn:sessionId >

</urn:SessionHeader>

</soapenv:Header>

- < soapenv:Body >

< ns0:getServerTimestamp xmlns:ns0 =" urn:enterprise.soap.sforce.com " />

</soapenv:Body>

</soapenv:Envelope>

But unfortunately, I'm stuck with the response message which I'm having  a hard time.

Here is the code which I have used in my mapping:

import com.sap.aii.mapping.api.*;

import java.io.*;
import java.util.Map;
import com.sap.aii.mapping.lookup.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;
import org.xml.sax.SAXException;

public class SoapEnvelopeForSFDC implements StreamTransformation
{

String sessionId ="";
String prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/" +
"\" xmlns:urn=\"urn:enterprise.soap.sforce.com\">"+
"<soapenv:Header> "+
"<urn:SessionHeader>"+
"<urn:sessionId> ";
String suffix = "</urn:sessionId> </urn:SessionHeader> </soapenv:Header> <soapenv:Body>";
String envelope = "</soapenv:Body> </soapenv:Envelope>";

private Map map;
/* method setParamters is required, but we do not anything with it*/
public void setParameter(Map param)
{
map = param;
}
public void execute(InputStream in, OutputStream out)
{

  AbstractTrace atTrace1 = null;
     atTrace1 = (AbstractTrace) map.get(StreamTransformationConstants.MAPPING_TRACE);

try
{
getSessionIdFromSFDC("actualuserID","actualPassword"); //Supply the SFDC developer account user name and password.

copyPayload(in,out);
}
catch (Exception t)
{
t.printStackTrace();
}
}
/* method is to build the Soap envelope for the input message payload */
private void copyPayload(InputStream in, OutputStream out) throws StreamTransformationException
{
String c = "";
String Newpayload = "";
try
{
InputStreamReader inr = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(inr);
//The following is to remove the <?xml version=\"1.0\" encoding=\"UTF-8\"?> from the input message payload
String temp = "";
while((temp = reader.readLine()) != null)
{
c = c + temp;
}
int len = c.indexOf(">");
Newpayload = c.substring(len+1);
// End of remove xml version tag
out.write(prefix.getBytes());
out.write(sessionId.getBytes());
out.write(suffix.getBytes());
out.write(Newpayload.getBytes());
out.write(envelope.getBytes());
}
 


catch (IOException e)
{
throw new StreamTransformationException(e.getMessage());
}
}

/* 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)
{
try
{
Channel channel = LookupService.getChannel("SalesForce","SOAP_Receiver_SalesForce");
SystemAccessor accessor = null;
accessor = LookupService.getSystemAccessor(channel);
String loginxml = " enterprise.soap.sforce.com\"> "
+ 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);
//Document doc = builder.parse(in);
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();}
}
/*public static void main (String[] args) throws Exception
{
try
{
SoapEnvelopeForSFDC obj = new SoapEnvelopeForSFDC();
FileInputStream in = new FileInputStream("c:/input.xml");
FileOutputStream out = new FileOutputStream ("c:/Output.xml");
obj.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}*/
}

Also, in my message mapping as suggested did the UDF as suggested in the wiki:

try
{

DynamicConfiguration conf = (DynamicConfiguration)
container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key2 = DynamicConfigurationKey.create("http://sap/xi/XI/System/SOAP","TServerLocation");
conf.put(key2, "https://cs8-api.salesforce.com/services/Soap/c/25.0/00DL00000000soj/0DFE0000000L6xk");

return" ";

}
catch(Exception e)
{
// for simple UDF return
String exception = e.toString();
return exception;
}

Please advise to see where I'm going wrong.

Thanks for your help...

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Nov 15, 2012 at 04:01 PM

    Hi Shrujan,

                       Copy from PI the source payload (the XML request) and paste in SOAP UI then test.

    Check if you are getting error here or not. Then you need to modify the message accordingly.

    Here I have discussed some SOAP faults in SFDC

    http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/06/02/troubleshooting-sap-pi-and-salesforcecom-integration-scenario

    Regards

    Anupam

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Shrujan,

                      I got busy with other assignments. I have to replicate the scenario built by Prasanna, let me check how this is giving errors in your case. Hopefully I can come back to you on Monday. I am not sure why you are receiving SOAP fault message.

      Regards

      Anupam

  • avatar image
    Former Member
    Nov 21, 2012 at 10:21 PM

    Hi Srujan,

    You can see what is the actual payload that is going out from SAP PI in SXMB_MONI.

    Other way is you can go to Operation Mapping and then execute both the Graphical mapping and java mapping in one step and see the output there. you will be able to see the soap header and soap body.

    Take the Soap payload and execute that in SOAP UI or XML Spy and you would be able to see the error response. Other option i sto implement the SOAP Fault to see the actual fault message in SAP PI.

    Regards

    Ravijeet

    Message was edited by: RAVIJEET DAS

    Add comment
    10|10000 characters needed characters exceeded