【问题标题】:how to Remove (&lt;) and ([CDATA[[) from SOAP response using java?如何使用 java 从 SOAP 响应中删除 (<) 和 ([CDATA[[)?
【发布时间】:2012-01-11 03:39:13
【问题描述】:

请帮我解决以下问题,我尝试了很长时间(3 周)但无法获得正确的解决方案。我必须尽快完成它,因为我的这么多 web 服务输出取决于自定义返回字符串.

我已经使用 javax.jws 编写了 java 代码。

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

    String returnStr = null;

    String responseCodeStart = "<responseCode>";
    String responseCodeEnd = "</responseCode>";
    String responseMessageStart = "<responseMessage>";
    String responseMessageEnd = "</responseMessage>";

将 JAVA 中的自定义字符串返回到 SOAP 响应/输出字符串 :::::::::

 returnStr = "\r\n" + responseCodeStart + "1000" + responseCodeEnd + "\r\n" + responseMessageStart + "Registration successful>>" + responseMessageEnd + "\r\n";

问题:

1)  I am getting (&lt;) tag instead of (<)
2) I am getting ([CDATA[[) tag in response.

SOAP 响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:registerUserResponse xmlns:ns2="http://impl.timecapsule.com/">
         <return>&lt;responseCode>1102&lt;/responseCode>
&lt;responseMessage> [!CDATA[[Please provide username] &lt;/responseMessage></return>
      </ns2:registerUserResponse>
   </soap:Body>
</soap:Envelope>

*需要的解决方案:*

    1) &lt; to remove
    2) CDATA to remove

I want to retrieve it as XML object instead of String using java code.


THANKS

【问题讨论】:

  • 这个问题是火车残骸,请考虑修复您的格式问题并提供更完整的 java sn-p。

标签: java soap response


【解决方案1】:

如果您想通过 SOAP 提供或使用 Web 服务,请使用框架。 您不必使用任何开始标签或结束标签,框架会处理这个。

String responseCodeStart = "<responseCode>";
String responseCodeEnd = "</responseCode>";
String responseMessageStart = "<responseMessage>";
String responseMessageEnd = "</responseMessage>";

如果您返回一个字符串(不是类中的数字),则编码是正确的。您返回一个带有特殊编码字符的字符串。它们必须以这种方式编码。否则您将创建格式错误的 XML。

javax.jws Tutorial at Oracle Webservice-Tutorial

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-23
    • 2014-10-16
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多