@@ -79,6 +79,7 @@ protected Map<Charset, DefaultHttpDataFactory> initialValue() throws Exception {
7979 private final UrlMapper <ServletRegistration > servletUrlMapper = new UrlMapper <>();
8080 private final FilterMapper <ServletFilterRegistration > filterUrlMapper = new FilterMapper <>();
8181 private final ClassLoader classLoader ;
82+ private LoggerX logger = LoggerFactoryX .getLogger (getLogName ("" ));
8283 Supplier <Executor > defaultExecutorSupplier ;
8384 String contextPath = "" ;
8485 /**
@@ -92,21 +93,23 @@ protected Map<Charset, DefaultHttpDataFactory> initialValue() throws Exception {
9293 /**
9394 * Minimum upload file length, in bytes (becomes temporary file storage if larger than uploadMinSize)
9495 */
95- private long fileSizeThreshold = 4096 * 16 ;
96+ int fileSizeThreshold = 4096 * 16 ;
9697 /**
9798 * Upload file timeout millisecond , -1 is not control timeout.
9899 */
99- private long uploadFileTimeoutMs = -1 ;
100+ long uploadFileTimeoutMs = -1 ;
100101 private Supplier <Executor > asyncExecutorSupplier ;
101102 private SessionService sessionService ;
102103 private Set <SessionTrackingMode > sessionTrackingModeSet ;
103104 private Servlet defaultServlet = new DefaultServlet ();
104- private boolean enableLookupFlag = false ;
105+ boolean enableLookupFlag = false ;
105106 private boolean mapperContextRootRedirectEnabled = true ;
106- private boolean useRelativeRedirects = true ;
107+ boolean useRelativeRedirects = true ;
107108 private String serverHeader ;
108- private String requestCharacterEncoding ;
109- private String responseCharacterEncoding ;
109+ String requestCharacterEncoding = HttpConstants .DEFAULT_CHARSET .name ();
110+ Charset requestCharacterEncodingCharset = HttpConstants .DEFAULT_CHARSET ;
111+ String responseCharacterEncoding = HttpConstants .DEFAULT_CHARSET .name ();
112+ Charset responseCharacterEncodingCharset = HttpConstants .DEFAULT_CHARSET ;
110113 private String servletContextName ;
111114 /**
112115 * output stream maxBufferBytes
@@ -151,6 +154,15 @@ public static void asyncClose(Closeable closeable) {
151154 }
152155 }
153156
157+ private static String getLogName (String name ) {
158+ if ((name == null ) || (name .isEmpty ())) {
159+ name = "/" ;
160+ } else if (name .startsWith ("##" )) {
161+ name = "/" + name ;
162+ }
163+ return "[" + name + "]" ;
164+ }
165+
154166 public static String normPath (String path ) {
155167 if (path .isEmpty ()) {
156168 return path ;
@@ -169,6 +181,28 @@ public static String normPath(String path) {
169181 return path ;
170182 }
171183
184+ /**
185+ * 是否开启UrlServlet的AntPathMatcher路径匹配,默认false不开启
186+ */
187+ public void setEnableUrlServletAntPathMatcher (boolean enableAntPathMatcher ) {
188+ servletUrlMapper .setEnableAntPathMatcher (enableAntPathMatcher );
189+ }
190+
191+ /**
192+ * 是否开启UrlFilter的AntPathMatcher路径匹配,默认false不开启
193+ */
194+ public void setEnableUrlFilterAntPathMatcher (boolean enableAntPathMatcher ) {
195+ filterUrlMapper .setEnableAntPathMatcher (enableAntPathMatcher );
196+ }
197+
198+ public boolean isEnableUrlServletAntPathMatcher () {
199+ return servletUrlMapper .isEnableAntPathMatcher ();
200+ }
201+
202+ public boolean isEnableUrlFilterAntPathMatcher () {
203+ return filterUrlMapper .isEnableAntPathMatcher ();
204+ }
205+
172206 public DefaultServlet getDefaultServletCast () {
173207 if (defaultServlet instanceof DefaultServlet ) {
174208 return (DefaultServlet ) defaultServlet ;
@@ -241,18 +275,14 @@ public void setDocBase(String docBase, String workspace) {
241275 ResourceManager old = this .resourceManager ;
242276 this .resourceManager = new ResourceManager (docBase , workspace , classLoader );
243277 if (old != null ) {
244- getLog () .warn ("ServletContext docBase override. old = {}, new = {}" , old , this .resourceManager );
278+ logger .warn ("ServletContext docBase override. old = {}, new = {}" , old , this .resourceManager );
245279 }
246280 DiskFileUpload .deleteOnExitTemporaryFile = true ;
247281 DiskAttribute .deleteOnExitTemporaryFile = true ;
248282 DiskFileUpload .baseDirectory = resourceManager .getRealPath (DEFAULT_UPLOAD_DIR );
249283 DiskAttribute .baseDirectory = resourceManager .getRealPath (DEFAULT_UPLOAD_DIR );
250284 }
251285
252- private LoggerX getLog () {
253- return LoggerFactoryX .getLogger (contextPath );
254- }
255-
256286 public Executor getExecutor () {
257287 Executor executor = asyncExecutorSupplier != null ? asyncExecutorSupplier .get () : null ;
258288 if (executor == null ) {
@@ -296,12 +326,12 @@ public HttpDataFactory getHttpDataFactory(Charset charset) {
296326 });
297327 }
298328
299- public long getFileSizeThreshold () {
329+ public int getFileSizeThreshold () {
300330 return fileSizeThreshold ;
301331 }
302332
303333 public void setFileSizeThreshold (long fileSizeThreshold ) {
304- this .fileSizeThreshold = Math .max (fileSizeThreshold , MIN_FILE_SIZE_THRESHOLD );
334+ this .fileSizeThreshold = ( int ) Math .max (fileSizeThreshold , MIN_FILE_SIZE_THRESHOLD );
305335 }
306336
307337 public MimeMappingsX getMimeMappings () {
@@ -387,6 +417,7 @@ public void setContextPath(String contextPath) {
387417 this .contextPath = normed ;
388418 this .filterUrlMapper .setRootPath (normed );
389419 this .servletUrlMapper .setRootPath (normed );
420+ this .logger = LoggerFactoryX .getLogger (getLogName (normed ));
390421 }
391422
392423 @ Override
@@ -455,11 +486,11 @@ public String getRealPath(String path) {
455486
456487 @ Override
457488 public ServletRequestDispatcher getRequestDispatcher (String path ) {
458- return getRequestDispatcher (path , DispatcherType .REQUEST );
489+ return getRequestDispatcher (path , DispatcherType .REQUEST , true );
459490 }
460491
461- ServletRequestDispatcher getRequestDispatcher (String path , DispatcherType dispatcherType ) {
462- String pathNormalize = ServletUtil .pathNormalize (path , true );
492+ ServletRequestDispatcher getRequestDispatcher (String path , DispatcherType dispatcherType , boolean normalize ) {
493+ String pathNormalize = normalize ? ServletUtil .pathNormalize (path , true ) : path ;
463494 if (pathNormalize == null ) {
464495 return null ;
465496 }
@@ -527,17 +558,23 @@ public Enumeration<String> getServletNames() {
527558
528559 @ Override
529560 public void log (String msg ) {
530- getLog ().debug (msg );
561+ if (logger .isInfoEnabled ()) {
562+ logger .info (msg );
563+ }
531564 }
532565
533566 @ Override
534567 public void log (Exception exception , String msg ) {
535- getLog ().debug (msg , exception );
568+ if (logger .isErrorEnabled ()) {
569+ logger .error (msg , exception );
570+ }
536571 }
537572
538573 @ Override
539574 public void log (String message , Throwable throwable ) {
540- getLog ().debug (message , throwable );
575+ if (logger .isErrorEnabled ()) {
576+ logger .error (message , throwable );
577+ }
541578 }
542579
543580 @ Override
@@ -592,7 +629,7 @@ public void setAttribute(String name, Object object) {
592629 }
593630
594631 Object oldObject = attributeMap .put (name , object );
595- ServletEventListenerManager listenerManager = getServletEventListenerManager () ;
632+ ServletEventListenerManager listenerManager = this . servletEventListenerManager ;
596633 if (listenerManager .hasServletContextAttributeListener ()) {
597634 listenerManager .onServletContextAttributeAdded (new ServletContextAttributeEvent (this , name , object ));
598635 if (oldObject != null ) {
@@ -604,7 +641,7 @@ public void setAttribute(String name, Object object) {
604641 @ Override
605642 public void removeAttribute (String name ) {
606643 Object oldObject = attributeMap .remove (name );
607- ServletEventListenerManager listenerManager = getServletEventListenerManager () ;
644+ ServletEventListenerManager listenerManager = this . servletEventListenerManager ;
608645 if (listenerManager .hasServletContextAttributeListener ()) {
609646 listenerManager .onServletContextAttributeRemoved (new ServletContextAttributeEvent (this , name , oldObject ));
610647 }
@@ -763,7 +800,7 @@ public <T extends EventListener> void addListener(T listener) {
763800 Objects .requireNonNull (listener );
764801
765802 boolean addFlag = false ;
766- ServletEventListenerManager listenerManager = getServletEventListenerManager () ;
803+ ServletEventListenerManager listenerManager = this . servletEventListenerManager ;
767804 if (listener instanceof ServletContextAttributeListener ) {
768805 listenerManager .addServletContextAttributeListener ((ServletContextAttributeListener ) listener );
769806 addFlag = true ;
@@ -843,28 +880,30 @@ public String getVirtualServerName() {
843880
844881 @ Override
845882 public String getRequestCharacterEncoding () {
846- if (requestCharacterEncoding == null ) {
847- return HttpConstants .DEFAULT_CHARSET .name ();
848- }
849883 return requestCharacterEncoding ;
850884 }
851885
852886 @ Override
853887 public void setRequestCharacterEncoding (String requestCharacterEncoding ) {
888+ if (requestCharacterEncoding == null ) {
889+ requestCharacterEncoding = HttpConstants .DEFAULT_CHARSET .name ();
890+ }
854891 this .requestCharacterEncoding = requestCharacterEncoding ;
892+ this .requestCharacterEncodingCharset = Charset .forName (requestCharacterEncoding );
855893 }
856894
857895 @ Override
858896 public String getResponseCharacterEncoding () {
859- if (responseCharacterEncoding == null ) {
860- return HttpConstants .DEFAULT_CHARSET .name ();
861- }
862897 return responseCharacterEncoding ;
863898 }
864899
865900 @ Override
866901 public void setResponseCharacterEncoding (String responseCharacterEncoding ) {
902+ if (responseCharacterEncoding == null ) {
903+ responseCharacterEncoding = HttpConstants .DEFAULT_CHARSET .name ();
904+ }
867905 this .responseCharacterEncoding = responseCharacterEncoding ;
906+ this .responseCharacterEncodingCharset = Charset .forName (responseCharacterEncoding );
868907 }
869908
870909 @ Override
0 commit comments