Hi Experts ,
In our present scenario i'm unable to call the SOAP Channel from the Java code to get the session ID from SalesForce, I had used the same Code as of in the link SFDC Integration using PI 7.1 - How to add SOAP Envelope in Java Mapping - Process Integration - SCN Wiki
please find the below Java Code and let me know if any modifications required for the Code
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformationConstants;
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.*;
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("SFDC USER NAME ", "SFDC PASSWORD"); //Supply the SFDC developer account username 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.replace("<ns0:sObjects>", "<ns0:sObjects xsi:type=\"Account\" xmlns=\'urn:enterprise.soap.sforce.com>");
/* 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("BC_SalesForce","SOAP_Reciver_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);
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("/D:/input.xml");
FileOutputStream out = new FileOutputStream ("D:/Output.xml");
obj.execute(in,out);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Thanks a lot for your help .
Regards,
yugandhar