Avoid wrapping in plain RuntimeException in favor of IllegalStateException
This commit is contained in:
parent
e7a53e37fb
commit
e5122d084a
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
@ -83,18 +83,10 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Collection<String> destinationPrefixes = new ArrayList<String>();
|
||||
|
||||
private final List<HandlerMethodArgumentResolver> customArgumentResolvers = new ArrayList<HandlerMethodArgumentResolver>(4);
|
||||
|
||||
private final List<HandlerMethodReturnValueHandler> customReturnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>(4);
|
||||
|
||||
private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite();
|
||||
|
||||
private HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite();
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<T, HandlerMethod>();
|
||||
|
||||
private final MultiValueMap<String, T> destinationLookup = new LinkedMultiValueMap<String, T>();
|
||||
|
@ -105,6 +97,20 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
private final Map<MessagingAdviceBean, AbstractExceptionHandlerMethodResolver> exceptionHandlerAdviceCache =
|
||||
new LinkedHashMap<MessagingAdviceBean, AbstractExceptionHandlerMethodResolver>(64);
|
||||
|
||||
private Collection<String> destinationPrefixes = new ArrayList<String>();
|
||||
|
||||
private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite();
|
||||
|
||||
private HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite();
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* Return the configured destination prefixes.
|
||||
*/
|
||||
public Collection<String> getDestinationPrefixes() {
|
||||
return this.destinationPrefixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* When this property is configured only messages to destinations matching
|
||||
|
@ -125,10 +131,10 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the configured destination prefixes.
|
||||
* Return the configured custom argument resolvers, if any.
|
||||
*/
|
||||
public Collection<String> getDestinationPrefixes() {
|
||||
return this.destinationPrefixes;
|
||||
public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers() {
|
||||
return this.customArgumentResolvers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,10 +150,10 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
}
|
||||
|
||||
/**
|
||||
* Return the configured custom argument resolvers, if any.
|
||||
* Return the configured custom return value handlers, if any.
|
||||
*/
|
||||
public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers() {
|
||||
return this.customArgumentResolvers;
|
||||
public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers() {
|
||||
return this.customReturnValueHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,11 +168,8 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured custom return value handlers, if any.
|
||||
*/
|
||||
public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers() {
|
||||
return this.customReturnValueHandlers;
|
||||
public List<HandlerMethodArgumentResolver> getArgumentResolvers() {
|
||||
return this.argumentResolvers.getResolvers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,8 +185,8 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
this.argumentResolvers.addResolvers(argumentResolvers);
|
||||
}
|
||||
|
||||
public List<HandlerMethodArgumentResolver> getArgumentResolvers() {
|
||||
return this.argumentResolvers.getResolvers();
|
||||
public List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
|
||||
return this.returnValueHandlers.getReturnValueHandlers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,10 +202,6 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
this.returnValueHandlers.addHandlers(returnValueHandlers);
|
||||
}
|
||||
|
||||
public List<HandlerMethodReturnValueHandler> getReturnValueHandlers() {
|
||||
return this.returnValueHandlers.getReturnValueHandlers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a map with all handler methods and their mappings.
|
||||
*/
|
||||
|
@ -210,15 +209,14 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
return Collections.unmodifiableMap(this.handlerMethods);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public ApplicationContext getApplicationContext() {
|
||||
return this.applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
|
@ -434,7 +432,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
Collections.sort(matches, comparator);
|
||||
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found " + matches.size() + " methods: " + matches);
|
||||
logger.trace("Found " + matches.size() + " handler methods: " + matches);
|
||||
}
|
||||
|
||||
Match bestMatch = matches.get(0);
|
||||
|
@ -472,7 +470,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
|
||||
|
||||
protected void handleNoMatch(Set<T> ts, String lookupDestination, Message<?> message) {
|
||||
logger.debug("No matching methods.");
|
||||
logger.debug("No matching message handler methods.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -520,7 +518,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
protected void processHandlerMethodException(HandlerMethod handlerMethod, Exception ex, Message<?> message) {
|
||||
InvocableHandlerMethod invocable = getExceptionHandlerMethod(handlerMethod, ex);
|
||||
if (invocable == null) {
|
||||
logger.error("Unhandled exception", ex);
|
||||
logger.error("Unhandled exception from message handler method", ex);
|
||||
return;
|
||||
}
|
||||
invocable.setMessageMethodArgumentResolvers(this.argumentResolvers);
|
||||
|
@ -598,7 +596,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
|
||||
private final HandlerMethod handlerMethod;
|
||||
|
||||
private Match(T mapping, HandlerMethod handlerMethod) {
|
||||
public Match(T mapping, HandlerMethod handlerMethod) {
|
||||
this.mapping = mapping;
|
||||
this.handlerMethod = handlerMethod;
|
||||
}
|
||||
|
@ -631,7 +629,6 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
|
||||
private final Message<?> message;
|
||||
|
||||
|
||||
public ReturnValueListenableFutureCallback(InvocableHandlerMethod handlerMethod, Message<?> message) {
|
||||
this.handlerMethod = handlerMethod;
|
||||
this.message = message;
|
||||
|
@ -654,7 +651,7 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
}
|
||||
|
||||
private void handleFailure(Throwable ex) {
|
||||
Exception cause = (ex instanceof Exception ? (Exception) ex : new RuntimeException(ex));
|
||||
Exception cause = (ex instanceof Exception ? (Exception) ex : new IllegalStateException(ex));
|
||||
processHandlerMethodException(this.handlerMethod, cause, this.message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,8 +105,8 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
String httpMethod = this.webRequest.getHttpMethod().name();
|
||||
UriComponents uriComponents = uriComponents();
|
||||
|
||||
MockHttpServletRequest request = new HtmlUnitMockHttpServletRequest(servletContext, httpMethod,
|
||||
uriComponents.getPath());
|
||||
MockHttpServletRequest request = new HtmlUnitMockHttpServletRequest(
|
||||
servletContext, httpMethod, uriComponents.getPath());
|
||||
parent(request, this.parentBuilder);
|
||||
request.setServerName(uriComponents.getHost()); // needs to be first for additional headers
|
||||
authType(request);
|
||||
|
@ -123,7 +123,7 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
request.setProtocol("HTTP/1.1");
|
||||
request.setQueryString(uriComponents.getQuery());
|
||||
request.setScheme(uriComponents.getScheme());
|
||||
pathInfo(uriComponents,request);
|
||||
request.setPathInfo(null);
|
||||
|
||||
return postProcess(request);
|
||||
}
|
||||
|
@ -223,14 +223,14 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
try {
|
||||
request.setContent(requestBody.getBytes(charset));
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void contentType(MockHttpServletRequest request) {
|
||||
String contentType = header("Content-Type");
|
||||
request.setContentType(contentType == null ? MediaType.ALL_VALUE.toString() : contentType);
|
||||
request.setContentType(contentType != null ? contentType : MediaType.ALL_VALUE);
|
||||
}
|
||||
|
||||
private void contextPath(MockHttpServletRequest request, UriComponents uriComponents) {
|
||||
|
@ -245,8 +245,8 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
}
|
||||
else {
|
||||
if (!uriComponents.getPath().startsWith(this.contextPath)) {
|
||||
throw new IllegalArgumentException(uriComponents.getPath() + " should start with contextPath "
|
||||
+ this.contextPath);
|
||||
throw new IllegalArgumentException(uriComponents.getPath() + " should start with contextPath " +
|
||||
this.contextPath);
|
||||
}
|
||||
request.setContextPath(this.contextPath);
|
||||
}
|
||||
|
@ -375,8 +375,8 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
try {
|
||||
return URLDecoder.decode(value, "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
catch (UnsupportedEncodingException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,10 +397,6 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
return new Locale(language, country, qualifier);
|
||||
}
|
||||
|
||||
private void pathInfo(UriComponents uriComponents, MockHttpServletRequest request) {
|
||||
request.setPathInfo(null);
|
||||
}
|
||||
|
||||
private void servletPath(MockHttpServletRequest request, String requestPath) {
|
||||
String servletPath = requestPath.substring(request.getContextPath().length());
|
||||
if ("".equals(servletPath)) {
|
||||
|
@ -455,6 +451,9 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
return this;
|
||||
}
|
||||
|
||||
private CookieManager getCookieManager() {
|
||||
return this.webClient.getCookieManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* An extension to {@link MockHttpServletRequest} that ensures that
|
||||
|
@ -519,8 +518,4 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
}
|
||||
}
|
||||
|
||||
private CookieManager getCookieManager() {
|
||||
return this.webClient.getCookieManager();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue