diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java b/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java index 8f54730ce..b7c9977a9 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/ApplicationMap.java @@ -18,9 +18,13 @@ */ package org.apache.struts2.dispatcher; -import javax.servlet.ServletContext; import java.io.Serializable; -import java.util.*; +import java.util.AbstractMap; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; + +import javax.servlet.ServletContext; /** * A simple implementation of the {@link java.util.Map} interface to handle a collection of attributes and @@ -28,12 +32,12 @@ import java.util.*; * enumerates over all servlet context attributes and init parameters and returns a collection of both. * Note, this will occur lazily - only when the entry set is asked for. */ -public class ApplicationMap extends AbstractMap implements Serializable { +public class ApplicationMap extends AbstractMap implements Serializable { private static final long serialVersionUID = 9136809763083228202L; private ServletContext context; - private Set entries; + private Set> entries; /** @@ -41,7 +45,7 @@ public class ApplicationMap extends AbstractMap implements Serializable { * * @param ctx the servlet context */ - public ApplicationMap(ServletContext ctx) { + public ApplicationMap(final ServletContext ctx) { this.context = ctx; } @@ -49,13 +53,14 @@ public class ApplicationMap extends AbstractMap implements Serializable { /** * Removes all entries from the Map and removes all attributes from the servlet context. */ + @Override public void clear() { entries = null; - Enumeration e = context.getAttributeNames(); + Enumeration e = context.getAttributeNames(); while (e.hasMoreElements()) { - context.removeAttribute(e.nextElement().toString()); + context.removeAttribute(e.nextElement()); } } @@ -64,39 +69,20 @@ public class ApplicationMap extends AbstractMap implements Serializable { * * @return a Set of all servlet context attributes as well as context init parameters. */ - public Set entrySet() { + @Override + public Set> entrySet() { if (entries == null) { entries = new HashSet<>(); // Add servlet context attributes - Enumeration enumeration = context.getAttributeNames(); + Enumeration enumeration = context.getAttributeNames(); while (enumeration.hasMoreElements()) { - final String key = enumeration.nextElement().toString(); + final String key = enumeration.nextElement(); final Object value = context.getAttribute(key); - entries.add(new Map.Entry() { - public boolean equals(Object obj) { - if (!(obj instanceof Map.Entry)) { - return false; - } - Map.Entry entry = (Map.Entry) obj; - - return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue())); - } - - public int hashCode() { - return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode()); - } - - public Object getKey() { - return key; - } - - public Object getValue() { - return value; - } - - public Object setValue(Object obj) { + entries.add(new StringObjectEntry(key, value) { + @Override + public Object setValue(final Object obj) { context.setAttribute(key, obj); return value; @@ -108,31 +94,11 @@ public class ApplicationMap extends AbstractMap implements Serializable { enumeration = context.getInitParameterNames(); while (enumeration.hasMoreElements()) { - final String key = enumeration.nextElement().toString(); + final String key = enumeration.nextElement(); final Object value = context.getInitParameter(key); - entries.add(new Map.Entry() { - public boolean equals(Object obj) { - if (!(obj instanceof Map.Entry)) { - return false; - } - Map.Entry entry = (Map.Entry) obj; - - return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue())); - } - - public int hashCode() { - return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode()); - } - - public Object getKey() { - return key; - } - - public Object getValue() { - return value; - } - - public Object setValue(Object obj) { + entries.add(new StringObjectEntry(key, value) { + @Override + public Object setValue(final Object obj) { context.setAttribute(key, obj); return value; @@ -151,13 +117,12 @@ public class ApplicationMap extends AbstractMap implements Serializable { * @param key the entry key. * @return the servlet context attribute or init parameter or null if the entry is not found. */ - public Object get(Object key) { + public Object get(final String key) { // Try context attributes first, then init params // This gives the proper shadowing effects - String keyString = key.toString(); - Object value = context.getAttribute(keyString); + Object value = context.getAttribute(key); - return (value == null) ? context.getInitParameter(keyString) : value; + return (value == null) ? context.getInitParameter(key) : value; } /** @@ -167,10 +132,13 @@ public class ApplicationMap extends AbstractMap implements Serializable { * @param value the value to set. * @return the attribute that was just set. */ - public Object put(Object key, Object value) { + @Override + public Object put(final String key, final Object value) { Object oldValue = get(key); entries = null; - context.setAttribute(key.toString(), value); + + context.setAttribute(key, value); + return oldValue; } @@ -180,11 +148,11 @@ public class ApplicationMap extends AbstractMap implements Serializable { * @param key the attribute to remove. * @return the entry that was just removed. */ - public Object remove(Object key) { + public Object remove(final String key) { entries = null; Object value = get(key); - context.removeAttribute(key.toString()); + context.removeAttribute(key); return value; } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java b/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java index 4b8148ab6..021a7347f 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/RequestMap.java @@ -28,11 +28,11 @@ import java.util.Set; /** * A simple implementation of the {@link java.util.Map} interface to handle a collection of request attributes. */ -public class RequestMap extends AbstractMap implements Serializable { +public class RequestMap extends AbstractMap implements Serializable { private static final long serialVersionUID = -7675640869293787926L; - private Set entries; + private Set> entries; private HttpServletRequest request; /** @@ -48,12 +48,13 @@ public class RequestMap extends AbstractMap implements Serializable { /** * Removes all attributes from the request as well as clears entries in this map. */ + @Override public void clear() { entries = null; - Enumeration keys = request.getAttributeNames(); + Enumeration keys = request.getAttributeNames(); while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); + String key = keys.nextElement(); request.removeAttribute(key); } } @@ -63,38 +64,19 @@ public class RequestMap extends AbstractMap implements Serializable { * * @return a Set of attributes from the http request. */ - public Set entrySet() { + @Override + public Set> entrySet() { if (entries == null) { entries = new HashSet<>(); - Enumeration enumeration = request.getAttributeNames(); + Enumeration enumeration = request.getAttributeNames(); while (enumeration.hasMoreElements()) { - final String key = enumeration.nextElement().toString(); + final String key = enumeration.nextElement(); final Object value = request.getAttribute(key); - entries.add(new Entry() { - public boolean equals(Object obj) { - if (!(obj instanceof Entry)) { - return false; - } - Entry entry = (Entry) obj; - - return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue())); - } - - public int hashCode() { - return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode()); - } - - public Object getKey() { - return key; - } - - public Object getValue() { - return value; - } - - public Object setValue(Object obj) { + entries.add(new StringObjectEntry(key, value) { + @Override + public Object setValue(final Object obj) { request.setAttribute(key, obj); return value; @@ -112,8 +94,8 @@ public class RequestMap extends AbstractMap implements Serializable { * @param key the name of the request attribute. * @return the request attribute or null if it doesn't exist. */ - public Object get(Object key) { - return request.getAttribute(key.toString()); + public Object get(final String key) { + return request.getAttribute(key); } /** @@ -123,10 +105,13 @@ public class RequestMap extends AbstractMap implements Serializable { * @param value the value to set. * @return the object that was just set. */ - public Object put(Object key, Object value) { + @Override + public Object put(final String key, final Object value) { Object oldValue = get(key); entries = null; - request.setAttribute(key.toString(), value); + + request.setAttribute(key, value); + return oldValue; } @@ -136,11 +121,11 @@ public class RequestMap extends AbstractMap implements Serializable { * @param key the name of the attribute to remove. * @return the value that was removed or null if the value was not found (and hence, not removed). */ - public Object remove(Object key) { + public Object remove(final String key) { entries = null; Object value = get(key); - request.removeAttribute(key.toString()); + request.removeAttribute(key); return value; } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java b/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java index 6d0b20f35..dac8404ea 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/SessionMap.java @@ -21,19 +21,23 @@ package org.apache.struts2.dispatcher; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.io.Serializable; -import java.util.*; +import java.util.AbstractMap; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; /** * A simple implementation of the {@link java.util.Map} interface to handle a collection of HTTP session * attributes. The {@link #entrySet()} method enumerates over all session attributes and creates a Set of entries. * Note, this will occur lazily - only when the entry set is asked for. */ -public class SessionMap extends AbstractMap implements Serializable { +public class SessionMap extends AbstractMap implements Serializable { private static final long serialVersionUID = 4678843241638046854L; protected HttpSession session; - protected Set> entries; + protected Set> entries; protected HttpServletRequest request; @@ -43,7 +47,7 @@ public class SessionMap extends AbstractMap implements Serializable * * @param request the http servlet request object. */ - public SessionMap(HttpServletRequest request) { + public SessionMap(final HttpServletRequest request) { // note, holding on to this request and relying on lazy session initalization will not work // if you are running your action invocation in a background task, such as using the // "execAndWait" interceptor @@ -70,7 +74,7 @@ public class SessionMap extends AbstractMap implements Serializable * Removes all attributes from the session as well as clears entries in this * map. */ - @SuppressWarnings("unchecked") + @Override public void clear() { if (session == null) { return; @@ -91,8 +95,8 @@ public class SessionMap extends AbstractMap implements Serializable * * @return a Set of attributes from the http session. */ - @SuppressWarnings("unchecked") - public Set> entrySet() { + @Override + public Set> entrySet() { if (session == null) { return Collections.emptySet(); } @@ -101,37 +105,17 @@ public class SessionMap extends AbstractMap implements Serializable if (entries == null) { entries = new HashSet<>(); - Enumeration enumeration = session.getAttributeNames(); + Enumeration enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { - final String key = enumeration.nextElement().toString(); + final String key = enumeration.nextElement(); final Object value = session.getAttribute(key); - entries.add(new Map.Entry() { - public boolean equals(Object obj) { - if (!(obj instanceof Map.Entry)) { - return false; - } - Map.Entry entry = (Map.Entry) obj; - - return ((key == null) ? (entry.getKey() == null) : key.equals(entry.getKey())) && ((value == null) ? (entry.getValue() == null) : value.equals(entry.getValue())); - } - - public int hashCode() { - return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode()); - } - - public K getKey() { - return (K) key; - } - - public V getValue() { - return (V) value; - } - - public V setValue(Object obj) { + entries.add(new StringObjectEntry(key, value) { + @Override + public Object setValue(final Object obj) { session.setAttribute(key, obj); - return (V) value; + return value; } }); } @@ -147,14 +131,13 @@ public class SessionMap extends AbstractMap implements Serializable * @param key the name of the session attribute. * @return the session attribute or null if it doesn't exist. */ - @SuppressWarnings("unchecked") - public V get(Object key) { + public Object get(final String key) { if (session == null) { return null; } synchronized (session.getId().intern()) { - return (V) session.getAttribute(key.toString()); + return session.getAttribute(key); } } @@ -165,16 +148,17 @@ public class SessionMap extends AbstractMap implements Serializable * @param value the value to set. * @return the object that was just set. */ - public V put(K key, V value) { + @Override + public Object put(final String key, final Object value) { synchronized (this) { if (session == null) { session = request.getSession(true); } } synchronized (session.getId().intern()) { - V oldValue = get(key); + Object oldValue = get(key); entries = null; - session.setAttribute(key.toString(), value); + session.setAttribute(key, value); return oldValue; } } @@ -185,7 +169,7 @@ public class SessionMap extends AbstractMap implements Serializable * @param key the name of the attribute to remove. * @return the value that was removed or null if the value was not found (and hence, not removed). */ - public V remove(Object key) { + public Object remove(final String key) { if (session == null) { return null; } @@ -193,8 +177,8 @@ public class SessionMap extends AbstractMap implements Serializable synchronized (session.getId().intern()) { entries = null; - V value = get(key); - session.removeAttribute(key.toString()); + Object value = get(key); + session.removeAttribute(key); return value; } @@ -207,7 +191,7 @@ public class SessionMap extends AbstractMap implements Serializable * @param key the name of the session attribute. * @return true if the session attribute exits or false if it doesn't exist. */ - public boolean containsKey(Object key) { + public boolean containsKey(final String key) { if (session == null) { return false; } diff --git a/core/src/main/java/org/apache/struts2/dispatcher/StringObjectEntry.java b/core/src/main/java/org/apache/struts2/dispatcher/StringObjectEntry.java new file mode 100644 index 000000000..1961616dc --- /dev/null +++ b/core/src/main/java/org/apache/struts2/dispatcher/StringObjectEntry.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.dispatcher; + +import java.util.Map.Entry; + +abstract class StringObjectEntry implements Entry { + private String key; + private Object value; + + StringObjectEntry(final String key, final Object value) { + this.key = key; + this.value = value; + } + + @Override + public String getKey() { + return key; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public boolean equals(final Object obj) { + if (!(obj instanceof Entry)) { + return false; + } + Entry entry = (Entry) obj; + + return keyEquals(entry) && valueEquals(entry); + } + + private boolean keyEquals(final Entry entry) { + return (key == null) ? (entry.getKey() == null) : key.equals(entry.getKey()); + } + + private boolean valueEquals(Entry entry) { + return (value == null) ? (entry.getValue() == null) : value.equals(entry.getValue()); + } + + @Override + public int hashCode() { + return ((key == null) ? 0 : key.hashCode()) ^ ((value == null) ? 0 : value.hashCode()); + } +} diff --git a/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java index b927c135e..d743e4e8a 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/CreateSessionInterceptor.java @@ -93,7 +93,7 @@ public class CreateSessionInterceptor extends AbstractInterceptor { if (httpSession == null) { LOG.debug("Creating new HttpSession and new SessionMap in ServletActionContext"); servletRequest.getSession(true); - invocation.getInvocationContext().withSession(new SessionMap<>(servletRequest)); + invocation.getInvocationContext().withSession(new SessionMap(servletRequest)); } return invocation.invoke(); } diff --git a/core/src/main/java/org/apache/struts2/interceptor/ScopeInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ScopeInterceptor.java index e9d09dc43..765fa40ed 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/ScopeInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/ScopeInterceptor.java @@ -273,7 +273,7 @@ public class ScopeInterceptor extends AbstractInterceptor implements PreResultLi invocation.addPreResultListener(this); Map session = ActionContext.getContext().getSession(); if (session == null && autoCreateSession) { - session = new SessionMap<>(ServletActionContext.getRequest()); + session = new SessionMap(ServletActionContext.getRequest()); ActionContext.getContext().withSession(session); } diff --git a/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java b/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java index 8b8c647d0..966ce1c55 100644 --- a/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java +++ b/core/src/main/java/org/apache/struts2/views/jsp/TagUtils.java @@ -64,7 +64,7 @@ public class TagUtils { Map extraContext = du.createContextMap(new RequestMap(req), params, - new SessionMap<>(req), + new SessionMap(req), new ApplicationMap(pageContext.getServletContext()), req, res); diff --git a/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java b/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java index 22afa2dff..8c292cdd5 100644 --- a/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java +++ b/core/src/test/java/org/apache/struts2/dispatcher/SessionMapTest.java @@ -50,13 +50,21 @@ public class SessionMapTest extends TestCase { List attributeNames = new ArrayList(); attributeNames.add("test"); attributeNames.add("anotherTest"); - Enumeration attributeNamesEnum = Collections.enumeration(attributeNames); + Enumeration attributeNamesEnum = Collections.enumeration(attributeNames); MockSessionMap sessionMap = new MockSessionMap((HttpServletRequest) requestMock.proxy()); + sessionMock.expect("getAttribute", + new Constraint[] { + new IsEqual("test") + }); sessionMock.expect("setAttribute", new Constraint[] { new IsEqual("test"), new IsEqual("test value") }); + sessionMock.expect("getAttribute", + new Constraint[] { + new IsEqual("anotherTest") + }); sessionMock.expect("setAttribute", new Constraint[] { new IsEqual("anotherTest"), new IsEqual("another test value") @@ -70,6 +78,14 @@ public class SessionMapTest extends TestCase { new Constraint[]{ new IsEqual("anotherTest") }); + sessionMock.expect("getAttribute", + new Constraint[] { + new IsEqual("test") + }); + sessionMock.expect("getAttribute", + new Constraint[] { + new IsEqual("anotherTest") + }); sessionMap.put("test", "test value"); sessionMap.put("anotherTest", "another test value"); sessionMap.clear(); @@ -102,7 +118,7 @@ public class SessionMapTest extends TestCase { } public void testGetObjectOnSessionMapUsesWrappedSessionsGetAttributeWithStringValue() throws Exception { - Object key = new Object(); + String key = "theKey"; Object value = new Object(); sessionMock.expectAndReturn("getAttribute", new Constraint[]{ new IsEqual(key.toString()) @@ -114,7 +130,7 @@ public class SessionMapTest extends TestCase { } public void testPutObjectOnSessionMapUsesWrappedSessionsSetsAttributeWithStringValue() throws Exception { - Object key = new Object(); + String key = "theKey"; Object value = new Object(); sessionMock.expect("getAttribute", new Constraint[]{new IsAnything()}); sessionMock.expect("setAttribute", new Constraint[]{ @@ -130,10 +146,10 @@ public class SessionMapTest extends TestCase { MockHttpServletRequest request = new MockHttpServletRequest(); - Object key = new Object(); + String key = "theKey"; Object value = new Object(); - SessionMap sessionMap = new SessionMap(request); + SessionMap sessionMap = new SessionMap(request); sessionMap.put(key, value); assertTrue(sessionMap.containsKey(key)); } @@ -142,11 +158,11 @@ public class SessionMapTest extends TestCase { MockHttpServletRequest request = new MockHttpServletRequest(); - Object key = new Object(); - Object someOtherKey = new Object(); + String key = "theKey"; + Object someOtherKey = "someOtherKey"; Object value = new Object(); - SessionMap sessionMap = new SessionMap(request); + SessionMap sessionMap = new SessionMap(request); sessionMap.put(key, value); assertFalse(sessionMap.containsKey(someOtherKey)); @@ -219,7 +235,7 @@ public class SessionMapTest extends TestCase { private static final long serialVersionUID = 8783604360786273764L; - private Map map = new HashMap(); + private Map map = new HashMap<>(); public MockSessionMap(HttpServletRequest request) { super(request); @@ -228,8 +244,8 @@ public class SessionMapTest extends TestCase { public Object get(Object key) { return map.get(key); } - - public Object put(Object key, Object value) { + + public Object put(String key, Object value) { Object originalValue = super.put(key, value); map.put(key, value); //put the value into our map after putting it in the superclass map to avoid polluting the get call. diff --git a/core/src/test/java/org/apache/struts2/dispatcher/StringObjectEntryTest.java b/core/src/test/java/org/apache/struts2/dispatcher/StringObjectEntryTest.java new file mode 100644 index 000000000..06188bb51 --- /dev/null +++ b/core/src/test/java/org/apache/struts2/dispatcher/StringObjectEntryTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.dispatcher; + +import static org.junit.Assert.assertNotEquals; + +import junit.framework.TestCase; + +public class StringObjectEntryTest extends TestCase { + public void testGetKey() { + StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue"); + assertEquals("theKey", entry.getKey()); + } + + public void testGetValue() { + StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue"); + assertEquals("theValue", entry.getValue()); + } + + public void testEquals() { + StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue"); + + assertEquals(entry, new StringObjectEntryTestImpl("theKey", "theValue")); + assertNotEquals(entry, new StringObjectEntryTestImpl("theKey", "differentValue")); + assertNotEquals(entry, new StringObjectEntryTestImpl("differentKey", "theValue")); + assertNotEquals(entry, new StringObjectEntryTestImpl("differentKey", "differentValue")); + } + + public void testHashCode() { + StringObjectEntry entry = new StringObjectEntryTestImpl("theKey", "theValue"); + assertEquals(-1962296402, entry.hashCode()); + } + + static class StringObjectEntryTestImpl extends StringObjectEntry { + StringObjectEntryTestImpl(final String key, final Object value) { + super(key, value); + } + + @Override + public Object setValue(final Object value) { + return value; + } + + } +} diff --git a/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java index 0dabc049c..2811b289f 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/CspInterceptorTest.java @@ -180,7 +180,7 @@ public class CspInterceptorTest extends StrutsInternalTestCase { ActionContext context = ActionContext.getContext() .withServletRequest(request) .withServletResponse(response) - .withSession(new SessionMap<>(request)) + .withSession(new SessionMap(request)) .bind(); mai.setInvocationContext(context); session = request.getSession(); diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java index 3a7c4b863..7801c50b0 100644 --- a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java +++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java @@ -38,7 +38,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.List; - import static org.apache.struts2.views.jsp.AbstractUITagTest.normalize; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.containsString; @@ -260,8 +259,8 @@ public class FreemarkerResultMockedTest extends StrutsInternalTestCase { EasyMock.replay(servletContext); init(); - // create session - request.getSession(); + // create session and add nonce + request.getSession().setAttribute("nonce", "aNonce"); request.setRequestURI("/tutorial/test10.action"); ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java index 42e6f7e92..243af7797 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java @@ -107,7 +107,7 @@ public abstract class AbstractTagTest extends StrutsInternalTestCase { MockDispatcher du = new MockDispatcher(pageContext.getServletContext(), new HashMap<>(), configurationManager); du.init(); Dispatcher.setInstance(du); - session = new SessionMap<>(request); + session = new SessionMap(request); Map extraContext = du.createContextMap(new RequestMap(request), HttpParameters.create(request.getParameterMap()).build(), session, diff --git a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java index fdb382f39..4bcec0c53 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/URLTagTest.java @@ -1674,7 +1674,7 @@ public class URLTagTest extends AbstractUITagTest { mockContainer = new Mock(Container.class); - session = new SessionMap<>(request); + session = new SessionMap(request); Map extraContext = du.createContextMap(new RequestMap(request), HttpParameters.create(request.getParameterMap()).build(), session, diff --git a/plugins/dwr/src/main/java/org/apache/struts2/validators/DWRValidator.java b/plugins/dwr/src/main/java/org/apache/struts2/validators/DWRValidator.java index c8cc66934..0809ea0e2 100644 --- a/plugins/dwr/src/main/java/org/apache/struts2/validators/DWRValidator.java +++ b/plugins/dwr/src/main/java/org/apache/struts2/validators/DWRValidator.java @@ -76,7 +76,7 @@ public class DWRValidator { requestParams = requestParams.withExtraParams(params); } Map requestMap = new RequestMap(req); - Map session = new SessionMap<>(req); + Map session = new SessionMap(req); Map application = new ApplicationMap(servletContext); Dispatcher du = Dispatcher.getInstance(); Map ctx = du.createContextMap(requestMap,