Java源码示例:io.undertow.servlet.api.MimeMapping
示例1
@BeforeClass
public static void setup() throws ServletException {
final PathHandler root = new PathHandler();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo()
.setClassIntrospecter(TestClassIntrospector.INSTANCE)
.setClassLoader(ContentTypeFilesTestCase.class.getClassLoader())
.setContextPath("/app")
.setDeploymentName("servletContext.war")
.setResourceManager(new TestResourceLoader(ContentTypeServlet.class))
.setDefaultServletConfig(new DefaultServletConfig(true))
.addMimeMapping(new MimeMapping("jnlp", "application/x-java-jnlp-file"));
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
root.addPrefixPath(builder.getContextPath(), manager.start());
DefaultServer.setRootHandler(root);
}
示例2
private void initializeMimeMappings(final DeploymentImpl deployment, final DeploymentInfo deploymentInfo) {
final Map<String, String> mappings = new HashMap<>(MimeMappings.DEFAULT_MIME_MAPPINGS);
for (MimeMapping mapping : deploymentInfo.getMimeMappings()) {
mappings.put(mapping.getExtension().toLowerCase(Locale.ENGLISH), mapping.getMimeType());
}
deployment.setMimeExtensionMappings(mappings);
}
示例3
private void initializeMimeMappings(final DeploymentImpl deployment, final DeploymentInfo deploymentInfo) {
final Map<String, String> mappings = new HashMap<>(MimeMappings.DEFAULT_MIME_MAPPINGS);
for (MimeMapping mapping : deploymentInfo.getMimeMappings()) {
mappings.put(mapping.getExtension().toLowerCase(Locale.ENGLISH), mapping.getMimeType());
}
deployment.setMimeExtensionMappings(mappings);
}
示例4
public void addMimeMapping(RuntimeValue<DeploymentInfo> info, String extension,
String mimeType) throws Exception {
info.getValue().addMimeMapping(new MimeMapping(extension, mimeType));
}
示例5
/**
* 让 undertow 支持音视频格式文件在线播放
*/
public static void init(DeploymentInfo di) {
for (Map.Entry<String,String> entry : mappings.entrySet()){
di.addMimeMapping(new MimeMapping(entry.getKey(),entry.getValue()));
}
}