Abhishek
Abhishek

Reputation: 297

WSO2 webservice null pointer exception

I am using below given command to generate wso2 client for a WSO2 webservice

wsimport -keep -verbose https://svn.wso2.org/repos/wso2/people/asela/user-mgt/jaxws/RemoteUserStoreManagerService.wsdl

I generated this client using JAVA 1.8.0_112. When i tried to invoke client by specifying the WSDL LOCATION using the generated method constructor(URL url) I am getting below exception:

Exception in thread "main" java.lang.NullPointerException
    at com.sun.xml.internal.ws.model.JavaMethodImpl.freeze(JavaMethodImpl.java:379)
    at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.freeze(AbstractSEIModelImpl.java:105)
    at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:320)
    at com.sun.xml.internal.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:85)
    at com.sun.xml.internal.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:59)
    at com.sun.xml.internal.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:43)
    at com.sun.xml.internal.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:105)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.buildRuntimeModel(WSServiceDelegate.java:875)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:892)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:855)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:435)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:404)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:386)
    at javax.xml.ws.Service.getPort(Service.java:119)
    at org.wso2.carbon.um.ws.service.RemoteUserStoreManagerService.getRemoteUserStoreManagerServiceHttpSoap11Endpoint(RemoteUserStoreManagerService.java:72)
    at org.wso2.carbon.test.TestUserLogin.main(TestUserLogin.java:15)

I am using wso2 identity server - 5.2.0 version. IT is also running on JAVA 1.8.0_112. My code to invoke client is -

package org.wso2.carbon.test;

import java.net.MalformedURLException;
import java.net.URL;

import org.wso2.carbon.um.ws.service.RemoteUserStoreManagerService;
import org.wso2.carbon.um.ws.service.RemoteUserStoreManagerServicePortType;
import org.wso2.carbon.um.ws.service.RemoteUserStoreManagerServiceUserStoreException_Exception;

public class TestUserLogin {
    public static void main(String args[]) throws MalformedURLException, RemoteUserStoreManagerServiceUserStoreException_Exception {
        RemoteUserStoreManagerService rus = 
                new RemoteUserStoreManagerService(new URL("https://ril15066yjb152:9443/services/RemoteUserStoreManagerService?wsdl"));

        RemoteUserStoreManagerServicePortType rusm = rus.getRemoteUserStoreManagerServiceHttpSoap11Endpoint();

        System.out.println(rusm.authenticate("admin", "admin"));
    }

} 

My RemoteUserStoreManagerService class is -

package org.wso2.carbon.um.ws.service;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.9-b130926.1035
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name = "RemoteUserStoreManagerService", targetNamespace = "http://service.ws.um.carbon.wso2.org", wsdlLocation = "https://svn.wso2.org/repos/wso2/people/asela/user-mgt/jaxws/RemoteUserStoreManagerService.wsdl")
public class RemoteUserStoreManagerService
    extends Service
{

    private final static URL REMOTEUSERSTOREMANAGERSERVICE_WSDL_LOCATION;
    private final static WebServiceException REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION;
    private final static QName REMOTEUSERSTOREMANAGERSERVICE_QNAME = new QName("http://service.ws.um.carbon.wso2.org", "RemoteUserStoreManagerService");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("https://svn.wso2.org/repos/wso2/people/asela/user-mgt/jaxws/RemoteUserStoreManagerService.wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        REMOTEUSERSTOREMANAGERSERVICE_WSDL_LOCATION = url;
        REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION = e;
    }

    public RemoteUserStoreManagerService() {
        super(__getWsdlLocation(), REMOTEUSERSTOREMANAGERSERVICE_QNAME);
    }

    public RemoteUserStoreManagerService(WebServiceFeature... features) {
        super(__getWsdlLocation(), REMOTEUSERSTOREMANAGERSERVICE_QNAME, features);
    }

    public RemoteUserStoreManagerService(URL wsdlLocation) {
        super(wsdlLocation, REMOTEUSERSTOREMANAGERSERVICE_QNAME);
    }

    public RemoteUserStoreManagerService(URL wsdlLocation, WebServiceFeature... features) {
        super(wsdlLocation, REMOTEUSERSTOREMANAGERSERVICE_QNAME, features);
    }

    public RemoteUserStoreManagerService(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public RemoteUserStoreManagerService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     * 
     * @return
     *     returns RemoteUserStoreManagerServicePortType
     */
    @WebEndpoint(name = "RemoteUserStoreManagerServiceHttpSoap11Endpoint")
    public RemoteUserStoreManagerServicePortType getRemoteUserStoreManagerServiceHttpSoap11Endpoint() {
        return super.getPort(new QName("http://service.ws.um.carbon.wso2.org", "RemoteUserStoreManagerServiceHttpsSoap11Endpoint"), RemoteUserStoreManagerServicePortType.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns RemoteUserStoreManagerServicePortType
     */
    @WebEndpoint(name = "RemoteUserStoreManagerServiceHttpSoap11Endpoint")
    public RemoteUserStoreManagerServicePortType getRemoteUserStoreManagerServiceHttpSoap11Endpoint(WebServiceFeature... features) {
        return super.getPort(new QName("http://service.ws.um.carbon.wso2.org", "RemoteUserStoreManagerServiceHttpSoap11Endpoint"), RemoteUserStoreManagerServicePortType.class, features);
    }

    private static URL __getWsdlLocation() {
        if (REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION!= null) {
            throw REMOTEUSERSTOREMANAGERSERVICE_EXCEPTION;
        }
        return REMOTEUSERSTOREMANAGERSERVICE_WSDL_LOCATION;
    }

}

Upvotes: 0

Views: 999

Answers (1)

Jorge Infante Osorio
Jorge Infante Osorio

Reputation: 2153

Try this code to remove the NPE:

    RemoteUserStoreManagerService rus =
            new RemoteUserStoreManagerService();

    RemoteUserStoreManagerServicePortType rusm = rus.getRemoteUserStoreManagerServiceHttpsSoap11Endpoint();
    ((BindingProvider) rusm).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    org.apache.cxf.endpoint.Client client = ClientProxy
            .getClient(rusm);

    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.getAuthorization().setUserName("admin");
    http.getAuthorization().setPassword("admin");

    System.out.println("User authenticate? " + rusm.authenticate("admin", "admin"));
    List<String> listUsers = rusm.listUsers("*", 100);
    for (String user : listUsers) {
        System.out.println("User: " + user);

    }

UPDATE 1: Also you need to update the WSDL with this port in the service section:

    <wsdl:port name="RemoteUserStoreManagerServiceHttpsSoap11Endpoint" binding="ns:RemoteUserStoreManagerServiceSoap11Binding">
        <soap:address location="https://localhost:9443/services/RemoteUserStoreManagerService.RemoteUserStoreManagerServiceHttpsSoap11Endpoint/"/>
    </wsdl:port>

UPDATE 2: Added http basic authentication before validate user authentication. check the code above.

My client response:

User authenticate? true
User: WSO2.ORG/admin
User: WSO2.ORG/isildurmac

Upvotes: 3

Related Questions