Running Jetty from Junit under Maven...differing behaviour on server
I am running a jetty-servlet-tester from a unit test; it stands up a spring servlet, which I then query in the rest of the tests. It works fine from my IDE, and from maven on my desktop's command line. However, when I try to run it using maven on the build server, it is suddenly unable to resolve the urls I'm sending it. Why would the SimpleUrlHandlerMapping behave differently on a different machine? The maven version is identical; the only environmental difference I see is the JRE version (my machine has 1.6.24, the server has 1.6.10).
In reverse order, the error message:
Code:
08/18/2011 18:39:53 WARN servlet.DispatcherServlet No mapping found for HTTP request with URI [/api/copyfile/to/1/artifact/source] in DispatcherServlet with name 'testApiServlet'
...the actual application context of the spring webapp (applicationContext-internalapi.xml):
Code:
<beans>
...
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/job/**=apiJobController
/copyfile/**=apiCopyFileController
/parsefile/**=apiParseFileController
</value>
</property>
</bean>
...
</bean>
...the testApiServlet.xml, which the Jetty fired spring servlet looks for (I had no luck attaching a ContextLoaderListener with the real webapp's config):
Code:
<beans>
<import resource="classpath*:applicationContext-internalapi.xml" />
</beans>
...and the Jetty setup:
Code:
private ServletTester tester;
private String baseUrl;
private final File currentDir = new File(System.getProperty("user.dir"));
@Before
public void setup() throws Exception {
// copy WEB-INF to the current dir so that when running from maven, we can find this
final PathMatchingResourcePatternResolver pmrpr = new PathMatchingResourcePatternResolver();
final File file = pmrpr.getResource("classpath:WEB-INF/testApiServlet-servlet.xml").getFile();
final File webinf = file.getParentFile();
org.apache.commons.io.FileUtils.copyDirectoryToDirectory(webinf, currentDir);
tester = new ServletTester();
tester.setContextPath("/api");
final ServletContextHandler context = tester.getContext();
final ServletHolder servletHolder = new ServletHolder(DispatcherServlet.class);
servletHolder.setName("testApiServlet");
context.addServlet(servletHolder, "/*");
context.setResourceBase(currentDir.getAbsolutePath());
baseUrl = tester.createSocketConnector(true);
client.setBaseUrl(baseUrl + "/api");
tester.start();
...
I don't really love the WEB-INF copying (or the lack of the ContextLoaderListener), but again, this works both from the IDE and from maven on my desktop's terminal.