Ho un semplice servizio Web "HelloWorld" distribuito su jboss sotto ubuntu. Ho creato un client semplice, ma non riesco a farlo funzionare. Ricevo NullPointerException ogni volta che eseguo il client.JAVA JAX-WS NullPointerException su javax.xml.ws.Service.getPort (Service.java:188)
Nota che sono in esecuzione su Oracle Java 7 su Ubuntu.
Ecco il codice: 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)
L'excepti on è gettato in questa linea:
HelloWorld hello = service.getPort(HelloWorld.class);
Solo un breve commento e forse completamente irrilevante per il tuo problema, ma il tuo 'QName' ha un extra'/'. È un errore di battitura? –
@SamRad potrebbe essere rilevante. Spiegherei perché 'service' potrebbe essere nullo – kolossus
Non c'è nessun"/"extra. Scrivi url come "http: // something /". In questo caso non c'è "qualcosa". Anche il servizio non è nullo. Guarda lo stacktrace – Bladositto