aspose file tools*
The moose likes Websphere and the fly likes SOAP Header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "SOAP Header" Watch "SOAP Header" New topic
Author

SOAP Header

Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
Hello everybody.
I work with WSAD, I'm doing a web service, and I want to add some values in the SOAP header, but I don't know how to do. I know that the message is generated with the rpcrouter and the messagrouter servlets.
Please help me.
[ February 16, 2004: Message edited by: Alexandre Alleaume ]
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Well, it depends on what version of WSAD (and thus WebSphere Application Sever) you are using. Let us know the version and I'll give you some instructions.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
I work on the v5.0.0 of WSAD, and the v4 of WAS.
[ February 16, 2004: Message edited by: Alexandre Alleaume ]
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
Here is an example.....
private Header header;
private Vector headerEntries;
private HttpServletRequest servletRequest;
private Body body;
private Vector bodyEntries;
public void doSomething(Envelop requestEnvelop, SOAPContext requestContext, SOAPContext responseContext)throws SOAPException{
servletRequest = (HttpServletRequest)requestContext.getProperty(Constants.BAG_HTTPSERVLETREQUEST);
try{
header = requestEnvelop.getHeader();
headerEntries = header.getHeaderEntries();
}
catch(Exception e){
throw new SOAPException(Constants.FAULT_CODE_SERVER, "Error processing header!", e);
}
try{
body = requestEnvelope.getBody();
bodyEntries = body.getBodyEntries();
}
catch(Exception e){
throw new SOAPException(Constants.FAULT_CODE_SERVER, "Error processing body!", e);
}

//do whatever....
}

This should give you an idea of how you can use the API to maipulate bodies and headers. You should be able to call a setHeader method and pass a string or DOM to it but its been a while since I've done this so I leave it to you to recrack the surface.
Hope this helps....
[ February 16, 2004: Message edited by: William Duncan ]

