为什么wsdl2java生成的代码会随意使用CXF依赖关系? [英] Why wsdl2java generated code use CXF dependencies at will?
问题描述
我使用Apache CXF 3.0.4 wsdl2java
从此wsdl 使用以下命令:
I use Apache CXF 3.0.4 wsdl2java
to generate code from this wsdl with following command:
./wsdl2java -client -exsh true -d weather -p weather -verbose url
据我所知,wsdl2java
仅使用JAX-WS生成纯Java代码.生成的代码可以正常运行,而无需任何其他库/依赖项.我已经找到它来查找任何CXF类,但是它似乎不受CXF的支持.当我将特定的CXF依赖项添加到pom.xml
时,问题就解决了.这种依赖关系是:
As far as I know wsdl2java
generates pure java code using only JAX-WS. Generated code works fine without any additional library/dependency. I've grepped it to find any CXF classes, but it seems to be free from CXF. The problem flows out when I add specific CXF dependency to my pom.xml
. This dependency is:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.0</version>
</dependency>
添加此内容后,应用程序似乎使用了JAX-WS的不同实现(甚至可能吗?).
After adding this, application seems to use different implementation of JAX-WS( is it even possible?).
生成的代码除其他外还包含WeatherSoap
接口.其中的一种方法是getWeatherInformation()
Generated code contains among other things WeatherSoap
interface. One of it's methods is getWeatherInformation()
@WebService(targetNamespace = "http://ws.cdyne.com/WeatherWS/", name = "WeatherSoap")
@XmlSeeAlso({ObjectFactory.class})
public interface WeatherSoap {
/**
* Gets Information for each WeatherID
*/
@WebResult(name = "GetWeatherInformationResult", targetNamespace = "http://ws.cdyne.com/WeatherWS/")
@RequestWrapper(localName = "GetWeatherInformation", targetNamespace = "http://ws.cdyne.com/WeatherWS/", className = "weather.GetWeatherInformation")
@WebMethod(operationName = "GetWeatherInformation", action = "http://ws.cdyne.com/WeatherWS/GetWeatherInformation")
@ResponseWrapper(localName = "GetWeatherInformationResponse", targetNamespace = "http://ws.cdyne.com/WeatherWS/", className = "weather.GetWeatherInformationResponse")
public weather.ArrayOfWeatherDescription getWeatherInformation();
...
}
没有cxf-rt-frontend-jaxws
依赖性
Without cxf-rt-frontend-jaxws
dependency
- 进入
getWeatherInformation()
的同时调试会导致GetWeatherInformation
(另一个生成的类. - 进入
GetWeatherInformation
会导致com.oracle.webservices.internal.api.message.BasePropertySet
- ...
- 收到SOAP Web服务的结果.
- Step into
getWeatherInformation()
while debugging leads toGetWeatherInformation
( another generated class. - Step into
GetWeatherInformation
leads tocom.oracle.webservices.internal.api.message.BasePropertySet
- ...
- Result from SOAP webservice received.
具有cxf-rt-frontend-jaxws
依赖项
With cxf-rt-frontend-jaxws
dependency
- 进入
getWeatherInformation
,而调试导致org.apache.cxf.jaxws.JaxWsClientProxy
(为什么?) - ...
- 引发异常:
- Step into
getWeatherInformation
while debugging leads toorg.apache.cxf.jaxws.JaxWsClientProxy
(why?) - ...
- Exception is thrown:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not find conduit initiator for address: http://wsf.cdyne.com/WeatherWS/Weather.asmx and transport: http://schemas.xmlsoap.org/soap/http
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:161)
at com.sun.proxy.$Proxy33.getWeatherInformation(Unknown Source)
at weather.WeatherSoap_WeatherSoap_Client.main(WeatherSoap_WeatherSoap_Client.java:49)
Caused by: java.lang.RuntimeException: Could not find conduit initiator for address: http://wsf.cdyne.com/WeatherWS/Weather.asmx and transport: http://schemas.xmlsoap.org/soap/http
at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:224)
at org.apache.cxf.binding.soap.SoapTransportFactory.getConduit(SoapTransportFactory.java:229)
at org.apache.cxf.endpoint.AbstractConduitSelector.createConduit(AbstractConduitSelector.java:145)
at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:107)
at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:63)
at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:853)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:511)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:425)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139)
... 2 more
I know that there is workaround for this exception which is mentioned here and it works. But not for my work application. It throws NPE after all:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
...
Caused by: org.apache.cxf.binding.soap.SoapFault: java.lang.NullPointerException
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:86)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:52)
at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:41)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:802)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1642)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1533)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1336)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:652)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:516)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:425)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:326)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:279)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139)
... 7 more
提问时间
- 即使没有该应用程序也能正常工作,为什么还要使用Apache-CXF?
- 在这种情况下是否可以强制应用程序停止使用Apache-CXF?
我不需要客户端依赖(因为没有它们,它可以正常工作).我也只想生产SOAP.这就是为什么我需要这种依赖关系.我看到的唯一解决方案是将应用程序分为单独的使用者和生产者.
I don't need this dependencies for client( since it works fine without them). I just want to produce SOAP as well. And thats why I need this dependencies. The only solution which I see is to split application into separate consumer and producer.
推荐答案
应用程序似乎使用了JAX-WS的不同实现(甚至可能吗?).
application seems to use different implementation of JAX-WS( is it even possible?).
是的. CXF有它自己的jax-ws提供程序,它的jar包含一个声明它的服务文件. (当JVM需要jax-ws提供程序时:它会在类路径上查看是否声明了非默认提供程序...,并且如果有使用它).
Yes. CXF have it's own jax-ws provider and it's jar contains a service file declaring it. (when the JVM needs a jax-ws provider: it looks on the classpath to see if there is a non-default provider declared... and if any use it).
为什么? 那就是Java规范: http: //docs.oracle.com/javaee/5/api/javax/xml/ws/spi/Provider.html#provider()
Why ? That's the Java specs : http://docs.oracle.com/javaee/5/api/javax/xml/ws/spi/Provider.html#provider()
在这种情况下是否可以强制应用程序停止使用Apache-CXF?
Is it possible to force application to stop using Apache-CXF in this case?
是的.在类路径上创建适当的资源文件,以重定向到默认实现.
Yes. Create the appropriate resource file on your classpath to redirect to the default implementation.
详细信息:该文件必须位于以下位置:META-INF/services/javax.xml.ws.spi.Provider
(如果使用maven,则将其放在此处:/src/main/resources/META-INF/services/javax.xml.ws.spi.Provider
)
In details : the file must be here : META-INF/services/javax.xml.ws.spi.Provider
(if you use maven: put it simply here : /src/main/resources/META-INF/services/javax.xml.ws.spi.Provider
)
它必须包含一行:
javax.xml.ws.spi.Provider
这篇关于为什么wsdl2java生成的代码会随意使用CXF依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!