hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vasile Alin <alinachegal...@gmail.com>
Subject Re: In-memory DNS resolver for HC
Date Fri, 02 Sep 2011 14:58:38 GMT
On 2 September 2011 17:45, Bill Speirs <bill.speirs@gmail.com> wrote:

> That does make for a slightly more compelling argument, but I would
> say disable auto-redirects and handle them manually doing the DNS
> resolution?
>

This is OK in most of the cases.I see that JMeter has the option to follow
redirects automatically (with the limitations defined in the RFC), maybe in
this case there is a nice feature to allow custom host entries in a section
in the Preferences section. The question is if this case is frequent and
worths the effort to change the httpclient library.

Regarding the interface and implementation classes names, maybe DnsOverrider
and InMemoryDnsOverriderImpl are more appropriate and less missleading.

Regards,
Alin



>
> Bill-
>
> On Fri, Sep 2, 2011 at 10:32 AM, Vasile Alin <alinachegalati@gmail.com>
> wrote:
> > This is ok when the first request is made, but how about the situation
> when
> > HttpClient follows redirects automatically?
> >
> > On 2 September 2011 16:39, Bill Speirs <bill.speirs@gmail.com> wrote:
> >
> >> Why wouldn't you just have the code around HttppClient do this
> translation
> >> for you? Then you setup your requests to IP addresses, set the Host
> header
> >> to whatever you want and go.
> >>
> >> Adding a DNS resolver seems like a big (and possibly confusing) thing to
> >> add
> >> to the library when you can code around it.
> >>
> >> Bill-
> >> On Sep 1, 2011 4:18 PM, "Vasile Alin" <alinachegalati@gmail.com> wrote:
> >> > Hi,
> >> >
> >> > I had some situations when working directly with http-client or JMeter
> in
> >> > restrictive environments, where I wasn't able to edit the local
> >> /etc/hosts
> >> > file for resolving some custom hostnames. Based on the HttpUnit
> solution
> >> > [1], I was thinking that would be great if httpclient can lookup a
> >> hostname
> >> > in a custom DNS Resolver, editable or programable in the Java
> >> environment,
> >> > and fall-back to the default system address resolver if this isn't
> found
> >> in
> >> > the first place. For example the above snippet will resolve the "
> >> > www.alin.com" hostname to the one of the Google IPs:
> >> >
> >> > interface DnsResolver{
> >> >
> >> > InetAddress[] resolve(String hostname);
> >> >
> >> > }
> >> >
> >> > class InMemoryDnsResolverImpl implements DnsResolver{
> >> >
> >> > public InetAddress[] resolve(final String hostname){
> >> > try {
> >> > if ("www.alin.com".equals(hostname)) {
> >> > String ip = "74.125.39.105";
> >> > String[] ipParts = ip.split("\\.");
> >> >
> >> > byte[] byteIpAddress = new byte[4];
> >> > for (int i = 0; i < 4; i++) {
> >> > byteIpAddress[i] = Byte.parseByte(ipParts[i]);
> >> > }
> >> >
> >> > return new InetAddress[] { InetAddress
> >> > .getByAddress(byteIpAddress) };
> >> > } else {
> >> > return null;
> >> > }
> >> > } catch (UnknownHostException e) {
> >> > // log exception
> >> > return null;
> >> > }
> >> > }
> >> >
> >> > }
> >> >
> >> > public class DefaultClientConnectionOperator implements
> >> > ClientConnectionOperator {
> >> >
> >> > ....
> >> >
> >> > private DnsResolver dnsResolver;
> >> >
> >> > ...
> >> >
> >> > protected InetAddress[] resolveHostname(final String host) throws
> >> > UnknownHostException {
> >> > InetAddress[] resolvedAddress = null;
> >> >
> >> > if(dnResolver != null){
> >> > resolvedAddress = dnResolver.resolve(host);
> >> > }
> >> >
> >> > if(resolverAddress==null){
> >> > resolvedAddress = InetAddress.getAllByName(host);
> >> > }
> >> >
> >> > return resolvedAddress;
> >> >
> >> > }
> >> >
> >> > }
> >> >
> >> >
> >> > This functionality can be extended to get the IP addresses from a
> >> > properties file through an PropertyFileDnsResolverImpl and so on. What
> do
> >> > you think?
> >> >
> >> >
> >> > Regards,
> >> > Alin
> >> >
> >> >
> >> > [1] http://httpunit.sourceforge.net/
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

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