1

I want to override the DNS resolution when using Html Unit, so that I can test an explicit server behind a load balancer. This should be done without changing the etc/hosts file.

This question got's an answer how to solve that task with plain java: How to override DNS in HTTP connections in Java

But I need a solution with Html Unit.

Html Unit uses the apache httpclient. Is it possible to change the connection manager of the httpclient? (see other question above)

final WebClient webClient = new WebClient();
webClient.getOptions().set???
Community
  • 1
  • 1
Matthias M
  • 12,906
  • 17
  • 87
  • 116
  • *"Is it possible to change the connection manager of the httpclient?"* Isn't that exactly what the [linked answer](http://stackoverflow.com/a/35327982/5221149) does? – Andreas Jan 26 '17 at 22:29
  • Not really, because I can't find a way how to achieve that when using Html Unit. So if you can tell me how to change the connection manager with Html Unit that would help, too. – Matthias M Jan 26 '17 at 22:31

1 Answers1

2

To replace the default HttpClient used by WebClient, call setWebConnection() with a custom subclass of HttpWebConnection where you override createHttpClient().

Andreas
  • 154,647
  • 11
  • 152
  • 247