You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Francois-Xavier Bonnet (JIRA)" <ji...@apache.org> on 2012/10/03 13:20:07 UTC

[jira] [Created] (HTTPCLIENT-1240) Empty HttpParams for cacheable requests

Francois-Xavier Bonnet created HTTPCLIENT-1240:
--------------------------------------------------

             Summary: Empty HttpParams for cacheable requests
                 Key: HTTPCLIENT-1240
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1240
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: Cache
    Affects Versions: 4.2.1
            Reporter: Francois-Xavier Bonnet
            Priority: Minor


With DefaultHttpClient, HttpResponse.getParams() returns a ClientParamsStack with all the parameters previously set at HttpClient or HttpRequest level.
With CachingHttpClient it returns an empty BasicHttpParams when a response is cached.

This feature can be very usefull when you are doing complex processing with Interceptors for example. It is described in HttpClient documentation:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e299
http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/ClientParamsStack.html

CachingHttpClient should not break this feature.

Here is some sample code:
	// Client and Request scoped params with DefaultHttpClient
	DefaultHttpClient httpClient = new DefaultHttpClient();
	httpClient.getParams().setParameter("testClientParam", "testClientParam");
	HttpGet httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
	HttpResponse response = httpClient.execute(httpGet);
	EntityUtils.consumeQuietly(response.getEntity());
	System.out.println(response.getParams().getParameter("testClientParam"));
	System.out.println(response.getParams().getParameter("testRequestParam"));

	// Same test with CachingHttpClient
	httpClient = new DefaultHttpClient();
	CachingHttpClient cachingHttpClient = new CachingHttpClient(httpClient);
	cachingHttpClient.getParams().setParameter("testClientParam", "testClientParam");
	httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
	response = cachingHttpClient.execute(httpGet);
	EntityUtils.consumeQuietly(response.getEntity());
	System.out.println(response.getParams().getParameter("testClientParam"));
	System.out.println(response.getParams().getParameter("testRequestParam"));

If you agree I can provide a patch and unit tests

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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


[jira] [Commented] (HTTPCLIENT-1240) Empty HttpParams for cacheable requests

Posted by "Francois-Xavier Bonnet (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1240?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470215#comment-13470215 ] 

Francois-Xavier Bonnet commented on HTTPCLIENT-1240:
----------------------------------------------------

I am trying to find a better solution.

I have to main problems:
1) there are several places in the code where we create the HttpResponse (for backend responses, cached responses, errors, not modified responses...) and most of the time the request params and HttpClient params are not available. Refactoring all that will be a lot of work. Another solution (but less clean) is to concentrate on org.apache.http.impl.client.cache.CachingHttpClient.execute(HttpHost, HttpRequest, HttpContext) and add the params just before returning the HttpResponse
2) adding calls to getParams() on HttpClient and HttpRequest breaks a lot of EasyMock unit tests because these calls are not expected

The solution I can see to avoid to have too much code to change and to break the unit tests would be in execute(HttpHost, HttpRequest, HttpContext) method to return a wrapper that would contain the original HttpRespone, the HttpRequest and the HttpClient so that it would be able to lazily build the HttpParams (lazily so that it would not break the unit tests as they probably do not call the method getParams()).

What do you think of this approach ?
                
> Empty HttpParams for cacheable requests
> ---------------------------------------
>
>                 Key: HTTPCLIENT-1240
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1240
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Francois-Xavier Bonnet
>            Priority: Minor
>             Fix For: 4.3 Alpha1
>
>
> With DefaultHttpClient, HttpResponse.getParams() returns a ClientParamsStack with all the parameters previously set at HttpClient or HttpRequest level.
> With CachingHttpClient it returns an empty BasicHttpParams when a response is cached.
> This feature can be very usefull when you are doing complex processing with Interceptors for example. It is described in HttpClient documentation:
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e299
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/ClientParamsStack.html
> CachingHttpClient should not break this feature.
> Here is some sample code:
> 	// Client and Request scoped params with DefaultHttpClient
> 	DefaultHttpClient httpClient = new DefaultHttpClient();
> 	httpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	HttpGet httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	HttpResponse response = httpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> 	// Same test with CachingHttpClient
> 	httpClient = new DefaultHttpClient();
> 	CachingHttpClient cachingHttpClient = new CachingHttpClient(httpClient);
> 	cachingHttpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	response = cachingHttpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> If you agree I can provide a patch and unit tests

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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


