Is it possible to access the raw SOA/XML message in a JAX-RPC java client?
I am trying to access the XML response via a JAX-RP开发者_Python百科C java client.
I have been looking into Axis custom handlers, but it looks like they are useful only in the service side.
Here's some code that will give you the XML response payload back. You can either get it directly from AXIS Stub class, or from a handler that wrote it to the MessageContext. Here's the one that reads it directly:
private String getSOAPResponseXML(Object clientstub) {
String returnValue = null;
org.apache.axis.client.Stub stub = (org.apache.axis.client.Stub)clientstub;
Call call = stub._getCall();
if (call != null) {
MessageContext ctx = call.getMessageContext();
// If I registered a handler
// returnValue = (String) ctx.getProperty( ClientHandler.SOAP_RESPONSE );
// or use:
try {
Message msg = call.getResponseMessage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// NOTE: If we never get a response (a request handler throws an uncaught error
// this can cause a java.lang.NullPointerException
msg.writeTo(baos);
returnValue = baos.toString();
} catch (java.io.IOException ex) {
log.debug("Error in getSOAPResponseXML", ex);
} catch (javax.xml.soap.SOAPException ex) {
log.debug("Error in getSOAPResponseXML", ex);
}
}
return returnValue;
} // getSOAPResponseXML
If you need the handler, just let me know.
精彩评论