Skip to content

Commit 73be8e9

Browse files
authored
Merge pull request #264 from jlahtinen/build-with-java-11
Enables building jruby-rack with java versions > 8
2 parents 55b183e + f1d50b1 commit 73be8e9

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

Gemfile.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ GEM
2323

2424
PLATFORMS
2525
universal-java-1.8
26+
universal-java-11
2627

2728
DEPENDENCIES
2829
appraisal (< 1.0)

src/spec/java/org/jruby/rack/mock/MockServletContext.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import java.io.InputStream;
2222
import java.net.MalformedURLException;
2323
import java.net.URL;
24+
import java.nio.file.Files;
25+
import java.nio.file.Path;
26+
import java.nio.file.Paths;
2427
import java.util.Collections;
2528
import java.util.EnumSet;
2629
import java.util.Enumeration;
@@ -31,7 +34,6 @@
3134
import java.util.LinkedHashSet;
3235
import java.util.Map;
3336
import java.util.Set;
34-
import javax.activation.FileTypeMap;
3537
import javax.servlet.Filter;
3638
import javax.servlet.FilterRegistration;
3739
import javax.servlet.RequestDispatcher;
@@ -263,7 +265,12 @@ public int getEffectiveMinorVersion() {
263265

264266
@Override
265267
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+
}
267274
}
268275

269276
@Override
@@ -456,20 +463,6 @@ public String getServletContextName() {
456463
return this.servletContextName;
457464
}
458465

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-
473466
//---------------------------------------------------------------------
474467
// Methods introduced in Servlet 3.0
475468
//---------------------------------------------------------------------

0 commit comments

Comments
 (0)