Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceConstructionException when creating a CXF web service client (scala+java+wsdl2java)

These other questions hint at a solution but I haven't been able to get this to work:
Could not resolve a binding for http://schemas.xmlsoap.org/wsdl/soap/
ServiceConstructionException when creating a CXF web service client
How to package an Apache CXF application into a monolithic JAR with the Maven "shade" plugin

When I start my application by doing java -Xdebug -jar myapp.jar I'm getting a ServiceConstructionException: Could not resolve a binding for null when the app makes a SOAP call. The app and the SOAP call works just fine when I start the application in IntelliJ. Here is a minimal example reproducing the error: https://github.com/stianlagstad/mainclass-and-jxf-problems-demo

Steps to reproduce:
- gradle clean build && java -Xdebug -jar build/libs/mainclass-and-jxf-problems-demo.jar
- Go to http://localhost:4242/endpoint/ and see the error

Can anyone help me figure out which changes I have to do to make the SOAP call work?

Edit to provide more information:

If I edit build.gradle to not exclude META-INF (i.e. having configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } instead of configurations.compile.collect { it.isDirectory() ? it : zipTree(it).matching{exclude{it.path.contains('META-INF')}} }) I get this error instead: Error: Could not find or load main class com.shadowjarcxfproblem.JettyLauncher (when starting the app as a jar). Starting the app in IntelliJ still works however, and the SOAP call works then as well.

The stacktrace for the cxf error:

org.apache.cxf.service.factory.ServiceConstructionException: Could not resolve a binding for null
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:352)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpointInfo(AbstractWSDLBasedEndpointFactory.java:259)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:144)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91)
    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)
    at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)
    at com.shadowjarcxfproblem.SoapServiceFactory.create(SoapServiceFactory.java:36)
    at com.shadowjarcxfproblem.service.CalculatorServiceComponent$CalculatorServiceImpl.<init>(CalculatorService.scala:17)
...
Caused by: org.apache.cxf.BusException: No binding factory for namespace http://schemas.xmlsoap.org/soap/ registered.
    at org.apache.cxf.bus.managers.BindingFactoryManagerImpl.getBindingFactory(BindingFactoryManagerImpl.java:93)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:339)
    ... 75 more
like image 443
L42 Avatar asked Oct 29 '22 05:10

L42


1 Answers

After reading these two and trying a bunch of different things I finally stumbled upon something that works!
How to package an Apache CXF application into a monolithic JAR with the Maven "shade" plugin
https://discuss.gradle.org/t/how-do-i-use-the-gradle-shadow-plugin-to-merge-spring-handlers-and-spring-schemas-files-of-multiple-spring-jar-dependencies/6713/6

Using the gradle shadowjar plugin with this task solved the problem:

import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
shadowJar {
    // Make sure the cxf service files are handled correctly so that the SOAP services work.
    // Ref https://stackoverflow.com/questions/45005287/serviceconstructionexception-when-creating-a-cxf-web-service-client-scalajava
    transform(ServiceFileTransformer) {
        path = 'META-INF/cxf'
        include 'bus-extensions.txt'
    }
}
like image 81
L42 Avatar answered Nov 15 '22 04:11

L42