2016-01-21 98 views
0

這條路線的作品,以及作品很好地使用了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("*")); 

謝謝!

+0

mycase第二條路線沒有終止,以調用post-url,是否有任何解決方法? – peaceUser

回答

2

我認爲你需要設置訪問控制允許來源爲上的價值*您迴應頭把和頭部有人建議。所以要做到這一點駱駝:

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

這來自閱讀:enable cors on your server

0

使用參數restletMethods或restletMethod用GET,POST,根據需要

+0

你可以舉一個「頭像需要」的例子嗎?我已經在uri中獲得了restletMethod = POST。我不知道你在說什麼。 – JoeTheSchmoe

+0

請忽略我的答案。 – Sundar