Polishing

This commit is contained in:
Juergen Hoeller
2015-03-31 18:42:28 +02:00
parent fc79ea3dd7
commit 35bf96763d
8 changed files with 90 additions and 91 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.web.servlet;
import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -182,7 +183,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
private String contextConfigLocation;
/** Actual ApplicationContextInitializer instances to apply to the context */
private final ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>> contextInitializers =
private final List<ApplicationContextInitializer<ConfigurableApplicationContext>> contextInitializers =
new ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>>();
/** Comma-delimited ApplicationContextInitializer class names set through init param */
@@ -364,12 +365,12 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
/**
* Specify which {@link ApplicationContextInitializer} instances should be used
* to initialize the application context used by this {@code FrameworkServlet}.
* @see #configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext)
* @see #applyInitializers(ConfigurableApplicationContext)
* @see #configureAndRefreshWebApplicationContext
* @see #applyInitializers
*/
@SuppressWarnings("unchecked")
public void setContextInitializers(ApplicationContextInitializer<? extends ConfigurableApplicationContext>... contextInitializers) {
for (ApplicationContextInitializer<? extends ConfigurableApplicationContext> initializer : contextInitializers) {
public void setContextInitializers(ApplicationContextInitializer<? extends ConfigurableApplicationContext>... initializers) {
for (ApplicationContextInitializer<? extends ConfigurableApplicationContext> initializer : initializers) {
this.contextInitializers.add((ApplicationContextInitializer<ConfigurableApplicationContext>) initializer);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -334,7 +334,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
* <p>Any such custom WebArgumentResolver will kick in first, having a chance to resolve
* an argument value before the standard argument handling kicks in.
*/
public void setCustomArgumentResolvers(WebArgumentResolver[] argumentResolvers) {
public void setCustomArgumentResolvers(WebArgumentResolver... argumentResolvers) {
this.customArgumentResolvers = argumentResolvers;
}
@@ -352,7 +352,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
* <p>Any such custom ModelAndViewResolver will kick in first, having a chance to resolve
* a return value before the standard ModelAndView handling kicks in.
*/
public void setCustomModelAndViewResolvers(ModelAndViewResolver[] customModelAndViewResolvers) {
public void setCustomModelAndViewResolvers(ModelAndViewResolver... customModelAndViewResolvers) {
this.customModelAndViewResolvers = customModelAndViewResolvers;
}
@@ -929,7 +929,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
// to be picked up by the RedirectView
webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, responseStatus);
responseArgumentUsed = true;
this.responseArgumentUsed = true;
}
// Invoke custom resolvers if present...
@@ -992,8 +992,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
}
}
private void handleResponseBody(Object returnValue, ServletWebRequest webRequest)
throws Exception {
private void handleResponseBody(Object returnValue, ServletWebRequest webRequest) throws Exception {
if (returnValue == null) {
return;
}
@@ -1002,8 +1001,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
writeWithMessageConverters(returnValue, inputMessage, outputMessage);
}
private void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest)
throws Exception {
private void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
if (responseEntity == null) {
return;
}
@@ -1030,6 +1028,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
private void writeWithMessageConverters(Object returnValue,
HttpInputMessage inputMessage, HttpOutputMessage outputMessage)
throws IOException, HttpMediaTypeNotAcceptableException {
List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
if (acceptedMediaTypes.isEmpty()) {
acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
@@ -1061,7 +1060,6 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
}
throw new HttpMediaTypeNotAcceptableException(allSupportedMediaTypes);
}
}
@@ -1079,30 +1077,30 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
private final String[] headers;
RequestMappingInfo(String[] patterns, RequestMethod[] methods, String[] params, String[] headers) {
this.patterns = patterns != null ? patterns : new String[0];
this.methods = methods != null ? methods : new RequestMethod[0];
this.params = params != null ? params : new String[0];
this.headers = headers != null ? headers : new String[0];
this.patterns = (patterns != null ? patterns : new String[0]);
this.methods = (methods != null ? methods : new RequestMethod[0]);
this.params = (params != null ? params : new String[0]);
this.headers = (headers != null ? headers : new String[0]);
}
public boolean hasPatterns() {
return patterns.length > 0;
return (this.patterns.length > 0);
}
public String[] getPatterns() {
return patterns;
return this.patterns;
}
public int getMethodCount() {
return methods.length;
return this.methods.length;
}
public int getParamCount() {
return params.length;
return this.params.length;
}
public int getHeaderCount() {
return headers.length;
return this.headers.length;
}
public boolean matches(HttpServletRequest request) {
@@ -1122,8 +1120,8 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
}
public Set<String> methodNames() {
Set<String> methodNames = new LinkedHashSet<String>(methods.length);
for (RequestMethod method : methods) {
Set<String> methodNames = new LinkedHashSet<String>(this.methods.length);
for (RequestMethod method : this.methods) {
methodNames.add(method.name());
}
return methodNames;
@@ -1145,18 +1143,18 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(Arrays.asList(patterns));
if (methods.length > 0) {
builder.append(Arrays.asList(this.patterns));
if (this.methods.length > 0) {
builder.append(',');
builder.append(Arrays.asList(methods));
builder.append(Arrays.asList(this.methods));
}
if (headers.length > 0) {
if (this.headers.length > 0) {
builder.append(',');
builder.append(Arrays.asList(headers));
builder.append(Arrays.asList(this.headers));
}
if (params.length > 0) {
if (this.params.length > 0) {
builder.append(',');
builder.append(Arrays.asList(params));
builder.append(Arrays.asList(this.params));
}
return builder.toString();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,7 +64,6 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
registerDispatcherServlet(servletContext);
}
@@ -80,7 +79,7 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte
*/
protected void registerDispatcherServlet(ServletContext servletContext) {
String servletName = getServletName();
Assert.hasLength(servletName, "getServletName() may not return empty or null");
Assert.hasLength(servletName, "getServletName() must not return empty or null");
WebApplicationContext servletAppContext = createServletApplicationContext();
Assert.notNull(servletAppContext,
@@ -178,9 +177,9 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte
}
private EnumSet<DispatcherType> getDispatcherTypes() {
return isAsyncSupported() ?
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC) :
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE);
return (isAsyncSupported() ?
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC) :
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
}
/**