简体   繁体   English

发送之前如何从Java Request对象获取XML文件。 Web服务SOAP

[英]How to get XML file from Java Request object before sending. Web services SOAP

I am building Java application for Online Web Services and let's call it application A . 我正在为Online Web Services构建Java应用程序,我们称之为application A I got the WSDL file form the second party so I can communicate with their application and let's call it application B . 我从第二方获得了WSDL文件,因此我可以与他们的应用程序通信,我们称之为application B

From the WSDL file I generate the Java classes needed which are Requests and Responses classes. WSDL文件中,我生成了所需的Java类,即RequestsResponses类。 Application A will send some request object after setting the needed parameters and excepting response object from application B . Application A将发送一些request设置所需要的参数和后除外对象response从对象application B

The connection is established and both applications A and B are communicating with each other. 建立连接,并且applications A and B相互通信。

Question: 题:

From application A how can I get the xml data(file or text) for the request object before sending it to application B ? application A发送到application B之前,如何获取request对象的xml数据(文件或文本)?

As described the connection is done by passing Java object as request and I know that in some point this request will be converted to xml file. 如前所述,通过将Java对象作为request传递来完成连接,我知道在某些情况下此request将转换为xml文件。 How to get it? 如何获得?

--- EDIT ---- -编辑-

Important Information is missing that may cause confusion. 重要信息丢失,可能导致混乱。

I am generated the Java Classed have been generated using Axis framework 我生成的Java Classed已使用Axis框架生成

我没有什么好发表评论的名声,所以这是我的回答:如果您尚未使用Apache CXF框架,并且希望在发送应用程序之前捕获该请求,则可以在其中使用cxf拦截器一些内置的拦截器可以做到这一点,或者您可以创建一个具有正确相位的自定义拦截器(例如,元帅后)

The problem is solved by adding the following statements in the bindingStub class that has been auto generated from the WSDL file for the web-services you are trying to access. 通过在已从WSDL文件为您要访问的web-services自动生成的bindingStub类中添加以下语句来解决该问题。

String request = _call.getMessageContext().getRequestMessage().getSOAPPartAsString();
String response = _call.getMessageContext().getResponseMessage().getSOAPPartAsString();

These statements should be placed after the following method call _call.invoke otherwise you will get NullPointerException . 这些语句应放在以下方法调用_call.invoke否则您将获得NullPointerException

_call is a variable of type org.apache.axis.client.Cal and it is auto generated by Axis _callorg.apache.axis.client.Cal类型的变量,由Axis自动生成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM