Hello everyone, and thanks in advance for your help.

I'm developing a client to consume a web service.  I used WSDL2Java
(axis1-4) to produce stub classes and everything works great - I
successfully process the service.  However, I'm required to store the actual
request/response documents with the transaction, and this is where I've run
into trouble.

The only way I could figure out how to do this properly was to modify the
generated service stub.

I added:

public void setClientHandlers(org.apache.axis.Handler requestHandler,
org.apache.axis.Handler responseHandler) {
                this.requestHandler = requestHandler;
                this.responseHandler = responseHandler;
        }

And modified the webservice method stub as follows:

org.apache.axis.client.Call _call = createCall(); //Added these lines...
if (requestHandler != null && responseHandler != null)
        _call.setClientHandlers(requestHandler, responseHandler); //end add
_call.setOperation(_operations[0]);
try {        
        java.lang.Object _resp = _call.invoke(new java.lang.Object[]
{parameters});

I created the following classes:

        public class MyRequestHandler extends
org.apache.axis.handlers.LogHandler {
                public void invoke(org.apache.axis.MessageContext
msgContext) throws org.apache.axis.AxisFault {
                        try {
                                SOAPMessageContext smc =
(SOAPMessageContext)msgContext;
                                SOAPMessage msg = smc.getMessage();
                                System.out.println("request:");
                                msg.writeTo(System.out);
                        }
                        catch (Exception e) {
                                e.printStackTrace();
                                throw new
org.apache.axis.AxisFault(e.getMessage());
                        }
                }
        }

        //super.invoke(msgContext);
        public class MyResponseHandler extends
org.apache.axis.handlers.LogHandler {
                public void invoke(org.apache.axis.MessageContext
msgContext) throws org.apache.axis.AxisFault {
            try {
                                SOAPMessageContext smc =
(SOAPMessageContext)msgContext;
                                SOAPMessage msg = smc.getMessage();
                                System.out.println("response:");
                                msg.writeTo(System.out);
                        }
                        catch (Exception e) {
                                e.printStackTrace();
                                throw new
org.apache.axis.AxisFault(e.getMessage());
                        }
                }
        }

And then set the handlers from the client code.  With this code in place, I
get the following exception:

org.xml.sax.SAXException: SimpleDeserializer encountered a child element,
which is NOT expected, in something it was trying to deserialize.
        at
org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeseriali
zer.java:145)
        at
org.apache.axis.encoding.DeserializationContext.startElement(Deserialization
Context.java:1035)
        at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
        at
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:
1141)
        at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
        at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
        at org.apache.axis.client.Call.invoke(Call.java:2467)
        at org.apache.axis.client.Call.invoke(Call.java:2366)
        at org.apache.axis.client.Call.invoke(Call.java:1812)...

I've experimented with different version of handler classes (which are run
by the way - I access the request and response), and even tried setting the
handler explicitly to null (in the stub class).  The bottom line:  if I have

the Call.setClientHandlers(handler, handler) in place, the exception is
returned.  Obviously I'm screwing something up, but not sure what.

I did, but the way, consider setting handlers the more conventional way
(handler chain from the client code), but this method only allows me to
specify a class, not an instance, so I loose all context (which I need to be
able to store the request/response along with the other transactional
information).

Please let me know if more information is needed.

Michael Lee

Reply via email to