hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "pierz (Created) (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HTTPCLIENT-1184) unexpected org.apache.http.client.ClientProtocolException triggered
Date Thu, 19 Apr 2012 19:28:40 GMT
unexpected org.apache.http.client.ClientProtocolException triggered
-------------------------------------------------------------------

                 Key: HTTPCLIENT-1184
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1184
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 4.1.3
         Environment: java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)

Linux
            Reporter: pierz


Hi, 

When I send the 2 followings requests on www.amazon.fr, with 5 seconds wait between them,
it trigger a org.apache.http.client.ClientProtocolException, I sniffed and I did see nothing
wrong sent by the amazon server. You can reproduce the bug with the test joined.

---
Logs
----
------------- Standard Output ---------------
HTTP/1.1 200 OK
------------- ---------------- ---------------
------------- Standard Error -----------------
2012/04/19 21:12:35:809 CEST [DEBUG] SingleClientConnManager - Get connection for route HttpRoute[{}->http://www.amazon.fr]
2012/04/19 21:12:35:817 CEST [DEBUG] DefaultClientConnectionOperator - Connecting to www.amazon.fr:80
2012/04/19 21:12:35:910 CEST [DEBUG] RequestAddCookies - CookieSpec selected: best-match
2012/04/19 21:12:35:919 CEST [DEBUG] RequestAuthCache - Auth cache not set in the context
2012/04/19 21:12:35:919 CEST [DEBUG] DefaultHttpClient - Attempt 1 to execute request
2012/04/19 21:12:35:920 CEST [DEBUG] DefaultClientConnection - Sending request: GET /b/?node=486048031
HTTP/1.1
2012/04/19 21:12:35:920 CEST [DEBUG] headers - >> GET /b/?node=486048031 HTTP/1.1
2012/04/19 21:12:35:921 CEST [DEBUG] headers - >> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
2012/04/19 21:12:35:921 CEST [DEBUG] headers - >> Host: www.amazon.fr
2012/04/19 21:12:35:921 CEST [DEBUG] headers - >> Connection: Keep-Alive
2012/04/19 21:12:35:921 CEST [DEBUG] headers - >> User-Agent: Mozilla/5.0 (compatible;
MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; yie9)
2012/04/19 21:12:36:177 CEST [DEBUG] DefaultClientConnection - Receiving response: HTTP/1.1
200 OK
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << HTTP/1.1 200 OK
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << Date: Thu, 19 Apr 2012 19:12:35 GMT
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << Server: Server
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << x-amz-id-1: B11EC0C415E04F168007
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << x-amz-id-2: RtNOi7MOVlKdI28FuzIJEpTzEIdTgcex6LtMuzWE+x4=
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << Content-Type: text/html;charset=UTF-8
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << Vary: Accept-Encoding,User-Agent
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << Set-Cookie: session-id=276-4057542-1754032;
Domain=.amazon.fr; Expires=Wed, 14-Apr-2032 19:12:36 GMT; Path=/
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << Set-Cookie: session-id-time=1965582756l;
Domain=.amazon.fr; Expires=Wed, 14-Apr-2032 19:12:36 GMT; Path=/
2012/04/19 21:12:36:177 CEST [DEBUG] headers - << Transfer-Encoding: chunked
2012/04/19 21:12:36:187 CEST [DEBUG] ResponseProcessCookies - Cookie accepted: "[version:
0][name: session-id][value: 276-4057542-1754032][domain: .amazon.fr][path: /][expiry: Wed
Apr 14 21:12:36 CEST 2032]". 
2012/04/19 21:12:36:187 CEST [DEBUG] ResponseProcessCookies - Cookie accepted: "[version:
0][name: session-id-time][value: 1965582756l][domain: .amazon.fr][path: /][expiry: Wed Apr
14 21:12:36 CEST 2032]". 
2012/04/19 21:12:36:187 CEST [DEBUG] DefaultHttpClient - Connection can be kept alive indefinitely
2012/04/19 21:12:36:915 CEST [DEBUG] SingleClientConnManager - Releasing connection org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@3787efea
2012/04/19 21:12:41:916 CEST [DEBUG] SingleClientConnManager - Get connection for route HttpRoute[{}->http://www.amazon.fr]
2012/04/19 21:12:41:918 CEST [DEBUG] DefaultHttpClient - Stale connection check
2012/04/19 21:12:41:919 CEST [DEBUG] RequestAddCookies - CookieSpec selected: best-match
2012/04/19 21:12:41:920 CEST [DEBUG] RequestAddCookies - Cookie [version: 0][name: session-id][value:
276-4057542-1754032][domain: .amazon.fr][path: /][expiry: Wed Apr 14 21:12:36 CEST 2032] match
[www.amazon.fr:80/b/]
2012/04/19 21:12:41:920 CEST [DEBUG] RequestAddCookies - Cookie [version: 0][name: session-id-time][value:
1965582756l][domain: .amazon.fr][path: /][expiry: Wed Apr 14 21:12:36 CEST 2032] match [www.amazon.fr:80/b/]
2012/04/19 21:12:41:922 CEST [DEBUG] RequestAuthCache - Auth cache not set in the context
2012/04/19 21:12:41:922 CEST [DEBUG] DefaultHttpClient - Attempt 1 to execute request
2012/04/19 21:12:41:922 CEST [DEBUG] DefaultClientConnection - Sending request: GET /b/?node=486048031
HTTP/1.1
2012/04/19 21:12:41:923 CEST [DEBUG] headers - >> GET /b/?node=486048031 HTTP/1.1
2012/04/19 21:12:41:923 CEST [DEBUG] headers - >> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
2012/04/19 21:12:41:923 CEST [DEBUG] headers - >> Host: www.amazon.fr
2012/04/19 21:12:41:923 CEST [DEBUG] headers - >> Connection: Keep-Alive
2012/04/19 21:12:41:923 CEST [DEBUG] headers - >> User-Agent: Mozilla/5.0 (compatible;
MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; yie9)
2012/04/19 21:12:41:924 CEST [DEBUG] headers - >> Cookie: session-id=276-4057542-1754032;
session-id-time=1965582756l
2012/04/19 21:12:41:924 CEST [DEBUG] headers - >> Cookie2: $Version=1
2012/04/19 21:12:41:924 CEST [DEBUG] DefaultResponseParser - Garbage in response: 0
2012/04/19 21:12:41:925 CEST [DEBUG] DefaultResponseParser - Garbage in response: 
2012/04/19 21:12:41:925 CEST [DEBUG] DefaultClientConnection - Connection closed
2012/04/19 21:12:41:925 CEST [DEBUG] DefaultClientConnection - Connection shut down
2012/04/19 21:12:41:925 CEST [DEBUG] SingleClientConnManager - Releasing connection org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@63388a78
------------- ---------------- ---------------
Testcase: testApp(jacky.AppTest):	Caused an ERROR
null
org.apache.http.client.ClientProtocolException
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
	at jacky.AppTest.testApp(AppTest.java:83)
Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP
response
	at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:109)
	at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
	at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:282)
	at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
	at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:216)
	at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
	at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
	at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:647)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)

