File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
main/java/org/springframework/boot/context/embedded
test/java/org/springframework/boot/context/embedded Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -230,7 +230,14 @@ public boolean isMatchAfter() {
230
230
@ Override
231
231
public void onStartup (ServletContext servletContext ) throws ServletException {
232
232
Assert .notNull (this .filter , "Filter must not be null" );
233
- configure (servletContext .addFilter (getOrDeduceName (this .filter ), this .filter ));
233
+ String name = getOrDeduceName (this .filter );
234
+ FilterRegistration .Dynamic added = servletContext .addFilter (name , this .filter );
235
+ if (added == null ) {
236
+ logger .info ("Filter " + name
237
+ + " was not registered (possibly already registered?)" );
238
+ return ;
239
+ }
240
+ configure (added );
234
241
}
235
242
236
243
/**
Original file line number Diff line number Diff line change 26
26
import javax .servlet .ServletContext ;
27
27
import javax .servlet .ServletException ;
28
28
import javax .servlet .ServletRegistration ;
29
+ import javax .servlet .ServletRegistration .Dynamic ;
29
30
30
31
import org .apache .commons .logging .Log ;
31
32
import org .apache .commons .logging .LogFactory ;
@@ -156,8 +157,15 @@ public String getServletName() {
156
157
@ Override
157
158
public void onStartup (ServletContext servletContext ) throws ServletException {
158
159
Assert .notNull (this .servlet , "Servlet must not be null" );
159
- logger .info ("Mapping servlet: '" + getServletName () + "' to " + this .urlMappings );
160
- configure (servletContext .addServlet (getServletName (), this .servlet ));
160
+ String name = getServletName ();
161
+ logger .info ("Mapping servlet: '" + name + "' to " + this .urlMappings );
162
+ Dynamic added = servletContext .addServlet (name , this .servlet );
163
+ if (added == null ) {
164
+ logger .info ("Servlet " + name
165
+ + " was not registered (possibly already registered?)" );
166
+ return ;
167
+ }
168
+ configure (added );
161
169
}
162
170
163
171
/**
Original file line number Diff line number Diff line change 38
38
import static org .mockito .BDDMockito .given ;
39
39
import static org .mockito .Matchers .anyObject ;
40
40
import static org .mockito .Matchers .anyString ;
41
+ import static org .mockito .Mockito .times ;
41
42
import static org .mockito .Mockito .verify ;
42
43
43
44
/**
@@ -79,6 +80,16 @@ public void startupWithDefaults() throws Exception {
79
80
verify (this .registration ).addMapping ("/*" );
80
81
}
81
82
83
+ @ Test
84
+ public void startupWithDoubleRegistration () throws Exception {
85
+ ServletRegistrationBean bean = new ServletRegistrationBean (this .servlet );
86
+ given (this .servletContext .addServlet (anyString (), (Servlet ) anyObject ()))
87
+ .willReturn (null );
88
+ bean .onStartup (this .servletContext );
89
+ verify (this .servletContext ).addServlet ("mockServlet" , this .servlet );
90
+ verify (this .registration , times (0 )).setAsyncSupported (true );
91
+ }
92
+
82
93
@ Test
83
94
public void startupWithSpecifiedValues () throws Exception {
84
95
ServletRegistrationBean bean = new ServletRegistrationBean ();
You can’t perform that action at this time.
0 commit comments