polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -75,8 +75,7 @@ public abstract class AbstractDetectingUrlHandlerMapping extends AbstractUrlHand
|
||||
getApplicationContext().getBeanNamesForType(Object.class));
|
||||
|
||||
// Take any bean name that we can determine URLs for.
|
||||
for (int i = 0; i < beanNames.length; i++) {
|
||||
String beanName = beanNames[i];
|
||||
for (String beanName : beanNames) {
|
||||
String[] urls = determineUrlsForHandler(beanName);
|
||||
if (!ObjectUtils.isEmpty(urls)) {
|
||||
// URL paths found: Let's consider it a handler.
|
||||
@@ -84,7 +83,7 @@ public abstract class AbstractDetectingUrlHandlerMapping extends AbstractUrlHand
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Rejected bean name '" + beanNames[i] + "': no URL paths identified");
|
||||
logger.debug("Rejected bean name '" + beanName + "': no URL paths identified");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,7 +454,8 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
|
||||
if (match && mappingInfo.methods.length == 0 && mappingInfo.params.length == 0 &&
|
||||
resolvedMethodName != null && !resolvedMethodName.equals(handlerMethod.getName())) {
|
||||
match = false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
for (RequestMethod requestMethod : mappingInfo.methods) {
|
||||
allowedMethods.add(requestMethod.toString());
|
||||
}
|
||||
@@ -786,7 +787,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
|
||||
for (MediaType acceptedMediaType : acceptedMediaTypes) {
|
||||
if (supportedMediaType.includes(acceptedMediaType)) {
|
||||
messageConverter.write(returnValue, outputMessage);
|
||||
responseArgumentUsed = true;
|
||||
this.responseArgumentUsed = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -811,8 +812,8 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator implemen
|
||||
|
||||
String[] headers = new String[0];
|
||||
|
||||
String bestMatchedPath() {
|
||||
return matchedPaths.isEmpty() ? null : matchedPaths.get(0);
|
||||
public String bestMatchedPath() {
|
||||
return (!this.matchedPaths.isEmpty() ? this.matchedPaths.get(0) : null);
|
||||
}
|
||||
|
||||
public boolean matches(HttpServletRequest request) {
|
||||
|
||||
@@ -35,7 +35,6 @@ abstract class ServletAnnotationMappingUtils {
|
||||
|
||||
/**
|
||||
* Check whether the given request matches the specified request methods.
|
||||
*
|
||||
* @param methods the HTTP request methods to check against
|
||||
* @param request the current HTTP request to check
|
||||
*/
|
||||
@@ -53,8 +52,7 @@ abstract class ServletAnnotationMappingUtils {
|
||||
|
||||
/**
|
||||
* Check whether the given request matches the specified parameter conditions.
|
||||
*
|
||||
* @param params the parameter conditions, following {@link org.springframework.web.bind.annotation.RequestMapping#params()}
|
||||
* @param params the parameter conditions, following {@link RequestMapping#params()}
|
||||
* @param request the current HTTP request to check
|
||||
*/
|
||||
public static boolean checkParameters(String[] params, HttpServletRequest request) {
|
||||
@@ -85,8 +83,7 @@ abstract class ServletAnnotationMappingUtils {
|
||||
|
||||
/**
|
||||
* Check whether the given request matches the specified header conditions.
|
||||
*
|
||||
* @param headers the header conditions, following {@link org.springframework.web.bind.annotation.RequestMapping#headers()}
|
||||
* @param headers the header conditions, following {@link RequestMapping#headers()}
|
||||
* @param request the current HTTP request to check
|
||||
*/
|
||||
public static boolean checkHeaders(String[] headers, HttpServletRequest request) {
|
||||
@@ -95,11 +92,11 @@ abstract class ServletAnnotationMappingUtils {
|
||||
int separator = header.indexOf('=');
|
||||
if (separator == -1) {
|
||||
if (header.startsWith("!")) {
|
||||
if (hasHeader(request, header.substring(1))) {
|
||||
if (request.getHeader(header.substring(1)) != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!hasHeader(request, header)) {
|
||||
else if (request.getHeader(header) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -111,9 +108,9 @@ abstract class ServletAnnotationMappingUtils {
|
||||
List<MediaType> valueMediaTypes = MediaType.parseMediaTypes(value);
|
||||
boolean found = false;
|
||||
for (Iterator<MediaType> valIter = valueMediaTypes.iterator(); valIter.hasNext() && !found;) {
|
||||
MediaType valueMediaType = valIter.next();
|
||||
MediaType valueMediaType = valIter.next();
|
||||
for (Iterator<MediaType> reqIter = requestMediaTypes.iterator(); reqIter.hasNext() && !found;) {
|
||||
MediaType requestMediaType = reqIter.next();
|
||||
MediaType requestMediaType = reqIter.next();
|
||||
if (valueMediaType.includes(requestMediaType)) {
|
||||
found = true;
|
||||
}
|
||||
@@ -133,10 +130,6 @@ abstract class ServletAnnotationMappingUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean hasHeader(HttpServletRequest request, String headerName) {
|
||||
return request.getHeader(headerName) != null;
|
||||
}
|
||||
|
||||
private static boolean isMediaTypeHeader(String headerName) {
|
||||
return "Accept".equalsIgnoreCase(headerName) || "Content-Type".equalsIgnoreCase(headerName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user