scream78 / oauth

Automatically exported from code.google.com/p/oauth
0 stars 0 forks source link

Java OAuth library should support gzip compression #60

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

Background:

 - I am building an OAuth consumer application (not a web service)

 - my Java application uses this class:

   net.oauth.client.httpclient4.OAuthHttpClient

Currently, the OAuthHttpClient class:

  -- does not set the "Accept-Encoding: gzip" request header

  -- assumes that HTTP responses are always uncompressed

I am going to implement support for gzip compression.  I plan to contribute
the code to the OAuth Java project.

Original issue reported on code.google.com by sean%sea...@gtempaccount.com on 4 Nov 2008 at 5:41

GoogleCodeExporter commented 9 years ago
Let's not add a dependency from the pre-existing OAuth library classes to any 
new .jars.  Applications that don't need gzip decompression must not be 
required to 
add anything to their classpath.

Ideally, this feature will be available in all subclasses of OAuthClient.  
Could 
they share code, to implement it?  A relevant question is whether the 
underlying 
HTTP implementations (the JRE, HttpClient 3 and HttpComponents 4) have built-in 
support for decompression.

Original comment by jmkrist...@gmail.com on 5 Nov 2008 at 5:19

GoogleCodeExporter commented 9 years ago

To support HttpClient 4, I have written a request interceptor and a response
interceptor.   

I am attaching 4 files that enable Gzip support in 
net.oauth.client.httpclient4.OAuthHttpClient

HttpClient 3 lacks the "interceptor" feature in HttpClient 4.   This makes Gzip
support less straightforward in the HttpClient 3 codebase.   

I don't have any personal interest in the HttpClient 3 OAuth classes but I can 
look
at adding Gzip support if others express interest.

Original comment by sean%sea...@gtempaccount.com on 5 Nov 2008 at 10:36

Attachments:

GoogleCodeExporter commented 9 years ago
HttpURLConnection and Apache HttpClient version 3 don't have built-in support 
for 
decompression either, I find.

I'm going to refactor OAuthClient and its subclasses, to separate OAuth from 
HTTP.  
This is needed to support Content-Encoding and other headers in a uniform way, 
for 
all three underlying HTTP libraries.  As part of this work, I intend to create 
a new 
class that models an HTTP message (distinct from an OAuth message).

Original comment by jmkrist...@gmail.com on 7 Nov 2008 at 5:21

GoogleCodeExporter commented 9 years ago
Implemented in -r728.

Original comment by jmkrist...@gmail.com on 13 Nov 2008 at 5:13

GoogleCodeExporter commented 9 years ago
Thanks!  I just ran "svn update" and "mvn clean package" in my local workspce.

I am seeing compilation errors in core/src/test:

[INFO] Compilation failure

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[30,36]
cannot find symbol
symbol  : class ExcerptInputStream
location: class net.oauth.client.OAuthClient

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/signature/Ec
ho.java:[65,35]
cannot find symbol
symbol  : method getContentType()
location: class net.oauth.OAuthMessage

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/signature/Ec
ho.java:[66,41]
cannot find symbol
symbol  : method getContentCharset()
location: class net.oauth.OAuthMessage

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[55,58]
cannot find symbol
symbol  : variable RESPONSE_HEADERS
location: class net.oauth.OAuthProblemException

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[119,64]
cannot find symbol
symbol  : method getContentCharset()
location: class net.oauth.OAuthMessage

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[120,58]
cannot find symbol
symbol  : method getContentType()
location: class net.oauth.OAuthMessage

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[210,59]
cannot find symbol
symbol  : method getContentCharset()
location: class net.oauth.client.OAuthClientTest.MessageWithBody

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[213,9]
method does not override a method from its superclass

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[219,22]
getHeader(java.lang.String) in net.oauth.client.OAuthClientTest.MessageWithBody
cannot override getHeader(java.lang.String) in net.oauth.OAuthMessage; 
overridden
method is final

/foobar/Documents/workspace/oauth-java/core/src/test/java/net/oauth/client/OAuth
ClientTest.java:[227,47]
getHeaders() in net.oauth.client.OAuthClientTest.MessageWithBody cannot override
getHeaders() in net.oauth.OAuthMessage; overridden method is final

Original comment by sean%sea...@gtempaccount.com on 13 Nov 2008 at 5:42

GoogleCodeExporter commented 9 years ago
The compile errors were due to a problem in my local workspace.  I replaced my 
local
files with the trunk code and everything compiles.

mvn clean package

Thanks John!

Original comment by sean%sea...@gtempaccount.com on 13 Nov 2008 at 5:55

GoogleCodeExporter commented 9 years ago

I just tested HTTP gzip support with Plaxo's PortableContacts service.  It 
works great.

  OAuthConsumer c = new OAuthConsumer(
    oauthCallBackUrl, 
    consumerToken.getPublicToken(), 
    consumerToken.getSecret(), 
    getOAuthServiceProvider());

  c.setProperty(OAuthClient.ACCEPT_ENCODING, "gzip, deflate");

I am using this feature in the jpoco project, http://code.google.com/p/jpoco

Great work John!

Original comment by sean%sea...@gtempaccount.com on 13 Nov 2008 at 5:53

GoogleCodeExporter commented 9 years ago
A slightly better idiom is:
c.setProperty(OAuthClient.ACCEPT_ENCODING, HttpMessageDecoder.ACCEPTED);

Incidentally, net.oauth.ConsumerProperties provides a convenient way to 
construct a 
Consumer from a resource or Properties object.

Original comment by jmkrist...@gmail.com on 13 Nov 2008 at 6:17