hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: org.apache.http.protocol.HttpCoreContext.getAttribute(String, Class<T>)
Date Mon, 03 Apr 2017 16:15:14 GMT
On Sun, 2017-04-02 at 16:14 -0700, Gary Gregory wrote:
> On Sat, Apr 1, 2017 at 10:19 AM, Oleg Kalnichevski <olegk@apache.org>
> 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: dev-unsubscribe@hc.apache.org
> > For additional commands, e-mail: dev-help@hc.apache.org
> > 
> > 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message