on 10-03-2005 7:44 AM
Hi all..
Iam using web services model in my web dynpro application. How will i send some paramters/info in SOAP header??
Hi Sujesh,
Please check the WebService tutorials and examples.
Regards, Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sujesh,
In your last thread of SOAP Headers I tried to paste the link containing some information on it's usage, but today when i navigated to the link it took me to different location , so the below message
The SOAP Headers Protocol
Definition
In some scenarios, the client may need to add SOAP headers to the request. This can be done using the SOAP headers protocol, which can be accessed by SOAP Web services. This protocol is not available to Web services with HTTP GET or POST bindings.
The SOAP headers protocol is a client runtime plugin located in com.sap.engine.services.webservices.jaxrpc.wsdl2java.features.builtin.SoapHeadersProtocol.
Use
To get an instance of the protocol, use:
SoapHeadersProtocol headers = (SoapHeadersProtocol) ((BaseGeneratedStub) client)._getGlobalProtocols().getProtocol("SoapHeadersProtocol");
Structure
The Service Endpoint Interface (SEI) is typecasted to BaseGeneratedStub, which exposes the internal plugin methods of the client:
com.sap.engine.services.webservices.jaxrpc.wsdl2java.BaseGeneratedStub
The basic methods of the SOAP headers protocol are as follows:
· headers.setOutputHeader(new Name("urn:myuri.com","myHeader"),value) With this method you can pass, as a value, any schema-derived element type that is generated by the proxy generator for your client or generic DOM element.
Remember that all header elements must be namespace-qualified and, if you use a schema-derived value, it must be declared by the schema element as follows:
<xs:element name="myHeader" namespace="urn:myuri.com" type=tns:myType/>
· The methods for getting response headers are as follows:
¡ headers.getInputHeader(headerName:QName):Element Returns the DOM element with the header content response
¡ headers.getInputHeader(headerName:QName,headerClass:Class):Object Deserializes the schema-declared header in the response class
and once again the link http://help.sap.com/saphelp_nw04/helpdata/en/45/f957507cb343f78e818c50620ed5ca/frameset.htm
Good Luck,
Dharmi
Hello Sujesh,
Thank you for the points. I looked up what is client and how you can use it, please have a look at the link below:
The title of the link is "Implementing a Web Service Client Application"
http://help.sap.com/saphelp_nw04/helpdata/en/bf/bc593b989c4f7298cef1ff430dd60f/frameset.htm
"A client is J2EE application. It communicates with the Web service using a service endpoint interface, implemented by a generated stub. The client can directly access the protocols through methods of the generated stub class."
I hope the above is clear. If not do let me know.
Regards,
Dharmi
Hello Sujesh,
From what you specify I understand that you have a Web Dynpro Application (which is Web Service client), and you have imported the web Service model by inputting the url of WSDL. If this is not the case please don't read any further (Sorry not able to help you) but if that is the case there is a proxies folder and in that you would see couple of java files use the one which <b>ends</b> with WSImpl:
StockWSImpl ws = new StockWSImpl();
Remote remote = ws.getLogicalPort(StockWS2ViRpc.class);
StockWS2ViRpc stocksWS = (StockWS2ViRpc) remote;
BaseGeneratedStub stub = (BaseGeneratedStub) remote;
SoapHeadersProtocol headers = (SoapHeadersProtocol) stub._getGlobalProtocols().getProtocol("SoapHeadersProtocol");
Then,
headers.setOutputHeader(new Name("urn:myuri.com","myHeader"),value) With this method you can pass, as a value, any schema-derived element type that is generated by the proxy generator for your client or generic DOM element.
Hope the above works, I haven't tried it but I think that should do the trick.
If the above works, do let me know.
Good Luck,
Dharmi
Thanks Dharmi,
Yes you are correct.iam using web service model.
I can see some java files in proxies folder under src/packages. Is that what you are refering to?My service name is AccBalService and i can see 1 impl file named AccBalServiceImpl.java. I hope you are talking about this file.
Ok. I now need to send some extra info, for example user name or some thing like that while calling the web service as part of my soap header. In this case should i write what ever you have given above(similer code) in my view??? pls elaborate.. I think we are coming closer...
Pls help
Hi Sujesh,
Try with following code:
serviceImpl service = WebServiceModel.getServiceImpl();
yourServiceViDocument logicalPort = (yourServiceViDocument) service.getLogicalPort("Config1Port_Document" , yourServiceViDocument.class );
BaseGeneratedStub stubForLogicalPort = (BaseGeneratedStub) logicalPort ;
SecurityProtocol securityProtocol = (SecurityProtocol) stubForLogicalPort._getGlobalProtocols().getProtocol("SecurityProtocol");
securityProtocol.addHeader("Cookie","MYSAPSSO2="getSSOTicket()";");
private String getSSOTicket() {
IWDMessageManager msgMgr = wdThis.wdGetAPI().getComponent().getMessageManager();
try {
HttpServletRequest req = TaskBinder.getCurrentTask().getWebContextAdapter().getHttpServletRequest();
if (req != null)
return SSOSession.getSSOTicket(req);
else
return"";
} catch (Exception e) {
msgMgr.reportException(e.getLocalizedMessage(), true);
return "";
}
}
For this you need to add servlet.jar file in classpath.
Regards,
Bhavik
Thanks Bhavik for the help. Would like to get this clarified
-
yourServiceViDocument logicalPort = (yourServiceViDocument) service.getLogicalPort("Config1Port_Document" , yourServiceViDocument.class );
which is this equivalant class(yourServiceViDocument)?where will i get to see this??
Also iam not able to see SSOSession class in my environment. Pls advice
Hi Sujesh,
here,
yourServiceVIDocument is your model class name.
And im not sure about SSOSession class.
I found this code from forums. So, i guess you can try with it. But, after getting Request object you can fetch cookie of logon ticket using getcookies methos also.
So, if previous part is working fine then ignore to use SSOSession class.
Regards,
Bhavik
Thanks Bhavik,
what is "Config1Port_Document"????
i guess its logical port name...am i correct??
my model name is AcctBalService..but iam getting null pointer exception in this..
AcctBalService logicalPort = (AcctBalService) service.getLogicalPort("AcctBalServiceIFPort" , AcctBalService.class );
my NWDS version is 2.0.9
any help?
Hi Sujesh,
wait...
I will give you all the class details.
If you check your package for your model, you will find one proxies folder under that.
You need to use all those classes here.
// here, serviceimpl is your impl class found in that proxies folder.
serviceImpl service = WebServiceModel.getServiceImpl();
//yourServiceViDocument is the class with <servicename>ViDocument as given in that folder
yourServiceViDocument logicalPort = (yourServiceViDocument) service.getLogicalPort("Config1Port_Document" , yourServiceViDocument.class );
BaseGeneratedStub stubForLogicalPort = (BaseGeneratedStub) logicalPort ;
SecurityProtocol securityProtocol = (SecurityProtocol) stubForLogicalPort._getGlobalProtocols().getProtocol("SecurityProtocol");
securityProtocol.addHeader("Cookie","MYSAPSSO2="getSSOTicket()";");
I hope now you will clear about this.
Regards,
Bhavik
Hello Sujesh,
Sorry for the delayed reply, if you are sing the securtiy protocol then you can make use of the following statements:
AuthenticationContext = securityProtocol.getAuthenticationContext();
Using user name and password for authentication
These are set with the AuthenticationContext methods:
¡ public void setPassword(String password)
¡ public void setUsername(String password)
Setting HTTP headers
To set additional HTTP headers use the following method of the Client Security protocol:
¡ public void addHeader(String key, String value)
When using the client security protocol from an application or library running in the engine (i.e. from a Web Dynpro application), you need to set a classloader reference to the service tcsecwssec~service.
Hope the above is helpful an clear.
Regards,
Dharmi
Hi,
do you realy want to send a SSO Ticket string via the HTTPHeader or some name value pairs via the SOAPHeader? If its realy an SSO Ticket String you should in deed use the SecurityProtocol, if its some name value pairs in the SOAPHeader you need to build up an xml node like this:
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
yourNode = doc.createElementNS(yourNamespace,
yourParameterName);
Element valueNode = doc.createElement(yourValueNode);
valueNode.appendChild(doc.createTextNode(valueToAdd));
valueNode.appendChild(valueNode);
and add it to the SOAPHeaderProtocol
regards,
Martin
Thanks Martin...
Yes i need to send some thing through SOAP Header. Becos my web service is running in Apache server.So my web service will parse header and get some details
need to clarify some things
yourNode = doc.createElementNS(yourNamespace,yourParameterName);
whats yourNode,yourNamespace,yourParameterName,yourParameterName etc?? how should i declare them..Iam very new to this...pls help..Thanks in advance
well, its just one example of how you can build up an xml node programatically. You can use any xml builder you like. Here is a concrete example:
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
parameterNode = doc.createElementNS("http://www.test.com/myParam/",
"test:myParamName");
Element valueNode = doc.createElement("myParamValueNode");
valueNode.appendChild(doc.createTextNode("testValue"));
parameterNode.appendChild(valueNode);
"testValue" is the value to be transfered, "myParamName" is the Name of the Parameter
Thanks Bhavik,
Now it works with out any error. But still i am not able to see any thing in my header my code is this
AcctBalService service = AccBalService.getServiceImpl();
AcctBalServicePortType port = (AcctBalServicePortType)service.getLogicalPort("AcctBalServiceIFPort" , AcctBalService.class );
BaseGeneratedStub stubForLogicalPort = (BaseGeneratedStub) port ;
SecurityProtocol securityProtocol = (SecurityProtocol) stubForLogicalPort._getGlobalProtocols().getProtocol("SecurityProtocol");
securityProtocol.addHeader("Cookie","MYSAPSSO2=abcdefghijklm;");
Iam not able to see any cookie in soap header. Any thing else need to be done???
my soap header is coming like this
<SOAP-ENV:Header><sapsess:Session xmlns:sapsess="http://www.sap.com/webas/63
0/soap/features/session/"><enableSession>true</enableSession></sapsess:Session></SOAP-ENV:Header>
My code is some thing like this...iam getting following error
"DOM Element must be passed when no element name is specified "
pls help
SoapHeadersProtocol headers = (SoapHeadersProtocol)((BaseGeneratedStub) port)._getGlobalProtocols().getProtocol("SoapHeadersProtocol");
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element parameterNode = doc.createElementNS("http://www.test.com/myParam/", "test:MYSAPSSO2");
Element valueNode = doc.createElement("myParamValueNode");
valueNode.appendChild(doc.createTextNode("abcdefghijklm"));
parameterNode.appendChild(valueNode);
headers.setOutputHeader(null, docBuilderFactory);
i think header object is not null..becos when i printed headers.toString() it gave me
com.sap.engine.services.webservices.jaxrpc.wsdl2java.features.builtin.SoapHeadersProtocol@223367
in this method why do we pass null argument???i guess it may be becos of that...we need to pass some Name object or some thing like that....any idea??
headers.setOutputHeader(null, parameterNode);
Hi,
I suppose the Null Pointer exception does occur in the method setOutputHeader, and not directly in your code, right? I remember that there was a bug in the implementation of the SoapHeaderProtocol. As a workaround you might try the following:
headers.setOutputHeader(new QName(parameterNode.getNamespaceURI(), parameterNode.getNodeName()), parameterNode);
I haven't tried it, but I hope it works..
best regards,
Martin
Hi Sujesh,
we had the same problem and also tried to call the method with a meaningful headerName (First parameter of setOutputHeader), but failed for the same reasons.
We then debugged the code and saw, that setOutputHeader had a simple bug when calling it with null, meaning that setOutputHeader should compose the right default headerName. We communicated that and got a quick fix. Now we can call it with null as headerName and the method will work correctly.
The proposal from Martin in the thread is exactly what the setOutputHeader does in the case, you call it with null (not working without the fix). Unfortunately, if you do set the headerName as setOutputHeader would set it in case of a null, this doesn't work either.
So back to the beginning: You need a fix for the bug in setOutputHeader and can not go around it by trying to set a valid headerName yourself.
Regards,
Vedran
Hi Sujesh,
I am sorry, but we requested a quick fix (for our release) - we found no workaround. Can you open a CSS/OSS message?
Just mention the bug in setOutputHeader() with the construction of the default headerName if the value for headerName is null when calling the method.
...and add information about your release.
Regards,
Vedran
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
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.