@Override
public void handle(String pathInContext, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws HttpException, IOException {
// Get the resource.
URL path = ResourcesResponseHandler.class.getResource(_testContext + pathInContext);
if (path == null) {
throw new HttpException(404, "Resource not found: " + pathInContext);
}
try {
File file = new File(path.getFile());
byte[] bytes = new byte[(int) file.length()];
DataInputStream in = new DataInputStream(new FileInputStream(file));
in.readFully(bytes);
response.setContentLength(bytes.length);
if (file.getName().endsWith(".png")) {
response.setContentType("image/png");
} else {
response.setContentType("text/html");
}
response.setStatus(200);
OutputStream os = response.getOutputStream();
os.write(bytes);
} catch (Exception e) {
throw new HttpException(500, e.getMessage());
}
}