从 Java Web 服务客户端获取原始 XML 响应

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11976234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:08:08  来源:igfitidea点击:

Getting raw XML response from Java web service client

javaweb-servicesjax-wsrad

提问by FrustratedWithFormsDesigner

I am trying to get the raw XML response from a web service, instead of the usual set of POJOs.

我试图从 Web 服务中获取原始 XML 响应,而不是通常的 POJO 集。

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

我正在使用我从 WSDL 和一些模式生成的网络服务客户端(所以我可以访问客户端的代码)。客户端是在 RAD 7.5 中生成的,我认为使用 JAX-WS。我一直在查看客户端代码本身,但我什至不确定客户端代码是否曾经处理过原始 XML 或者是否将其传递给其他库。

回答by Ilya

You can do it using

你可以使用

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

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

您可以简单地SOAPMessageContext#getMessage()使用方法获取消息并使用方法将消息转换为字符串

   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);    
         }
   }  

Also you can read here about SOAP handler on client side
Article

您也可以在此处阅读有关客户端文章的SOAP 处理程序

回答by jtahlborn

It's not widely documented, but you can use the Dispatchinterface to implement JAXWS clients which work directly w/ the XML. Hereand hereare some articles for getting started.

它没有被广泛记录,但您可以使用Dispatch接口来实现直接使用 XML 工作的 JAXWS 客户端。 这里这里有一些入门文章。