创建CXF Web服务客户端时发生ServiceConstructionException(scala + java + wsdl2java) [英] ServiceConstructionException when creating a CXF web service client (scala+java+wsdl2java)
问题描述
这些其他问题暗示了一个解决方案,但我一直无法得到这个工作:
无法解析http://schemas.xmlsoap.org/wsdl/soap/ 的绑定
创建CXF Web服务客户端时的ServiceConstructionException < br>
当我通过执行 java -Xdebug -jar myapp.jar
m得到一个 ServiceConstructionException:当应用程序进行SOAP调用时,无法解析null
的绑定。当我在IntelliJ中启动应用程序时,应用程序和SOAP调用工作得很好。以下是重现错误的最简单示例: https://github.com/stianlagstad / mainclass-and-jxf-problems-demo
重现步骤:
- gradle clean build &安培;&安培; java -Xdebug -jar build / libs / mainclass-and-jxf-problems-demo.jar
- 转到 http:// localhost:4242 / endpoint / 并查看错误
任何人都可以帮我弄清楚哪个我必须做些改变才能使SOAP调用起作用?
编辑以提供更多信息:
如果我编辑 build.gradle
不排除META-INF(即具有 configurations.compile.collect {it.isDirectory()?it:zipTree(it) }
代替 configurations.compile.collect {it.isDirectory()?it:zipTree(it).matching {exclude {it.path.contains('META-INF' )}}}
)我得到这个错误:错误:无法找到或加载主类com.shadowjarcxfproblem.JettyLauncher
作为一个罐子)。在IntelliJ中启动应用程序仍然有效,然后SOAP调用也可以工作。
cxf错误的堆栈跟踪:
org.apache.cxf.service.factory.ServiceConstructionException:无法解析在org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo空
A结合( AbstractWSDLBasedEndpointFactory.java:352)
在org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpointInfo(AbstractWSDLBasedEndpointFactory.java:259)
在org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:在org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:91 144)
)
。在org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:157)$ b在org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:142)$ b。在com.shadowjarcxfproblem.SoapServiceFactory.create
(所以INIT> apServiceFactory.java:36)LT
。在com.shadowjarcxfproblem.service.CalculatorServiceComponent $ CalculatorServiceImpl&(CalculatorService.scala:17)
...
。通过引起:org.apache。 cxf.BusException:没有注册名称空间http://schemas.xmlsoap.org/soap/的绑定工厂。在org.apache.cxf.bus.managers.BindingFactoryManagerImpl.getBindingFactory(BindingFactoryManagerImpl.java:93)
在org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createBindingInfo(AbstractWSDLBasedEndpointFactory.java:339)
... 75 more
并尝试了一堆不同的东西,我终于偶然发现了一些有用的东西!
https://discuss.gradle.org/t/how-doi-i- $ b $ use-the-gradle-shadow-plugin-to-merge-spring-handlers-and-spring-schemas-files-of-multiple-spring-jar-dependencies / 6713/6 b
在此任务中使用gradle shadowjar插件可解决此问题:
import com.github.jengelman .gradle.plugins.shadow.transformers.ServiceFileTransformer
shadowJar {
//确保正确处理cxf服务文件,以便SOAP服务正常工作。
//价https://stackoverflow.com/questions/45005287/serviceconstructionexception-when-creating-a-cxf-web-service-client-scalajava
变换(ServiceFileTransformer){
路径='META-INF / cxf'
包含'bus-extensions.txt'
}
}
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'
}
}
这篇关于创建CXF Web服务客户端时发生ServiceConstructionException(scala + java + wsdl2java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!