cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting from SAP PI To Salesforce

Former Member
0 Kudos

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 = "<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);
//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...

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

anupam_ghosh2
Active Contributor
0 Kudos

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

Regards

Anupam

Former Member
0 Kudos

Hi Anupam,

Thanks for your quick reply when I tried the way you said here is the error which I got...

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

   <soapenv:Body>

      <soapenv:Fault>

         <faultcode>soapenv:VersionMismatch</faultcode>

         <faultstring>The SOAP request must use SOAP 1.1, did not recieve a SOAP 1.1 Envelope as the document root</faultstring>

      </soapenv:Fault>

   </soapenv:Body>

</soapenv:Envelope>

I'm trying to correct this issue...please let me know if you have any inputs.

Thanks,

Srujan

anupam_ghosh2
Active Contributor
0 Kudos

Hi Srujan,

                 Glad to know that you now know the reason of error.

SOAP faults of this kind arises because some invalid namespace information is present in SOAP header. Now you need to carefully make changes in default namespace in SOAP header and keep checking using SOAP-UI which request works. In my blog read carefully problem number 2. The blog looks simple and without codes, but believe me to catch a small namespace error I spend 18 days. Then came up with the blog so that no one suffers as I did.   

Regards

Anupam

Former Member
0 Kudos

Hi Anupam,

Thanks for the blog...I have looked into and here is what I have observed like you said...when I pasted my request message which I sent it from Java map to get the sessionId it came back successfully both in PI as well as SOAP UI without any issues:

<?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, for the response I still get the same error: Internal 500 Server error.

Is it because, the wrapping of the return message is not happening that it could be failing? Because, when I tested the message in Operation mapping it doesn't retreive the timestamp but at the sametime it is not wrapped with the envelope. Is there a possiblity that the java code is not wrapping the payload which  I'm asking for in an envelope and that's the  reason for failure?

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

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

   <ns0:result>

      <ns0:timestamp/>

   </ns0:result>

</ns0:getServerTimestampResponse>

This is what I get and without timestamp as well no wrapping of the envelope...like this as below this is how it should look?

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

   <soapenv:Body>

      <getServerTimestampResponse>

         <result>

            <timestamp>2012-11-16T06:46:13.915Z</timestamp>

         </result>

      </getServerTimestampResponse>

   </soapenv:Body>

</soapenv:Envelope>

Can you please guide me where in the code that I have to modify to get the desired output if you know? Also, if possible can you please paste me the code that is working for you as you would have had that? It would be huge help for me as I have to deliver this interface at the earliest.

Thanks for your help,

Srujan

anupam_ghosh2
Active Contributor
0 Kudos

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