Search code examples
javaandroidjsonrestjersey-client

posting large JSON string with Jersey client on android


I need to post large JSON string from android to a webservice using Jersey client. The below code fails with HTTP status 505 error. Looks like the length of the JSON string is causing the trouble because the call works fine when the length of JSON string is not too high(I tested with 200 characters lenght). I also suspect this has something to do with jersey library on android because the same exact code works fine from Jersey client running in eclipse. In eclipse I don't even have to set the compression header in the request. Does anybody have a clue what is that I'm missing here ?

formData.add("payload",payload);
config = new DefaultClientConfig(); // SSL configuration
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
        new HTTPSProperties(JerseyClientBKS.getHostnameVerifier(), JerseyClientBKS.getSSLContext(getApplicationContext())));
ServiceFinder.setIteratorProvider(new AndroidServiceIteratorProvider()); 
client = Client.create(config);
webResource =  client.resource(getSeletctedAddress()+"/api/document/submitHybridJSON");
builder = webResource.queryParams(formData).getRequestBuilder();
for (NewCookie c : getCookies()) {
    if (c.getValue().indexOf("_") != -1){
        builder = builder.cookie(c);
    }
}
builder = builder.header("Content-Encoding", "gzip");
builder = builder.header("Accept-Encoding", "gzip");
Log.d(TAG, "posting.... =  ");
response =builder.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class);
Log.d(TAG,"response code "+response.getStatus());
Log.d(TAG,"valuesets "+response.getEntity(String.class));

Solution

  • I solved this problem by posting an InputStream instead of long JSON string.