Skip to content

Instantly share code, notes, and snippets.

@amahdy
Last active March 7, 2017 10:06
Show Gist options
  • Save amahdy/43a8f528b6ae9f6de1e95f3f3cb5616c to your computer and use it in GitHub Desktop.
Save amahdy/43a8f528b6ae9f6de1e95f3f3cb5616c to your computer and use it in GitHub Desktop.
public static class MyUIServlet extends VaadinServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String pathInfo = request.getPathInfo();
if (pathInfo.endsWith("sw.js")) {
try (InputStream in = getClass().getResourceAsStream("/sw.js")) {
if (in == null) {
response.sendError(404);
return;
}
response.setContentType("application/javascript");
OutputStream out = response.getOutputStream();
IOUtils.copy(in, out);
in.close();
out.close();
}
} else {
super.service(request, response);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment