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();
}
}
Aggregations