【问题标题】:Why wsdl2java generated code use CXF dependencies at will?为什么wsdl2java生成的代码随意使用CXF依赖?
【发布时间】:2015-08-14 17:33:21
【问题描述】:

我使用 Apache CXF 3.0.4 wsdl2java 通过以下命令从 this wsdl 生成代码:

./wsdl2java -client -exsh true -d weather -p weather -verbose url

据我所知wsdl2java 仅使用 JAX-WS 生成纯 Java 代码。生成的代码可以正常工作,无需任何额外的库/依赖项。我已经找到了任何 CXF 类,但它似乎没有 CXF。当我将特定的 CXF 依赖项添加到我的 pom.xml 时,问题就出现了。这个依赖是:

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>3.1.0</version>
</dependency>

添加后,应用程序似乎使用了不同的 JAX-WS 实现(甚至可能吗?)。

生成的代码包含WeatherSoap 接口等。其中一种方法是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依赖

  1. 进入getWeatherInformation(),同时调试导致GetWeatherInformation(另一个生成的类。
  2. 进入GetWeatherInformation 导致com.oracle.webservices.internal.api.message.BasePropertySet
  3. ...
  4. 收到来自 SOAP 网络服务的结果。

cxf-rt-frontend-jaxws依赖

  1. 进入getWeatherInformation,同时调试导致org.apache.cxf.jaxws.JaxWsClientProxy(为什么?)
  2. ...
  3. 抛出异常:
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

我知道here 提到的这个异常有解决方法,它可以工作。但不适用于我的工作申请。毕竟它会抛出 NPE:

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

提问时间

  1. 即使没有 Apache-CXF 应用程序也能正常工作,为什么还要使用它?
  2. 在这种情况下是否可以强制应用停止使用 Apache-CXF?

我不需要客户端的这个依赖项(因为没有它们它可以正常工作)。我也只想生产 SOAP。这就是为什么我需要这种依赖关系。我看到的唯一解决方案是将应用程序拆分为单独的消费者和生产者。

【问题讨论】:

    标签: maven cxf jax-ws wsdl2java


    【解决方案1】:

    应用程序似乎使用了不同的 JAX-WS 实现(甚至可能吗?)。

    是的。 CXF 有它自己的 jax-ws 提供程序,它的 jar 包含一个声明它的服务文件。 (当 JVM 需要一个 jax-ws 提供者时:它会在类路径中查看是否声明了一个非默认提供者......并且如果有使用它)。

    为什么? 这就是 Java 规范:http://docs.oracle.com/javaee/5/api/javax/xml/ws/spi/Provider.html#provider()

    在这种情况下是否可以强制应用停止使用 Apache-CXF?

    是的。在您的类路径上创建适当的资源文件以重定向到默认实现。

    详细说明:文件必须在此处:META-INF/services/javax.xml.ws.spi.Provider(如果您使用 maven:将其简单地放在此处:/src/main/resources/META-INF/services/javax.xml.ws.spi.Provider

    而且它必须包含一行:

    javax.xml.ws.spi.Provider
    

    【讨论】:

      猜你喜欢
      • 2014-04-20
      • 2013-10-26
      • 1970-01-01
      • 2013-05-14
      • 2012-10-05
      • 1970-01-01
      • 2014-09-27
      • 2015-12-18
      • 1970-01-01
      相关资源
      最近更新 更多