Search code examples
wso2esb

issue with wso2 jax-ws client


So I have mapped a WSO2 DSS service through WSO2 ESB. I have generated a jax-ws client and I am using it successfully to get some data.

The problem is that sometimes when I call the client it throws a

Exception in thread "main" java.lang.NullPointerException
at com.sirmaitt.egov.codelist.client.Client.main(Client.java:77)

At that line of the source code I am trying to print the response data in the console.

Here's the code I'm using to call the service

    // Initialize service
        Codelists_Service service = new Codelists_Service();

        // Adds custom handler so we can add custom SOAP security header.
        service.setHandlerResolver(new HandlerResolver() {
            @SuppressWarnings("rawtypes")
            public List<Handler> getHandlerChain(PortInfo portInfo) {
                List<Handler> handlers = new ArrayList<Handler>();
                handlers.add(new SecuritySOAPHandler());
                return handlers;
            }
        });

        CodelistsPortType port = service.getCodelistsHttpsSoap11Endpoint();

        Codelists codelists = null;
        try {
            codelists = port.getcodelists();
        } catch (DataServiceFault e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // Prints the response.
        for (Codelist cList : codelists.getCodelist()) {
}

Rest of the project are mainly jax-ws generated classes and one custom SOAPHandler, which I use to add a security header.

The issue is that this same client actually starts working when I log in the WSO2 ESB and click on the service I've mapped there. And it throws exception when I don't use the service for some time.

This issue really puzzles me. What can be the cause of it?

EDIT: Clarification, the code on line 77 is the for loop. It seems the codelists object is null.

EDIT: Here's the method that adds the security header to the request.

public boolean handleMessage(SOAPMessageContext messageContext) {
    Boolean isOutboundMessage = (Boolean) messageContext
            .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (isOutboundMessage) {
        SOAPPart messageSoapPart = messageContext.getMessage()
                .getSOAPPart();

        WSSecHeader securityHeader = new WSSecHeader();
        securityHeader.insertSecurityHeader(messageSoapPart);

        WSSecUsernameToken usernameToken = new WSSecUsernameToken();

        usernameToken.setPasswordType(WSConstants.PASSWORD_TEXT);
        usernameToken.setUserInfo(USER_NAME, PASSWORD);

        WSSecTimestamp timestamp = new WSSecTimestamp();

        usernameToken.build(messageSoapPart, securityHeader);
        timestamp.build(messageSoapPart, securityHeader);
    }

    return true;
}

And here is what the request looks like (taken from console)

    ---[HTTP request]---
SOAPAction: "urn:_getcodelists"
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type: text/xml;charset="utf-8"
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" S:mustUnderstand="1"><wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-11800260"><wsu:Created>2012-09-18T13:17:56.707Z</wsu:Created><wsu:Expires>2012-09-18T13:22:56.707Z</wsu:Expires></wsu:Timestamp><wsse:UsernameToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-9299042"><wsse:Username>admin</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password></wsse:UsernameToken></wsse:Security></S:Header><S:Body></S:Body></S:Envelope>--------------------
---[HTTP response 202]---
Transfer-encoding: chunked
null: HTTP/1.1 202 Accepted
Connection: keep-alive
Server: Synapse-HttpComponents-NIO
Date: Tue, 18 Sep 2012 13:19:57 GMT

Solution

  • I think it is because your session timed out and you needed to log in again to authenticate the service.