hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AbelMacAdam <abel.maca...@gmail.com>
Subject Re: java.lang.IllegalArgumentException: host parameter is null
Date Wed, 23 Jan 2008 13:02:56 GMT

Sorry, theUrl should be "http://localhost". :-[

AbelMacAdam wrote:
> 
> Hi,
> 
> After a few fruitless days struggling with JSSE, I finally found
> Commons-HTTPClient. I'm trying out the example TrivialApp you can download
> from the examples directory. And that example gives me an
> IllegalArgumentException headache. 
> 
> The code looks like:
>     static String username = "";
>     static String password = "";
>     static String theUrl   = "localhost";
>     static Logger logger;
> 
>     private static final void printUsage(String text)
>     {
>     	logger.info(text);
>     	System.out.println (text);
>     }
> 
>    public static void main(String[] args)
>     {
>     	logger = Logger.getLogger(TrivialApp.class);
>     	
>         Credentials creds = null;
>         creds = new UsernamePasswordCredentials(username, password);
> 
>         //create a singular HttpClient object
>         HttpClient client = new HttpClient();
> 
>         //establish a connection within 5 seconds
>         client.getHttpConnectionManager().
>             getParams().setConnectionTimeout(5000);
> 
>         //set the default credentials
>         if (creds != null) {
>             client.getState().setCredentials(AuthScope.ANY, creds);
>         }
> 
>         String url = theUrl;
>         HttpMethod method = null;
> 
>         //create a method object
>         method = new GetMethod(url);
>         method.setFollowRedirects(true);
> 
>         //execute the method
>         String responseBody = null;
>         try{
>             client.executeMethod(method);
>             responseBody = method.getResponseBodyAsString();
>         } catch (HttpException he) {
>             printUsage("Http error connecting to '" + url + "'");
>             printUsage(he.getMessage());
>             System.exit(-4);
>         } catch (IOException ioe){
>         	printUsage("Unable to connect to '" + url + "'");
>             System.exit(-3);
>         }
> 
>         //write out the request headers
>         printUsage("*** Request ***");
>         printUsage("Request Path: " + method.getPath());
>         printUsage("Request Query: " + method.getQueryString());
>         Header[] requestHeaders = method.getRequestHeaders();
>         for (int i=0; i<requestHeaders.length; i++){
>             System.out.print(requestHeaders[i]);
>         }
> 
>         //write out the response headers
>         printUsage("*** Response ***");
>         printUsage("Status Line: " + method.getStatusLine());
>         Header[] responseHeaders = method.getResponseHeaders();
>         for (int i=0; i<responseHeaders.length; i++){
>             System.out.print(responseHeaders[i]);
>         }
> 
>         //write out the response body
>         System.out.println("*** Response Body ***");
>         System.out.println(responseBody);
> 
>         //clean up the connection resources
>         method.releaseConnection();
> 
>         System.exit(0);
>     }
> 
> The stack trace I got for the Exception is:
> Exception in thread "main" java.lang.IllegalArgumentException: host
> parameter is null
> 	at
> org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:206)
> 	at
> org.apache.commons.httpclient.HttpConnection.<init>(HttpConnection.java:155)
> 	at
> org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnectionWithTimeout(SimpleHttpConnectionManager.java:175)
> 	at
> org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
> 	at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
> 	at TrivialApp.main(TrivialApp.java:107)
> 
> Long introduction. Concluding: Am I wrong in assuming the assignment 
>     theURL = "localhost"; 
> is wrong?
> 
> It is a real head scratcher. If you could point out where this goes wrong,
> I would be obliged.
> 
> TIA,
> Abel
> 

-- 
View this message in context: http://www.nabble.com/java.lang.IllegalArgumentException%3A-host-parameter-is-null-tp15040749p15041125.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Mime
View raw message