• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SOAP Header

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Alexandre Alleaume
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I work on the v5.0.0 of WSAD, and the v4 of WAS.
[ February 16, 2004: Message edited by: Alexandre Alleaume ]
 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Alexandre Alleaume
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, thanks.
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code tags did not help either?
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope.
Kyle
 
Alexandre Alleaume
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've heard about handler on the server side. Is it a good solution?
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, the error because i want to setHeaderEntries.
Can you give me a solution pleassseeeeeeee.........
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic