【发布时间】:2015-04-10 17:46:45
【问题描述】:
我需要调用 WildFly 8 上可用的 JAX-WS Web 服务。我从一个简单的示例开始。这是我的网络服务:
import javax.jws.WebService;
@WebService
public class HelloWorld implements Hello{
@Override
public String greet(String s) {
return "Hello "+s;
}
}
WSDL 位于:http://localhost:8080/DemoWS/HelloWorld?wsdl
看一下 Tomcat-CXF 示例,我编写了以下路由:
public class CamelRoute extends RouteBuilder {
private String uri = "cxf:http://localhost:8080/helloWorld?serviceClass=com.sample.HelloWorld";
@Override
public void configure() throws Exception {
from(uri)
.to("log:input")
.recipientList(simple("direct:${header.operationName}"));
from("direct:greet")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String id = exchange.getIn().getBody(String.class);
exchange.getOut().setBody(id);
}
})
.to("log:output");
}
}
通过在骆驼上下文中运行上述代码,返回以下错误:
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route[[From[cxf:http://localhost:8080/helloWorld?serviceClas... because of Failed to resolve endpoint: cxf://http://localhost:8080/helloWorld?serviceClass=com.sample.HelloWorld due to: No component found with scheme: cxf
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:177)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:731)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:1803)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1589)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1453)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1421)
at com.sample.Main.main(Main.java:15)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cxf://http://localhost:8080/helloWorld?
serviceClass=com.sample.HelloWorld 由于:未找到具有方案的组件:cxf
看来我什至无法调用它。有什么帮助吗? 谢谢
【问题讨论】:
-
您需要将 camel-cxf 组件添加到您的类路径中。如果您使用 Maven,请将其添加为依赖项。
-
如果您有兴趣,这里有一个 Camel Spring 示例,它完全符合您的要求。
-
如果你想从camel route调用web服务,你需要使用to("cxf:xxx")而不是from("cxf:xxx")。
标签: apache-camel cxf