[jira] [Commented] (HTTPCLIENT-1240) Empty HttpParams for cacheable requests

Posted by "Jon Moore (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1240?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13468597#comment-13468597 ] 

Jon Moore commented on HTTPCLIENT-1240:
---------------------------------------

@Xavier: Sure, we'd definitely like to take a look at this patch. I'm presuming that the params we'd want to see for a response generated by the cache should be drawn from the current request/client (as we have no way to remember what the params were for the request that originally created the cache entry). We'd definitely like to support this feature with CachingHttpClient if we can.

                
> Empty HttpParams for cacheable requests
> ---------------------------------------
>
>                 Key: HTTPCLIENT-1240
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1240
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Francois-Xavier Bonnet
>            Priority: Minor
>
> With DefaultHttpClient, HttpResponse.getParams() returns a ClientParamsStack with all the parameters previously set at HttpClient or HttpRequest level.
> With CachingHttpClient it returns an empty BasicHttpParams when a response is cached.
> This feature can be very usefull when you are doing complex processing with Interceptors for example. It is described in HttpClient documentation:
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e299
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/ClientParamsStack.html
> CachingHttpClient should not break this feature.
> Here is some sample code:
> 	// Client and Request scoped params with DefaultHttpClient
> 	DefaultHttpClient httpClient = new DefaultHttpClient();
> 	httpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	HttpGet httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	HttpResponse response = httpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> 	// Same test with CachingHttpClient
> 	httpClient = new DefaultHttpClient();
> 	CachingHttpClient cachingHttpClient = new CachingHttpClient(httpClient);
> 	cachingHttpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	response = cachingHttpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> If you agree I can provide a patch and unit tests

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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


[jira] [Commented] (HTTPCLIENT-1240) Empty HttpParams for cacheable requests

Posted by "Jon Moore (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1240?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469472#comment-13469472 ] 

Jon Moore commented on HTTPCLIENT-1240:
---------------------------------------

Hmm. Unfortunately, we can't take a patch that breaks the unit tests. Probably we are running up against technical debt here, where the rest of httpclient uses Mockito (where it has useful defaults for expect/verify behavior that isn't specified) but the caching module uses EasyMock. I'll open an improvement ticket to do that work, then we can make this issue dependent on that one and leave it open. I'm not sure that I have time anytime soon to get to that change, though.


                
> Empty HttpParams for cacheable requests
> ---------------------------------------
>
>                 Key: HTTPCLIENT-1240
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1240
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Francois-Xavier Bonnet
>            Priority: Minor
>             Fix For: 4.3 Alpha1
>
>
> With DefaultHttpClient, HttpResponse.getParams() returns a ClientParamsStack with all the parameters previously set at HttpClient or HttpRequest level.
> With CachingHttpClient it returns an empty BasicHttpParams when a response is cached.
> This feature can be very usefull when you are doing complex processing with Interceptors for example. It is described in HttpClient documentation:
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e299
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/ClientParamsStack.html
> CachingHttpClient should not break this feature.
> Here is some sample code:
> 	// Client and Request scoped params with DefaultHttpClient
> 	DefaultHttpClient httpClient = new DefaultHttpClient();
> 	httpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	HttpGet httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	HttpResponse response = httpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> 	// Same test with CachingHttpClient
> 	httpClient = new DefaultHttpClient();
> 	CachingHttpClient cachingHttpClient = new CachingHttpClient(httpClient);
> 	cachingHttpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	response = cachingHttpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> If you agree I can provide a patch and unit tests

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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


