diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java index 583ac1b85e73..3160c7b7b6b2 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java @@ -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 protected final Log logger = LogFactory.getLog(getClass()); - private Collection destinationPrefixes = new ArrayList(); - private final List customArgumentResolvers = new ArrayList(4); private final List customReturnValueHandlers = new ArrayList(4); - private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite(); - - private HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite(); - - private ApplicationContext applicationContext; - private final Map handlerMethods = new LinkedHashMap(); private final MultiValueMap destinationLookup = new LinkedMultiValueMap(); @@ -105,6 +97,20 @@ public abstract class AbstractMethodMessageHandler private final Map exceptionHandlerAdviceCache = new LinkedHashMap(64); + private Collection destinationPrefixes = new ArrayList(); + + private HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite(); + + private HandlerMethodReturnValueHandlerComposite returnValueHandlers =new HandlerMethodReturnValueHandlerComposite(); + + private ApplicationContext applicationContext; + + /** + * Return the configured destination prefixes. + */ + public Collection getDestinationPrefixes() { + return this.destinationPrefixes; + } /** * When this property is configured only messages to destinations matching @@ -125,10 +131,10 @@ public void setDestinationPrefixes(Collection prefixes) { } /** - * Return the configured destination prefixes. + * Return the configured custom argument resolvers, if any. */ - public Collection getDestinationPrefixes() { - return this.destinationPrefixes; + public List getCustomArgumentResolvers() { + return this.customArgumentResolvers; } /** @@ -144,10 +150,10 @@ public void setCustomArgumentResolvers(List custo } /** - * Return the configured custom argument resolvers, if any. + * Return the configured custom return value handlers, if any. */ - public List getCustomArgumentResolvers() { - return this.customArgumentResolvers; + public List getCustomReturnValueHandlers() { + return this.customReturnValueHandlers; } /** @@ -162,11 +168,8 @@ public void setCustomReturnValueHandlers(List c } } - /** - * Return the configured custom return value handlers, if any. - */ - public List getCustomReturnValueHandlers() { - return this.customReturnValueHandlers; + public List getArgumentResolvers() { + return this.argumentResolvers.getResolvers(); } /** @@ -182,8 +185,8 @@ public void setArgumentResolvers(List argumentRes this.argumentResolvers.addResolvers(argumentResolvers); } - public List getArgumentResolvers() { - return this.argumentResolvers.getResolvers(); + public List getReturnValueHandlers() { + return this.returnValueHandlers.getReturnValueHandlers(); } /** @@ -199,10 +202,6 @@ public void setReturnValueHandlers(List returnV this.returnValueHandlers.addHandlers(returnValueHandlers); } - public List getReturnValueHandlers() { - return this.returnValueHandlers.getReturnValueHandlers(); - } - /** * Return a map with all handler methods and their mappings. */ @@ -210,15 +209,14 @@ public Map getHandlerMethods() { 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 @@ protected void handleMessageInternal(Message message, String lookupDestinatio 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 @@ private void addMatchesToCollection(Collection mappingsToCheck, Message me protected void handleNoMatch(Set ts, String lookupDestination, Message message) { - logger.debug("No matching methods."); + logger.debug("No matching message handler methods."); } /** @@ -520,7 +518,7 @@ protected void handleMatch(T mapping, HandlerMethod handlerMethod, String lookup 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 @@ private class Match { 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 @@ private class ReturnValueListenableFutureCallback implements ListenableFutureCal private final Message message; - public ReturnValueListenableFutureCallback(InvocableHandlerMethod handlerMethod, Message message) { this.handlerMethod = handlerMethod; this.message = message; @@ -654,7 +651,7 @@ public void onFailure(Throwable ex) { } 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); } } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java index 17fe1eeea206..32246149ff0b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java @@ -105,8 +105,8 @@ public MockHttpServletRequest buildRequest(ServletContext servletContext) { 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 @@ public MockHttpServletRequest buildRequest(ServletContext servletContext) { 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 @@ private void content(MockHttpServletRequest request, String charset) { 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 @@ private void contextPath(MockHttpServletRequest request, UriComponents uriCompon } 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 @@ private String urlDecode(String value) { 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 @@ private Locale parseLocale(String locale) { 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 @@ public Object merge(Object parent) { return this; } + private CookieManager getCookieManager() { + return this.webClient.getCookieManager(); + } /** * An extension to {@link MockHttpServletRequest} that ensures that @@ -519,8 +518,4 @@ public void invalidate() { } } - private CookieManager getCookieManager() { - return this.webClient.getCookieManager(); - } - }