mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
Merge pull request #670 from sdutry/issue/WW-5251
WW-5251 remove deprecated interfaces related to ServletConfigInterceptor
This commit is contained in:
@@ -21,16 +21,17 @@
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
public class ChatLoginAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -60,8 +61,8 @@ public class ChatLoginAction extends ActionSupport implements SessionAware {
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,18 @@
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
public class ChatLogoutAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
|
||||
|
||||
public ChatLogoutAction(ChatService chatService) {
|
||||
@@ -50,8 +51,8 @@ public class ChatLogoutAction extends ActionSupport implements SessionAware {
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,16 +21,17 @@
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
public class EnterRoomAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
private String roomName;
|
||||
|
||||
public String getRoomName() {
|
||||
@@ -56,10 +57,9 @@ public class EnterRoomAction extends ActionSupport implements SessionAware {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,17 +21,18 @@
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
public class ExitRoomAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String roomName;
|
||||
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
|
||||
public String getRoomName() {
|
||||
return roomName;
|
||||
@@ -54,9 +55,9 @@ public class ExitRoomAction extends ActionSupport implements SessionAware {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-5
@@ -21,10 +21,11 @@
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
public class SendMessageToRoomAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -33,7 +34,7 @@ public class SendMessageToRoomAction extends ActionSupport implements SessionAwa
|
||||
|
||||
private String roomName;
|
||||
private String message;
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
|
||||
|
||||
public SendMessageToRoomAction(ChatService chatService) {
|
||||
@@ -67,9 +68,10 @@ public class SendMessageToRoomAction extends ActionSupport implements SessionAwa
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+8
-6
@@ -21,15 +21,16 @@
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
public class GetUpdatedHangmanAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 5506025785406043027L;
|
||||
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
private Hangman hangman;
|
||||
|
||||
|
||||
@@ -45,10 +46,6 @@ public class GetUpdatedHangmanAction extends ActionSupport implements SessionAwa
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public Hangman getHangman() {
|
||||
return hangman;
|
||||
}
|
||||
@@ -56,4 +53,9 @@ public class GetUpdatedHangmanAction extends ActionSupport implements SessionAwa
|
||||
public void setHangman(Hangman hangman) {
|
||||
this.hangman = hangman;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -21,15 +21,16 @@
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
public class GuessCharacterAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 9050915577007590674L;
|
||||
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
private Character character;
|
||||
private Hangman hangman;
|
||||
|
||||
@@ -44,10 +45,6 @@ public class GuessCharacterAction extends ActionSupport implements SessionAware
|
||||
return hangman;
|
||||
}
|
||||
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void setCharacter(Character character) {
|
||||
this.character = character;
|
||||
}
|
||||
@@ -55,4 +52,9 @@ public class GuessCharacterAction extends ActionSupport implements SessionAware
|
||||
public Character getCharacter() {
|
||||
return this.character;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -21,10 +21,11 @@
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
|
||||
import static org.apache.struts2.showcase.hangman.HangmanConstants.HANGMAN_SESSION_KEY;
|
||||
|
||||
public class StartHangmanAction extends ActionSupport implements SessionAware {
|
||||
@@ -33,7 +34,7 @@ public class StartHangmanAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private HangmanService service;
|
||||
private Hangman hangman;
|
||||
private Map session;
|
||||
private Map<String, Object> session;
|
||||
|
||||
|
||||
public StartHangmanAction(HangmanService service) {
|
||||
@@ -53,8 +54,8 @@ public class StartHangmanAction extends ActionSupport implements SessionAware {
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
package org.apache.struts2.showcase.xslt;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.ServletRequestAware;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.struts2.action.ServletRequestAware;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -53,10 +55,6 @@ public class JVMAction implements ServletRequestAware {
|
||||
return servletRequest;
|
||||
}
|
||||
|
||||
public void setServletRequest(HttpServletRequest servletRequest) {
|
||||
this.servletRequest = servletRequest;
|
||||
}
|
||||
|
||||
public Map<String, String> getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
@@ -100,4 +98,9 @@ public class JVMAction implements ServletRequestAware {
|
||||
this.systemProperties = systemProperties;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withServletRequest(HttpServletRequest request) {
|
||||
this.servletRequest = request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
*/
|
||||
package org.apache.struts2.dispatcher;
|
||||
|
||||
import org.apache.struts2.interceptor.ParameterAware;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
@@ -81,10 +78,6 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void applyParameters(ParameterAware parameterAware) {
|
||||
parameterAware.setParameters(toMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return parameters.size();
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Actions that want to be aware of the application Map object should implement this interface.
|
||||
* This will give them access to a Map where they can put objects that should be available
|
||||
* to other parts of the application.
|
||||
* </p>
|
||||
* <p>
|
||||
* Typical uses are configuration objects and caches.
|
||||
* </p>
|
||||
* @deprecated please use {@link org.apache.struts2.action.ApplicationAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ApplicationAware {
|
||||
|
||||
/**
|
||||
* Sets the map of application properties in the implementing class.
|
||||
*
|
||||
* @param application a Map of application properties.
|
||||
* @deprecated please use {@link org.apache.struts2.action.ApplicationAware#withApplication(Map)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setApplication(Map<String,Object> application);
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This interface gives actions an alternative way of receiving input parameters. The parameters will
|
||||
* contain all input parameters as implementation of {@link org.apache.struts2.dispatcher.Parameter}.
|
||||
* Actions that need this should simply implement it.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* One common use for this is to have the action propagate parameters to internally instantiated data
|
||||
* objects.
|
||||
* </p>
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface HttpParametersAware {
|
||||
|
||||
/**
|
||||
* Sets the HTTP parameters in the implementing class.
|
||||
*
|
||||
* @param parameters an instance of {@link HttpParameters}.
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware#withParameters(HttpParameters)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
void setParameters(HttpParameters parameters);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This interface gives actions an alternative way of receiving input parameters. The map will
|
||||
* contain all input parameters as name/value entries. Actions that need this should simply implement it.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* One common use for this is to have the action propagate parameters to internally instantiated data
|
||||
* objects.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Note that all parameter values for a given name will be returned, so the type of the objects in
|
||||
* the map is <tt>java.lang.String[]</tt>.
|
||||
* </p>
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ParameterAware {
|
||||
|
||||
/**
|
||||
* Sets the map of input parameters in the implementing class.
|
||||
*
|
||||
* @param parameters a Map of parameters (name/value Strings).
|
||||
*/
|
||||
public void setParameters(Map<String, String[]> parameters);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
/**
|
||||
* Actions that want access to the Principal information from HttpServletRequest object
|
||||
* should implement this interface.
|
||||
*
|
||||
* <p>This interface is only relevant if the Action is used in a servlet environment.
|
||||
* By using this interface you will not become tied to servlet environment.</p>
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.action.PrincipalAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface PrincipalAware {
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.action.PrincipalAware#withPrincipalProxy(PrincipalProxy)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
void setPrincipalProxy(PrincipalProxy principalProxy);
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Actions that want access to the current servlet request attributes should implement this interface.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This interface is only relevant if the Action is used in a servlet environment.
|
||||
* </p>
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface RequestAware {
|
||||
|
||||
/**
|
||||
* Sets the Map of request attributes in the implementing class.
|
||||
*
|
||||
* @param request a Map of HTTP request attribute name/value pairs.
|
||||
* @deprecated please use {@link org.apache.struts2.action.ParametersAware#withParameters(HttpParameters)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setRequest(Map<String,Object> request);
|
||||
}
|
||||
@@ -18,16 +18,19 @@
|
||||
*/
|
||||
package org.apache.struts2.interceptor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.action.ApplicationAware;
|
||||
import org.apache.struts2.action.ParametersAware;
|
||||
import org.apache.struts2.action.PrincipalAware;
|
||||
import org.apache.struts2.action.ServletContextAware;
|
||||
import org.apache.struts2.action.ServletRequestAware;
|
||||
import org.apache.struts2.action.ServletResponseAware;
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
import org.apache.struts2.interceptor.servlet.ServletPrincipalProxy;
|
||||
import org.apache.struts2.util.ServletContextAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
@@ -46,22 +49,13 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link ServletContextAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.ServletContextAware}</li>
|
||||
* <li>{@link ServletRequestAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.ServletRequestAware}</li>
|
||||
* <li>{@link ServletResponseAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.ServletResponseAware}</li>
|
||||
* <li>{@link ParameterAware} - deprecated since 2.5.4, please use {@link HttpParametersAware}</li>
|
||||
* <li>{@link HttpParametersAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.ParametersAware}</li>
|
||||
* <li>{@link RequestAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.ServletRequestAware}</li>
|
||||
* <li>{@link ParametersAware}</li>
|
||||
* <li>{@link ServletRequestAware}</li>
|
||||
* <li>{@link SessionAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.SessionAware}</li>
|
||||
* <li>{@link ApplicationAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.ApplicationAware}</li>
|
||||
* <li>{@link PrincipalAware}</li>
|
||||
* <li>{@link org.apache.struts2.action.PrincipalAware}</li>
|
||||
* </ul>
|
||||
*
|
||||
* <!-- END SNIPPET: description -->
|
||||
@@ -101,17 +95,11 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
* @see ServletContextAware
|
||||
* @see org.apache.struts2.action.ServletContextAware
|
||||
* @see ServletRequestAware
|
||||
* @see org.apache.struts2.action.ServletRequestAware
|
||||
* @see ServletResponseAware
|
||||
* @see org.apache.struts2.action.ServletResponseAware
|
||||
* @see ParameterAware
|
||||
* @see org.apache.struts2.action.ParametersAware
|
||||
* @see ParametersAware
|
||||
* @see SessionAware
|
||||
* @see org.apache.struts2.action.SessionAware
|
||||
* @see ApplicationAware
|
||||
* @see org.apache.struts2.action.ApplicationAware
|
||||
* @see PrincipalAware
|
||||
* @see org.apache.struts2.action.PrincipalAware
|
||||
*/
|
||||
public class ServletConfigInterceptor extends AbstractInterceptor implements StrutsStatics {
|
||||
|
||||
@@ -130,30 +118,12 @@ public class ServletConfigInterceptor extends AbstractInterceptor implements Str
|
||||
|
||||
if (action instanceof ServletRequestAware) {
|
||||
HttpServletRequest request = context.getServletRequest();
|
||||
((ServletRequestAware) action).setServletRequest(request);
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.action.ServletRequestAware) {
|
||||
HttpServletRequest request = context.getServletRequest();
|
||||
((org.apache.struts2.action.ServletRequestAware) action).withServletRequest(request);
|
||||
((ServletRequestAware) action).withServletRequest(request);
|
||||
}
|
||||
|
||||
if (action instanceof ServletResponseAware) {
|
||||
HttpServletResponse response = context.getServletResponse();
|
||||
((ServletResponseAware) action).setServletResponse(response);
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.action.ServletResponseAware) {
|
||||
HttpServletResponse response = context.getServletResponse();
|
||||
((org.apache.struts2.action.ServletResponseAware) action).withServletResponse(response);
|
||||
}
|
||||
|
||||
if (action instanceof ParameterAware) {
|
||||
context.getParameters().applyParameters((ParameterAware) action);
|
||||
}
|
||||
|
||||
if (action instanceof HttpParametersAware) {
|
||||
((HttpParametersAware) action).setParameters(context.getParameters());
|
||||
((ServletResponseAware) action).withServletResponse(response);
|
||||
}
|
||||
|
||||
if (action instanceof ParametersAware) {
|
||||
@@ -161,49 +131,24 @@ public class ServletConfigInterceptor extends AbstractInterceptor implements Str
|
||||
}
|
||||
|
||||
if (action instanceof ApplicationAware) {
|
||||
((ApplicationAware) action).setApplication(context.getApplication());
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.action.ApplicationAware) {
|
||||
((org.apache.struts2.action.ApplicationAware) action).withApplication(context.getApplication());
|
||||
((ApplicationAware) action).withApplication(context.getApplication());
|
||||
}
|
||||
|
||||
if (action instanceof SessionAware) {
|
||||
((SessionAware) action).setSession(context.getSession());
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.action.SessionAware) {
|
||||
((org.apache.struts2.action.SessionAware) action).withSession(context.getSession());
|
||||
}
|
||||
|
||||
if (action instanceof RequestAware) {
|
||||
((RequestAware) action).setRequest((Map) context.get("request"));
|
||||
((SessionAware) action).withSession(context.getSession());
|
||||
}
|
||||
|
||||
if (action instanceof PrincipalAware) {
|
||||
HttpServletRequest request = context.getServletRequest();
|
||||
if(request != null) {
|
||||
// We are in servlet environment, so principal information resides in HttpServletRequest
|
||||
((PrincipalAware) action).setPrincipalProxy(new ServletPrincipalProxy(request));
|
||||
}
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.action.PrincipalAware) {
|
||||
HttpServletRequest request = context.getServletRequest();
|
||||
if(request != null) {
|
||||
// We are in servlet environment, so principal information resides in HttpServletRequest
|
||||
((org.apache.struts2.action.PrincipalAware) action).withPrincipalProxy(new ServletPrincipalProxy(request));
|
||||
((PrincipalAware) action).withPrincipalProxy(new ServletPrincipalProxy(request));
|
||||
}
|
||||
}
|
||||
|
||||
if (action instanceof ServletContextAware) {
|
||||
ServletContext servletContext = context.getServletContext();
|
||||
((ServletContextAware) action).setServletContext(servletContext);
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.action.ServletContextAware) {
|
||||
ServletContext servletContext = context.getServletContext();
|
||||
((org.apache.struts2.action.ServletContextAware) action).withServletContext(servletContext);
|
||||
((ServletContextAware) action).withServletContext(servletContext);
|
||||
}
|
||||
|
||||
return invocation.invoke();
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* All Actions that want to have access to the servlet request object must implement this interface.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This interface is only relevant if the Action is used in a servlet environment.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Note that using this interface makes the Action tied to a servlet environment, so it should be
|
||||
* avoided if possible since things like unit testing will become more difficult.
|
||||
* </p>
|
||||
* @deprecated please use {@link org.apache.struts2.action.ServletRequestAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ServletRequestAware {
|
||||
|
||||
/**
|
||||
* Sets the HTTP request object in implementing classes.
|
||||
*
|
||||
* @param request the HTTP request.
|
||||
* @deprecated please use {@link org.apache.struts2.action.ServletRequestAware#withServletRequest(HttpServletRequest)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setServletRequest(HttpServletRequest request);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* All Actions that want to have access to the servlet response object must implement this interface.
|
||||
* </p>
|
||||
* <p>
|
||||
* This interface is only relevant if the Action is used in a servlet environment.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that using this interface makes the Action tied to a servlet environment, so it should be
|
||||
* avoided if possible since things like unit testing will become more difficult.
|
||||
* </p>
|
||||
* @deprecated please use {@link org.apache.struts2.action.ServletResponseAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ServletResponseAware {
|
||||
|
||||
/**
|
||||
* Sets the HTTP response object in implementing classes.
|
||||
*
|
||||
* @param response the HTTP response.
|
||||
* @deprecated please use {@link org.apache.struts2.action.ServletResponseAware#withServletResponse(HttpServletResponse)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setServletResponse(HttpServletResponse response);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Actions that want access to the user's HTTP session attributes should implement this interface.
|
||||
* </p>
|
||||
* <p>
|
||||
* This will give them access to a Map where they can put objects that can be made available
|
||||
* to subsequent requests.
|
||||
* </p>
|
||||
* <p>
|
||||
* Typical uses may be cached user data such as name, or a shopping cart.
|
||||
* </p>
|
||||
* @deprecated use {@link org.apache.struts2.action.SessionAware}
|
||||
*/
|
||||
@Deprecated
|
||||
public interface SessionAware {
|
||||
|
||||
/**
|
||||
* Sets the Map of session attributes in the implementing class.
|
||||
*
|
||||
* @param session a Map of HTTP session attribute name/value pairs.
|
||||
* @deprecated please use {@link org.apache.struts2.action.SessionAware#withSession(Map)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSession(Map<String,Object> session);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* For components that have a dependence on the Servlet context.
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.action.ServletContextAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ServletContextAware {
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.action.ServletContextAware#withServletContext(ServletContext)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void setServletContext(ServletContext context);
|
||||
}
|
||||
+12
-182
@@ -23,17 +23,18 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.action.ApplicationAware;
|
||||
import org.apache.struts2.action.ParametersAware;
|
||||
import org.apache.struts2.action.PrincipalAware;
|
||||
import org.apache.struts2.action.ServletRequestAware;
|
||||
import org.apache.struts2.action.ServletResponseAware;
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
import org.apache.struts2.interceptor.servlet.ServletPrincipalProxy;
|
||||
import org.apache.struts2.util.ServletContextAware;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -51,23 +52,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
private ServletConfigInterceptor interceptor;
|
||||
|
||||
public void testServletRequestAware() throws Exception {
|
||||
ServletRequestAware mock = (ServletRequestAware) createMock(ServletRequestAware.class);
|
||||
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
mai.getInvocationContext().put(StrutsStatics.HTTP_REQUEST, req);
|
||||
|
||||
mock.setServletRequest((HttpServletRequest) req);
|
||||
expectLastCall();
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionServletRequestAware() throws Exception {
|
||||
org.apache.struts2.action.ServletRequestAware mock = createMock(org.apache.struts2.action.ServletRequestAware.class);
|
||||
ServletRequestAware mock = createMock(ServletRequestAware.class);
|
||||
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
|
||||
@@ -83,23 +68,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
public void testServletResponseAware() throws Exception {
|
||||
ServletResponseAware mock = (ServletResponseAware) createMock(ServletResponseAware.class);
|
||||
|
||||
MockHttpServletResponse res = new MockHttpServletResponse();
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
mai.getInvocationContext().put(StrutsStatics.HTTP_RESPONSE, res);
|
||||
|
||||
mock.setServletResponse((HttpServletResponse) res);
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionServletResponseAware() throws Exception {
|
||||
org.apache.struts2.action.ServletResponseAware mock = createMock(org.apache.struts2.action.ServletResponseAware.class);
|
||||
ServletResponseAware mock = createMock(ServletResponseAware.class);
|
||||
|
||||
MockHttpServletResponse res = new MockHttpServletResponse();
|
||||
|
||||
@@ -114,39 +83,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testParameterAware() throws Exception {
|
||||
ParameterAware mock = createMock(ParameterAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
HttpParameters param = HttpParameters.create().build();
|
||||
mai.getInvocationContext().setParameters(param);
|
||||
|
||||
param.applyParameters(mock);
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testHttpParametersAware() throws Exception {
|
||||
HttpParametersAware mock = createMock(HttpParametersAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
HttpParameters param = HttpParameters.create().build();
|
||||
mai.getInvocationContext().setParameters(param);
|
||||
|
||||
mock.setParameters(param);
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionParametersAware() throws Exception {
|
||||
public void testParametersAware() throws Exception {
|
||||
ParametersAware mock = createMock(ParametersAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
@@ -163,23 +100,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
public void testSessionAware() throws Exception {
|
||||
SessionAware mock = (SessionAware) createMock(SessionAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
Map<String, Object> session = new HashMap<String, Object>();
|
||||
mai.getInvocationContext().setSession(session);
|
||||
|
||||
mock.setSession(session);
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionSessionAware() throws Exception {
|
||||
org.apache.struts2.action.SessionAware mock = createMock(org.apache.struts2.action.SessionAware.class);
|
||||
SessionAware mock = createMock(SessionAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
@@ -199,22 +120,6 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
Map<String, Object> app = new HashMap<String, Object>();
|
||||
mai.getInvocationContext().withApplication(app);
|
||||
|
||||
mock.setApplication(app);
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionApplicationAware() throws Exception {
|
||||
org.apache.struts2.action.ApplicationAware mock = createMock(org.apache.struts2.action.ApplicationAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
Map<String, Object> app = new HashMap<>();
|
||||
mai.getInvocationContext().withApplication(app);
|
||||
|
||||
@@ -230,27 +135,7 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
req.setUserPrincipal(null);
|
||||
req.setRemoteUser("Santa");
|
||||
PrincipalAware mock = (PrincipalAware) createMock(PrincipalAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
mai.getInvocationContext().put(StrutsStatics.HTTP_REQUEST, req);
|
||||
|
||||
MockServletContext ctx = new MockServletContext();
|
||||
mai.getInvocationContext().put(StrutsStatics.SERVLET_CONTEXT, ctx);
|
||||
|
||||
mock.setPrincipalProxy(anyObject(ServletPrincipalProxy.class)); // less strick match is needed for this unit test to be conducted using mocks
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionPrincipalAware() throws Exception {
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
req.setUserPrincipal(null);
|
||||
req.setRemoteUser("Santa");
|
||||
org.apache.struts2.action.PrincipalAware mock = createMock(org.apache.struts2.action.PrincipalAware.class);
|
||||
PrincipalAware mock = createMock(PrincipalAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
mai.getInvocationContext().put(StrutsStatics.HTTP_REQUEST, req);
|
||||
@@ -266,8 +151,8 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testPrincipalProxy() throws Exception {
|
||||
// uni test that does not use mock, but an Action so we also get code coverage for the PrincipalProxy class
|
||||
public void testActionPrincipalProxy() throws Exception {
|
||||
// unit test that does not use mock, but an Action so we also get code coverage for the PrincipalProxy class
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
req.setUserPrincipal(null);
|
||||
req.setRemoteUser("Santa");
|
||||
@@ -280,28 +165,6 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
interceptor.intercept(mai);
|
||||
assertNotNull(action.getProxy());
|
||||
|
||||
PrincipalProxy proxy = action.getProxy();
|
||||
assertNull(proxy.getUserPrincipal());
|
||||
assertTrue(!proxy.isRequestSecure());
|
||||
assertTrue(!proxy.isUserInRole("no.role"));
|
||||
assertEquals("Santa", proxy.getRemoteUser());
|
||||
|
||||
}
|
||||
|
||||
public void testActionPrincipalProxy() throws Exception {
|
||||
// unit test that does not use mock, but an Action so we also get code coverage for the PrincipalProxy class
|
||||
MockHttpServletRequest req = new MockHttpServletRequest();
|
||||
req.setUserPrincipal(null);
|
||||
req.setRemoteUser("Santa");
|
||||
|
||||
MyNewPrincipalAction action = new MyNewPrincipalAction();
|
||||
MockActionInvocation mai = createActionInvocation(action);
|
||||
mai.getInvocationContext().put(StrutsStatics.HTTP_REQUEST, req);
|
||||
|
||||
assertNull(action.getProxy());
|
||||
interceptor.intercept(mai);
|
||||
assertNotNull(action.getProxy());
|
||||
|
||||
PrincipalProxy proxy = action.getProxy();
|
||||
assertNull(proxy.getUserPrincipal());
|
||||
assertFalse(proxy.isRequestSecure());
|
||||
@@ -310,22 +173,6 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testServletContextAware() throws Exception {
|
||||
ServletContextAware mock = (ServletContextAware) createMock(ServletContextAware.class);
|
||||
|
||||
MockActionInvocation mai = createActionInvocation(mock);
|
||||
|
||||
MockServletContext ctx = new MockServletContext();
|
||||
mai.getInvocationContext().put(StrutsStatics.SERVLET_CONTEXT, ctx);
|
||||
|
||||
mock.setServletContext((ServletContext) ctx);
|
||||
expectLastCall().times(1);
|
||||
|
||||
replay(mock);
|
||||
interceptor.intercept(mai);
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
public void testActionServletContextAware() throws Exception {
|
||||
org.apache.struts2.action.ServletContextAware mock = createMock(org.apache.struts2.action.ServletContextAware.class);
|
||||
|
||||
@@ -371,23 +218,6 @@ public class ServletConfigInterceptorTest extends StrutsInternalTestCase {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setPrincipalProxy(PrincipalProxy proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
public PrincipalProxy getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyNewPrincipalAction implements Action, org.apache.struts2.action.PrincipalAware {
|
||||
|
||||
private PrincipalProxy proxy;
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void withPrincipalProxy(PrincipalProxy proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
+6
-4
@@ -19,7 +19,8 @@
|
||||
package org.apache.struts2.portlet.dispatcher;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import org.apache.struts2.action.SessionAware;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -67,7 +68,8 @@ public class DirectRenderFromEventAction implements SessionAware, Action, Serial
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setSession(Map session) {
|
||||
location = (String)session.get(PortletConstants.RENDER_DIRECT_LOCATION);
|
||||
}
|
||||
@Override
|
||||
public void withSession(Map<String, Object> session) {
|
||||
location = (String)session.get(PortletConstants.RENDER_DIRECT_LOCATION);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-39
@@ -24,8 +24,12 @@ import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.interceptor.PrincipalAware;
|
||||
import org.apache.struts2.action.PrincipalAware;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.action.PortletContextAware;
|
||||
import org.apache.struts2.portlet.action.PortletPreferencesAware;
|
||||
import org.apache.struts2.portlet.action.PortletRequestAware;
|
||||
import org.apache.struts2.portlet.action.PortletResponseAware;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletRequest;
|
||||
@@ -50,42 +54,22 @@ public class PortletAwareInterceptor extends AbstractInterceptor implements Stru
|
||||
|
||||
if (action instanceof PortletRequestAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
((PortletRequestAware) action).setPortletRequest(request);
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.portlet.action.PortletRequestAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
((org.apache.struts2.portlet.action.PortletRequestAware) action).withPortletRequest(request);
|
||||
((PortletRequestAware) action).withPortletRequest(request);
|
||||
}
|
||||
|
||||
if (action instanceof PortletResponseAware) {
|
||||
PortletResponse response = (PortletResponse) context.get(PortletConstants.RESPONSE);
|
||||
((PortletResponseAware) action).setPortletResponse(response);
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.portlet.action.PortletResponseAware) {
|
||||
PortletResponse response = (PortletResponse) context.get(PortletConstants.RESPONSE);
|
||||
((org.apache.struts2.portlet.action.PortletResponseAware) action).withPortletResponse(response);
|
||||
((PortletResponseAware) action).withPortletResponse(response);
|
||||
}
|
||||
|
||||
if (action instanceof PrincipalAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
((PrincipalAware) action).setPrincipalProxy(new PortletPrincipalProxy(request));
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.action.PrincipalAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
((org.apache.struts2.action.PrincipalAware) action).withPrincipalProxy(new PortletPrincipalProxy(request));
|
||||
((PrincipalAware) action).withPrincipalProxy(new PortletPrincipalProxy(request));
|
||||
}
|
||||
|
||||
if (action instanceof PortletContextAware) {
|
||||
PortletContext portletContext = (PortletContext) context.get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
|
||||
((PortletContextAware) action).setPortletContext(portletContext);
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.portlet.action.PortletContextAware) {
|
||||
PortletContext portletContext = (PortletContext) context.get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
|
||||
((org.apache.struts2.portlet.action.PortletContextAware) action).withPortletContext(portletContext);
|
||||
((PortletContextAware) action).withPortletContext(portletContext);
|
||||
}
|
||||
|
||||
if (action instanceof PortletPreferencesAware) {
|
||||
@@ -94,21 +78,9 @@ public class PortletAwareInterceptor extends AbstractInterceptor implements Stru
|
||||
// Check if running in a servlet environment
|
||||
if (request == null) {
|
||||
LOG.warn("This portlet preferences implementation should only be used during development");
|
||||
((PortletPreferencesAware) action).setPortletPreferences(new ServletPortletPreferences(ActionContext.getContext().getSession()));
|
||||
((PortletPreferencesAware) action).withPortletPreferences(new ServletPortletPreferences(ActionContext.getContext().getSession()));
|
||||
} else {
|
||||
((PortletPreferencesAware) action).setPortletPreferences(request.getPreferences());
|
||||
}
|
||||
}
|
||||
|
||||
if (action instanceof org.apache.struts2.portlet.action.PortletPreferencesAware) {
|
||||
PortletRequest request = (PortletRequest) context.get(PortletConstants.REQUEST);
|
||||
|
||||
// Check if running in a servlet environment
|
||||
if (request == null) {
|
||||
LOG.warn("This portlet preferences implementation should only be used during development");
|
||||
((org.apache.struts2.portlet.action.PortletPreferencesAware) action).withPortletPreferences(new ServletPortletPreferences(ActionContext.getContext().getSession()));
|
||||
} else {
|
||||
((org.apache.struts2.portlet.action.PortletPreferencesAware) action).withPortletPreferences(request.getPreferences());
|
||||
((PortletPreferencesAware) action).withPortletPreferences(request.getPreferences());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.portlet.interceptor;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletContextAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface PortletContextAware {
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletContextAware#withPortletContext(PortletContext)} instead
|
||||
*/
|
||||
void setPortletContext(PortletContext portletContext);
|
||||
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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.portlet.interceptor;
|
||||
|
||||
import javax.portlet.PortletPreferences;
|
||||
|
||||
|
||||
/**
|
||||
* All Actions that want to have access to the portlet preferences should
|
||||
* implement this interface. If running in a servlet environment, an
|
||||
* appropriate testing implementation will be provided.
|
||||
*
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletPreferencesAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface PortletPreferencesAware {
|
||||
|
||||
/**
|
||||
* Sets the HTTP request object in implementing classes.
|
||||
*
|
||||
* @param prefs the portlet preferences.
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletPreferencesAware#withPortletPreferences(PortletPreferences)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
void setPortletPreferences(PortletPreferences prefs);
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.portlet.interceptor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletRequestAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface PortletRequestAware {
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletRequestAware#withPortletRequest(PortletRequest)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
void setPortletRequest(PortletRequest request);
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* 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.portlet.interceptor;
|
||||
|
||||
import javax.portlet.PortletResponse;
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletResponseAware} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface PortletResponseAware {
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link org.apache.struts2.portlet.action.PortletResponseAware#withPortletResponse(PortletResponse)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
void setPortletResponse(PortletResponse response);
|
||||
|
||||
}
|
||||
+6
-25
@@ -22,6 +22,8 @@ import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.action.PortletRequestAware;
|
||||
import org.apache.struts2.portlet.action.PortletResponseAware;
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
@@ -42,33 +44,12 @@ public class PortletAwareInterceptorTest extends TestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testPortletRequestIsSet() throws Exception {
|
||||
public void testPortletRequestAware() throws Exception {
|
||||
PortletRequest request = EasyMock.createMock(PortletRequest.class);
|
||||
Map<String, Object> ctx = new HashMap<>();
|
||||
ctx.put(PortletConstants.REQUEST, request);
|
||||
ActionContext actionContext = ActionContext.of(ctx).bind();
|
||||
|
||||
ctx.put(PortletConstants.REQUEST, request);
|
||||
PortletRequestAware action = EasyMock.createMock(PortletRequestAware.class);
|
||||
action.setPortletRequest(request);
|
||||
|
||||
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
|
||||
EasyMock.expect(invocation.getInvocationContext()).andReturn(actionContext);
|
||||
EasyMock.expect(invocation.getAction()).andReturn(action);
|
||||
|
||||
EasyMock.replay(action);
|
||||
EasyMock.replay(invocation);
|
||||
|
||||
interceptor.intercept(invocation);
|
||||
|
||||
EasyMock.verify(action);
|
||||
}
|
||||
|
||||
public void testActionPortletRequestAware() throws Exception {
|
||||
PortletRequest request = EasyMock.createMock(PortletRequest.class);
|
||||
Map<String, Object> ctx = new HashMap<>();
|
||||
ActionContext actionContext = ActionContext.of(ctx).bind();
|
||||
ctx.put(PortletConstants.REQUEST, request);
|
||||
org.apache.struts2.portlet.action.PortletRequestAware action = EasyMock.createMock(org.apache.struts2.portlet.action.PortletRequestAware.class);
|
||||
action.withPortletRequest(request);
|
||||
|
||||
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
|
||||
@@ -83,12 +64,12 @@ public class PortletAwareInterceptorTest extends TestCase {
|
||||
EasyMock.verify(action);
|
||||
}
|
||||
|
||||
public void testActionPortletResponseAware() throws Exception {
|
||||
public void testPortletResponseAware() throws Exception {
|
||||
PortletResponse response = EasyMock.createMock(PortletResponse.class);
|
||||
Map<String, Object> ctx = new HashMap<>();
|
||||
ctx.put(PortletConstants.RESPONSE, response);
|
||||
ActionContext actionContext = ActionContext.of(ctx).bind();
|
||||
org.apache.struts2.portlet.action.PortletResponseAware action = EasyMock.createMock(org.apache.struts2.portlet.action.PortletResponseAware.class);
|
||||
PortletResponseAware action = EasyMock.createMock(PortletResponseAware.class);
|
||||
action.withPortletResponse(response);
|
||||
|
||||
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
|
||||
|
||||
+3
-3
@@ -58,7 +58,7 @@ public class PortletStateInterceptorTest extends StrutsTestCasePortletTests {
|
||||
Map<String, Object> session = new HashMap<>();
|
||||
|
||||
ActionContext ctx = ActionContext.of(ctxMap).bind();
|
||||
ctx.setSession(session);
|
||||
ctx.withSession(session);
|
||||
EasyMock.expect(invocation.getInvocationContext()).andStubReturn(ctx);
|
||||
actionResponse.setRenderParameter(EVENT_ACTION, "true");
|
||||
|
||||
@@ -97,7 +97,7 @@ public class PortletStateInterceptorTest extends StrutsTestCasePortletTests {
|
||||
ctxMap.put(REQUEST, renderRequest);
|
||||
|
||||
ActionContext ctx = ActionContext.of(ctxMap).bind();
|
||||
ctx.setSession(session);
|
||||
ctx.withSession(session);
|
||||
|
||||
EasyMock.expect(invocation.getInvocationContext()).andStubReturn(ctx);
|
||||
EasyMock.expect(invocation.getStack()).andStubReturn(currentStack);
|
||||
@@ -138,7 +138,7 @@ public class PortletStateInterceptorTest extends StrutsTestCasePortletTests {
|
||||
ctxMap.put(REQUEST, renderRequest);
|
||||
|
||||
ActionContext ctx = ActionContext.of(ctxMap).bind();
|
||||
ctx.setSession(session);
|
||||
ctx.withSession(session);
|
||||
|
||||
EasyMock.expect(invocation.getInvocationContext()).andStubReturn(ctx);
|
||||
EasyMock.expect(invocation.getStack()).andStubReturn(currentStack);
|
||||
|
||||
Reference in New Issue
Block a user