cancel
Showing results for 
Search instead for 
Did you mean: 

Interface Sales Force - JavaMapping - unable to create a socket - RFC -> SOAP

RJSA
Active Participant
0 Kudos

Hi experts,

We have a specific scenario in our integration project were we need to consume a Salesforce.com Webservice. This webservice requires a TAG into the SOAP Envelope Header - sessionId.

In order to solve this problem, we developed two RFCs. The first one gets the sessionId and passes it as parameter to the second one.

For this second message, we performed a Java Mapping as below:

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Map;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

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

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

public class EnvioNFe implements StreamTransformation {

    public static void main(String[] args) {

            

    }

   

    public void setParameter(Map param) {

    }

   

    public void execute(InputStream input, OutputStream output) throws StreamTransformationException {

    String RESULT = new String();   

    

    try {

   

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    DocumentBuilder db = dbf.newDocumentBuilder();

    Document doc = db.parse(input);

   

    // HEADER and SESSIONID

    NodeList HeadElmntLst = doc.getElementsByTagName("I_SESSIONID");

    Element HeadNmElmnt = (Element) HeadElmntLst.item(0);

    NodeList HeadNm = HeadNmElmnt.getChildNodes();   

   

    RESULT = HeadNm.item(0).getNodeValue();

     

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

                           + "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\""

                           + " xmlns:sfw=\"http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda\"" + ">"    

                           + "<soapenv:Header>"

                           + "<sfw:SessionHeader>"

                           + "<sfw:sessionId>"

                           + RESULT

                           + "</sfw:sessionId>"

                           + "</sfw:SessionHeader>"

                           + "</soapenv:Header>"

                           + "<soapenv:Body>"

                           + "<sfw:NFE_CRM>"

                           + "<sfw:data>";

   

    NodeList nodeLst = doc.getElementsByTagName("I_CAB");       

   

    for (int s = 0; s < nodeLst.getLength(); s++) {

        Node fstNode = nodeLst.item(s);

     

        if (fstNode.getNodeType() == Node.ELEMENT_NODE) {

   

          // AUBEL   

          Element AubelElmnt = (Element) fstNode;

          NodeList AubelElmntLst = AubelElmnt.getElementsByTagName("AUBEL");

          Element AubelNmElmnt = (Element) AubelElmntLst.item(0);

          NodeList AubelNm = AubelNmElmnt.getChildNodes();            

         

          RESULT = AubelNm.item(0).getNodeValue();

     

          document_exit = document_exit + "<sfw:AUBEL>" + RESULT + "</sfw:AUBEL>";

       

          // NFENUM

          Element NfeElmnt = (Element) fstNode;

          NodeList NfeNmElmntLst = NfeElmnt.getElementsByTagName("NFENUM");

          Element NfeNmElmnt = (Element) NfeNmElmntLst.item(0);

          NodeList NfeNm = NfeNmElmnt.getChildNodes();

       

          RESULT = NfeNm.item(0).getNodeValue();

          document_exit = document_exit + "<sfw:NFENUM>" + RESULT + "</sfw:NFENUM>";

       

        }

    }   

  

    document_exit = document_exit + "</sfw:data>"

                                  + "</sfw:NFE_CRM>"

                                  + "</soapenv:Body>"

                                  + "</soapenv:Envelope>";

   

    output.write(document_exit.getBytes());

    } catch (Exception e) {

            }       

    }

}

Besides that we checked option "Do not use SOAP Envelope" and added "localejbs/AF_Modules/MessageTransformBean" and Key as "Transform.ContentType" with value "text/xml" at SOAP Receiver Adapter.

The result, when testing at eclipse and/or at TEST functionality in the Interface Mapping is OK. The following XML is generated:

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

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sfw="http://soap.sforce.com/schemas/class/SfWsNotaFiscalVenda">

<soapenv:Header>

     <sfw:SessionHeader>

          <sfw:sessionId>XXXXXXXX</sfw:sessionId>

     </sfw:SessionHeader>

</soapenv:Header>

<soapenv:Body>

     <sfw:NFE_CRM>

          <sfw:data>

               <sfw:AUBEL>123</sfw:AUBEL>

               <sfw:NFENUM>999</sfw:NFENUM>

          </sfw:data>

     </sfw:NFE_CRM>

</soapenv:Body>

</soapenv:Envelope>

We can successfully test in using SOAPUi. But when we test it using the RFC from ECC, we get the following error at adapter/SXMB_MONI;


com.sap.aii.af.ra.ms.api.DeliveryException: java.io.IOException: unable to create a socket

We are aware that this might be a network issue but not so sure which steps to take to test SAPCRIPTO and network.

Thanks in advance!

Accepted Solutions (0)

Answers (3)

Answers (3)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Rafael,

                Please check this blog on SFDC

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

Regards

Anupam

nabendu_sen
Active Contributor
0 Kudos

Hi Rafael,

Not sure, but why you are performing RFC Lookup to fetch Session ID?

Session ID needs to be fetched from Salesforce site, which is a Web Service, so it should be SOAP Lookup.

SAP ECC (Sender RFC) -> SAP PI (SOAP Lookup to Sales Force and Populate Session ID in your Target Message) -> (Receiver SOAP) Sales Force.

Let me know if I am missing anything.

Former Member
0 Kudos

This error can come due to various reason when connecting to Salesforce.

1) Expired session ID

2) URL where you are sending data is expired.

3)  Format of data is wrong or even wrong data, if it is unable to fullfill any condition programmed in salesforce like validation or relation.

Are you using exactly same data as in SOAP UI ? I think xml is case sensitive also for Salesforce..

can you copy the data you are sending through SOAP UI ? Also make sure that you are able to ping Salesforce from  PI ? There are list of IP addresses for which you need to open your firewalls.. You can get it from salesforce documentation.

Regards

Imder