ContentTypeResolver { public static String get(final String fileName) { final String extension = FilenameUtils.getExtension(WroUtil.removeQueryString(fileName.toLowerCase())); if (defaultContentTypeMap.containsKey(extension)) { return defaultContentTypeMap.get(extension); } try { final Class<?> fileTypeMapClass = ClassLoader.getSystemClassLoader().loadClass("javax.activation.FileTypeMap"); LOG.debug("using {} to resolve contentType", fileTypeMapClass.getName()); final Object fileTypeMap = fileTypeMapClass.getMethod("getDefaultFileTypeMap").invoke(fileTypeMapClass); return (String) fileTypeMapClass.getMethod("getContentType", String.class).invoke(fileTypeMap, fileName); } catch (final Exception e) { LOG.debug("FileTypeMap is not available (probably jdk5 is used). Exception {}, with message: {}", e.getClass(), e.getMessage()); LOG.debug("Will use default content type: {} for fileName: {}", DEFAULT_CONTENT_TYPE, fileName); } return DEFAULT_CONTENT_TYPE; }  static String get(final String fileName); static String get(final String fileName, final String encoding);  }
@Test public void shouldResolveCSSExtenstion() { assertEquals("text/css", ContentTypeResolver.get("somefile.css")); }
@Test public void shouldResolveJPGExtenstion() { assertEquals("image/jpeg", ContentTypeResolver.get("s/bvews/omefile.jpg")); }
@Test public void shouldResolveJPGExtenstionWithoutCharset() { assertEquals("image/jpeg", ContentTypeResolver.get("s/bvews/omefile.jpg", StandardCharsets.UTF_8.name())); }
@Test public void shouldResolveHTMLExtenstion() { assertEquals("text/html", ContentTypeResolver.get("mefile.html")); }
@Test public void shouldResolveHTMLExtenstionWitCharset() { assertEquals("text/html; charset=UTF-8", ContentTypeResolver.get("mefile.html", StandardCharsets.UTF_8.name())); }
@Test public void shouldResolveJSExtenstion() { assertEquals("application/javascript", ContentTypeResolver.get("/ad/df/mefile.js")); }
@Test public void shouldResolveUnknownExtenstion() { assertEquals("application/octet-stream", ContentTypeResolver.get("/ad/df/mefile.unknown")); }
@Test public void shouldOnlyUseLastDot() { assertEquals("image/png", ContentTypeResolver.get("somefile.js.png")); }
@Test public void shouldResolveHTMLUpperCaseExtenstion() { assertEquals("text/css", ContentTypeResolver.get("mefile.CSS")); }
@Test public void shouldResolveFontExtensionEot() { assertEquals("application/vnd.ms-fontobject", ContentTypeResolver.get("font.eot")); }
@Test public void shouldResolveFontExtensionOtf() { assertEquals("application/x-font-opentype", ContentTypeResolver.get("font.otf")); }
@Test public void shouldResolveFontExtensionTtf() { assertEquals("application/octet-stream", ContentTypeResolver.get("font.ttf")); }
@Test public void shouldResolveSvg() { assertEquals("image/svg+xml", ContentTypeResolver.get("graphic.svg")); }
@Test public void shouldResolveWoff() { assertEquals("application/font-woff", ContentTypeResolver.get("webjars/font-awesome/4.4.0/fonts/fontawesome-webfont.woff")); }
@Test public void shouldResolveWoffAlsoWhenQueryParamsPresent() { assertEquals("application/font-woff", ContentTypeResolver.get("webjars/font-awesome/4.4.0/fonts/fontawesome-webfont.woff?v=4.4.0")); }
@Test public void shouldResolveWoff2() { assertEquals("application/font-woff2", ContentTypeResolver.get("webjars/font-awesome/4.4.0/fonts/fontawesome-webfont.woff2")); }