SDLServiceFactory中抛出NullpointerE

SDLServiceFactory中抛出NullpointerE

本文介绍了Apache CXF客户端在Eclipse中加载正常,但独立的jar在WSDLServiceFactory中抛出NullpointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是创建一个Web服务客户端,该客户端使用mvn程序集在所有依赖项的独立jar中运行:single

My goal is to create a Web Service client that runs in a standalone jar with all the dependencies using mvn assembly:single

我使用CXF codegen生成客户端wsdl2java ,创建一个名为NetBanxAutostatementService的@WebServiceClient

I generated the client using CXF codegen wsdl2java, creating a @WebServiceClient called NetBanxAutostatementService

对于我有的依赖项

<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>

我甚至试图添加更多东西

desperately I even tried to add more "stuff"

    <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

The problem: everytime I try to run "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传递为null

This happens in the line that invokes the WebServiceClient autostatementService = new NetBanxAutostatementService(autostatement_wsdlLocation);I know by the log line that I am not passing autostatement_wsdlLocation as null

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);

}

推荐答案

很可能是你创建单个jar的方式。正常使用程序集插件不允许这样,因为需要将CXF的各种部分META-INF / *东西合并在一起。这将包括所有的/ META-INF / spring *以及/ META-INF / cxf / *中的大部分内容我建议使用shade插件。有关示例,请参阅pom.xml以获取CXF的bundle jar。

Most likely it's how you are creating your single jar. A normal usage of the assembly plugin would not allow that as various parts of CXFs META-INF/* stuff would need to be merged together. That would include all the /META-INF/spring* and much of the stuff in /META-INF/cxf/* I would suggest using the shade plugin for that. See the pom.xml for CXF's bundle jar for an example.

这篇关于Apache CXF客户端在Eclipse中加载正常,但独立的jar在WSDLServiceFactory中抛出NullpointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:27