Apache Abdera Client POST not posting to IBM Connections API

1.2k views Asked by At

I have a web service that is using the Apache Abdera lib to communicate with our IBM Connections 4 server's REST API.

The problem I'm having, is that my request doesn't work. When I say that it is not working, I mean that all my GET operations work fine returning the data I'm after, but my first POST operation I tried to implement fails. My ClientResponse object returns with Type "REDIRECTION" and the StatusText "found". My data does not update on connections.

Please note that I'm calling this service from a JSONP AJAX call due to Cross-Domain restrictions.(This webservice is on the same server and domain as our connections environment)

Here is my code: (P.S. I'm a java noob trying to post a small micro blog entry to the connections status updates)

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)+")");
}

Here is the console.log() from my Ajax call :

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

There are 1 answers

0
Corne On BEST ANSWER

I have managed to resolve my problem. The problem came in that when I do the authentication, my authentication uri was pointing to http and our connections server auto redirect to https. Changing this uri to https resolved my redirection issue