Apache camel ApacheCammel Restlet-CORS问题

Apache camel ApacheCammel Restlet-CORS问题,apache-camel,Apache Camel,这条路线很有效,并且在使用SoapUI时效果很好: from("restlet:http://localhost:8484/restletTestService/submit?restletMethod=POST") .routeId("myRestletSubmitRoute") .unmarshal().json(JsonLibrary.Jackson, MyRequest.class) .to("bean:myServiceSubmitProcessor")

这条路线很有效,并且在使用SoapUI时效果很好:

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类结构的json,然后我得到一个json,其中包含我认为应该提供的信息

然而,当我创建了一个快速angularjs页面,允许用户动态生成请求,然后“发布”到我的rest端点时,那么:

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.
我非常确定,我必须以某种方式将头访问控制Allow Origin设置为restlet URI上的某个值,但我不知道如何做到这一点。我研究了文档()并用谷歌搜索了一下,但没有找到任何有用的东西

有人知道答案吗?谢谢

更新

因此,来自fiw的答案给了我所需要的提示,以及一些关于调用rest资源如何决定允许的内容的google研究(加上相当多的ole风格的尝试和错误:)。这就是最终起作用的原因:

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("*"));

谢谢

我认为您需要将Access Control Allow Origin设置为响应的标题,其值为*正如您所建议的那样。因此,要在camel中执行此操作:

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)
    .setHeader("Access-Control-Allow-Origin", constant("*"));

这是通过阅读得出的:。

我认为您需要将Access Control Allow Origin设置为响应的标题,如您所建议的,其值为*。因此,要在camel中执行此操作:

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)
    .setHeader("Access-Control-Allow-Origin", constant("*"));

这来自阅读:。

在我的情况下,第二条路线没有终止到呼叫post url,是否有任何解决方法?在我的情况下,第二条路线没有终止到呼叫post url,是否有任何解决方法?