Skip to content

Commit

Permalink
Merge pull request #264 from jlahtinen/build-with-java-11
Browse files Browse the repository at this point in the history
Enables building jruby-rack with java versions > 8
  • Loading branch information
enebo authored Aug 21, 2024
2 parents 55b183e + f1d50b1 commit 73be8e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ GEM

PLATFORMS
universal-java-1.8
universal-java-11

DEPENDENCIES
appraisal (< 1.0)
Expand Down
25 changes: 9 additions & 16 deletions src/spec/java/org/jruby/rack/mock/MockServletContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
//---------------------------------------------------------------------
Expand Down

0 comments on commit 73be8e9

Please sign in to comment.