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
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'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With