2013-04-29 52 views
0

我有一個Web服務正在使用Apache Abdera lib與我們的IBM Connections 4服務器的REST API進行通信。Apache Abdera客戶端POST未發佈到IBM Connections API

我遇到的問題是我的請求不起作用。當我說它不工作時,我的意思是我所有的GET操作都能很好地返回我之後的數據,但是我嘗試實現的第一個POST操作失敗。我的ClientResponse對象返回Type「REDIRECTION」和StatusText「found」。我的數據不會在連接上更新。 。

請注意,我打電話從JSONP AJAX調用由於跨域限制該服務(此WebService是相同的服務器和域連接我們的環境上)

這裏是我的代碼:( PS我是一個Java小白嘗試後從我的Ajax調用小微博客條目的連接狀態更新)

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    JSONObject json; 
    JSONObject rtn = new JSONObject(); 
    String rtnVal = ""; 

    String username = request.getParameter("username"); 
    String password = request.getParameter("password"); 
    String statusPost = request.getParameter("msg"); 
    String container = request.getParameter("container"); 

    String url = Authentication.uri+"/connections/opensocial/basic/rest/ublog/@me/@all"; 
    if(container != null){ 
     url += "/"+container+"/comments"; 
    } 

    json = new JSONObject(); 
    json.put("content", statusPost); 
    try { 
     AbderaClient client = Authentication.getClient(Authentication.EMPTY, username, password, Authentication.uri); 
     RequestOptions options = client.getDefaultRequestOptions(); 
     options.setFollowRedirects(true); 
     InputStream inStream = new ByteArrayInputStream(json.toString().getBytes("UTF-8")); 

     ClientResponse resp = client.post(url, inStream, options); 
     rtn.put("Status", resp.getType() + " : " + resp.getStatusText()); 
    } catch (URISyntaxException e) { 
     e.printStackTrace(); 
    } 

    response.setContentType("application/json"); 
    PrintWriter out = response.getWriter(); 
    out.println(request.getParameter("callback")+ "(" + (rtn)+")"); 
} 

這裏是執行console.log():

Ext.data.JsonP.callback3({"Status":"REDIRECTION : Found"}) 
+0

我設法解決我的問題。問題在於,當我進行身份驗證時,我的身份驗證URI指向http,而我們的連接服務器自動重定向到https。將此uri更改爲https解決了我的重定向問題。 – Corne 2013-04-30 12:24:35

回答

0

我設法解決了我的問題。問題在於,當我進行身份驗證時,我的身份驗證URI指向http,而我們的連接服務器自動重定向到https。更改此uri https解決我的重定向問題