Getting a raw XML response from a Java web service client

I am trying to get the original XML response from a web service instead of the usual POJO set.

I am using the webservice client that I generated (so that I have access to the client code) from WSDL and some schemas. The client is created in RAD 7.5, I think using JAX-WS. I myself looked at the client code itself, but I'm not even sure if the client code ever processes raw XML or if it passes it to other libraries.

+1
source share
2 answers

You can do this using

javax.xml.ws.handler.soap.SOAPHandler<javax.xml.ws.handler.soap.SOAPMessageContext>

you can just get the message using SOAPMessageContext#getMessage()and convert the message to String using the method

   public static String getXmlMessage(SOAPMessage message) throws Exception
   {
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         message.writeTo(os);
         final String encoding = (String) message.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
         if (encoding == null)
         {
             return new String(os.toByteArray());
         }
         else
         {
            return new String(os.toByteArray(), encoding);    
         }
   }  

SOAP

+2

, Dispatch JAXWS-, XML. Here here - .

+1

All Articles