Null Pointer Exception in WSDServiceFactory - Apache CXF libs - java

I have an problem with my code. The WSDL file was parsed by wsdl2java from apache cxf. Now I'm trying to get connection with web service but still I'm getting null pointer exception.
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:203)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:97)
at javax.xml.ws.Service.<init>(Service.java:56)...
The url address is pointing to place from where I have downloaded the WSDL file. For building jar I'm using Maven with dependencies such as:
jaxws-api
cxf-rt-transports-http
cxf-rt-frontend-jaxws
cxf-rt-bindings-soap
jar with deps is created by maven-assembly-plugin
For sure the wsdl file exists there because it have been downloaded from there.
Any suggestions? Thanks for any help.
BTW. It's not duplicated question any of solution which I have found does not work for me.

I ran into the same issue using shadowJar in gradle. The solution is to explicitly merge bus-extensions.txt service files in the META-INF/cxf/ directory:
shadowJar {
archiveName = 'application.jar'
mergeServiceFiles{
path='META-INF/cxf'
}
}

Instead using maven-assembly-plugin when deploying Java app that depends on Apache CXF libs, I have used maven-dependency-plugin with goal set to copy-dependencies. That will not produce single JAR, but will copy all required JARs into target/ folder. It is then easy to put them all in class path and start Java app.

The soloution is quite simple, I just changed the version of Apache CXF lib to older one, and it works. So probably I had a problem in my configuration or Apache CXF have a bug.
So as a solution just check the older version of provided lib.

Related

Akka: unable to read configuration in karaf

I am using Akka actors for Remote communication in karaf.
When I deploy the jar file generated after compiling using maven, I get the following error:
Exception in thread "Thread-113"
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:152)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:170)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:176)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:184)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:189)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:246)
at akka.actor.ActorSystem$Settings.(ActorSystem.scala:168)
at akka.actor.ActorSystemImpl.(ActorSystem.scala:522)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:142)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:119)
at org.opendaylight.com.test.rem$$anon$1.run(rem.scala:19)
I even added Maven shade plugin in the pom file which was suggested in other answers, but adding the plugin makes all the karaf features to change to ''Resolved'' state. The configuration file for akka is in the classpath too. As of my knowledge, the akka configuration file is not being read at all, as I got the same exception even after removing the configuration file.
This error is most often caused by combining multiple Akka jars into a single super-jar and not handling the reference.conf files correctly. The reference.conf file in each of the Akka module jar-files needs to be concatenated into a single file in the super jar.
Follow the instructions in the docs here: https://doc.akka.io/docs/akka/current/scala/general/configuration.html#when-using-jarjar-onejar-assembly-or-any-jar-bundler
And then verify that the jar-file you use when running has the contents of all those reference.conf files concatenated into a single file.

org.apache.cxf.bus.extension.ExtensionException in WAS9 server

Can you please help me with following error I'm facing in WAS9 environment:
In order to resolve the import
org.apache.cxf.binding.soap.SoapHeader
I added the following dependencies in my pom.xml:
cxf-api-2.7.7
cxf-rt-bindings-soap-2.7.7
But when I'm trying to run my application, I'm getting the following error.
Default Executor-thread-7] ([ ]) Controllerclass - org.apache.cxf.bus.extension.ExtensionException
at org.apache.cxf.bus.extension.Extension.load(Extension.java:222)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.loadAndRegister(ExtensionManagerImpl.java:199)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.initialize(ExtensionManagerImpl.java:118)
at org.apache.cxf.bus.extension.ExtensionManagerBus.doInitializeInternal(ExtensionManagerBus.java:147)
at org.apache.cxf.bus.CXFBusImpl.initialize(CXFBusImpl.java:191)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createBus(LibertyApplicationBusFactory.java:119)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createClientScopedBus(LibertyApplicationBusFactory.java:86)
at com.ibm.ws.jaxws.metadata.JaxWsClientMetaData.<init>(JaxWsClientMetaData.java:28)
at com.ibm.ws.jaxws.metadata.JaxWsModuleMetaData.getClientMetaData(JaxWsModuleMetaData.java:123)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:84)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:123)
at com.ibm.ws.jaxws.client.LibertyProviderImpl.createServiceDelegate(LibertyProviderImpl.java:56)
at javax.xml.ws.Service.<init>(Service.java:57)
Caused by: java.lang.InstantiationException:org.apache.cxf.bus.osgi.OSGIBusListener
at java.lang.Class.newInstance(Class.java:427)
at org.apache.cxf.bus.extension.Extension.load(Extension.java:218)
Caused by: java.lang.NoSuchMethodException:org.apache.cxf.bus.osgi.OSGIBusListener.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
The server where your WAS9 has been deployed has different version of the above jar file. You need to have same version of jar files both in your eclipse where you have developed your codes and the server where you are deploying the war or ear.
mavan dependency file pom.xml is used during your project compilation. It might add the jar in your binary under lib folder as well. But WAS9 might considering the one which is in server's CLASSPATH. Hence check your class path and replace that jar with the one which you have mentioned in your pom.xml file. Hope that will fix your issue.
We can eliminate this exception by adding webProfile-7.0 in our server.xml, but how ever this is not working with javaee-7.0 not sure, if one knows about how to handle this in javaee-7.0 please share your approach.

