CXF客户端:未找到命名空间错误的管道启动器

时间:2014-07-04 21:08:07

标签: web-services rest cxf cxf-client

我正在使用CXF 3.0创建一个宁静的Web服务。我的web服务工作正常,但我的cxf客户端抛出了如下所示的异常

    [qtp392289808-96] WARN org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://localhost:8080/userdetailservice}WebClient has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No conduit initiator was found for the namespace http://cxf.apache.org/transports/http.
    at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:116)
    at org.apache.cxf.endpoint.UpfrontConduitSelector.selectConduit(UpfrontConduitSelector.java:77)
    at org.apache.cxf.message.ExchangeImpl.getConduit(ExchangeImpl.java:148)
    at org.apache.cxf.interceptor.MessageSenderInterceptor.getConduit(MessageSenderInterceptor.java:71)
    at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:620)
    at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1087)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:882)
    at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:853)
    at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:320)
    at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:329)
    at com.sell.mystuff.web.service.impl.UserInfoServiceImpl.processCredentials(UserInfoServiceImpl.java:47)

以下是我的代码:

@Resource(name = "cxfWebClient")
    private WebClient restClient;

private UserDetail processCredentials(UserAuthenticationRequest userData)
            throws AuthenticationException {
    try {
        LOGGER.debug("About to authenticate the user {1}",
                userData.getUsername());
        addCommonAttributes(WebConstants.AUTHENTICATE_URL);
        LOGGER.info("About to make a restful call to the userDetailService for user {}", userData.getUsername());
        Response response = restClient.post(userData);
        LOGGER.info("Got the response back from userDetailService");
        UserDetail authenticatedData = response
                .readEntity(UserDetail.class);
        if (authenticatedData == null
                || authenticatedData.getUsername() == null) {
            throw new SellServiceException(
                    StatusCodes.AUTHENTICATION_ERROR_CODE);
        }
        return authenticatedData;
    } catch (RuntimeException ex) {
        LOGGER.error("Error in the processCredentials()", ex);
        throw new SellServiceException(
                StatusCodes.AUTHENTICATION_ERROR_CODE);
    }

}

private void addCommonAttributes(String url) {
        restClient.path(url);
        restClient.accept(MediaType.APPLICATION_JSON).type(
                MediaType.APPLICATION_XML);

    }

POM.xml文件

<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-client</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxrs</artifactId>
        <version>3.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-extension-search</artifactId>
        <version>3.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-extension-providers</artifactId>
        <version>3.0.0</version>
    </dependency>

我想我错过了一个重要的maven依赖,但不确定是哪一个。任何人都可以帮我这方面吗?

1 个答案:

答案 0 :(得分:0)

经过一番努力,我能够实施解决方案。解决方案是在cxfWebClient中配置JacksonJaxbJsonProvider,如下所示:

<beans:bean id="myJsonProvider"
    class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider">
</beans:bean>

<util:list id="webClientProviders">
    <beans:ref bean="myJsonProvider" />
</util:list>
<beans:bean id="cxfWebClient" class="org.apache.cxf.jaxrs.client.WebClient"
        factory-method="create">
        <beans:constructor-arg type="java.lang.String"
            value="${userDetailService.base.url}" />
        <beans:constructor-arg ref="webClientProviders" />
    </beans:bean>