【发布时间】:2015-12-19 15:25:44
【问题描述】:
我有多年来在 Java 6 中成功运行的 JaxWS Web 服务客户端。现在当 Java 升级到版本 8 时,我们在获取端口时得到 NullPointerException
java.lang.NullPointerException
at com.sun.xml.internal.ws.client.ClientContainer$1.getResource(Unknown Source)
at com.sun.xml.internal.ws.assembler.MetroConfigLoader.locateResource(Unknown Source)
at com.sun.xml.internal.ws.assembler.MetroConfigLoader.locateResource(Unknown Source)
at com.sun.xml.internal.ws.assembler.MetroConfigLoader.init(Unknown Source)
at com.sun.xml.internal.ws.assembler.MetroConfigLoader.<init>(Unknown Source)
at com.sun.xml.internal.ws.assembler.TubelineAssemblyController.getTubeCreators(Unknown Source)
at com.sun.xml.internal.ws.assembler.MetroTubelineAssembler.createClient(Unknown Source)
at com.sun.xml.internal.ws.client.Stub.createPipeline(Unknown Source)
at com.sun.xml.internal.ws.client.Stub.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.Stub.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.Stub.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.sei.SEIStub.<init>(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getStubHandler(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source)
at javax.xml.ws.Service.getPort(Unknown Source)
at myclient.stub.MyService.<init>(MyService.java:38)
我尝试使用 Java 7 版本 1.7.0_80 运行它,它也可以工作,但 Java 8 的第一个版本会导致此异常。
我已经为此烦恼了很长一段时间,所以如果有人能给我任何线索,从哪里开始解决这个问题,那就太好了。
这是 WSDL,我对其进行了一些编辑,因为它不是我的服务,但希望它足够了吗?
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<wsdl:definitions xmlns:ns1="http://www.dummyservice/sample/interface" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Sample"
targetNamespace="http://www.dummyservice/sample/interface">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
targetNamespace="http://www.dummyservice/sample/interface" xmlns="http://www.dummyservice/sample/interface"
elementFormDefault="qualified" jaxb:version="2.0">
<xs:element name="PersonQuery">
<xs:complexType>
<xs:sequence>
<xs:element name="system" type="xs:string" />
<xs:element name="user" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PersonReply">
<xs:complexType>
<xs:sequence>
<xs:element name="Header" type="HeaderType" />
<xs:element name="person" type="PersonType" minOccurs="0" maxOccurs="1" />
<xs:element name="address" type="AddressType" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="HeaderType">
<xs:sequence>
<xs:element name="tila" type="StatusType" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="StatusType">
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumClass>
<jaxb:typesafeEnumMember name="SUCCESS" value="0001" />
<jaxb:typesafeEnumMember name="FAIL" value="0000" />
</jaxb:typesafeEnumClass>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="0000" />
<xs:enumeration value="0001" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element name="firstname" type="xs:string" minOccurs="0" />
<xs:element name="lastname" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="AddressType">
<xs:sequence>
<xs:element name="addresstype" type="AddresstypeType" minOccurs="0" />
<xs:element name="streetaddress" type="xs:string" minOccurs="0" />
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="postalcode" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="AddresstypeType">
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumClass>
<jaxb:typesafeEnumMember name="HOME" value="001" />
<jaxb:typesafeEnumMember name="OFFICE" value="002" />
</jaxb:typesafeEnumClass>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="001" />
<xs:enumeration value="002" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
</wsdl:types>
<wsdl:message name="PersonQueryOperationRequest">
<wsdl:part element="ns1:PersonQuery" name="parameters" />
</wsdl:message>
<wsdl:message name="PersonQueryOperationResponse">
<wsdl:part element="ns1:PersonReply" name="parameters" />
</wsdl:message>
<wsdl:portType name="SamplePort">
<wsdl:operation name="PersonQueryOperation">
<wsdl:input message="ns1:PersonQueryOperationRequest" />
<wsdl:output message="ns1:PersonQueryOperationResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SampleSOAP" type="ns1:SamplePort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="PersonQueryOperation">
<soap:operation soapAction="http://www.dummyservice/sample/interface/SampleOperation" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SampleService">
<wsdl:port binding="ns1:SampleSOAP" name="Sample">
<soap:address location="https://127.0.0.1/data/ws" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
编辑:类加载似乎是问题,上下文类加载器和类的类加载器在那个 ClientContainer 中都是空的。
private final ResourceLoader loader = new ResourceLoader() {
public URL More ...getResource(String resource) throws MalformedURLException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = this.getClass().getClassLoader();
}
return cl.getResource("META-INF/"+resource);
}
};
当我们在调用 ws call 之前将系统类加载器显式设置为上下文类加载器时,它开始工作。但是,这是很好的解决方法吗?我想知道为什么这在 Java8 中停止工作,这可能是他们的 ws 实现中的问题吗?
问候,
珍妮
【问题讨论】:
-
您能否编辑您的问题以包含您的 WSDL,以便我们尝试重新创建问题?
-
我已包含 WSDL,我必须对其进行编辑以将其与原始文件区分开来,但希望没问题。
-
看起来that method 可以抛出 NullPointerException 的唯一方法是在系统 ClassLoader 加载类时(因为Java is allowed to return null to indicate the system ClassLoader)。你在什么操作系统上运行?您是否尝试过使用最新版本的 Java?
-
此问题出现在 Windows Server 2008 R2 环境中。我试过 1.8.0_60,如果我记得是最新的可用版本。我们的 Java 是通过 JNI 从用 C 编写的应用程序中使用的。现在,如果我从 Eclipse 中的单元测试中运行相同的 jar,它可以完美运行。
标签: java web-services java-8 jax-ws