为SOAP设置XML响应

时间:2013-02-25 19:27:49

标签: java xml web-services soap

我在这个问题上遇到了很多困难。

基本上我使用Java / JAX-WS构建了一个WebService,这是我的接口

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface OperationsInterface {

@WebResult(name = "result")
LoginResponse Login(@WebParam(name = "login") Login login);

@WebResult(name = "result")
String Purchase(@WebParam(name = "purchase") Purchase purchase);

}

登录只是一个包含2个字符串(用户名和密码)的POJO

LoginResponse是另一个POJO,它有这个

String status;
int code;
String message;
SubscriptionTier subscriptionTier;
String accountNumber;
String firstName;
String lastName;

没什么好看的,事实上很简单。请求是这样的

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ott="http://ott.amentum.net/">
   <soapenv:Header/>
   <soapenv:Body>
      <ott:Login>
         <login>
            <username>USERNAME</username>
            <password>1234</password>
         </login>
      </ott:Login>
   </soapenv:Body>
</soapenv:Envelope>

响应就像这样

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:LoginResponse xmlns:ns2="http://ott.amentum.net/">
         <result>
            <accountNumber>0110000076</accountNumber>
            <code>1</code>
            <firstName>JOHN</firstName>
            <lastName>DOE</lastName>
            <message>Login has been successful.</message>
            <status>success</status>
            <subscriptionTier>
               <tier>TVOD</tier>
               <tier>CANAL</tier>
               <tier>CATCHUP</tier>
            </subscriptionTier>
         </result>
      </ns2:LoginResponse>
   </soap:Body>
</soap:Envelope>

据我所知,这是正确的,但是,我的客户期待这样的事情

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:LoginResponse xmlns:ns2="http://ott.amentum.net/">
         <accountNumber>0410089676</accountNumber>
         <code>1</code>
         <firstName>MARIA DEL CARMEN</firstName>
         <lastName>PADILLA MARTIN</lastName>
         <message>Login has been successful.</message>
         <status>success</status>
         <subscriptionTier>
            <tier>TVOD</tier>
            <tier>CANAL</tier>
            <tier>CATCHUP</tier>
         </subscriptionTier>
      </ns2:LoginResponse>
   </soap:Body>
</soap:Envelope>

他们希望我删除结果标记,这是我为返回信息而创建的LoginResponse对象的名称。

有办法做到这一点吗?

提前致谢

0 个答案:

没有答案