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
(details) com.sun.xml.rpc.server Aug 19, 2010 15:44:10.312 _ThreadID=22;
2009 SEVERE Can't overwrite cause
(details) com.sun.xml.rpc.server Aug 19, 2010 15:44:10.296 _ThreadID=22;
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.
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.
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?
Log Level: SEVERE
Name-Value Pairs: _ThreadID=25;
Record Number: 3099
Message ID: Can't overwrite cause java.lang.IllegalStateException
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.
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. 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.
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.
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.
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)