On Sat, Nov 17, 2012 at 4:54 PM, Oleg Kalnichevski <[email protected]> wrote:

> On Sat, 2012-11-17 at 12:49 -0500, Gary Gregory wrote:
> > On Sat, Nov 17, 2012 at 10:25 AM, Oleg Kalnichevski <[email protected]
> >wrote:
> >
> > > On Fri, 2012-11-16 at 21:19 -0500, Gary Gregory wrote:
> > > > As a tangent I want to reduce this code pattern which is duplicated
> no
> > > less
> > > > than six times:
> > > >
> > > >         // determine the release version from packaged version info
> > > >         final VersionInfo vi = VersionInfo.loadVersionInfo
> > > >             ("org.apache.http.client",
> > > > HttpClientBuilder.class.getClassLoader());
> > > >         final String release = (vi != null) ?
> > > >             vi.getRelease() : VersionInfo.UNAVAILABLE;
> > > >         HttpProtocolParams.setUserAgent(params,
> > > >                 "Apache-HttpClient/" + release + " (java 1.5)");
> > > >
> > > > into a new method:
> > > >
> > > >     setUserAgent(params, "Apache-HttpClient",
> "org.apache.http.client",
> > > > HttpClientBuilder.class);
> > > >
> > > >     public static void setUserAgent(HttpParams params, String name,
> > > String
> > > > pkg, Class<?> cls) {
> > > >         final VersionInfo vi = VersionInfo.loadVersionInfo(pkg,
> > > > cls.getClassLoader());
> > > >         final String release = (vi != null) ? vi.getRelease() :
> > > > VersionInfo.UNAVAILABLE;
> > > >         HttpProtocolParams.setUserAgent(params, name + "/" + release
> + "
> > > > (java 1.5)");
> > > >     }
> > > >
> > > > The question is: where in Core should it go?
> > > >
> > > > I see that HttpProtocolParams is deprecated, so it cannot go in
> there.
> > > >
> > > > So... where?
> > > >
> > > > Gary
> > > >
> > >
> > > Gary
> > >
> > > HttpClient trunk is in a state of flux right now. But please bear with
> > > me a little while longer. I think HttpCore 4.3-alpha1 should be ready
> > > quite soon. Once HttpClient trunk picks up new APIs from HttpCore 4.3 a
> > > lot of things should become clearer (or so I would like to hope).
> > >
> > > ---
> > > I think this particular bit belongs to HttpClientBuilder and it should
> > > only be used once. Another place for it might be HttpClientUtils.
> > >
> >
> > But neither of these classes are in the Core. The 3 (not 6) code
> > duplications are in both the regular and async clients such that the core
> > is the only place to put it to avoid duplication. Am I missing something?
> > -
> >
> org.apache.http.impl.nio.client.DefaultHttpAsyncClient.setDefaultHttpParams(HttpParams)
> > -
> >
> org.apache.http.impl.client.builder.HttpClientBuilder.setUserAgent(HttpParams,
> > String, String, Class<?>)
> > -
> >
> org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(HttpParams)
> >
> >
>
> I was just thinking that the client was the right place given the
> snippet in question clearly had HttpClient specific bits.
>
> Anyway, feel free to put that code in a place you deem most appropriate.
> There is now o.a.h.config package in core for configuration components.
> o.a.h.utils might be another place.
>

Hi Oleg,

I'm not sure how this would work in the o.a.h.config context. I can add new
Utils class in o.a.h.utils but how would that be better or different than
the deprecated HttpProtocolParams?

Thank you for your guidance,
Gary

>
> > > I am also in favor of option 3. Besides, we might even have something
> > > that combine option 2 and 3
> > >
> > > 3) User-Agent: Apache-HttpClient/4.2.1 (Java 1.5 compatible;
> > > Java/1.6.0_35)
> > >
> >
> > Hm... but HttpClient is also "compatible" with Java 1.6, that's why I
> > considered the "minimum" verbiage:
> >
> > 3) User-Agent: Apache-HttpClient/4.2.1 (Java 1.5 minimum; Java/1.6.0_35)
> >
>
> Fair enough. Makes sense.
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
E-Mail: [email protected] | [email protected]
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Reply via email to