on 07-07-2014 12:25 PM
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...
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
HI Yugandhar,
Can you please try pushing the credentials in SOAP UI,
we can see Session ID and TargetURL if the credentials and the URL was correct.
pls enable proxy while triggering the message from SOAP UI.
Also provide Host and Server details while enabling the proxy.
pls let me know in case of any issues.
Thanks,
Prasad Venkata K.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please provide me any update regarding the above issue facing
Thankyou
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Yugandhar,
1) Did you maintain proper Salesforce user credentials in Java lookup class !!
2) Have you maintained the SOAP look-up channel adapter module parameters
3) Try to test your Operation Mapping with Trace level all, Check the log.
4) Using XPI inspector run the Interface and check detailed audit log of SOAP lookup channel.
Regards
RK N
Hi
What is the error that you are getting?
Regards
Osman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ygandhar,
You need to pass the user id and password details in the method code of Java mapping.
getSessionIdFromSFDC("SFDC USER NAME ", "SFDC PASSWORD");
user: user created by SFDC team
pwd: password # token generated by SFDC Team
Please find the communication channel to retrieve the sessionID as below
Regards
Hanumantha Rao
Hi Yugandhar,
Please check the configuration parameters of the channel "SOAP_Reciver_SalesForce"
1) Target URL as ex: " https://login.salesforce.com:443/services/Soap/c/28.0/0DF80000000xxx"
2) Proxy details : hosname woth port if you have any secured proxy...
3) SOAP action: login
Regards
Hanumantha Rao
Hi Rao,
Thanks for your reply's , i had done as you mention . But no use , i'm not getting the session ID .Please find the below code that i got .
<?xml version="1.0" encoding="UTF-8" ?>
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.