这条路线的作品,以及作品很好地使用了SoapUI:Apache的骆驼的Restlet - CORS问题
from("restlet:http://localhost:8484/restletTestService/submit?restletMethod=POST")
.routeId("myRestletSubmitRoute")
.unmarshal().json(JsonLibrary.Jackson, MyRequest.class)
.to("bean:myServiceSubmitProcessor")
.marshal().json(JsonLibrary.Jackson, MyResponse.class);
使用了SoapUI,我可以张贴符合MyRequest类的结构jsons,我得到一个JSON回来的信息我认为我应该。
然而,当我创建了一个快速angularjs页面,允许用户建立对飞,然后“POST”我休息端点的请求,以及:
XMLHttpRequest cannot load http://localhost:8484/restletAddressService/addressPersonator/submit. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 405.
我敢肯定,我有以某种方式将标题Access-Control-Allow-Origin设置为restlet URI上的某个值,但我不知道如何做到这一点。我研究了文档(http://camel.apache.org/restlet.html)并将其用于搜索,但我没有找到任何有用的信息。
有谁知道答案?谢谢!
UPDATE
所以从FIW的答案给了我,我对一些谷歌的研究需要沿提示如何休息资源的调用确定哪些是允许的(加了不少好极了老式试验和错误:))。这是清盘工作:
from("restlet:http://localhost:8484/restletTestService/submit?restletMethod=POST")
.routeId("myRestletSubmitRoutePOST")
.unmarshal().json(JsonLibrary.Jackson, MyRequest.class)
.to("bean:myServiceSubmitProcessor")
.marshal().json(JsonLibrary.Jackson, MyResponse.class)
.setHeader("Access-Control-Allow-Headers", constant("Content-Type"))
.setHeader("Access-Control-Allow-Origin", constant("*"));
from("restlet:http://localhost:8484/restletTestService/submit?restletMethod=OPTIONS")
.routeId("myRestletSubmitRouteOPTIONS")
.setHeader("Access-Control-Allow-Headers", constant("Content-Type"))
.setHeader("Access-Control-Allow-Origin", constant("*"));
谢谢!
mycase第二条路线没有终止,以调用post-url,是否有任何解决方法? – peaceUser