diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java index 017bc18aeda..8b7f6d95fe3 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -771,8 +771,8 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator for (RequestMethod method : methods) { this.methods.add(method.name()); } - this.params = StringUtils.mergeStringArrays(this.params, params); - this.headers = StringUtils.mergeStringArrays(this.headers, headers); + this.params = PortletAnnotationMappingUtils.mergeStringArrays(this.params, params); + this.headers = PortletAnnotationMappingUtils.mergeStringArrays(this.headers, headers); } public void initPhaseMapping(String phase, String value, String[] params) { @@ -782,7 +782,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator } this.phase = phase; this.value = value; - this.params = StringUtils.mergeStringArrays(this.params, params); + this.params = PortletAnnotationMappingUtils.mergeStringArrays(this.params, params); } public boolean match(PortletRequest request) { diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/DefaultAnnotationHandlerMapping.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/DefaultAnnotationHandlerMapping.java index ef792dd0363..b602a2cb3a1 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/DefaultAnnotationHandlerMapping.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/DefaultAnnotationHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -154,7 +154,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp String[] modeKeys = new String[0]; String[] params = new String[0]; if (typeMapping != null) { - params = StringUtils.mergeStringArrays(typeMapping.params(), params); + params = PortletAnnotationMappingUtils.mergeStringArrays(typeMapping.params(), params); } ActionMapping actionMapping = AnnotationUtils.findAnnotation(method, ActionMapping.class); RenderMapping renderMapping = AnnotationUtils.findAnnotation(method, RenderMapping.class); @@ -162,11 +162,11 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp EventMapping eventMapping = AnnotationUtils.findAnnotation(method, EventMapping.class); RequestMapping requestMapping = AnnotationUtils.findAnnotation(method, RequestMapping.class); if (actionMapping != null) { - params = StringUtils.mergeStringArrays(params, actionMapping.params()); + params = PortletAnnotationMappingUtils.mergeStringArrays(params, actionMapping.params()); predicate = new ActionMappingPredicate(actionMapping.name(), params); } else if (renderMapping != null) { - params = StringUtils.mergeStringArrays(params, renderMapping.params()); + params = PortletAnnotationMappingUtils.mergeStringArrays(params, renderMapping.params()); predicate = new RenderMappingPredicate(renderMapping.windowState(), params); } else if (resourceMapping != null) { @@ -183,7 +183,7 @@ public class DefaultAnnotationHandlerMapping extends AbstractMapBasedHandlerMapp Arrays.asList(modeKeys) + " versus " + Arrays.asList(typeMapping.value())); } } - params = StringUtils.mergeStringArrays(params, requestMapping.params()); + params = PortletAnnotationMappingUtils.mergeStringArrays(params, requestMapping.params()); if (predicate == null) { predicate = new MethodLevelMappingPredicate(params); } diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/PortletAnnotationMappingUtils.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/PortletAnnotationMappingUtils.java index f1796355cf4..ac3b6f2dc54 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/PortletAnnotationMappingUtils.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/PortletAnnotationMappingUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2018 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. @@ -16,7 +16,9 @@ package org.springframework.web.portlet.mvc.annotation; +import java.util.Arrays; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.portlet.ClientDataRequest; @@ -24,6 +26,7 @@ import javax.portlet.PortletRequest; import org.springframework.http.MediaType; import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.portlet.util.PortletUtils; @@ -35,6 +38,29 @@ import org.springframework.web.portlet.util.PortletUtils; */ abstract class PortletAnnotationMappingUtils { + /** + * Merge the given {@code String} arrays into one, with each element only included once. + *
The order of elements in the original arrays is preserved (with the exception of
+ * overlapping elements, which are only included on their first occurrence).
+ * @param array1 the first array (can be {@code null})
+ * @param array2 the second array (can be {@code null})
+ * @return the new array ({@code null} if both given arrays were {@code null})
+ * @since 4.3.15 (superseding {@link StringUtils#mergeStringArrays})
+ */
+ public static String[] mergeStringArrays(String[] array1, String[] array2) {
+ if (ObjectUtils.isEmpty(array1)) {
+ return array2;
+ }
+ if (ObjectUtils.isEmpty(array2)) {
+ return array1;
+ }
+
+ Set