Apache CXF 客户端在 Eclipse 中加载良好,但独立 jar 在 WSDLServiceFactory 中抛出 NullpointerException [英] Apache CXF client loads fine in Eclipse but standalone jar throws NullpointerException in WSDLServiceFactory

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

问题描述

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

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 插件.有关示例,请参阅 CXF 捆绑包 jar 的 pom.xml.

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.

http://svn.apache.org/repos/asf/cxf/主干/osgi/bundle/all/

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