Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient exception: java.lang.IllegalArgumentException: host parameter is null

Tags:

java

http

apache

I have next code

    URL targetUrl = ...
    HttpClient client = new HttpClient(connectionManager);
    GetMethod getMethod = new GetMethod();
    getMethod.setPath(targetUrl.getPath());

    HostConfiguration hostConfiguration = getConfiguration(targetUrl) //unknown lib code

    client.executeMethod(hostConfiguration, getMethod);

In some cases(on some hosts) I get

java.lang.IllegalArgumentException: host parameter is null"

on client.executeMethod call.

Why may this happen?

like image 560
user590444 Avatar asked Jan 14 '23 12:01

user590444


1 Answers

The error message is misleading...

You must add the protocol in front of the host, something like HTTP:// or whatever you want to use. There may be other circumstances in which this happens, according to this blog article, but setHostConfiguration has been deprecated so this only applies to legacy code.

The client code should catch it earlier instead of failing so deep in the system, how can incorrect data go that far?

like image 54
Christophe Roussy Avatar answered Jan 17 '23 15:01

Christophe Roussy