List of usage examples for java.net JarURLConnection getContentLength
public int getContentLength()
From source file:org.apache.cxf.management.web.browser.bootstrapping.BootstrapStorage.java
@GET @Path("{resource:.*}") public Response getResource(@Context final MessageContext mc, @PathParam("resource") final String resource) { if (isLastModifiedRequest(mc)) { return Response.notModified().build(); }/*from w w w . j a v a 2 s . co m*/ try { URL url; URL jar = getClass().getProtectionDomain().getCodeSource().getLocation(); url = new URL(String.format("jar:%s!/static-content/logbrowser/%s", jar, resource)); JarURLConnection connection = (JarURLConnection) url.openConnection(); if (connection.getContentLength() == -1 || connection.getJarEntry() == null) { return Response.status(Status.NOT_FOUND).build(); } else if (connection.getJarEntry().isDirectory()) { return Response.status(Status.FORBIDDEN).build(); } else { // correct MediaType mime = getMimeType(mc, resource); StaticFile staticFile = new StaticFile(url, acceptsGzip(mc), mime); Response.ResponseBuilder builder = Response.ok(staticFile); builder.variant(new Variant(mime, (Locale) null, staticFile.isGzipEnabled() ? "gzip" : null)); return builder.build(); } } catch (MalformedURLException e) { return Response.status(Status.BAD_REQUEST).build(); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Error occur while retrieve static file", e); return Response.serverError().build(); } }