On Sun, 2017-04-02 at 16:14 -0700, Gary Gregory wrote:
> On Sat, Apr 1, 2017 at 10:19 AM, Oleg Kalnichevski <[email protected]>
> wrote:
>
> > On Fri, 2017-03-31 at 16:34 -0700, Gary Gregory wrote:
> > > I am always casting when I call HttpContext.getAttribute(String)
> > > for
> > > well-known keys defined HttpCoreContext like HTTP_CONNECTION.
> > >
> > > It seems we could make
> > >
> > > org.apache.http.protocol.HttpCoreContext.getAttribute(String,
> > > Class<T>)
> > >
> > > part of the interface HttpContext.
> > >
> > > Thoughts?
> > >
> > > Gayr
> > >
> >
> > Hi Gary
> >
> > Usually one would probably want to use an adapter class such
> > HttpCoreContext or HttpClientContext to get access to context
> > specific
> > attributes but I am fine with moving the method to the generic
> > HttpContext interface.
> >
>
> Let me try to solve this from a different angle.
>
> I have an HttpContext and I want it's HttpConnection.
>
> - If I do an instanceof test for HttpCoreContext and call
> getConnection(),
> am I always going to get a non-null connection object?
> - If I call getAttribute(HttpCoreContext.HTTP_CONNECTION) on any
> HttpContext, will I only get a non-null object when the receiver is a
> HttpCoreContext?
>
> I do not want to make getAttribute(String, Class<T>) part of the
> interface
> if it is going to make things more confusing.
>
> Thank you,
> Gary
>
Hi Gary
Of course, casting HttpContext to HttpCoreContext cannot ensure
presence of a HttpConection attribute in the context but it can provide
an easier access to it.
---
HttpContext context = ...
HttpCoreContext coreContext = HttpCoreContext.adapt(context);
HttpClientConnection connection =
coreContext.getConnection(HttpClientConnection.class);
if (connection != null) {
// do stuff
}
---
Oleg
>
>
> >
> > Oleg
> >
> > -----------------------------------------------------------------
> > ----
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]