Apache CXF 客户端在 Eclipse 中加载良好,但独立 jar 在 WSDLServiceFactory 中抛出 NullpointerException
2022-09-02 11:18:39
我的目标是创建一个Web服务客户端,该客户端在一个独立的jar中运行,所有依赖项都使用mvn assembly:single
我使用CXF codegen wsdl2java生成了客户端,创建了一个名为NetBanxAutostatementService@WebServiceClient。
对于我拥有的依赖项
<cxf.version>2.5.2</cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
<scope>runtime</scope>
</dependency>
我甚至拼命地试图添加更多的“东西”。
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>2.5.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf</artifactId>
<version>2.5.2</version>
<type>pom</type>
<scope>runtime</scope>
</dependency>
问题:每次我尝试运行“java -jar target/Netbanx-0.0.1-SNAPSHOT-jar-with-dependencies.jar”
INFO [main] (Netbanx.java:97) - autostatement_wsdlLocation:https://www.test.netbanx.com/cgi-bin/autostatement_wsdl
Exception in thread "main" java.lang.NullPointerException
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:91)
at javax.xml.ws.Service.<init>(Service.java:56)
at com.netbanx.autostatement.NetBanxAutostatementService.<init> (NetBanxAutostatementService.java:39)
at my.project.netbanx.Netbanx.<init>(Netbanx.java:98)
at my.project.netbanx.Netbanx.main(Netbanx.java:130)
这发生在调用WebServiceClient autostatementService = new NetBanxAutostatementService(autostatement_wsdlLocation)的行中;我通过日志行知道我没有将autostatement_wsdlLocation作为空值传递
Java 代码:
URL autostatement_wsdlLocation = null;
URL payment_wsdlLocation = null;
try {
autostatement_wsdlLocation = new URL(properties.getProperty("autostatement_wsdlLocation"));
payment_wsdlLocation = new URL(properties.getProperty("payment_wsdlLocation"));
} catch (MalformedURLException e) {
logger.error("MalformedURLException",e);
}
/**
* Load the Netbanx's webservices AutostatementService and PaymentService
*/
try {
logger.info("autostatement_wsdlLocation:"+autostatement_wsdlLocation.toString());
autostatementService = new NetBanxAutostatementService(autostatement_wsdlLocation); //it is here I get the NullPointerException error
logger.info("payment_wsdlLocation:"+payment_wsdlLocation.toString());
paymentService = new NetBanxPaymentService(payment_wsdlLocation);
webServiceStarted = true;
} catch(javax.xml.ws.WebServiceException wsException ){
String error = "Cannot create NetBanx web service please make sure this host can reach:" + autostatement_wsdlLocation +" and " + payment_wsdlLocation;
logger.error(error);
logger.error("WebServiceException",wsException);
}