简体   繁体   English

如何使用Java代码修改SOAP响应?

[英]How to modify SOAP response using java code?

I have SOAP Request and also SOAP response in java code. 我在Java代码中有SOAP请求和SOAP响应。 In SOAP response I am getting <return> statement using java code. 在SOAP响应中,我正在使用Java代码获取<return>语句。

I want to modify my SOAP response : Instead of <return> ::: 我想修改我的SOAP响应:而不是<return> :::

I need it as 我需要它

<userResponse> <userResponse> 
<userId> <userId> 
<image> <image> 

can anybody help me out using java code to get the response for SOAP or any useful link to get example. 谁能帮我使用Java代码获取SOAP响应或任何有用的链接获取示例。

Maybe I'm missing something here, but since you're coding the web service, can't you just modify the return string to be as you've indicated in your post? 也许我在这里遗漏了一些东西,但是由于您正在编写Web服务的代码,难道不能仅将返回字符串修改为您在帖子中所指出的那样吗? Using JAX-WS (http://docs.oracle.com/javaee/5/tutorial/doc/bnayn.html) , you can return a result string in an XML-formatted style and then the client can consume your return string as it needs to. 使用JAX-WS (http://docs.oracle.com/javaee/5/tutorial/doc/bnayn.html) ,您可以返回XML格式的结果字符串,然后客户端可以将您的返回字符串用作它需要。

You could have multiple, separate methods to return individual components if you needed to as well (one method for the userResponse, one for the userId, etc...). 如果需要的话,您可以有多个单独的方法来返回单个组件(一个用于userResponse的方法,一个用于userId的方法,等等)。

For example (a very simple one)... 例如(一个非常简单的例子)...

package some_package_for_your_web_service;

import javax.jws.WebService;

@WebService
public class SomeClassForYourWebService {

    public void SomeClassForYourWebService() {}

    @WebMethod
    public String response() {
        return "<response>" +
                  "<userResponse>a_response</userResponse>" +
                  "<userId>a_user_id</userId>" +
                  "<image>an_image_url</image>" +
               "</response>";
    }
}

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

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