From f1d50b1b4fbf570e3c6b4ca1c2f0f2bac4068205 Mon Sep 17 00:00:00 2001 From: Joni Lahtinen Date: Wed, 14 Aug 2024 09:28:06 +0300 Subject: [PATCH] Build with java 11 --- Gemfile.lock | 1 + .../jruby/rack/mock/MockServletContext.java | 25 +++++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ea3386b7..442a6001 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -23,6 +23,7 @@ GEM PLATFORMS universal-java-1.8 + universal-java-11 DEPENDENCIES appraisal (< 1.0) diff --git a/src/spec/java/org/jruby/rack/mock/MockServletContext.java b/src/spec/java/org/jruby/rack/mock/MockServletContext.java index 8592f55d..79c54da0 100644 --- a/src/spec/java/org/jruby/rack/mock/MockServletContext.java +++ b/src/spec/java/org/jruby/rack/mock/MockServletContext.java @@ -21,6 +21,9 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collections; import java.util.EnumSet; import java.util.Enumeration; @@ -31,7 +34,6 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import javax.activation.FileTypeMap; import javax.servlet.Filter; import javax.servlet.FilterRegistration; import javax.servlet.RequestDispatcher; @@ -263,7 +265,12 @@ public int getEffectiveMinorVersion() { @Override public String getMimeType(String filePath) { - return MimeTypeResolver.getMimeType(filePath); + try { + Path path = Paths.get(filePath); + return Files.probeContentType(path); + } catch (IOException e) { + return "application/octet-stream"; // default MIME type + } } @Override @@ -456,20 +463,6 @@ public String getServletContextName() { return this.servletContextName; } - - /** - * Inner factory class used to just introduce a Java Activation Framework - * dependency when actually asked to resolve a MIME type. - */ - private static class MimeTypeResolver { - - public static String getMimeType(String filePath) { - return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath); - } - - } - - //--------------------------------------------------------------------- // Methods introduced in Servlet 3.0 //---------------------------------------------------------------------