Apache Cayenne "DI container has no binding for key ObjectContextFactory" error

I'm using Apache 4.0 BETA and I'm getting the following runtime error:
org.apache.cayenne.di.DIRuntimeException: DI container has no binding for key <BindingKey: org.apache.cayenne.configuration.ObjectContextFactory>
at org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:158)
at org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:144)
at org.apache.cayenne.di.spi.DefaultInjector.getInstance(DefaultInjector.java:134)
at org.apache.cayenne.configuration.CayenneRuntime.newContext(CayenneRuntime.java:124)
As Cayenne is modular, I've included only these dependencies (see pic).
What library needs to be included?
Thanks!
(The backend db is postgres but I don't this this is relavant to this error.)
I resolved this problem myself. Turns out that I need to build the artifact with "copy to output directory and link via manifest" (using IntelliJ IDEA) and upload the entire generated _jar directory to the server.

NullPointerException while generating web service with Apache CXF

I want to create a web service and using Apache CXF 2.7.12. My jdk version is 1.8.0_20. While generating WSDL file in eclipse got this exception.
java.lang.NullPointerException
at org.apache.cxf.common.util.Compiler.useJava6Compiler(Compiler.java:187)
at org.apache.cxf.common.util.Compiler.compileFiles(Compiler.java:141)
at org.apache.cxf.tools.java2wsdl.generator.wsdl11.BeanGenerator.generateAndCompile(BeanGenerator.java:91)
at org.apache.cxf.tools.java2wsdl.generator.wsdl11.BeanGenerator.generate(BeanGenerator.java:58)
at org.apache.cxf.tools.java2wsdl.generator.wsdl11.BeanGenerator.generate(BeanGenerator.java:35)
at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.generate(JavaToWSDLProcessor.java:156)
at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.process(JavaToWSDLProcessor.java:118)
at org.apache.cxf.tools.java2ws.JavaToWSContainer.processWSDL(JavaToWSContainer.java:110)
at org.apache.cxf.tools.java2ws.JavaToWSContainer.execute(JavaToWSContainer.java:75)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:58)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:40)
at org.apache.cxf.tools.java2ws.JavaToWS.run(JavaToWS.java:77)
at org.apache.cxf.tools.java2ws.JavaToWS.main(JavaToWS.java:45)
I have no idea about the problem related with Java6Compiler.
I solved problem after selecting JavaSE-1.8 execution environment in eclipse. It shows compatible jars
jre1.8.0_20[perfect match]

web client for web service

I've a web-service that works fine when I access them from a J2SE (desktop) application. To access this service I do follow:
generate stub classes by wsdl link using java wsimport tool
then I create service using generated classes and run one of wsdl operations.It looks like this:
MyWebServiceService webService = new MyWebServiceService();
MyWebService port = webService.getMyWebServicePort();
webService.run("XYZ");
As I sad it work fine when I use it in a standalone application.
But...when I try to access web-service in the same way but from servlet-client, using generated stubs I get following error:
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.bind.api.JAXBRIContext
org.jboss.ws.metadata.umdm.EndpointMetaData.eagerInitializeAccessors(EndpointMetaData.java:686)
org.jboss.ws.metadata.umdm.EndpointMetaData.initializeInternal(EndpointMetaData.java:567)
org.jboss.ws.metadata.umdm.EndpointMetaData.eagerInitialize(EndpointMetaData.java:553)
org.jboss.ws.metadata.builder.jaxws.JAXWSClientMetaDataBuilder.rebuildEndpointMetaData(JAXWSClientMetaDataBuilder.java:314)
org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPortInternal(ServiceDelegateImpl.java:271)
org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPort(ServiceDelegateImpl.java:202)
javax.xml.ws.Service.getPort(Service.java:143...
I've searched google long time but found nothing helpful topics. Some topics show examples accessing web-services from servlet, but unfortunately I can't do this...( And don't know what is cause of trouble.
Application server: jboss 4.2.3GA
Is it possible to connect web-service from servlet? How?
I've tried use #WebServiceRef annotation, but it seem web-container can't inject web-service stub. And I think that container must not do this itself, because stub classes have already been generated by wsimport tool, and its enouph to use this classes for accessing of web-service.
Stub classes were generated using the following command:
wsimport -keep -p com.myhost.ws http://www.myhost.com/services/MyWebService?wsdl
Did you make sure your classpath does not contain multiple JAX-B Jars with differing versions ? The exception looks like a version conflict to me. Application servers usually have some kind of "endorsed" lib directory that holds JARS that are always added in front of web application classpaths. Maybe your app server has a conflicting JAX-B implementation there ?
If you use Maven to package your application, make sure transitive dependencies don't pull in unwanted JAX-B Jars (use 'mvn dependency:tree' to check this).
This definitely sounds like a JAXB conflict to me. Check out the jaxb versions that you have in your war and make sure that they are not conflicting with a jaxb jar that Jboss may have in its lib directory.
Addytionally if jbossws-native library was installed correctly the following packages should be deleted from jboss_home/lib/endorsed directory:
jboss-jaxrpc.jar
jboss-jaxws-ext.jar
jboss-jaxws.jar
jboss-saaj.jar
Otherwise you don't have ability to connect to web service through EJB or servlet.

Categories

Resources