This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
<!--
|
||||
全局的参数配置, 可以通过@Resource(name="property.xxxxxx") 进行注入, 被注解的字段类型只能是String、primitive class
|
||||
如果name是system.property.开头的值将会在进程启动时进行System.setProperty("yyyy", "YYYYYY")操作。
|
||||
如果name是mimetype.property.开头的值将会在进程启动时进行MimeType.add("yyyy", "YYYYYY")操作。
|
||||
load: 加载文件,多个用;隔开。
|
||||
默认置入的system.property.的有:
|
||||
System.setProperty("convert.bson.pool.size", "128");
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.xml.parsers.*;
|
||||
import org.redkale.convert.bson.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.source.*;
|
||||
@@ -248,6 +249,8 @@ public final class Application {
|
||||
if (name == null || value == null) continue;
|
||||
if (name.startsWith("system.property.")) {
|
||||
System.setProperty(name.substring("system.property.".length()), value);
|
||||
} else if (name.startsWith("mimetype.property.")) {
|
||||
MimeType.add(name.substring("mimetype.property.".length()), value);
|
||||
} else {
|
||||
factory.register("property." + name, value);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* 配合 BasedHttpServlet 使用, 当标记为 @AuthIgnore 的方法不会再调用之前调用authenticate 方法。
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@Inherited
|
||||
|
||||
@@ -8,6 +8,8 @@ package org.redkale.net.http;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 配合 BasedHttpServlet 使用, 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一定时间(默认值timeout=15秒)。
|
||||
* 通常情况下 @HttpCacheable 需要与 @AuthIgnore 一起使用,因为没有标记@AuthIgnore的方法一般输出的结果与当前用户信息有关。
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
|
||||
@@ -169,72 +169,30 @@ public class MimeType {
|
||||
contentTypes.put("zip", "application/zip");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param extension the extension
|
||||
*
|
||||
* @return the content type associated with <code>extension</code>. If no association is found, this method will return <code>text/plain</code>
|
||||
*/
|
||||
public static String get(String extension) {
|
||||
return get(extension, "text/plain");
|
||||
return contentTypes.getOrDefault(extension, "text/plain");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param extension the extension
|
||||
* @param defaultCt the content type to return if there is no known association for the specified extension
|
||||
*
|
||||
* @return the content type associated with <code>extension</code> or if no associate is found, returns <code>defaultCt</code>
|
||||
*/
|
||||
public static String get(String extension, String defaultCt) {
|
||||
final String mime = contentTypes.get(extension);
|
||||
return mime == null ? defaultCt : mime;
|
||||
return contentTypes.getOrDefault(extension, defaultCt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param extension the extension
|
||||
*
|
||||
* @return <code>true</code> if the specified extension has been registered otherwise, returns <code>false</code>
|
||||
*/
|
||||
public static boolean contains(String extension) {
|
||||
return contentTypes.containsKey(extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Associates the specified extension and content type </p>
|
||||
*
|
||||
* @param extension the extension
|
||||
* @param contentType the content type associated with the extension
|
||||
*/
|
||||
public static void add(String extension, String contentType) {
|
||||
if (extension != null && extension.length() != 0
|
||||
&& contentType != null && contentType.length() != 0) {
|
||||
if (extension != null && extension.length() != 0 && contentType != null && contentType.length() != 0) {
|
||||
contentTypes.put(extension, contentType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName the filename
|
||||
*
|
||||
* @return the content type associated with <code>extension</code> of the given filename or if no associate is found, returns <code>null</code>
|
||||
*/
|
||||
public static String getByFilename(String fileName) {
|
||||
String extn = getExtension(fileName);
|
||||
return extn == null ? null : get(extn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension of file, without fragment id
|
||||
*/
|
||||
private static String getExtension(String fileName) {
|
||||
// play it safe and get rid of any fragment id
|
||||
// that might be there
|
||||
int length = fileName.length();
|
||||
|
||||
int newEnd = fileName.lastIndexOf('#');
|
||||
if (newEnd == -1) newEnd = length;
|
||||
// Instead of creating a new string.
|
||||
// if (i != -1) fileName = fileName.substring(0, i);
|
||||
int i = fileName.lastIndexOf('.', newEnd);
|
||||
return i == -1 ? null : fileName.substring(i + 1, newEnd);
|
||||
return (i < 0) ? null : get(fileName.substring(i + 1, newEnd));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user