Apache Camel + Spring(战争)+ Tomcat + REST [英] Apache Camel + Spring (war) + Tomcat + REST
问题描述
我正在尝试使用 apache camel 开发休息服务.我的项目是部署在tomcat上的spring mvc war.
I am trying to develp a rest service using apache camel. My project is a spring mvc war deployed on tomcat.
我不想使用 apache cxf(cxf servlet).
I dont want to use apache cxf (cxf servlet).
public class SampleRouter extends RouteBuilder {
@override
public void configure() throws Exception {
from("cxfrs://http://localhost:1234/sample")
.process (new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("test");
}
})).setBody(constant("SUCCESS"));
}
}
@Path("/sample")
public class SampleResource {
@GET
public void test() {
}
}
web.xml 有 dispatcherservlet、contextloaderlistener.
web.xml has dispatcherservlet, contextloaderlistener.
dispatcher-servlet.xml 有 mvc:annotation-drivem, context:component-scan,
dispatcher-servlet.xml has mvc:annotation-drivem, context:component-scan,
<camelContext id="server" trace="true" xmlns="http://camel.apache.org/schema/spring">
<contextScan />
</camelContext>
pom.xml 有camel-core、camel-cxf、camel-stream、cxf-rt-transports-http-jetty、cxf-rs-frontend-jaxrs、camel-spring、spring-webmvc、spring-web、spring-上下文.
pom.xml has camel-core, camel-cxf, camel-stream, cxf-rt-transports-http-jetty, cxf-rs-frontend-jaxrs, camel-spring, spring-webmvc, spring-web, spring-context.
Tomcat 运行在 8080 上,服务器上来似乎也没有异常.但是,我尝试点击 url (http://localhost:1234/sample
),似乎没有任何反应.
Tomcat runs on 8080, there seems to be no exception when server comes up. But, I tried hitting the url (http://localhost:1234/sample
), nothing seems to be happening.
我错过了什么?我最终会通过身份验证、过滤器和拦截器将其扩展到 REST 到 Spring DSL 或 REST 到 Java DSL.
What am i missing? I would eventually extend this to REST to Spring DSL or REST to Java DSL with authentication, filters and interceptors.
我也尝试了 cxf:rsServer 并在路由器类中引用了它.
I also tried cxf:rsServer and referred that in router class.
此外,将来是否必须使用 https 而不是 http?或者我如何没有硬编码的网址?
Also, in the future if i have to use https instead of http? or how do i have the url not hard-coded?
推荐答案
可能为时已晚,但要消费 HTTP 请求,可以使用 Apache Camel Servlet 组件
It may be too late, but to consume HTTP requests, one may use Apache Camel Servlet component
http://camel.apache.org/servlet.html
这篇关于Apache Camel + Spring(战争)+ Tomcat + REST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!