Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using java-http-client library and Apache Transport with it on client side and Rails on server side. From time to time a get error like this:

11-24 17:37:02.469: WARN/BaseActivity(5925): org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    at com.google.api.client.http.apache.ApacheHttpRequest.execute(ApacheHttpRequest.java:58)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:639)
    at com.sk.api.SkClient.updateUser(SkClient.java:157)
    at com.sk.api.SkClient$3.call(SkClient.java:76)
    at com.sk.api.SkClient$3.call(SkClient.java:71)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    at java.lang.Thread.run(Thread.java:1019)
    Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:413)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    ... 12 more

What should I do to avoid this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
714 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have an similar error because I used CountingInputStreamEntity that is a non-repeteable http client. The solution was to use BufferedHttpEntity which converts the non-repeteable to repeteable httpclient.

ParcelFileDescriptor fileDescriptor = this.getContentResolver().openFileDescriptor(uri, "r");
            InputStream in = this.getContentResolver().openInputStream(uri);

            CountingInputStreamEntity entity = new CountingInputStreamEntity(in, fileDescriptor.getStatSize());
            entity.setUploadListener(this);
            entity.setContentType("binary/octet-stream");
            entity.setChunked(true); 
        
            BufferedHttpEntity myEntity = null;
            try {
                myEntity = new BufferedHttpEntity(entity);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            put.setEntity(myEntity);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...