Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA JAX-WS NullPointerException at javax.xml.ws.Service.getPort(Service.java:188)

I have simple "HelloWorld" web service deployed on jboss under ubuntu. I have created simple client, but I can't get it to work. I'm getting NullPointerException each time I run the client.

Note that I'm running on Oracle Java 7 under Ubuntu.

Here is the code: HelloWorldClient.java

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

import javax.xml.namespace.QName;
import javax.xml.ws.Service;


public class HelloWorldClient {

public static void main(String[] args){
    URL url;
    try {
        url = new URL("http://localhost:8080/WebServiceProject/helloWorld?wsdl");
        QName qname = new QName("http:///", "HelloWorldImplService");

        Service service = Service.create(url, qname);

        HelloWorld hello = service.getPort(HelloWorld.class);

         System.out.println(hello.sayHello("mkyong"));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}

HelloWorld.java

import javax.jws.WebMethod;
import javax.jws.WebService;


@WebService
public interface HelloWorld {

    @WebMethod
    public String sayHello(String name);

}

Stacktrace:

Exception in thread "main" java.lang.NullPointerException
at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1407)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:334)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:354)
at javax.xml.ws.Service.getPort(Service.java:188)
at HelloWorldClient.main(HelloWorldClient.java:18)

The exception is thrown at this line:

HelloWorld hello = service.getPort(HelloWorld.class);
like image 824
Bladositto Avatar asked Jun 01 '13 11:06

Bladositto


1 Answers

I have had the same problem myself for a few days now, because the WSDL-file (and service) I was using was moved to a new URL. I finally found the solution here:

http://techtracer.com/2007/08/15/jax-ws-jaxp-tutorial-building-a-stockquote-web-service-client/

In short, everything (should have) started working after I re-generated all the auto-generated java and class files with the following command (on Windows/CygWin)

"C:/Program Files/Java/jdk1.8.0_31/bin/wsimport.exe" -keep  https://domain.com/path_to_wsdl

I had some extra trouble because some old files were left around and clashing with the newly generated ones, but everything slowly started working after I moved all the old files to the recycle bin.

like image 79
Rune Avatar answered Sep 20 '22 00:09

Rune