No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
Thank you but I don't know what to do with that.
When I'm supposed to call the function?
[ February 16, 2004: Message edited by: Alexandre Alleaume ]
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
Basic steps for calling the message service from a client (straight from the Redbook):
1. obtain the interface description of the SOAP service, so that you know what the format of the SOAP message is.
2. construct an org.apache.soap.Envelope containing the info needed by the service.
3. create an org.apache.soap.messaging.Message object.
4. invoke the send method on this message object. Pass the URL of the port that provides the service, the SOAP action URI for the HTTP header, and the envelope.
5. If your service returns data and the transport supports two-way interaction, you have to retrieve the SOAPTransport object from the message object by using the getSOAPTransport method. You can then invoke the receive method on this transport object in order to access the returned data.
Note that there are no cool wizards to create the service or the client. My suggestion is to take a look at chapter 14 - Message Oriented Services in Web Services Wizardry with WebSphere Studio Application Developer
by Mark Tomlinson (IBM Redbook). The version of WSAD may still be 4.0 during the writing of this book but I don't think WSAD 5.0 has wizard support for message oriented services either. That's old school....
Wish I could be of more help than pointing you to a resource but I am no expert in this area as I have only done it once. But everything I did was with the help of the book mentioned above.
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
In fact I have created a web service with WSAD, which generate a proxy and a test client via the wizard. The rpcrouter and the messagerouter servlet, wich are associated with the web service, generate the SOAP message. That's why I don't know how to add informations in the header of the SOAP message.
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 363
Hmmm...when I did this, there were no wizards for a message oriented web service. There may be now. I copied and pasted chapter 14 of the book in an email and sent it to you. Hope it helps...
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
OK, thanks.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
I have code that solves this, but unfortunately for some reason I can't post it. UBB screams at me when I try. Robert Englander's book "Java and SOAP" (O'Reilly) has code that shows how to do create headers in Apache SOAP. The key to getting the headers back on the server side is to use the Pluggable providers feature of Apache SOAP. Providers are a bridge between the SOAP engine and the service being invoked. You can specify your own provider using the < isd :provider > tag in the Apache DD. Take a look at the Apache documentation for more information.
Kyle
[ February 17, 2004: Message edited by: Kyle Brown ]
[ February 17, 2004: Message edited by: Kyle Brown ]
Rufus BugleWeed
Ranch Hand

Joined: Feb 22, 2002
Posts: 1551
Is your posting problem that you have to insert amperstand+lt and amperstand+gt for the arrow symbols?
[ February 17, 2004: Message edited by: Rufus BugleWeed ]
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Would that it were, Rufus. The post it was rejecting contained only actual Java code and not XML brackets (I'd already replaced them with the lt and gt) -- I've yet to figure out what it didn't like...
Kyle
Rufus BugleWeed
Ranch Hand

Joined: Feb 22, 2002
Posts: 1551
The code tags did not help either?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Nope.
Kyle
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
I've found something that could help me , but I have another problem.
It's a ClassCastException. Here is the code, which is in the client proxy :
call.setMethodName("partResult");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
call.setTargetObjectURI(targetObjectURI);
Header head = new Header();
Vector params = new Vector();
Vector vRes = new Vector();
Parameter sessionIDParam = new Parameter("sessionID", java.lang.String.class, sessionID, Constants.NS_URI_SOAP_ENC);
params.addElement(sessionIDParam);
[...]
vRes.addElement((Object)sessionIDParam); (1)
head.setHeaderEntries(vRes);
call.setHeader(head);
[...]
(1) I have noticed that the exception is here. sessionIDParam is a Parameter, and the method addElement need an Object type.
Because of the exception, I've made a transtype from Parameter to Object, as you can see in the code. But the exception is still there and I don't know what I can do.
Please help me.
[ February 19, 2004: Message edited by: Alexandre Alleaume ]
Rufus BugleWeed
Ranch Hand

Joined: Feb 22, 2002
Posts: 1551
It would be fun to test org.omg.Dynamic.Parameter to see if it's an interface. Why Dynamic is capitalized too?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Don't do a vres.addElement() with params as the argument. Instead use the Call method setParams() and pass the Vector of params as the argument.
This is the code I was unsuccessfully trying to post yesterday.
Kyle
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
Originally posted by Kyle Brown:
Don't do a vres.addElement() with params as the argument. Instead use the Call method setParams() and pass the Vector of params as the argument.
This is the code I was unsuccessfully trying to post yesterday.
Kyle

in fact I use the setParams() method to put the value in the SOAP message's body.
If I let the Vector empty and if I use the Header.setAttribute() method like in this code :
[...]
head.setHeaderEntries(vRes);
QName qname1 = new QName("", "SessionID");
QName qname2 = new QName("", "LastRecord");
head.setAttribute(qname1, (sessionIDParam.getValue()).toString());
head.setAttribute(qname2,(lastRecordParam.getValue()).toString());
call.setHeader(head);
[...]
I can see the values in the SOAP message like this one :
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header LastRecord="7" SessionID="7050936c:fad1ee9477:-7ff9">
</SOAP-ENV:Header>
<SOAP-ENV:Body>
[...]
but if I don't use the Header.setHeaderEntries method, the SOAP header disappear.
My problem is solved for the client proxy, but now for the server I still don't know how to create the SOAP header, because the SOAP message is generated by the rpcrouter and messagerouter servlets.
Don't you think it could be a solution if I create my own servlets?
And if it is the solution how can I do that? And how can I get the values that I've put in th SOAP header?
[ February 20, 2004: Message edited by: Alexandre Alleaume ]
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
The solution for headers on the server side is contained in my previous post. You need to create a new pluggable provider. Go look at Robert Englander's book.
Kyle
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
I've heard about handler on the server side. Is it a good solution?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Handlers are a feature of JAX-RPC, which is implemented by Apache Axis, not Apache SOAP. This is something that's in WebSphere 5.02 and WSAD 5.1. But yes, they are a good way of doing things.
Kyle
Alexandre Alleaume
Greenhorn

Joined: Feb 16, 2004
Posts: 11
My version of WSAD is the 5.0.0, I've download the Apache Axis 1.1 binaries files too. But right now, I'm stuck in front of my PC. I don't know what to do.
I've tried to follow this article, but it didn't work.
[ February 25, 2004: Message edited by: Alexandre Alleaume ]
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Alexandre, as I've said earlier, if you're using apache soap the way to solve this is to go buy Robert Englander's book (come on, it's $7 on Amazon, used!) and follow his instructions for building a pluggable provider.
Otherwise, upgrade to WSAD 5.1. Either solution will work, but you need to pick one or the other. Half-way measures won't work.
Kyle
ASTA VISTA
Greenhorn

Joined: Oct 21, 2004
Posts: 2
I have follow your code for add soap-header.
But i got error when call.invoke(url,"").
The error are :

java.lang.ClassCastException
java.lang.ClassCastException
at org.apache.soap.Header.marshall(Header.java:134)
at org.apache.soap.Envelope.marshall(Envelope.java:189)
at org.apache.soap.transport.http.SOAPHTTPConnection.send(SOAPHTTPConnec
tion.java:273)
at org.apache.soap.rpc.Call.invoke(Call.java:248)

I'm tired of thinking what to do.

TQ
ASTA VISTA
Greenhorn

Joined: Oct 21, 2004
Posts: 2
Sorry, the error because i want to setHeaderEntries.
Can you give me a solution pleassseeeeeeee.........
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SOAP Header