1
1
/*
2
- * Copyright 2002-2010 the original author or authors.
2
+ * Copyright 2002-2011 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -143,9 +143,9 @@ public abstract class FrameworkServlet extends HttpServletBean {
143
143
/**
144
144
* Any number of these characters are considered delimiters between
145
145
* multiple values in a single init-param String value.
146
- * @see #initializeWebApplicationContext
147
146
*/
148
- private String INIT_PARAM_DELIMITERS = ",; \t \n " ;
147
+ private static final String INIT_PARAM_DELIMITERS = ",; \t \n " ;
148
+
149
149
150
150
/** ServletContext attribute to find the WebApplicationContext in */
151
151
private String contextAttribute ;
@@ -188,7 +188,7 @@ public abstract class FrameworkServlet extends HttpServletBean {
188
188
189
189
/** Actual ApplicationContextInitializer instances to apply to the context */
190
190
private ArrayList <ApplicationContextInitializer <ConfigurableApplicationContext >> contextInitializers =
191
- new ArrayList <ApplicationContextInitializer <ConfigurableApplicationContext >>();
191
+ new ArrayList <ApplicationContextInitializer <ConfigurableApplicationContext >>();
192
192
193
193
194
194
/**
@@ -408,8 +408,8 @@ public void setThreadContextInheritable(boolean threadContextInheritable) {
408
408
* means that your controllers will receive those requests; make sure
409
409
* that those endpoints are actually able to handle an OPTIONS request.
410
410
* <p>Note that HttpServlet's default OPTIONS processing will be applied
411
- * in any case. Your controllers are simply available to override the
412
- * default headers and optionally generate a response body .
411
+ * in any case if your controllers happen to not set the 'Allow' header
412
+ * (as required for an OPTIONS response) .
413
413
*/
414
414
public void setDispatchOptionsRequest (boolean dispatchOptionsRequest ) {
415
415
this .dispatchOptionsRequest = dispatchOptionsRequest ;
@@ -425,9 +425,8 @@ public void setDispatchOptionsRequest(boolean dispatchOptionsRequest) {
425
425
* means that your controllers will receive those requests; make sure
426
426
* that those endpoints are actually able to handle a TRACE request.
427
427
* <p>Note that HttpServlet's default TRACE processing will be applied
428
- * in any case. Your controllers are simply available to override the
429
- * default headers and the default body, calling <code>response.reset()</code>
430
- * if necessary.
428
+ * in any case if your controllers happen to not generate a response
429
+ * of content type 'message/http' (as required for a TRACE response).
431
430
*/
432
431
public void setDispatchTraceRequest (boolean dispatchTraceRequest ) {
433
432
this .dispatchTraceRequest = dispatchTraceRequest ;
@@ -661,23 +660,23 @@ protected WebApplicationContext createWebApplicationContext(WebApplicationContex
661
660
@ SuppressWarnings ("unchecked" )
662
661
protected void applyInitializers (ConfigurableApplicationContext wac ) {
663
662
if (this .contextInitializerClasses != null ) {
664
- String [] initializerClassNames = StringUtils .tokenizeToStringArray (this .contextInitializerClasses , INIT_PARAM_DELIMITERS );
665
- for (String initializerClassName : initializerClassNames ) {
666
- ApplicationContextInitializer <ConfigurableApplicationContext > initializer = null ;
663
+ String [] initializerClassNames =
664
+ StringUtils .tokenizeToStringArray (this .contextInitializerClasses , INIT_PARAM_DELIMITERS );
665
+ for (String initializerClassName : initializerClassNames ) {
666
+ ApplicationContextInitializer <ConfigurableApplicationContext > initializer ;
667
667
try {
668
668
Class <?> initializerClass = ClassUtils .forName (initializerClassName , wac .getClassLoader ());
669
669
initializer = BeanUtils .instantiateClass (initializerClass , ApplicationContextInitializer .class );
670
- } catch (Exception ex ) {
670
+ }
671
+ catch (Exception ex ) {
671
672
throw new IllegalArgumentException (
672
673
String .format ("Could not instantiate class [%s] specified via " +
673
674
"'contextInitializerClasses' init-param" , initializerClassName ), ex );
674
675
}
675
676
this .contextInitializers .add (initializer );
676
677
}
677
678
}
678
-
679
679
Collections .sort (this .contextInitializers , new AnnotationAwareOrderComparator ());
680
-
681
680
for (ApplicationContextInitializer <ConfigurableApplicationContext > initializer : this .contextInitializers ) {
682
681
initializer .initialize (wac );
683
682
}
@@ -814,32 +813,41 @@ protected final void doDelete(HttpServletRequest request, HttpServletResponse re
814
813
815
814
/**
816
815
* Delegate OPTIONS requests to {@link #processRequest}, if desired.
817
- * <p>Applies HttpServlet's standard OPTIONS processing first.
816
+ * <p>Applies HttpServlet's standard OPTIONS processing otherwise,
817
+ * and also if there is still no 'Allow' header set after dispatching.
818
818
* @see #doService
819
819
*/
820
820
@ Override
821
821
protected void doOptions (HttpServletRequest request , HttpServletResponse response )
822
822
throws ServletException , IOException {
823
823
824
- super .doOptions (request , response );
825
824
if (this .dispatchOptionsRequest ) {
826
825
processRequest (request , response );
826
+ if (response .containsHeader ("Allow" )) {
827
+ // Proper OPTIONS response coming from a handler - we're done.
828
+ return ;
829
+ }
827
830
}
831
+ super .doOptions (request , response );
828
832
}
829
833
830
834
/**
831
835
* Delegate TRACE requests to {@link #processRequest}, if desired.
832
- * <p>Applies HttpServlet's standard TRACE processing first .
836
+ * <p>Applies HttpServlet's standard TRACE processing otherwise .
833
837
* @see #doService
834
838
*/
835
839
@ Override
836
840
protected void doTrace (HttpServletRequest request , HttpServletResponse response )
837
841
throws ServletException , IOException {
838
842
839
- super .doTrace (request , response );
840
843
if (this .dispatchTraceRequest ) {
841
844
processRequest (request , response );
845
+ if ("message/http" .equals (response .getContentType ())) {
846
+ // Proper TRACE response coming from a handler - we're done.
847
+ return ;
848
+ }
842
849
}
850
+ super .doTrace (request , response );
843
851
}
844
852
845
853
0 commit comments