Search in sources :

Example 1 with JFinalFilter

use of com.jfinal.core.JFinalFilter in project HttpApiJava by thevsk.

the class JettyStart method main.

public static void main(String[] args) {
    String path = JettyStart.class.getProtectionDomain().getCodeSource().getLocation().getFile();
    if (path == null) {
        throw new RuntimeException("jar path can't find");
    }
    if (path.contains(".jar")) {
        log.info("[服务] jar 环境");
        path = path.substring(0, path.lastIndexOf(separator));
    } else {
        log.info("[服务] 非 jar 环境");
        path = path.substring(0, path.length() - 1);
        path = path.substring(0, path.lastIndexOf(separator));
    }
    path += separator + "config.properties";
    File file = new File(path);
    if (!file.exists()) {
        throw new RuntimeException("properties can't find");
    }
    PropKit.use(file);
    EnumSet<DispatcherType> all = EnumSet.of(DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST);
    int port = PropKit.getInt("server.port");
    final Server server = new Server(port);
    log.info("[服务] 端口 " + port);
    try {
        WebAppContext context = new WebAppContext("/", "/");
        FilterHolder filter = new FilterHolder(new JFinalFilter());
        filter.setInitParameter("configClass", PropKit.get("config.class.path"));
        context.addFilter(filter, "/*", all);
        server.setHandler(context);
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) DispatcherType(javax.servlet.DispatcherType) File(java.io.File) JFinalFilter(com.jfinal.core.JFinalFilter)

Aggregations

JFinalFilter (com.jfinal.core.JFinalFilter)1 File (java.io.File)1 DispatcherType (javax.servlet.DispatcherType)1 Server (org.eclipse.jetty.server.Server)1 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1