本文整理汇总了Java中io.undertow.util.MimeMappings类的典型用法代码示例。如果您正苦于以下问题:Java MimeMappings类的具体用法?Java MimeMappings怎么用?Java MimeMappings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MimeMappings类属于io.undertow.util包,在下文中一共展示了MimeMappings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: init
import io.undertow.util.MimeMappings; //导入依赖的package包/类
public void init() throws IOException {
final int apiPort = Configuration.integer(DefaultConfSettings.API_PORT);
final String apiHost = Configuration.string(DefaultConfSettings.API_HOST);
log.debug("Binding JSON-REST API Undertown server on {}:{}", apiHost, apiPort);
server = Undertow.builder().addHttpListener(apiPort, apiHost)
.setHandler(path().addPrefixPath("/", new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
HttpString requestMethod = exchange.getRequestMethod();
if (Methods.OPTIONS.equals(requestMethod)) {
String allowedMethods = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,CONNECT,PATCH";
// return list of allowed methods in response headers
exchange.setStatusCode(StatusCodes.OK);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE,
MimeMappings.DEFAULT_MIME_MAPPINGS.get("txt"));
exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0);
exchange.getResponseHeaders().put(Headers.ALLOW, allowedMethods);
exchange.getResponseHeaders().put(new HttpString("Access-Control-Allow-Origin"), "*");
exchange.getResponseHeaders().put(new HttpString("Access-Control-Allow-Headers"),
"Origin, X-Requested-With, Content-Type, Accept");
exchange.getResponseSender().close();
return;
}
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
processRequest(exchange);
}
})).build();
server.start();
}
开发者ID:AidosKuneen,项目名称:aidos-node,代码行数:36,代码来源:API.java
示例2: initializeMimeMappings
import io.undertow.util.MimeMappings; //导入依赖的package包/类
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(), mapping.getMimeType());
}
deployment.setMimeExtensionMappings(mappings);
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:DeploymentManagerImpl.java
示例3: getContentType
import io.undertow.util.MimeMappings; //导入依赖的package包/类
@Override
public String getContentType(final MimeMappings mimeMappings) {
final String fileName = file.getName();
int index = fileName.lastIndexOf('.');
if (index != -1 && index != fileName.length() - 1) {
return mimeMappings.getMimeType(fileName.substring(index + 1));
}
return null;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:FileResource.java
示例4: getContentType
import io.undertow.util.MimeMappings; //导入依赖的package包/类
@Override
public String getContentType(final MimeMappings mimeMappings) {
final String fileName = getName();
int index = fileName.lastIndexOf('.');
if (index != -1 && index != fileName.length() - 1) {
return mimeMappings.getMimeType(fileName.substring(index + 1));
}
return null;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:URLResource.java
示例5: identicon
import io.undertow.util.MimeMappings; //导入依赖的package包/类
public Object identicon(Request req, Response res) throws Exception {
String seed = req.params("seed").orElse("0000000");
String type = req.params("type")
.filter(s -> types.contains(s.toLowerCase())).orElse("png");
int size = req.query("s").filter(s -> s.matches("\\d{1,3}"))
.map(Integer::parseInt).filter(i -> i < 4097).orElse(48);
MimeMappings mm = req.raw().getAttachment(Core.CONFIG)
.get(Config.MIME_MAPPINGS);
res.type(mm.getMimeType(type));
return res.render(seed, Renderer.ofStream((p, os) -> {
render(seed, size, type, os);
}));
}
开发者ID:taichi,项目名称:sirusi,代码行数:16,代码来源:Sirusi.java
示例6: addCacheHandler
import io.undertow.util.MimeMappings; //导入依赖的package包/类
private void addCacheHandler(final DeploymentInfo servletBuilder) {
// this handles mime types and adds a simple cache for static files
servletBuilder.addInitialHandlerChainWrapper(new HandlerWrapper() {
@Override
public HttpHandler wrap(final HttpHandler handler) {
final ResourceHandler resourceHandler = new ResourceHandler(servletBuilder.getResourceManager());
io.undertow.util.MimeMappings.Builder mimes = MimeMappings.builder();
List<String> suffixList = new ArrayList<String>();
// add font mime types not included by default
mimes.addMapping("eot", "application/vnd.ms-fontobject");
mimes.addMapping("otf", "font/opentype");
mimes.addMapping("ttf", "application/x-font-ttf");
mimes.addMapping("woff", "application/x-font-woff");
suffixList.addAll(Arrays.asList(".eot",".otf",".ttf",".woff"));
// add the default types and any added in web.xml files
for(MimeMapping mime : servletBuilder.getMimeMappings()) {
log.debug("Adding mime-type: " + mime.getExtension() + " - " + mime.getMimeType());
mimes.addMapping(mime.getExtension(), mime.getMimeType());
suffixList.add("."+mime.getExtension());
}
resourceHandler.setMimeMappings(mimes.build());
String[] suffixes = new String[suffixList.size()];
suffixes = suffixList.toArray(suffixes);
// simple cacheHandler, someday maybe make this configurable
final CacheHandler cacheHandler = new CacheHandler(new DirectBufferCache(1024, 10, 10480), resourceHandler);
final PredicateHandler predicateHandler = predicate(Predicates.suffixes(suffixes), cacheHandler, handler);
return predicateHandler;
}
});
}
开发者ID:cfmlprojects,项目名称:runwar,代码行数:31,代码来源:Server.java
示例7: defaults
import io.undertow.util.MimeMappings; //导入依赖的package包/类
static OptionMap.Builder defaults() {
OptionMap.Builder omb = OptionMap.builder();
omb.set(ENV,
Objects.toString(System.getenv("SIDEN_ENV"), "development"));
omb.set(SIDEN_FAVICON, false);
omb.set(WAIT_FOR_GRACEFUL_SHUTDOWN, 30 * 1000);
omb.set(METHOD_OVERRIDE, false);
omb.set(DEFAULT_RENDERER, new RendererSelector<Object>());
omb.set(RENDERER_REPOSITORY, RendererRepository.EMPTY);
omb.set(CHARSET, StandardCharsets.UTF_8);
omb.set(DEFAULT_CONTENT_TYPE, "text/plain; charset=UTF-8");
MimeMappings.Builder mmb = MimeMappings.builder();
mmb.addMapping("ico", "image/x-icon");
omb.set(MIME_MAPPINGS, mmb.build());
omb.set(TRANSFER_MIN_SIZE, 16 * 1024);
omb.set(MAX_FILE_SIZE, -1);
omb.set(TEMP_DIR, new File(System.getProperty("java.io.tmpdir")));
omb.set(SESSION_COOKIE_NAME, "sid");
omb.set(MAX_SESSIONS, -1);
omb.set(DEFAULT_SESSION_TIMEOUT_SECONDS, 30 * 60);
omb.set(WS_MAX_IDLE_TIMEOUT, 0L);
omb.set(WS_BINARY_MESSAGE_BUFFER_SIZE, -1);
omb.set(WS_TEXT_MESSAGE_BUFFER_SIZE, -1);
omb.set(FRAME_OPTIONS, "SAMEORIGIN");
omb.set(USE_XSS_PROTECTION, true);
omb.set(USE_CONTENT_TYPE_OPTIONS, true);
return omb;
}
开发者ID:taichi,项目名称:siden,代码行数:36,代码来源:Config.java
示例8: render
import io.undertow.util.MimeMappings; //导入依赖的package包/类
@Override
public void render(Object model, HttpServerExchange sink)
throws IOException {
URL url = (URL) model;
OptionMap config = sink.getAttachment(Core.CONFIG);
MimeMappings mm = config.get(Config.MIME_MAPPINGS);
// TODO proxy?
URLResource resource = new URLResource(url, url.openConnection(),
url.getPath());
SecurityHandler.addContentType(sink, resource.getContentType(mm));
resource.serve(sink.getResponseSender(), sink,
IoCallback.END_EXCHANGE);
}
开发者ID:taichi,项目名称:siden,代码行数:14,代码来源:RendererSelector.java
示例9: start
import io.undertow.util.MimeMappings; //导入依赖的package包/类
@Override
public void start(FolderContext music, FolderContext mount, int port, String user, String password) throws Exception {
final ResourceHandler musicResourceHandler = new ResourceHandler();
musicResourceHandler.setResourceManager(new FileResourceManager(music.getFolder(), 0));
MimeMappings.Builder musicMimeMappingsBuilder = MimeMappings.builder(true);
musicMimeMappingsBuilder.addMapping("mp3", "audio/mpeg");
musicMimeMappingsBuilder.addMapping("m4a", "audio/mp4");
musicResourceHandler.setMimeMappings(musicMimeMappingsBuilder.build());
final ResourceHandler mountResourceHandler = new ResourceHandler();
mountResourceHandler.setResourceManager(new FileResourceManager(mount.getFolder(), 0));
mountResourceHandler.addWelcomeFiles("index.json");
MimeMappings.Builder mountMimeMappingsBuilder = MimeMappings.builder(false);
mountMimeMappingsBuilder.addMapping("json", "text/json");
mountResourceHandler.setMimeMappings(mountMimeMappingsBuilder.build());
final PathHandler pathHandler = new PathHandler(mountResourceHandler);
pathHandler.addPrefixPath(music.getPath(), musicResourceHandler);
pathHandler.addPrefixPath(mount.getPath(), mountResourceHandler);
HttpHandler handler = new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
System.out.println(exchange.getRequestPath());
pathHandler.handleRequest(exchange);
}
};
undertow = Undertow.builder().addHttpListener(port, null).setHandler(handler).build();
undertow.start();
}
开发者ID:beckchr,项目名称:musicmount,代码行数:32,代码来源:MusicMountServerUndertow.java
示例10: getMimeMappings
import io.undertow.util.MimeMappings; //导入依赖的package包/类
public MimeMappings getMimeMappings() {
return mimeMappings;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:ResourceHandler.java
示例11: setMimeMappings
import io.undertow.util.MimeMappings; //导入依赖的package包/类
public ResourceHandler setMimeMappings(final MimeMappings mimeMappings) {
this.mimeMappings = mimeMappings;
return this;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:ResourceHandler.java
示例12: getContentType
import io.undertow.util.MimeMappings; //导入依赖的package包/类
@Override
public String getContentType(final MimeMappings mimeMappings) {
return underlyingResource.getContentType(mimeMappings);
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:CachedResource.java
示例13: toHttpResponse
import io.undertow.util.MimeMappings; //导入依赖的package包/类
@Override
public Object toHttpResponse(HttpServerExchange httpExchange, Message message) {
boolean failed = message.getExchange().isFailed();
int defaultCode = failed ? 500 : 200;
int code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, defaultCode, int.class);
httpExchange.setResponseCode(code);
TypeConverter tc = message.getExchange().getContext().getTypeConverter();
//copy headers from Message to Response
for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
// use an iterator as there can be multiple values. (must not use a delimiter)
final Iterator<?> it = ObjectHelper.createIterator(value, null);
while (it.hasNext()) {
String headerValue = tc.convertTo(String.class, it.next());
if (headerValue != null && headerFilterStrategy != null
&& !headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue, message.getExchange())) {
LOG.trace("HTTP-Header: {}={}", key, headerValue);
httpExchange.getResponseHeaders().add(new HttpString(key), headerValue);
}
}
}
Exception exception = message.getExchange().getException();
if (exception != null) {
httpExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MimeMappings.DEFAULT_MIME_MAPPINGS.get("txt"));
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
String exceptionMessage = sw.toString();
ExchangeHelper.setFailureHandled(message.getExchange());
return exceptionMessage;
}
// set the content type in the response.
String contentType = MessageHelper.getContentType(message);
if (contentType != null) {
// set content-type
httpExchange.getResponseHeaders().put(Headers.CONTENT_TYPE, contentType);
LOG.trace("Content-Type: {}", contentType);
}
return message.getBody();
}
开发者ID:HydAu,项目名称:Camel,代码行数:53,代码来源:DefaultUndertowHttpBinding.java
示例14: handleRequest
import io.undertow.util.MimeMappings; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange httpExchange) throws Exception {
UndertowConsumer consumer = resolver.resolve(httpExchange, consumers);
if (consumer == null) {
LOG.debug("Unable to resolve consumer matching path {}", httpExchange.getRequestPath());
new NotFoundHandler().handleRequest(httpExchange);
return;
}
HttpString requestMethod = httpExchange.getRequestMethod();
if (Methods.OPTIONS.equals(requestMethod) && !consumer.getEndpoint().isOptionsEnabled()) {
String allowedMethods;
if (consumer.getEndpoint().getHttpMethodRestrict() != null) {
allowedMethods = "OPTIONS," + consumer.getEndpoint().getHttpMethodRestrict();
} else {
allowedMethods = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,CONNECT,PATCH";
}
//return list of allowed methods in response headers
httpExchange.setResponseCode(StatusCodes.OK);
httpExchange.getResponseHeaders().put(ExchangeHeaders.CONTENT_TYPE, MimeMappings.DEFAULT_MIME_MAPPINGS.get("txt"));
httpExchange.getResponseHeaders().put(ExchangeHeaders.CONTENT_LENGTH, 0);
httpExchange.getResponseHeaders().put(Headers.ALLOW, allowedMethods);
httpExchange.getResponseSender().close();
return;
}
//reject if the method is not allowed
if (consumer.getEndpoint().getHttpMethodRestrict() != null
&& !consumer.getEndpoint().getHttpMethodRestrict().contains(requestMethod.toString())) {
httpExchange.setResponseCode(StatusCodes.METHOD_NOT_ALLOWED);
httpExchange.getResponseHeaders().put(ExchangeHeaders.CONTENT_TYPE, MimeMappings.DEFAULT_MIME_MAPPINGS.get("txt"));
httpExchange.getResponseHeaders().put(ExchangeHeaders.CONTENT_LENGTH, 0);
httpExchange.getResponseSender().close();
return;
}
//perform blocking operation on exchange
if (httpExchange.isInIoThread()) {
httpExchange.dispatch(this);
return;
}
//create new Exchange
//binding is used to extract header and payload(if available)
Exchange camelExchange = consumer.getEndpoint().createExchange(httpExchange);
//Unit of Work to process the Exchange
consumer.createUoW(camelExchange);
try {
consumer.getProcessor().process(camelExchange);
} catch (Exception e) {
consumer.getExceptionHandler().handleException(e);
} finally {
consumer.doneUoW(camelExchange);
}
Object body = getResponseBody(httpExchange, camelExchange, consumer);
TypeConverter tc = consumer.getEndpoint().getCamelContext().getTypeConverter();
if (body == null) {
LOG.trace("No payload to send as reply for exchange: " + camelExchange);
httpExchange.getResponseHeaders().put(ExchangeHeaders.CONTENT_TYPE, MimeMappings.DEFAULT_MIME_MAPPINGS.get("txt"));
httpExchange.getResponseSender().send("No response available");
} else {
ByteBuffer bodyAsByteBuffer = tc.convertTo(ByteBuffer.class, body);
httpExchange.getResponseSender().send(bodyAsByteBuffer);
}
httpExchange.getResponseSender().close();
}
开发者ID:HydAu,项目名称:Camel,代码行数:72,代码来源:HttpCamelHandler.java
示例15: getContentType
import io.undertow.util.MimeMappings; //导入依赖的package包/类
/**
* Return the resources content type. In most cases this will simply use the provided
* mime mappings, however in some cases the resource may have additional information as
* to the actual content type.
*/
String getContentType(final MimeMappings mimeMappings);
开发者ID:lamsfoundation,项目名称:lams,代码行数:7,代码来源:Resource.java
注:本文中的io.undertow.util.MimeMappings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论