Skip to Content
0

How to add sessionId and serverURL in SOAP header in webdynpro java code

Nov 09, 2017 at 12:51 PM

65

avatar image
Former Member

Hi All,

I have a requirement where I need to add sessionId and serverUrl in SOAP header in webdynpro java code.

1. I have created provider system and I am able to ping system successfully.
2. I have created WSDL model and have done service configuration manually.

cusersa673366documentsclmwebuisoapui.png

Below is my code:

Request_Query requestQuery = new Request_Query(ipassModel);
requestQuery.wdSetInvocationModifier(new IWDWSInvocationModifier() {
SOAPHeaderInterface headerInterface = null;
public void doModifyInvocation(Object port) {

// Creating the SOAP Header node.
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
wdComponentAPI.getMessageManager().reportSuccess("docBuilder: "+docBuilder.toString());
}
catch (ParserConfigurationException e) {
wdComponentAPI.getMessageManager().reportException("Error in Executing webservice. Error Description is: " + e.getLocalizedMessage());
return;
}

Document soapDoc = docBuilder.newDocument();
Element AuthHeader = soapDoc.createElementNS("EndPoint From WSDL URL","

"urn:AuthHeader"); //Set the URI as mentioned in WSDL
Element ValSessionID = soapDoc.createElement("urn:sessionId");
ValSessionID.setTextContent(wdContext.currentResultElement().getSessionId());//Set the sessionID
Element ValServerURL = soapDoc.createElement("urn:serverUrl");
ValServerURL.setTextContent(wdContext.currentResultElement().getServerUrl());//Set the ServerUrl

AuthHeader.appendChild(ValSessionID);
AuthHeader.appendChild(ValServerURL);

headerInterface = SOAPHeaderIFactory.getInterface(port);
try {
headerInterface.setOutputHeader(null, AuthHeader);
}
catch (MarshalException e) {
// TODO: handle exception
wdComponentAPI.getMessageManager().reportException("Error in Executing webservice. Error Description is: " + e.getLocalizedMessage());
e.printStackTrace();

}

}
public void doModifyAfterInvocation(){}
});

Query query = new Query(ipassModel);
query.setQueryString("SELECT Id from Account");
requestQuery.setQuery(query);

wdContext.nodeRequest_Query().bind(requestQuery);
wdContext.nodeRequest_Query().currentRequest_QueryElement().modelObject().execute();

I am getting below error:

Exception on execution of web service with operation 'query' in interface '{urn:enterprise.soap.sforce.com}Soap'

When I checked in log and traces I could not found anything related to the above error.

Please help where I am wrong whether in code or in configuration?

Thanks in Advance!

10 |10000 characters needed characters left characters exceeded
Former Member

I am following https://archive.sap.com/discussions/thread/3638194 and I am using external WSDL.

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

avatar image
Former Member Nov 15, 2017 at 06:06 AM
0

Hi All, Please help as I am not able to proceed. Any help/suggestion would be appreciated.

Thanks.

Share
10 |10000 characters needed characters left characters exceeded