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 {
public StrictMapAppenderConstructor() {
super();
}
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
try {
return super.constructMapping(node);
} catch (IllegalStateException e) {
}
catch (IllegalStateException ex) {
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
public Object put(Object key, Object value) {
if (delegate.containsKey(key)) {
throw new IllegalStateException("duplicate key: " + key);
throw new IllegalStateException("Duplicate key: " + key);
}
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");
* you may not use this file except in compliance with the License.
@ -80,13 +80,14 @@ public class ReflectiveMethodExecutor implements MethodExecutor {
try {
clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
return clazz;
} catch (NoSuchMethodException nsme) {
}
catch (NoSuchMethodException ex) {
// Continue below...
}
}
Class<?>[] intfaces = clazz.getInterfaces();
for (Class<?> intface: intfaces) {
discoverPublicClass(method, intface);
Class<?>[] ifcs = clazz.getInterfaces();
for (Class<?> ifc: ifcs) {
discoverPublicClass(method, ifc);
}
if (clazz.getSuperclass() != null) {
return discoverPublicClass(method, clazz.getSuperclass());

View File

@ -58,9 +58,8 @@ public class StompDecoder {
/**
* Configure a
* {@link org.springframework.messaging.support.MessageHeaderInitializer MessageHeaderInitializer}
* to apply to the headers of {@link Message}s from decoded STOMP frames.
* Configure a {@link MessageHeaderInitializer} to apply to the headers of
* {@link Message}s from decoded STOMP frames.
*/
public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) {
this.headerInitializer = headerInitializer;
@ -216,7 +215,7 @@ public class StompDecoder {
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
int colonIndex = header.indexOf(':');
if (colonIndex <= 0) {
if(buffer.remaining() > 0) {
if (buffer.remaining() > 0) {
throw new StompConversionException("Illegal header: '" + header +
"'. 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.Map;
import java.util.TimeZone;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
@ -499,7 +498,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
dateFormat.setTimeZone(GMT);
try {
return dateFormat.parse(getHeader(name)).getTime();
} catch (ParseException exception) {
}
catch (ParseException ex) {
throw new IllegalArgumentException(
"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");
* you may not use this file except in compliance with the License.
@ -38,22 +38,21 @@ public class ResponseBodyTests {
@Test
public void json() throws Exception {
standaloneSetup(new PersonController()).build()
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json;charset=UTF-8"))
.andExpect(jsonPath("$.name").value("Lee"));
}
@Controller
private class PersonController {
@RequestMapping(value="/person/{name}")
@ResponseBody
public Person get(@PathVariable String name) {
Person person = new Person(name);
return person;
return new Person(name);
}
}

View File

@ -422,10 +422,10 @@ public class ResponseEntity<T> extends HttpEntity<T> {
@Override
public BodyBuilder eTag(String eTag) {
if (eTag != null) {
if(!eTag.startsWith("\"") && !eTag.startsWith("W/\"")) {
if (!eTag.startsWith("\"") && !eTag.startsWith("W/\"")) {
eTag = "\"" + eTag;
}
if(!eTag.endsWith("\"")) {
if (!eTag.endsWith("\"")) {
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");
* you may not use this file except in compliance with the License.
@ -234,7 +234,7 @@ public class ContentNegotiationManagerFactoryBean
strategies.add(new HeaderContentNegotiationStrategy());
}
if(this.defaultNegotiationStrategy != null) {
if (this.defaultNegotiationStrategy != null) {
strategies.add(defaultNegotiationStrategy);
}

View File

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

View File

@ -61,7 +61,7 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse {
responseStatus == HttpStatus.NOT_MODIFIED) {
return false;
}
else if(this.getHeaders().getContentLength() == 0) {
else if (this.getHeaders().getContentLength() == 0) {
return false;
}
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");
* you may not use this file except in compliance with the License.
@ -180,7 +180,7 @@ public class UrlPathHelper {
String path;
// 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);
}
else {

View File

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

View File

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