2012-01-11 160 views
-3

請幫我解決以下問題,我嘗試了很長時間(3周),但無法獲得正確的解決方案。我必須儘快完成它,因爲我的許多web服務輸出取決於自定義返回字符串。如何使用java從SOAP響應中刪除(<)和([CDATA [[))?

我已經使用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響應/輸出String :::::::::

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 
+1

這個問題是一個火車事故,請考慮您的固定格式問題,並提供更完整的Java代碼片斷。 – 2012-01-11 16:13:54

回答

2

使用框架,如果你想提供或使用通過SOAP web服務。 您不必使用任何開始標籤或結束標籤,框架將處理此問題。

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

如果您返回一個字符串(不是類中的數字),則編碼是正確的。您返回一個帶有特殊編碼字符的字符串。他們必須這樣編碼。否則你將創建格式不正確的XML。

javax.jws Tutorial at Oracle Webservice-Tutorial