Skip to Content
0
Former Member
Nov 15, 2012 at 12:59 PM

Connecting from SAP PI To Salesforce

211 Views

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...