---
Test.java
---
package jacky.bhdownloader;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;

/**
 * Unit test for simple App.
 */
public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }
    
    public static void setHeader(HttpClient httpclient,String name, String value, boolean
bOverride){
        if(name != null && value != null && httpclient != null){
            ArrayList<Header> headers = (ArrayList<Header>)httpclient.getParams().getParameter("http.default-headers");
            if(headers == null)
                headers = new ArrayList<>();

            if(bOverride){
                Iterator<Header> it = headers.iterator();
                while(it.hasNext()){
                    Header header = it.next();
                    if(header.getName().equalsIgnoreCase(name)){
                        it.remove();
                    }
                }
            }

            headers.add(new BasicHeader(name,value));
            httpclient.getParams().setParameter("http.default-headers", headers);
        }
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp() throws IOException, InterruptedException
    {
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
        System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
        System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "DEBUG");
       
        System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire",
"ERROR");  
        
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter("http.useragent", "Mozilla/5.0 (compatible; MSIE
9.0; Windows NT 6.1; WOW64; Trident/5.0; yie9)");
        setHeader(httpclient, "Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
true);
        
        HttpGet get = new HttpGet("http://www.amazon.fr/b/?node=486048031");
        HttpResponse execute = httpclient.execute(get);
        System.out.println(execute.getStatusLine());
        execute.getEntity().consumeContent();
        
        Thread.sleep(5000l);
        
        get = new HttpGet("http://www.amazon.fr/b/?node=486048031");
        execute = httpclient.execute(get);
        System.out.println(execute.getStatusLine());        

        
    }
}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message