hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xu, Lilu" <cooki...@gmail.com>
Subject Re: Fluent HttpClient
Date Tue, 14 Jun 2011 11:34:12 GMT
Hi Thom,

thank you very much! Your suggestions really help me a lot.

Currently, I added a pair of methods named encodingOn() and encodingOff() to
support the URI escaping. Example codes are in the Encoding Swicher part of
WikiPage of UriBuilder [1].
[1] http://code.google.com/p/fluent-hc/wiki/UriBuilder


On Tue, Jun 7, 2011 at 7:22 PM, Thom Nichols <tmnichols@gmail.com> wrote:

> Looks great, I'm really excited about this project. (I think I mentioned
> before, I wrote an equivalent for Groovy:
> http://groovy.codehaus.org/modules/http-builder/ )
>
> Here's some more quick feedback:
>
> FluentResponse:
>
> Have a convenience method to get just the content-type value (without any
> encoding part) or just the encoding without the content-type.  Note that
> the
> content-encoding header is NOT the character set.
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5  To get the
> character set, you have to do this:
>
> https://fisheye.codehaus.org/browse/gmod/httpbuilder/tags/0.5.1/src/main/java/groovyx/net/http/ParserRegistry.java?hb=true#to128
> (see the next function down to get just the content-type without any
> encoding parameter.)
>
>
I have already updated the HttpResponse part [2], and now the content-type
value and charset can be accessed directly.
[2] http://code.google.com/p/fluent-hc/wiki/FluentResponse


> FluentRequest:
>
> One possibility would be to have a builder with a base URI, e.g.
>  FluentRequest req = RequestBuilder.build("http://hc.apache.org",
> GET_METHOD);
>
> but then allow the executed request to be against different paths, which
> makes for easy REST interface implementation.  e.g.
>
> FluentResponse resp1 = req.exec( '/httpcomponents-core-ga' )
> FluentResponse resp2 = req.exec( '/httpcomponents-client-ga' )
> I suppose the best way to implement this might be to implement clone() on
> FluentRequest so you could essentially take a base configured request
> object
> and copy it to add your specific changes.  Then you could call all the
> setPath, addQueryParameter functions without needing an exec() method that
> only can take pre-defined arguments.
>
> So something like this:
>  FluentRequest req = RequestBuilder.build("http://twitter.com/statuses/",
> GET_METHOD);
>
> resp1 = req.clone().setPath("user_timeline.xml").exec();
> resp2 = req.clone().setPath("update.xml").set(POST_METHOD).set( new
> StringEntity("status=updated%20status") ).exec()
>

I use another way to implement this job. The main idea is using UriBuilder's
setPath(String) method. You may find the example code on the bottom of the
WikiPage of UriBuilder [1].
[1] http://code.google.com/p/fluent-hc/wiki/UriBuilder



>
> A shortcut to create a url-encoded post body from a HashMap with the
> correct
> content-type set automatically would be super-handy :)
>
> Now we have the setQuery(HashMap) method to set the query part of an URI.
But if we do the similar things to create a POST body, how to detect the
content-type if the value set of the HashMap consisted of multiple types
instances? For example:
entity:HashMap {
  "key1" : value1,
  "key2" : value2
}
where value1 is an Integer or String, and value2 is a binary stream (e.g.
byte[])?


> XML parsing:
>
> (wishlist/ possibility) - ability to pass an XmlStreamReader instance
> instead of getting the response as DOM?  Or pass an XPath string to get a
> DOM element?
>
> Also, note that if you're going to allow built-in XML parsing, you really
> should have a catalog so that the HTTP DTD doesn't get requested every time
> -- this is a recipe for disaster because eventually the w3c server will
> start rejecting HTTP requests to the DTD URI, and the XML parsing will
> fail.  See:
> http://www.w3.org/blog/systeam/2008/02/08/w3c_s_excessive_dtd_traffic/
>
> I am not quite familiar with the XML parsing. Why does the built-in XML
parsing need to request to W3C server every time? Does it mean that we would
not able to parse XML without an Internet connection?


> Here's an example of how to use an XML catalog:
>
> https://fisheye.codehaus.org/browse/gmod/httpbuilder/tags/0.5.1/src/main/java/groovyx/net/http/ParserRegistry.java?hb=true#to103
>
> https://fisheye.codehaus.org/browse/gmod/httpbuilder/tags/0.5.1/src/main/resources/catalog
>
> Another wishlist item - built-in support for common content-encodings.
> (Someone else may have mentioned it.)  Here's my implementation:
>
> https://fisheye.codehaus.org/browse/gmod/httpbuilder/tags/0.5.1/src/main/java/groovyx/net/http/ContentEncoding.java?hb=true
>
> https://fisheye.codehaus.org/browse/gmod/httpbuilder/tags/0.5.1/src/main/java/groovyx/net/http/GZIPEncoding.java?hb=true
>
> https://fisheye.codehaus.org/browse/gmod/httpbuilder/tags/0.5.1/src/main/java/groovyx/net/http/DeflateEncoding.java?hb=true
>
> Thanks!  Although I wrote a client for Groovy, there are plenty of times
> when I have to use Java (think Android) and this would be super-handy to
> have.  Good work so far!
>
> -Thom
>
>
> On Wed, Jun 1, 2011 at 11:40 AM, Xu, Lilu <cookieme@gmail.com> wrote:
>
> > Hi,
> >
> > I almost finished the request execution module and most classes have been
> > re-designed. Please have a look at the wiki pages [1] of this project and
> > drop me some comments.
> > The wiki pages contain some simple examples to illustrate how to use the
> > facade API of httpclient.
> >
> > [1] http://code.google.com/p/fluent-hc/w/list
> > --
> > Best regards,
> > Lilu
> >
>



-- 
Best regards,
Lilu

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message