web-servicesbooleanwebsphere-6.1jax-rpc

IBM JAX-RPC web service : Though the response is Boolean we are getting a number in the output


We have a generated webservice based on WSDL using JAX-RPC, in WSDL we have response like below

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

Even the generated code has the method return type as Boolean

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

But when we invoke the service from Soap UI, we are seeing the response 'Ack' as 0, 1 not as true / false. This was working fine with JAX-WS.

Any help on this is highly appreciated


Solution

  • I have solved it using Handlers. Handlers can be added to webservices.xml file as below

    <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 class should override handleResponse() method to intercept the response

    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() {
        }       
    }