Hi,

I am using the code below (1) to test a servlet. The test fails saying that the returned content type is "application/octet-stream", whereas it should be "application/x-javascript" as defined in my web.xml (2). When I use my servlet through a Tomcat server, I get the right content type.

Am I doing something wrong ? Thanks and best regards.

--
(1) Code for the test:

File resFile = new File("data/tabs.js");
resFile.delete();

File webfile = new File("web/WEB-INF/web.xml");
ServletRunner sr = new ServletRunner(webfile, "/context");
ServletUnitClient sc = sr.newClient();
WebRequest request = new GetMethodWebRequest("http://localhost:8080/context/_resources/js/tabs.js");
WebResponse response = sc.getResponse(request);

System.err.println(response.getContentType());
InputStream in = response.getInputStream();
OutputStream out = new FileOutputStream(resFile);
   
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
}
in.close();
out.close();

assertNotNull("No response", response);
assertEquals("Bad content type", "application/x-javascript", response.getContentType());

sr.shutDown();

--
(2) web.xml snippet:
  <mime-mapping>
    <extension>js</extension>
    <mime-type>application/x-javascript</mime-type>
  </mime-mapping>

--
J-B.L - Anyware Technologies