From 55d042c7906468c21aaec9c7da52c6dc882a5a13 Mon Sep 17 00:00:00 2001 From: Jinbokai Date: Wed, 18 Jul 2018 19:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=87=E6=BB=A4=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E7=A6=81=E6=AD=A2=E8=AE=BF=E9=97=AE=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jinbokai --- .../server/FineEmbedServerActivator.java | 22 ++++++++++++++ .../java/com/fr/start/server/ForbidType.java | 29 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 designer-base/src/main/java/com/fr/start/server/ForbidType.java diff --git a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java index 2292da99a3..01856ccd5b 100644 --- a/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java +++ b/designer-base/src/main/java/com/fr/start/server/FineEmbedServerActivator.java @@ -14,6 +14,8 @@ import org.apache.catalina.Context; import org.apache.catalina.LifecycleException; import org.apache.catalina.Wrapper; +import org.apache.catalina.deploy.FilterDef; +import org.apache.catalina.deploy.FilterMap; import org.apache.catalina.loader.WebappLoader; import org.apache.catalina.startup.Tomcat; @@ -62,6 +64,10 @@ public class FineEmbedServerActivator extends Activator { String docBase = new File(WorkContext.getCurrent().getPath()).getParent(); String appName = "/" + FRContext.getCommonOperator().getAppName(); Context context = tomcat.addContext(appName, docBase); + + //添加过滤器 + addFilter(context); + addDefaultServlet(context); //覆盖tomcat的WebAppClassLoader context.setLoader(new FRTomcatLoader()); @@ -72,6 +78,22 @@ public class FineEmbedServerActivator extends Activator { classes.add(FineWebApplicationInitializer.class); context.addServletContainerInitializer(initializer, classes); } + + private void addFilter(Context context){ + FilterDef filterDef = new FilterDef(); + filterDef.setFilterName("Forbidden"); + filterDef.setFilterClass("com.fr.start.server.ForbidType"); + + FilterMap filterMap = new FilterMap(); + filterMap.setFilterName("Forbidden"); + //指定过滤文件类型 + filterMap.addURLPattern("*.txt"); + filterMap.addURLPattern("*.xml"); + filterMap.addURLPattern("*.jar"); + + context.addFilterDef(filterDef); + context.addFilterMap(filterMap); + } private void addDefaultServlet(Context context) { diff --git a/designer-base/src/main/java/com/fr/start/server/ForbidType.java b/designer-base/src/main/java/com/fr/start/server/ForbidType.java new file mode 100644 index 0000000000..4dac8a69f3 --- /dev/null +++ b/designer-base/src/main/java/com/fr/start/server/ForbidType.java @@ -0,0 +1,29 @@ +package com.fr.start.server; + +import javax.servlet.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +public class ForbidType implements Filter { + private String message; + + public void init(FilterConfig config) throws ServletException { + message = config.getInitParameter("msg"); + + System.out.println("Filter is ready."); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + System.out.println(message); + + HttpServletResponse response = (HttpServletResponse) servletResponse; + + response.sendRedirect("/webroot/decision"); + } + + public void destroy() { + + } + +} \ No newline at end of file