java web-services cxf webservice-client

java - El cliente Apache CXF se carga bien en Eclipse, pero el frasco independiente lanza NullpointerException en WSDLServiceFactory



web-services webservice-client (4)

Ampliando la respuesta de @DankkKulp, que funcionó muy bien para mí con CXF 2.7.7 (en caso de que el enlace muera). Configure su complemento de sombra con los siguientes transformadores adicionales:

<configuration> <transformers> <!-- transformers for CXF (see http://stackoverflow.com/a/9069435/61298) --> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/services/com.sun.tools.xjc.Plugin</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/cxf/cxf.extension</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/extensions.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/cxf/extensions.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/cxf/bus-extensions.txt</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/cxf/bus-extensions.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/wsdl.plugin.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/tools.service.validator.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/cxf/java2wsbeans.xml</resource> </transformer> </transformers> </configuration>

Mi objetivo es crear un cliente de servicio web que se ejecute en un jar independiente con todas las dependencias usando mvn assembly: single

Generé el cliente utilizando CXF codegen wsdl2java, creando un @WebServiceClient llamado NetBanxAutostatementService

Para las dependencias que tengo.

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

desesperadamente incluso traté de agregar más "cosas"

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

El problema: cada vez que intento ejecutar "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)

Esto sucede en la línea que invoca a WebServiceClient autostatementService = new NetBanxAutostatementService (autostatement_wsdlLocation); Sé por la línea de registro que no estoy pasando autostatement_wsdlLocation como nulo

Código de 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);

}


Como complemento a la respuesta de @Matt R, reemplacé la parte de POM con el complemento de montaje de maven con este código:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.xxx.App</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <!-- transformers for CXF (see http://.com/a/9069435/61298) --> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/services/com.sun.tools.xjc.Plugin</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/spring.schemas</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/cxf/cxf.extension</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/extensions.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/cxf/extensions.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/cxf/bus-extensions.txt</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/cxf/bus-extensions.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/wsdl.plugin.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/tools.service.validator.xml</resource> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> <resource>META-INF/cxf/java2wsbeans.xml</resource> </transformer> </transformers> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin>

La parte excluir es evitar tener problemas de seguridad de Java.



Lo más probable es que estés creando tu único frasco. Un uso normal del complemento de ensamblaje no permitiría que varias partes de CXFs META-INF / * tuvieran que fusionarse. Eso incluiría todo el / META-INF / spring * y muchas de las cosas en / META-INF / cxf / * Yo sugeriría usar el complemento de sombra para eso. Vea el pom.xml para ver el paquete de CXF para ver un ejemplo.

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