001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.app.undertow; 017 018import com.jfinal.server.undertow.UndertowConfig; 019import com.jfinal.server.undertow.UndertowServer; 020import io.jboot.app.config.JbootConfigManager; 021import io.undertow.servlet.Servlets; 022 023import javax.servlet.DispatcherType; 024import javax.servlet.Filter; 025 026 027public class JbootUndertowServer extends UndertowServer { 028 029 public JbootUndertowServer(UndertowConfig undertowConfig) { 030 super(undertowConfig); 031 } 032 033 /** 034 * 添加 自定义 filter 的支持 035 */ 036 @Override 037 protected void configJFinalFilter() { 038 deploymentInfo.addFilter( 039 Servlets.filter("jfinal", getJFinalFilter()).addInitParam("configClass", config.getJFinalConfig()) 040 ).addFilterUrlMapping("jfinal", "/*", DispatcherType.REQUEST); 041 } 042 043 044 private Class<? extends Filter> getJFinalFilter() { 045 try { 046 String jfinalFilter = JbootConfigManager.me().getConfigValue("undertow.jfinalFilter"); 047 if (jfinalFilter == null || jfinalFilter.trim().length() == 0){ 048 jfinalFilter = "com.jfinal.core.JFinalFilter"; 049 } 050 return (Class<? extends Filter>)config.getClassLoader().loadClass(jfinalFilter); 051 } catch (ClassNotFoundException e) { 052 throw new RuntimeException(e); 053 } 054 } 055 056}