This commit is contained in:
@@ -29,7 +29,7 @@ import org.redkale.util.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Server节点的初始化配置类
|
* Server节点的初始化配置类
|
||||||
*
|
* <p>
|
||||||
* <p>
|
* <p>
|
||||||
* 详情见: http://redkale.org
|
* 详情见: http://redkale.org
|
||||||
*
|
*
|
||||||
@@ -170,6 +170,8 @@ public abstract class NodeServer {
|
|||||||
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");
|
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");
|
||||||
loadService(serviceFilter); //必须在servlet之前
|
loadService(serviceFilter); //必须在servlet之前
|
||||||
loadServlet(servletFilter);
|
loadServlet(servletFilter);
|
||||||
|
|
||||||
|
if (this.interceptor != null) this.resourceFactory.inject(this.interceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void loadServlet(ClassFilter<? extends Servlet> servletFilter) throws Exception;
|
protected abstract void loadServlet(ClassFilter<? extends Servlet> servletFilter) throws Exception;
|
||||||
@@ -384,7 +386,7 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ClassFilter createClassFilter(final String localGroup, Class<? extends Annotation> ref,
|
protected ClassFilter createClassFilter(final String localGroup, Class<? extends Annotation> ref,
|
||||||
Class inter, Class<? extends Annotation> ref2, String properties, String property) {
|
Class inter, Class<? extends Annotation> ref2, String properties, String property) {
|
||||||
ClassFilter cf = new ClassFilter(ref, inter, null);
|
ClassFilter cf = new ClassFilter(ref, inter, null);
|
||||||
if (properties == null && properties == null) return cf;
|
if (properties == null && properties == null) return cf;
|
||||||
if (this.serverConf == null) return cf;
|
if (this.serverConf == null) return cf;
|
||||||
@@ -454,6 +456,10 @@ public abstract class NodeServer {
|
|||||||
return sncpAddress;
|
return sncpAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AnyValue getServerConf() {
|
||||||
|
return serverConf;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSncpGroup() {
|
public String getSncpGroup() {
|
||||||
return sncpGroup;
|
return sncpGroup;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
|||||||
|
|
||||||
private HttpServlet resourceHttpServlet = new HttpResourceServlet();
|
private HttpServlet resourceHttpServlet = new HttpResourceServlet();
|
||||||
|
|
||||||
|
private final Map<String, Class> mapStrings = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(HttpContext context, AnyValue config) {
|
public void init(HttpContext context, AnyValue config) {
|
||||||
this.servlets.forEach(s -> {
|
this.servlets.forEach(s -> {
|
||||||
@@ -89,6 +91,10 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
|||||||
if (prefix == null) prefix = "";
|
if (prefix == null) prefix = "";
|
||||||
for (String mapping : mappings) {
|
for (String mapping : mappings) {
|
||||||
if (!prefix.toString().isEmpty()) mapping = prefix + mapping;
|
if (!prefix.toString().isEmpty()) mapping = prefix + mapping;
|
||||||
|
if (this.mapStrings.containsKey(mapping)) {
|
||||||
|
Class old = this.mapStrings.get(mapping);
|
||||||
|
throw new RuntimeException("mapping [" + mapping + "] repeat on " + old.getName() + " and " + servlet.getClass().getName());
|
||||||
|
}
|
||||||
if (contains(mapping, '.', '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\')) { //是否是正则表达式))
|
if (contains(mapping, '.', '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\')) { //是否是正则表达式))
|
||||||
if (mapping.charAt(0) != '^') mapping = '^' + mapping;
|
if (mapping.charAt(0) != '^') mapping = '^' + mapping;
|
||||||
if (mapping.endsWith("/*")) {
|
if (mapping.endsWith("/*")) {
|
||||||
@@ -104,11 +110,12 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
|||||||
regArray[regArray.length - 1] = new SimpleEntry<>(Pattern.compile(mapping).asPredicate(), servlet);
|
regArray[regArray.length - 1] = new SimpleEntry<>(Pattern.compile(mapping).asPredicate(), servlet);
|
||||||
}
|
}
|
||||||
} else if (mapping != null && !mapping.isEmpty()) {
|
} else if (mapping != null && !mapping.isEmpty()) {
|
||||||
this.mappings.put(mapping, servlet);
|
super.mappings.put(mapping, servlet);
|
||||||
}
|
}
|
||||||
|
this.mapStrings.put(mapping, servlet.getClass());
|
||||||
}
|
}
|
||||||
setServletConf(servlet, conf);
|
setServletConf(servlet, conf);
|
||||||
servlet._prefix = prefix == null ? "" : prefix.toString();
|
servlet._prefix = prefix.toString();
|
||||||
this.servlets.add(servlet);
|
this.servlets.add(servlet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +146,7 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
|||||||
((BasedHttpServlet) s).postDestroy(context, getServletConf(s));
|
((BasedHttpServlet) s).postDestroy(context, getServletConf(s));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.mapStrings.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user