2015-06-25 80 views
1

我试图用Apache Camel创建REST端点。我已经有一个返回JSON内容的REST服务,我希望这个端点能够得到它。我的问题是,当我的骆驼路线建成时,我不知道发生了什么。目前,它什么也没有做。这里是我的代码:REST EndPoint for Apache Camel

restConfiguration().component("servlet") 
.bindingMode(RestBindingMode.json) 
.dataFormatProperty("prettyPrint", "true").host("localhost") 
.port(9080);  

rest("/ContextServices/rest/contextServices/document") 
.consumes("application/json").produces("application/json") 
.get("/testContext/557064c8f7f71f29cea0e657").outTypeList(String.class) 
.to("bean:processor?method=affiche") 
.to(dest.getRouteTo()); 

我在端口9080运行我的REST服务上的本地Tomcat的,我的完整URL是

/ContextServices/REST/contextServices /文件/ {}集合/ {ID}。

我试图读取文档,但在两个语法和都不起作用:

from("rest:get:hello:/french/{me}").transform().simple("Bonjour ${header.me}"); 

rest("/say") 
    .get("/hello").to("direct:hello") 
    .get("/bye").consumes("application/json").to("direct:bye") 
    .post("/bye").to("mock:update"); 

首先是Java的DSL,第二个是REST DSL有什么区别?

非常感谢!

+0

您是否有任何支持REST的组件?例如camel-servlet – Sergey

+0

嗨,如果这是你的问题,我已经将骆驼servlet加入了pom –

+0

只对pom?你也必须在web.xml中设置servlet(检查camel.apache.org/servlet.html) – Sergey

回答

1

首先,REST组件本身不是REST实现。 它只是声明语言来描述REST端点。 你应该用实际执行的休息时间,像的Restlet(查看完整列表here

我可能是错的,但是当你想监听从其他应用程序REST请求AFAIR,REST端点仅供情况。 您需要的是向REST端点发出请求并处理它。 现在的问题是:你想要什么时候触发请求? 是否有些事件,或者您可能想要定期检查外部REST服务? 对于我使用下面的图案后一种情况下:

<route> 
    <from uri="timer:polling-rest?period=60000"/> 
    <setHeader headerName="CamelHttpMethod"> 
    <constant>GET</constant> 
    </setHeader> 
    <recipientList> 
    <simple>http://${properties:service.url}/api/outbound-messages/all</simple> 
    </recipientList> 
    <unmarshal ref="message-format"/> 

    <!-- do something with the message, transform it, log, 
     send to another services, etc --> 

    <setHeader headerName="CamelHttpMethod"> 
    <constant>DELETE</constant> 
    </setHeader> 
    <recipientList> 
    <simple>http://${properties:service.url}/api/outbound-messages/by-id/${header.id}</simple> 
    </recipientList> 
</route> 

对不起,例如用http组件,而不是REST。 我只是从我的工作项目复制粘贴它,它使用纯粹的http。 我想,通过类似Restlet或CXF组件的方式重写它。

+0

嗨,谢谢你的回答,我用restlet替换它,并且它工作的很完美。对于REST组件,我还没有理解这样的事情! –