cancel
Showing results for 
Search instead for 
Did you mean: 

Sending parameters through SOAP header

Former Member
0 Kudos

Hi all..

Iam using web services model in my web dynpro application. How will i send some paramters/info in SOAP header??

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sujesh,

Please check the WebService tutorials and examples.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/uuid/9fc0e990-0201...

Regards, Anilkumar

Former Member
0 Kudos

Hi aim working with web services model...its fine..

all i wanted is to know how we can add some info to SOAP header, whihc iam not able to get from any where...pls help...is there any API for it???

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Thanks a lot for the message

but in the code theres an object "client"..can u please tell me wht this means?? how do we use it??

SoapHeadersProtocol headers = (SoapHeadersProtocol) ((BaseGeneratedStub) client)._getGlobalProtocols().getProtocol("SoapHeadersProtocol");

Former Member
0 Kudos

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

Former Member
0 Kudos

I dont have a j2ee application. All i have is a web service client using web dynpro and i need to send some extr parameters through soap header. So i gotto add soap header info..

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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?

Former Member
0 Kudos

Hi Sujesh,

yes that is correct.

Check service value is coming null or what?

If service value is not null then first get logical port in variable type Object. Then check its value. then type cast to AcctbalService.

Regards,

Bhavik

Former Member
0 Kudos

Hi Bhavik,

Thanks for the info. I have tried what you have said.

1. Object obj = service.getLogicalPort("AcctBalServiceIFPort" , AcctBalService.class );

2. AcctBalService logicalPort = (AcctBalService) obj;

Iam getting NullPointerException at 2. What could be wrong???

Former Member
0 Kudos

Hi Sujesh,

R you getting any value in obj? Means, have you checked whether is it null or not?

Regards,

Bhavik

Former Member
0 Kudos

yes. Iam getting the following value for obj.toString()...

accbalservice.proxies.AcctBalServiceIFBindingStub@1964738

This means this is not null...am i correct?????

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Sujesh,

If you have the logical Port you can access the SOAP Header like this:

SoapHeadersProtocol headers = (SoapHeadersProtocol)((BaseGeneratedStub) logicalPort)._getGlobalProtocols().getProtocol("SoapHeadersProtocol");

headers.setOutputHeader(null, yourHeaderXMLNode);

regards,

Martin

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks a lot Bhavik,

I have tried this. Now iam getting new error

java.lang.NoClassDefFoundError: com/sap/security/core/client/ws/SecurityProtocol

should i need to add some ext jar or some thing like that???

What could be wrong???

Former Member
0 Kudos

Hello Sujesh,

As mention in the last post,

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.

Regards,

Dharmi

Former Member
0 Kudos

Hi Sujesh,

You don't need the SecurityProtocol but the SOAPHeadersProtocol to add a Parameter to the SOAP Header (see my posting above)

regards,

Martin

Former Member
0 Kudos

Hi Martin,

Ok...great.

But in the method

headers.setOutputHeader(null,data)

how can i send data???

wht i need to do is to add some thing like this in soap header.

MYSAPSSO2=ABSHDHDFHDH

how can i do it???

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Sujesh,

Add webservice reference in your webdynpro properties-> webdynpro references-> webservice reference as given below:

tc/sec/wssec/service

Regards,

Bhavik

Former Member
0 Kudos

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

Former Member
0 Kudos

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>

Former Member
0 Kudos

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);

Former Member
0 Kudos

you must add the parameterNode, not the docBuilderFactory.

Former Member
0 Kudos

Thanks Martin..

Iam getting null pointer exception in this line..

headers.setOutputHeader(null, parameterNode);

Any idea????

Former Member
0 Kudos

Seems that the headers object is null. Can you check this? But unfortunately I have no idea why it is null.

Former Member
0 Kudos

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);

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks Martin..now iam getting another

exception

<i>Element test:MYSAPSSO2 not declared in schema</i>

I had to send a parameter MYSAPSSO2 in header. my code was

Element parameterNode = doc.createElementNS("http://www.test.com/myParam/", "test:MYSAPSSO2");

wht else need to be done for this?????

0 Kudos

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

Former Member
0 Kudos

Thanx for that useful info Vedran. Pls advice me how can i move forward in this case. Iam close to my target. Some how i need to send some parameters through SOAP Header. What needs to be done now?? I have been behind this ting for quite some time...:):)

0 Kudos

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

Former Member
0 Kudos

How do I request for a bug fix...?? Iam new to NetWeaver platform...

Iam using NetWeaver04 with SP9...

Former Member
0 Kudos

Hello Sujesh,

You can open an OSS meesage by following the thread

or you can go to the service.sap.com and open an OSS message there

Sorry, I have no idea what a CSS message is.

Regards,

Dharmi

Answers (0)