[jira] [Updated] (HTTPCLIENT-1240) Empty HttpParams for cacheable requests

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1240?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski updated HTTPCLIENT-1240:
------------------------------------------

    Fix Version/s: 4.3 Alpha1

The way HttpClient components are wired together is going to change dramatically in the 4.3 series, so this issue will no longer be applicable. However, do feel free to submit a patch for the 4.2.x branch.

Oleg 
                
> Empty HttpParams for cacheable requests
> ---------------------------------------
>
>                 Key: HTTPCLIENT-1240
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1240
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Francois-Xavier Bonnet
>            Priority: Minor
>             Fix For: 4.3 Alpha1
>
>
> With DefaultHttpClient, HttpResponse.getParams() returns a ClientParamsStack with all the parameters previously set at HttpClient or HttpRequest level.
> With CachingHttpClient it returns an empty BasicHttpParams when a response is cached.
> This feature can be very usefull when you are doing complex processing with Interceptors for example. It is described in HttpClient documentation:
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e299
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/ClientParamsStack.html
> CachingHttpClient should not break this feature.
> Here is some sample code:
> 	// Client and Request scoped params with DefaultHttpClient
> 	DefaultHttpClient httpClient = new DefaultHttpClient();
> 	httpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	HttpGet httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	HttpResponse response = httpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> 	// Same test with CachingHttpClient
> 	httpClient = new DefaultHttpClient();
> 	CachingHttpClient cachingHttpClient = new CachingHttpClient(httpClient);
> 	cachingHttpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	response = cachingHttpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> If you agree I can provide a patch and unit tests

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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


[jira] [Commented] (HTTPCLIENT-1240) Empty HttpParams for cacheable requests

Posted by "Francois-Xavier Bonnet (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1240?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13469405#comment-13469405 ] 

Francois-Xavier Bonnet commented on HTTPCLIENT-1240:
----------------------------------------------------

I just made the fix but as it adds a call to method getParams() on the backend, it breaks hundreds of unit tests.

Tests run: 963, Failures: 509, Errors: 0, Skipped: 2

java.lang.AssertionError:
  Unexpected method call getParams():

I don't see a way I can fix it without fixing 509 unit tests.
                
> Empty HttpParams for cacheable requests
> ---------------------------------------
>
>                 Key: HTTPCLIENT-1240
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1240
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: Cache
>    Affects Versions: 4.2.1
>            Reporter: Francois-Xavier Bonnet
>            Priority: Minor
>             Fix For: 4.3 Alpha1
>
>
> With DefaultHttpClient, HttpResponse.getParams() returns a ClientParamsStack with all the parameters previously set at HttpClient or HttpRequest level.
> With CachingHttpClient it returns an empty BasicHttpParams when a response is cached.
> This feature can be very usefull when you are doing complex processing with Interceptors for example. It is described in HttpClient documentation:
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e299
> http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/ClientParamsStack.html
> CachingHttpClient should not break this feature.
> Here is some sample code:
> 	// Client and Request scoped params with DefaultHttpClient
> 	DefaultHttpClient httpClient = new DefaultHttpClient();
> 	httpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	HttpGet httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	HttpResponse response = httpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> 	// Same test with CachingHttpClient
> 	httpClient = new DefaultHttpClient();
> 	CachingHttpClient cachingHttpClient = new CachingHttpClient(httpClient);
> 	cachingHttpClient.getParams().setParameter("testClientParam", "testClientParam");
> 	httpGet = new HttpGet("http://www.google.fr/images/srpr/logo3w.png");
> 	httpGet.getParams().setParameter("testRequestParam", "testRequestParam");
> 	response = cachingHttpClient.execute(httpGet);
> 	EntityUtils.consumeQuietly(response.getEntity());
> 	System.out.println(response.getParams().getParameter("testClientParam"));
> 	System.out.println(response.getParams().getParameter("testRequestParam"));
> If you agree I can provide a patch and unit tests

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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