|
21 | 21 | import java.io.InputStream;
|
22 | 22 | import java.net.MalformedURLException;
|
23 | 23 | import java.net.URL;
|
| 24 | +import java.nio.file.Files; |
| 25 | +import java.nio.file.Path; |
| 26 | +import java.nio.file.Paths; |
24 | 27 | import java.util.Collections;
|
25 | 28 | import java.util.EnumSet;
|
26 | 29 | import java.util.Enumeration;
|
|
31 | 34 | import java.util.LinkedHashSet;
|
32 | 35 | import java.util.Map;
|
33 | 36 | import java.util.Set;
|
34 |
| -import javax.activation.FileTypeMap; |
35 | 37 | import javax.servlet.Filter;
|
36 | 38 | import javax.servlet.FilterRegistration;
|
37 | 39 | import javax.servlet.RequestDispatcher;
|
@@ -263,7 +265,12 @@ public int getEffectiveMinorVersion() {
|
263 | 265 |
|
264 | 266 | @Override
|
265 | 267 | public String getMimeType(String filePath) {
|
266 |
| - return MimeTypeResolver.getMimeType(filePath); |
| 268 | + try { |
| 269 | + Path path = Paths.get(filePath); |
| 270 | + return Files.probeContentType(path); |
| 271 | + } catch (IOException e) { |
| 272 | + return "application/octet-stream"; // default MIME type |
| 273 | + } |
267 | 274 | }
|
268 | 275 |
|
269 | 276 | @Override
|
@@ -456,20 +463,6 @@ public String getServletContextName() {
|
456 | 463 | return this.servletContextName;
|
457 | 464 | }
|
458 | 465 |
|
459 |
| - |
460 |
| - /** |
461 |
| - * Inner factory class used to just introduce a Java Activation Framework |
462 |
| - * dependency when actually asked to resolve a MIME type. |
463 |
| - */ |
464 |
| - private static class MimeTypeResolver { |
465 |
| - |
466 |
| - public static String getMimeType(String filePath) { |
467 |
| - return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath); |
468 |
| - } |
469 |
| - |
470 |
| - } |
471 |
| - |
472 |
| - |
473 | 466 | //---------------------------------------------------------------------
|
474 | 467 | // Methods introduced in Servlet 3.0
|
475 | 468 | //---------------------------------------------------------------------
|
|
0 commit comments