I have a website and I’ve been trying to gather statistical data (mostly page render times) for the end user, for example: login time, search result time. I need something to mimic end-user activity.
So I did some searching and I came across HtmlUnit which seems to be able to do what I need. But I seem to be having trouble
Here is some text code that I pulled off of thier website:
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class htmlUnit {
public static void main(String[] args) throws Exception {
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://google.ca");
webClient.closeAllWindows();
}
}
Seems to give this error:
Exception in thread “main”
org.apache.http.conn.HttpHostConnectException:
Connection to http://google.ca refused
at
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:127)
at
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
at
org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
…………………………………………..
1) Am I on the right track? or do I need to look into something else?
2) How do I fix this error.
You must have a firewall forbidding you to directly access google.ca from a Java application. Or you need to go through a proxy to access google.ca.
Read http://htmlunit.sourceforge.net/gettingStarted.html for instructions about proxies and HtmlUnit.
You’re on the right track if you want to simulate one user activity. If you need to load-test your application with several users, you should look at something else (Apache JMeter for example)