我正在使用 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 依赖项,但不确定是哪个。任何人都可以在这方面帮助我吗?