Polishing

This commit is contained in:
Juergen Hoeller 2015-09-04 14:38:47 +02:00
parent 811de8e50b
commit 667fc7e4a9
12 changed files with 32 additions and 37 deletions

View File

@ -393,17 +393,14 @@ public abstract class YamlProcessor {
*/ */
protected static class StrictMapAppenderConstructor extends Constructor { protected static class StrictMapAppenderConstructor extends Constructor {
public StrictMapAppenderConstructor() {
super();
}
@Override @Override
protected Map<Object, Object> constructMapping(MappingNode node) { protected Map<Object, Object> constructMapping(MappingNode node) {
try { try {
return super.constructMapping(node); return super.constructMapping(node);
} catch (IllegalStateException e) { }
catch (IllegalStateException ex) {
throw new ParserException("while parsing MappingNode", throw new ParserException("while parsing MappingNode",
node.getStartMark(), e.getMessage(), node.getEndMark()); node.getStartMark(), ex.getMessage(), node.getEndMark());
} }
} }
@ -414,7 +411,7 @@ public abstract class YamlProcessor {
@Override @Override
public Object put(Object key, Object value) { public Object put(Object key, Object value) {
if (delegate.containsKey(key)) { if (delegate.containsKey(key)) {
throw new IllegalStateException("duplicate key: " + key); throw new IllegalStateException("Duplicate key: " + key);
} }
return delegate.put(key, value); return delegate.put(key, value);
} }

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -80,13 +80,14 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
try { try {
clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
return clazz; return clazz;
} catch (NoSuchMethodException nsme) { }
catch (NoSuchMethodException ex) {
// Continue below...
} }
} }
Class<?>[] intfaces = clazz.getInterfaces(); Class<?>[] ifcs = clazz.getInterfaces();
for (Class<?> intface: intfaces) { for (Class<?> ifc: ifcs) {
discoverPublicClass(method, intface); discoverPublicClass(method, ifc);
} }
if (clazz.getSuperclass() != null) { if (clazz.getSuperclass() != null) {
return discoverPublicClass(method, clazz.getSuperclass()); return discoverPublicClass(method, clazz.getSuperclass());

View File

@ -58,9 +58,8 @@ public class StompDecoder {
/** /**
* Configure a * Configure a {@link MessageHeaderInitializer} to apply to the headers of
* {@link org.springframework.messaging.support.MessageHeaderInitializer MessageHeaderInitializer} * {@link Message}s from decoded STOMP frames.
* to apply to the headers of {@link Message}s from decoded STOMP frames.
*/ */
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) { public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer; this.headerInitializer = headerInitializer;
@ -216,7 +215,7 @@ public class StompDecoder {
String header = new String(headerStream.toByteArray(), UTF8_CHARSET); String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
int colonIndex = header.indexOf(':'); int colonIndex = header.indexOf(':');
if (colonIndex <= 0) { if (colonIndex <= 0) {
if(buffer.remaining() > 0) { if (buffer.remaining() > 0) {
throw new StompConversionException("Illegal header: '" + header + throw new StompConversionException("Illegal header: '" + header +
"'. A header must be of the form <name>:[<value>]."); "'. A header must be of the form <name>:[<value>].");
} }

View File

@ -33,7 +33,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -499,7 +498,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
dateFormat.setTimeZone(GMT); dateFormat.setTimeZone(GMT);
try { try {
return dateFormat.parse(getHeader(name)).getTime(); return dateFormat.parse(getHeader(name)).getTime();
} catch (ParseException exception) { }
catch (ParseException ex) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Value for header '" + name + "' is not a valid Date: " + getHeader(name)); "Value for header '" + name + "' is not a valid Date: " + getHeader(name));
} }

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -38,7 +38,6 @@ public class ResponseBodyTests {
@Test @Test
public void json() throws Exception { public void json() throws Exception {
standaloneSetup(new PersonController()).build() standaloneSetup(new PersonController()).build()
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON)) .perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
@ -46,14 +45,14 @@ public class ResponseBodyTests {
.andExpect(jsonPath("$.name").value("Lee")); .andExpect(jsonPath("$.name").value("Lee"));
} }
@Controller @Controller
private class PersonController { private class PersonController {
@RequestMapping(value="/person/{name}") @RequestMapping(value="/person/{name}")
@ResponseBody @ResponseBody
public Person get(@PathVariable String name) { public Person get(@PathVariable String name) {
Person person = new Person(name); return new Person(name);
return person;
} }
} }

View File

@ -422,10 +422,10 @@ public class ResponseEntity<T> extends HttpEntity<T> {
@Override @Override
public BodyBuilder eTag(String eTag) { public BodyBuilder eTag(String eTag) {
if (eTag != null) { if (eTag != null) {
if(!eTag.startsWith("\"") && !eTag.startsWith("W/\"")) { if (!eTag.startsWith("\"") && !eTag.startsWith("W/\"")) {
eTag = "\"" + eTag; eTag = "\"" + eTag;
} }
if(!eTag.endsWith("\"")) { if (!eTag.endsWith("\"")) {
eTag = eTag + "\""; eTag = eTag + "\"";
} }
} }

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -234,7 +234,7 @@ public class ContentNegotiationManagerFactoryBean
strategies.add(new HeaderContentNegotiationStrategy()); strategies.add(new HeaderContentNegotiationStrategy());
} }
if(this.defaultNegotiationStrategy != null) { if (this.defaultNegotiationStrategy != null) {
strategies.add(defaultNegotiationStrategy); strategies.add(defaultNegotiationStrategy);
} }

View File

@ -80,7 +80,7 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
public T extractData(ClientHttpResponse response) throws IOException { public T extractData(ClientHttpResponse response) throws IOException {
MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response); MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response);
if(!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) { if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
return null; return null;
} }
MediaType contentType = getContentType(responseWrapper); MediaType contentType = getContentType(responseWrapper);

View File

@ -61,7 +61,7 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse {
responseStatus == HttpStatus.NOT_MODIFIED) { responseStatus == HttpStatus.NOT_MODIFIED) {
return false; return false;
} }
else if(this.getHeaders().getContentLength() == 0) { else if (this.getHeaders().getContentLength() == 0) {
return false; return false;
} }
return true; return true;

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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -180,7 +180,7 @@ public class UrlPathHelper {
String path; String path;
// if the app container sanitized the servletPath, check against the sanitized version // if the app container sanitized the servletPath, check against the sanitized version
if(servletPath.indexOf(sanitizedPathWithinApp) != -1) { if (servletPath.indexOf(sanitizedPathWithinApp) != -1) {
path = getRemainingPath(sanitizedPathWithinApp, servletPath, false); path = getRemainingPath(sanitizedPathWithinApp, servletPath, false);
} }
else { else {

View File

@ -35,7 +35,6 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotWritableException; import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.http.server.ServletServerHttpResponse; import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.accept.ContentNegotiationManager; import org.springframework.web.accept.ContentNegotiationManager;
@ -121,8 +120,9 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
List<MediaType> requestedMediaTypes = getAcceptableMediaTypes(servletRequest); List<MediaType> requestedMediaTypes = getAcceptableMediaTypes(servletRequest);
List<MediaType> producibleMediaTypes = getProducibleMediaTypes(servletRequest, returnValueClass, returnValueType); List<MediaType> producibleMediaTypes = getProducibleMediaTypes(servletRequest, returnValueClass, returnValueType);
Assert.isTrue(returnValue == null || !producibleMediaTypes.isEmpty(), if (returnValue != null && producibleMediaTypes.isEmpty()) {
"No converter found for return value of type: " + returnValueClass); throw new IllegalArgumentException("No converter found for return value of type: " + returnValueClass);
}
Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>(); Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>();
for (MediaType requestedType : requestedMediaTypes) { for (MediaType requestedType : requestedMediaTypes) {

View File

@ -144,8 +144,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(servletRequest); ServletServerHttpRequest inputMessage = new ServletServerHttpRequest(servletRequest);
Object arg = null; Object arg = readWithMessageConverters(inputMessage, methodParam, paramType);
arg = readWithMessageConverters(inputMessage, methodParam, paramType);
if (arg == null) { if (arg == null) {
if (methodParam.getParameterAnnotation(RequestBody.class).required()) { if (methodParam.getParameterAnnotation(RequestBody.class).required()) {
throw new HttpMessageNotReadableException("Required request body is missing: " + throw new HttpMessageNotReadableException("Required request body is missing: " +