1

我们有一个基于 WSDL 使用 JAX-RPC 生成的 web 服务,在 WSDL 中我们有如下响应

<element name="notificationsResponse">
<complexType>
<sequence>
<element name="Ack" type="xsd:boolean"/>
</sequence>
</complexType>
</element>
</schema>

甚至生成的代码也有方法返回类型为 Boolean

public boolean notificationXXXXX(java.lang.String XXXX,
            java.lang.String XXXX, java.lang.String XXXX)

但是当我们从 Soap UI 调用服务时,我们看到响应 'Ack' 为 0,而不是 true / false。这在 JAX-WS 上运行良好。

对此的任何帮助都非常感谢

4

2 回答 2

0

根据XML Schema Datatypes specification,布尔值可能有 4 个值:

booleanRep ::= 'true' | 'false' | '1' | '0'
于 2013-07-13T11:48:18.907 回答
0

我已经使用处理程序解决了它。可以将处理程序添加到 webservices.xml 文件中,如下所示

<webservice-description>
        <webservice-description-name>XXXXXXXXXXXX</webservice-description-name>
        <wsdl-file>WEB-INF/wsdl/XXXXXXXXXXXXX.wsdl</wsdl-file>
        <jaxrpc-mapping-file>WEB-INF/XXXXXXXXXXX.xml</jaxrpc-mapping-file>
        <port-component>
            <port-component-name>XXXXXXXXXX</port-component-name>
            <wsdl-port xmlns:pfx="http://XXXXX">pfx:XXXXX</wsdl-port>
            <service-endpoint-interface>XXXXXXXXX</service-endpoint-interface>
            <service-impl-bean>
                <servlet-link>XXXXXXXXXXXX</servlet-link>
            </service-impl-bean>
             **<handler id="Handler_1066493401322">
               <handler-name>com.a.b.ResponseHandler</handler-name>
               <handler-class>com.a.b.ResponseHandler</handler-class>
            </handler>**     
        </port-component>
    </webservice-description>

Handler 类应该重写 handleResponse() 方法来拦截响应

import java.util.Date;
import java.util.Iterator;

import javax.xml.namespace.QName;
import javax.xml.rpc.handler.GenericHandler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;

import org.w3c.dom.NodeList;

import com.ibm.ws.webcontainer.srt.SRTServletResponse;


public class ResponseHandler extends GenericHandler {

    protected HandlerInfo info = null;





    public boolean handleResponse(MessageContext context) {
        try {

                SOAPMessageContext smc = (SOAPMessageContext) context;
                SOAPMessage message = smc.getMessage();

                SOAPBody sb = message.getSOAPBody();


                NodeList nl = sb.getChildNodes();


                 nl= sb.getChildNodes().item(0).getChildNodes().item(0).getChildNodes();

                 String responseValue = nl.item(0).getNodeValue();

                 System.out.println("Received response value is"+ responseValue);

                 if("1".equals(responseValue))
                 {
                     System.out.println(" Setting the response value to true");
                    nl.item(0).setNodeValue("true");
                 }
                 else
                 {
                     System.out.println(" Setting the response value to false");
                     nl.item(0).setNodeValue("false");
                 }


        } catch (Exception x) {
            // insert error handling here
            x.printStackTrace();
        }
        return true;
    }


    /* (non-Javadoc)
     * @see javax.xml.rpc.handler.Handler#getHeaders()
     */
    public QName[] getHeaders() {
        return info.getHeaders();
    }

    public void init(HandlerInfo arg) {
        info = arg;
    }

    public void destroy() {
    }       
}
于 2013-09-03T08:20:00.557 回答