wood burning stoves 2.0*
The moose likes Web Services and the fly likes JAX-RPC web service soap message handler issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX-RPC web service soap message handler issues" Watch "JAX-RPC web service soap message handler issues" New topic
Author

JAX-RPC web service soap message handler issues

Lavanya Halliwell
Ranch Hand

Joined: Apr 09, 2010
Posts: 57
I am having troubles creating a handler to intercept the header information in my soap message.

my service works fine without the handler, but when I add the handler I get errors in the sun java app server 8.2 logs.

the service takes 2 numbers in the soap request, and adds them, and then prints the result in the response.

then I put in the webservices.xml file:



and I add my handler class to the project: (just a lot of print statements for now)




a snap shot of the log is here: (this occurs when I try to submit a soap request in soapUI to the service)

2012 SEVERE caught exception while preparing response: java.lang.ClassCastException: com.sun.xml.internal.messag...
(details) com.sun.xml.rpc.server Aug 19, 2010 15:44:10.328 _ThreadID=22;
2011 SEVERE caught exception while handling request: java.lang.ClassCastException: com.sun.xml.internal.messagin...
(details) com.sun.xml.rpc.server Aug 19, 2010 15:44:10.328 _ThreadID=22;
2010 SEVERE caught exception while handling request: java.lang.IllegalStateException: Can't overwrite cause
java...
(details) com.sun.xml.rpc.server Aug 19, 2010 15:44:10.312 _ThreadID=22;
2009 SEVERE Can't overwrite cause
at java.lang.Throwable.initCause(Throwable.java:320)
at com.sun.enterprise.w...
(details) com.sun.xml.rpc.server Aug 19, 2010 15:44:10.296 _ThreadID=22;
R Srini
Ranch Hand

Joined: Feb 19, 2010
Posts: 215
Hi. I see that you are implementing Handler. Nothing wrong with that, but its at a lower level and requires more work I presume, when compared with using SOAPHandler.

