2013-04-29 49 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解决我的重定向问题