|
|
@ -12,8 +12,6 @@ import com.fr.third.springframework.web.context.support.AnnotationConfigWebAppli |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import org.apache.catalina.Context; |
|
|
|
import org.apache.catalina.Context; |
|
|
|
import org.apache.catalina.LifecycleException; |
|
|
|
import org.apache.catalina.LifecycleException; |
|
|
|
import org.apache.catalina.Wrapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.catalina.loader.WebappLoader; |
|
|
|
import org.apache.catalina.loader.WebappLoader; |
|
|
|
import org.apache.catalina.startup.Tomcat; |
|
|
|
import org.apache.catalina.startup.Tomcat; |
|
|
|
|
|
|
|
|
|
|
@ -25,12 +23,12 @@ import java.util.Set; |
|
|
|
* Created by juhaoyu on 2018/6/5. |
|
|
|
* Created by juhaoyu on 2018/6/5. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FineEmbedServerActivator extends Activator { |
|
|
|
public class FineEmbedServerActivator extends Activator { |
|
|
|
|
|
|
|
|
|
|
|
private Tomcat tomcat; |
|
|
|
private Tomcat tomcat; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public synchronized void start() { |
|
|
|
public synchronized void start() { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
//初始化tomcat
|
|
|
|
//初始化tomcat
|
|
|
|
initTomcat(); |
|
|
|
initTomcat(); |
|
|
@ -39,10 +37,10 @@ public class FineEmbedServerActivator extends Activator { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public synchronized void stop() { |
|
|
|
public synchronized void stop() { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
stopSpring(); |
|
|
|
stopSpring(); |
|
|
|
stopServerActivator(); |
|
|
|
stopServerActivator(); |
|
|
@ -51,75 +49,62 @@ public class FineEmbedServerActivator extends Activator { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initTomcat() { |
|
|
|
private void initTomcat() { |
|
|
|
|
|
|
|
|
|
|
|
tomcat = new Tomcat(); |
|
|
|
tomcat = new Tomcat(); |
|
|
|
|
|
|
|
|
|
|
|
tomcat.setPort(DesignerEnvManager.getEnvManager().getEmbedServerPort()); |
|
|
|
tomcat.setPort(DesignerEnvManager.getEnvManager().getEmbedServerPort()); |
|
|
|
// 设置解码uri使用的字符编码
|
|
|
|
// 设置解码uri使用的字符编码
|
|
|
|
tomcat.getConnector().setURIEncoding(EncodeConstants.ENCODING_UTF_8); |
|
|
|
tomcat.getConnector().setURIEncoding(EncodeConstants.ENCODING_UTF_8); |
|
|
|
String docBase = new File(WorkContext.getCurrent().getPath()).getParent(); |
|
|
|
String docBase = new File(WorkContext.getCurrent().getPath()).getParent(); |
|
|
|
String appName = "/" + FRContext.getCommonOperator().getAppName(); |
|
|
|
String appName = "/" + FRContext.getCommonOperator().getAppName(); |
|
|
|
Context context = tomcat.addContext(appName, docBase); |
|
|
|
Context context = tomcat.addContext(appName, docBase); |
|
|
|
addDefaultServlet(context); |
|
|
|
Tomcat.initWebappDefaults(context); |
|
|
|
//覆盖tomcat的WebAppClassLoader
|
|
|
|
//覆盖tomcat的WebAppClassLoader
|
|
|
|
context.setLoader(new FRTomcatLoader()); |
|
|
|
context.setLoader(new FRTomcatLoader()); |
|
|
|
|
|
|
|
|
|
|
|
//直接指定initializer,tomcat就不用再扫描一遍了
|
|
|
|
//直接指定initializer,tomcat就不用再扫描一遍了
|
|
|
|
SpringServletContainerInitializer initializer = new SpringServletContainerInitializer(); |
|
|
|
SpringServletContainerInitializer initializer = new SpringServletContainerInitializer(); |
|
|
|
Set<Class<?>> classes = new HashSet<Class<?>>(); |
|
|
|
Set<Class<?>> classes = new HashSet<Class<?>>(); |
|
|
|
classes.add(FineWebApplicationInitializer.class); |
|
|
|
classes.add(FineWebApplicationInitializer.class); |
|
|
|
context.addServletContainerInitializer(initializer, classes); |
|
|
|
context.addServletContainerInitializer(initializer, classes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addDefaultServlet(Context context) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Wrapper defaultServlet = context.createWrapper(); |
|
|
|
|
|
|
|
defaultServlet.setName("default"); |
|
|
|
|
|
|
|
defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); |
|
|
|
|
|
|
|
defaultServlet.addInitParameter("debug", "0"); |
|
|
|
|
|
|
|
defaultServlet.addInitParameter("listings", "false"); |
|
|
|
|
|
|
|
defaultServlet.setLoadOnStartup(1); |
|
|
|
|
|
|
|
defaultServlet.setOverridable(true); |
|
|
|
|
|
|
|
context.addChild(defaultServlet); |
|
|
|
|
|
|
|
context.addServletMapping("/","default"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void stopServerActivator() { |
|
|
|
private void stopServerActivator() { |
|
|
|
|
|
|
|
|
|
|
|
ModuleRole.ServerRoot.stop(); |
|
|
|
ModuleRole.ServerRoot.stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void stopSpring() { |
|
|
|
private void stopSpring() { |
|
|
|
|
|
|
|
|
|
|
|
AnnotationConfigWebApplicationContext context = ModuleRole.ServerRoot.getSingleton(AnnotationConfigWebApplicationContext.class); |
|
|
|
AnnotationConfigWebApplicationContext context = ModuleRole.ServerRoot.getSingleton(AnnotationConfigWebApplicationContext.class); |
|
|
|
if (context != null) { |
|
|
|
if (context != null) { |
|
|
|
context.stop(); |
|
|
|
context.stop(); |
|
|
|
context.destroy(); |
|
|
|
context.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void stopTomcat() throws LifecycleException { |
|
|
|
private void stopTomcat() throws LifecycleException { |
|
|
|
|
|
|
|
|
|
|
|
tomcat.stop(); |
|
|
|
tomcat.stop(); |
|
|
|
tomcat.destroy(); |
|
|
|
tomcat.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by juhaoyu on 2018/6/5. |
|
|
|
* Created by juhaoyu on 2018/6/5. |
|
|
|
* 自定义的tomcat loader,主要用于防止内置服务器再加载一遍class |
|
|
|
* 自定义的tomcat loader,主要用于防止内置服务器再加载一遍class |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static class FRTomcatLoader extends WebappLoader { |
|
|
|
private static class FRTomcatLoader extends WebappLoader { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public ClassLoader getClassLoader() { |
|
|
|
public ClassLoader getClassLoader() { |
|
|
|
|
|
|
|
|
|
|
|
return this.getClass().getClassLoader(); |
|
|
|
return this.getClass().getClassLoader(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|