The handlers that I have created implement javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> (http://download.oracle.com/javaee/5/api/javax/xml/ws/handler/soap/SOAPHandler.html), and this method "public boolean handleMessage(SOAPMessageContext messageContext)" is overridden to provide the handler functionality.

So In Netbeans/Glassfish, I have

HelloWebService_handler.xmlLogMessageHandler.java

HTH.
Lavanya Halliwell
Ranch Hand

Joined: Apr 09, 2010
Posts: 57
srini thanks for the reply!

my goal, for now that is, is to print the soap username/password to a file.

sounds like you have figured this out, is this just a small webservice example for printing out text such as Hello World?

could you send me the code so I can take a look at how you did it?
It would be helpful to see how your sample project is layed out, do you just add the handler stuff to the web service project?


if I get you correctly, once I have a web service (and I have one that simply takes in 2 numbers and addes them and returns the result), there are ONLY 2 things required?

1. the handler class file

2. the handler xml file


thanks! Lavanya
R Srini
Ranch Hand

Joined: Feb 19, 2010
Posts: 215
Yes, I think that is correct. Once you have the basic web service, you need to:

- develop the handler implementing SOAPHandler
- wire it up into the handler chain in an XML file
- And annotate your web service class with "@HandlerChain(file = "MyMessage_handler.xml")".

My guess is that wiring the handler chain depends on the JAX-WS implementation that you use. So the way to incorporate the handler chain XML into the system may be different in Glassfish than when using Axis. So you may have to look up the documentation for that.

I have tried this in Netbeans/Glassfish, and this is easy to do.
Lavanya Halliwell
Ranch Hand

Joined: Apr 09, 2010
Posts: 57
so I'm still exploring this, looks like Srini's code for the sample webservice using Annotations via j2ee 5 or higher is the way to go.

Instead of using this...arguably better...approach, is there a way to add a handler to a webservice deployed to sun java app server 8.2 using j2ee 1.4. No annotations, jdk 1.5. In the form of an ejb jar file.

I have a small webservice working which takes in a string, appends text to it, and prints the resulting string. (this I am trying to add the handler to)

if anyone knows of good tutorials for this, please post one, thanks.
R Srini
Ranch Hand

Joined: Feb 19, 2010
Posts: 215
Ohhh. So you are developing in J2EE 1.4? Sorry I don't have experience developing web services in 1.4. However:

1. This may be of help to you.
2. Go to your app server documentation site, and search for "web service handler". Some of the results should be of help, including this one on how to create handlers.

All the best!
Lavanya Halliwell
Ranch Hand

Joined: Apr 09, 2010
Posts: 57
Thanks for posting those links Srini, I think from them I need to just creat my handler class and configure it in webservice.xml file.

when I do this I get an error at run time. (after I post request to service using soapUI)
this happens after I add the handler entry in the webservice.xml file. (the handler class itself builds)

do we have any sun java app server 8.2 experts that have seen something like this before?


error is:

Log Level: SEVERE
Logger: com.sun.xml.rpc.server
Name-Value Pairs: _ThreadID=25;
Record Number: 3099
Message ID: Can't overwrite cause java.lang.IllegalStateException
Complete Message
Can't overwrite cause at java.lang.Throwable.initCause(Throwable.java:320) at com.sun.enterprise.webservice.EjbContainerPreHandler.handleRequest(EjbContainerPreHandler.java:80) at com.sun.xml.rpc.client.HandlerChainImpl.handleRequest(HandlerChainImpl.java:86) at com.sun.xml.rpc.server.StreamingHandler.callRequestHandlers(StreamingHandler.java:945) at com.sun.xml.rpc.server.StreamingHandler.preHandlingHook(StreamingHandler.java:851) at com.sun.xml.rpc.server.StreamingHandler.handle(StreamingHandler.java:110) at com.sun.enterprise.webservice.EjbWebServiceDispatcher.handlePost(EjbWebServiceDispatcher.java:140) at com.sun.enterprise.webservice.EjbWebServiceDispatcher.invoke(EjbWebServiceDispatcher.java:79) at com.sun.enterprise.webservice.EjbWebServiceValve.dispatchToEjbEndpoint(EjbWebServiceValve.java:187) at com.sun.enterprise.webservice.EjbWebServiceValve.invoke(EjbWebServiceValve.java:131) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:542) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:132) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:189) at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doProcess(ProcessorTask.java:604) at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:475) at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:371) at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:264) at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:281) at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:83)



notes: I am using netbeans 6.8, I right click the webservice, click "configure handlers", click "add" and select my handler class that I have put in it's own src folder next to the src folder for the code for the webservice.

Lavanya
R Srini
Ranch Hand

Joined: Feb 19, 2010
Posts: 215
Ok. Back to square one then Now, if you look at the sample handler code in that documentation, it is a bit different. For example:

- your getHeaders method returns QName[0]. Is this valid though? I don't know if its even populated with values.
- your init method doesn't do anything, but its probably critical to the rest of it working.

So: can you try using the sample code instead and implement some of it, including init(), destroy(), getHeaders(), formLogMessage() and handleRequest? In order words, all of it I think it will work if you try it.
Lavanya Halliwell
Ranch Hand

Joined: Apr 09, 2010
Posts: 57
ok, so I think I'm going in the right direction now....

in my handler class:



apparently this is where if gets the header from your soap request, however header.toString() returns null....
(by the way, I added writeOut(test4), it just creates a file so I can see where the program is getting to)

SO...header is null, which as I read the tutorial site posted I have to register each header and assign it to a qname.
(see "Adding a SOAP Header Block To a Handler" in http://docs.sun.com/source/817-2324/CreatingHandlers.html#42596)

any ideas how to do this? the editor I use is netbeans 6.8 so slightly different then the one in the tutorial...

starting to get there....Lavanya
R Srini
Ranch Hand

Joined: Feb 19, 2010
Posts: 215
Well, that is good. So you are on your way now.
SO...header is null, which as I read the tutorial site posted I have to register each header and assign it to a qname.

What is it you are trying to do? Obtain/get the headers in an incoming SOAP message? Or add a header to an outgoing message?
For an incoming message with a header, I would expect the header to not be null. The link you posted is meant for adding a header to a SOAP message before its sent on its way to the destination.
Lavanya Halliwell
Ranch Hand

Joined: Apr 09, 2010
Posts: 57
Srini - thanks for all the tips and that sample code you sent me. As for my code, the handler isn't the issue, but I think my Sun Java AppServer 8.2 has some incorrect soap library. (so I will have to look into that)

I did try to implement the J2EE version 5 with Annotations, and a handler web service using weblogic 10.3.2 and I can successfully build/deploy/and run my web service.
I can even view SOME aspect of the header info, although I still have to make it print the correct data. (have to manipulate the soap message methods...painful...oh well)

I have projects that deal with both sun app server AND weblogic, so it's good for me to try both ways.

if you all know of some good tutorials for reading parts of a soap header for authentication purposes, it would be wonderful if you'd post them.
(but if not i'm just shouting out a thank you for all the tips reguarding this)

Cheers! Lavanya
 
 
subject: JAX-RPC web service soap message handler issues
 
Similar Threads
Service with handlers on JBoss. BIG Problem
Question about design of WS clients and their handlers
How to use Handler?
capture request and response to/from webservice
Web service handler could not registered/called in client web service