Polishing
This commit is contained in:
parent
811de8e50b
commit
667fc7e4a9
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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: " +
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue