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-tp15040749p15040749.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]