views:

26

answers:

0

I was wondering how I could test two servlets that need to communicate with one another in JUnit. I'm using com.meterware.servletunit.ServletRunner to run each servlet, but for some reason they cannot communicate with one another.

For example, servlet A needs to open up a URLConnection to servlet B, but when run in JUnit with both servlets registered (all context paths assumed correct) a ConnectException with the summary "Connection refused".

for instance:

csr = new ServletRunner();
csr.registerServlet("/boo/baz/*", xxx.class.getName());
gsr = new ServletRunner();
gsr.registerServlet("/foo/bar/*", yyy.class.getName());

// this request uses /foo/bar to make a new request for additional information from /boo/baz
WebRequest request = new GetMethodWebRequest("http://localhost:8080/foo/bar"); 
request.setHeaderField("Accept", WebTestHelper.BROWSER_ACCEPTS);
WebResponse response = gsr.newClient().getResponse(request); //Exception thrown 

Thanks!