#java #web-services #soap #nullpointerexception #jax-ws
#java #веб-службы #soap #исключение nullpointerexception #jax-ws
Вопрос:
Я пишу веб-службу JAX-WS. Когда я запускаю свой клиентский код удаленного веб-сервиса, я получаю следующую ошибку:
Исключение в потоке «main» com.sun.xml.internal.ws.fault.Исключение ServerSOAPFaultException: клиент получил ошибку SOAP от сервера: java.lang.NullPointerException Пожалуйста, ознакомьтесь с журналом сервера, чтобы найти более подробную информацию о точной причине сбоя. в com.sun.xml.internal.ws.ошибка.SOAP11Fault.getProtocolException(SOAP11Fault.java:178) по адресу com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java: 116) в com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:238) в com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189 ) в com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276) в com.sun.xml.internal.ws.client.sei.SyncMethod Handler.invoke(SyncMethod handler.java:104) в com.sun.xml.internal.ws.client.sei.SyncMethod handler.invoke(SyncMethod handler.java:77) в com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147) в com.sun.proxy.$Proxy40.getShoes(неизвестный источник) в org.example.shoesshop.client.ShoesServiceClient.main(ShoesServiceClient.java:32)
Вот код удаленного клиента веб-службы:
public class ShoesServiceClient {
public static void main(String[] args) throws MalformedURLException, ShoesNotFound_Exception{
System.setProperty("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", "true");
System.setProperty("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", "true");
URL wsdl = new URL("file:///" new File("").getAbsolutePath() "/shoesservice.wsdl");
ShoesServiceImpl service = new ShoesService(wsdl).getShoesPort();
service.getShoes(1); // ShoesServiceClient.java:32 is here
}
}
Также совместно используется код издателя веб-службы (адрес localhost: 8080 / shoesservice)
public class ShoesServicePublisher {
public static void main(String[] args) {
final String addr = "http://localhost:8080/shoesservice";
final Object impl = new ShoesServiceImpl();
Endpoint shoesPub = Endpoint.publish(addr, impl);
Scanner sc = new Scanner(System.in);
sc.nextLine();
sc.close();
shoesPub.stop();
}
}
Вот изображение конфигурации монитора TCP / IP
Конфигурация монитора TCP / IP
Wsdl-файл имеет следующую структуру (он хранится в папке моего проекта)
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://shoeshop.example/jaxws/shoes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://shoeshop.example/jaxws/shoes" name="Shoes">
<types>
<xsd:schema>
<xsd:import namespace="http://www.example.org/ShoesShop" schemaLocation="http://localhost:8080/shoesservice?xsd=1"></xsd:import>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://shoeshop.example/jaxws/shoes" schemaLocation="http://localhost:8080/shoesservice?xsd=2"></xsd:import>
</xsd:schema>
</types>
<message name="getShoes">
<part name="parameters" element="tns:getShoes"></part>
</message>
<message name="getShoesResponse">
<part name="parameters" element="tns:getShoesResponse"></part>
</message>
<message name="ShoesNotFound">
<part name="fault" element="tns:ShoesNotFound"></part>
</message>
<message name="getAllShoes">
<part name="parameters" element="tns:getAllShoes"></part>
</message>
<message name="getAllShoesResponse">
<part name="parameters" element="tns:getAllShoesResponse"></part>
</message>
<message name="updateShoes">
<part name="parameters" element="tns:updateShoes"></part>
</message>
<message name="updateShoesResponse">
<part name="parameters" element="tns:updateShoesResponse"></part>
</message>
<message name="addShoes">
<part name="parameters" element="tns:addShoes"></part>
</message>
<message name="addShoesResponse">
<part name="parameters" element="tns:addShoesResponse"></part>
</message>
<message name="ShoesAlreadyExists">
<part name="fault" element="tns:ShoesAlreadyExists"></part>
</message>
<message name="deleteShoes">
<part name="parameters" element="tns:deleteShoes"></part>
</message>
<message name="deleteShoesResponse">
<part name="parameters" element="tns:deleteShoesResponse"></part>
</message>
<message name="countShoes">
<part name="parameters" element="tns:countShoes"></part>
</message>
<message name="countShoesResponse">
<part name="parameters" element="tns:countShoesResponse"></part>
</message>
<portType name="ShoesServiceImpl">
<operation name="getShoes">
<input wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/getShoesRequest" message="tns:getShoes"></input>
<output wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/getShoesResponse" message="tns:getShoesResponse"></output>
<fault message="tns:ShoesNotFound" name="ShoesNotFound" wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/getShoes/Fault/ShoesNotFound"></fault>
</operation>
<operation name="getAllShoes">
<input wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/getAllShoesRequest" message="tns:getAllShoes"></input>
<output wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/getAllShoesResponse" message="tns:getAllShoesResponse"></output>
</operation>
<operation name="updateShoes">
<input wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/updateShoesRequest" message="tns:updateShoes"></input>
<output wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/updateShoesResponse" message="tns:updateShoesResponse"></output>
<fault message="tns:ShoesNotFound" name="ShoesNotFound" wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/updateShoes/Fault/ShoesNotFound"></fault>
</operation>
<operation name="addShoes">
<input wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/addShoesRequest" message="tns:addShoes"></input>
<output wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/addShoesResponse" message="tns:addShoesResponse"></output>
<fault message="tns:ShoesAlreadyExists" name="ShoesAlreadyExists" wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/addShoes/Fault/ShoesAlreadyExists"></fault>
</operation>
<operation name="deleteShoes">
<input wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/deleteShoesRequest" message="tns:deleteShoes"></input>
<output wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/deleteShoesResponse" message="tns:deleteShoesResponse"></output>
<fault message="tns:ShoesNotFound" name="ShoesNotFound" wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/deleteShoes/Fault/ShoesNotFound"></fault>
</operation>
<operation name="countShoes">
<input wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/countShoesRequest" message="tns:countShoes"></input>
<output wsam:Action="http://shoeshop.example/jaxws/shoes/ShoesServiceImpl/countShoesResponse" message="tns:countShoesResponse"></output>
</operation>
</portType>
<binding name="ShoesPortBinding" type="tns:ShoesServiceImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="getShoes">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
<fault name="ShoesNotFound">
<soap:fault name="ShoesNotFound" use="literal"></soap:fault>
</fault>
</operation>
<operation name="getAllShoes">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
<operation name="updateShoes">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
<fault name="ShoesNotFound">
<soap:fault name="ShoesNotFound" use="literal"></soap:fault>
</fault>
</operation>
<operation name="addShoes">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
<fault name="ShoesAlreadyExists">
<soap:fault name="ShoesAlreadyExists" use="literal"></soap:fault>
</fault>
</operation>
<operation name="deleteShoes">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
<fault name="ShoesNotFound">
<soap:fault name="ShoesNotFound" use="literal"></soap:fault>
</fault>
</operation>
<operation name="countShoes">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="Shoes">
<port name="ShoesPort" binding="tns:ShoesPortBinding">
<soap:address location="http://localhost:18080/shoesservice"></soap:address>
</port>
</service>
</definitions>
When I launch the TCP/IP Monitor with running Remote Web Service Client code, I get the next messages in XML format:
Request Message
<?xml version="1.0" standalone="no"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:getShoes xmlns:ns2="http://www.example.org/ShoesShop" xmlns:ns3="http://shoeshop.example/jaxws/shoes">
<arg0>1</arg0>
</ns3:getShoes>
</S:Body>
</S:Envelope>
Response Message
<?xml version="1.0" standalone="no"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>java.lang.NullPointerException</faultstring>
</S:Fault>
</S:Body>
</S:Envelope>
Вот код класса ShoesService:
@WebServiceClient(name = "Shoes", targetNamespace = "http://shoeshop.example/jaxws/shoes", wsdlLocation = "http://localhost:8080/shoesservice?wsdl")
public class ShoesService
extends Service
{
private final static URL SHOES_WSDL_LOCATION;
private final static WebServiceException SHOES_EXCEPTION;
private final static QName SHOES_QNAME = new QName("http://shoeshop.example/jaxws/shoes", "Shoes");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://localhost:8080/shoesservice?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
SHOES_WSDL_LOCATION = url;
SHOES_EXCEPTION = e;
}
public ShoesService() {
super(__getWsdlLocation(), SHOES_QNAME);
}
public ShoesService(WebServiceFeature... features) {
super(__getWsdlLocation(), SHOES_QNAME, features);
}
public ShoesService(URL wsdlLocation) {
super(wsdlLocation, SHOES_QNAME);
}
public ShoesService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, SHOES_QNAME, features);
}
public ShoesService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public ShoesService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
@WebEndpoint(name = "ShoesPort")
public ShoesServiceImpl getShoesPort() {
return super.getPort(new QName("http://shoeshop.example/jaxws/shoes", "ShoesPort"), ShoesServiceImpl.class);
}
@WebEndpoint(name = "ShoesPort")
public ShoesServiceImpl getShoesPort(WebServiceFeature... features) {
return super.getPort(new QName("http://shoeshop.example/jaxws/shoes", "ShoesPort"), ShoesServiceImpl.class, features);
}
private static URL __getWsdlLocation() {
if (SHOES_EXCEPTION!= null) {
throw SHOES_EXCEPTION;
}
return SHOES_WSDL_LOCATION;
}
}
Кроме того, совместное использование кода класса GetShoes:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getShoes", propOrder = {
"arg0"
})
public class GetShoes {
protected int arg0;
public int getArg0() {
return arg0;
}
public void setArg0(int value) {
this.arg0 = value;
}
}
и получает класс ответа
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getShoesResponse", propOrder = {
"_return"
})
public class GetShoesResponse {
@XmlElement(name = "return")
protected Shoes _return;
public Shoes getReturn() {
return _return;
}
public void setReturn(Shoes value) {
this._return = value;
}
}
Если вам нужна дополнительная информация, пожалуйста, дайте мне знать
Комментарии:
1. У меня точно такая же проблема, но здесь нет ответа
2. То же самое для меня… вы поняли это?