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:32:56 GMT
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/
>

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