Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tomcat crossContext #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,24 @@ public ActionBean getActionBean(ActionBeanContext context, String path) throws S
}

String bindingPath = getUrlBinding(beanClass);
final String contextPath = context.getServletContext().getContextPath() != null ?
context.getServletContext().getContextPath() : "";
final String attribName = contextPath + bindingPath;
try {
HttpServletRequest request = context.getRequest();

if (beanClass.isAnnotationPresent(SessionScope.class)) {
bean = (ActionBean) request.getSession().getAttribute(bindingPath);
bean = (ActionBean) request.getSession().getAttribute(attribName);

if (bean == null) {
bean = makeNewActionBean(beanClass, context);
request.getSession().setAttribute(bindingPath, bean);
request.getSession().setAttribute(attribName, bean);
}
} else {
bean = (ActionBean) request.getAttribute(bindingPath);
bean = (ActionBean) request.getAttribute(attribName);
if (bean == null) {
bean = makeNewActionBean(beanClass, context);
request.setAttribute(bindingPath, bean);
request.setAttribute(attribName, bean);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ protected void restoreActionBean(HttpServletRequest request) {
Stack<ActionBean> stack = getActionBeanStack(request, false);
if (stack != null && !stack.empty()) {
request.setAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN, stack.pop());
} else {
request.removeAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public interface StripesConstants {
*/
String REQ_ATTR_ACTION_BEAN = "actionBean";

/**
* The name under which the last ActionBean for a request is stored before restoring from
* the stack.
*/
String REQ_ATTR_LAST_ACTION_BEAN = "lastActionBean";

/**
* The name of a request attribute in which a Stack of action beans is some times stored
* when a single request involves includes of action beans.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,12 @@ public void execute(String event) throws Exception {
*/
@SuppressWarnings("unchecked")
public <A extends ActionBean> A getActionBean(Class<A> type) {
A bean = (A) this.request.getAttribute(getUrlBinding(type, this.context));
final String bindingPath = getUrlBinding(type, this.context);
final String contextPath = context.getContextPath() != null ? context.getContextPath() : "";
final String attribName = contextPath + bindingPath;
A bean = (A) this.request.getAttribute(attribName);
if (bean == null) {
bean = (A) this.request.getSession().getAttribute(getUrlBinding(type, this.context));
bean = (A) this.request.getSession().getAttribute(attribName);
}
return bean;
}
Expand All @@ -285,7 +288,7 @@ public <A extends ActionBean> A getActionBean(Class<A> type) {
* Gets the (potentially empty) set of Validation Errors that were produced by the request.
*/
public ValidationErrors getValidationErrors() {
ActionBean bean = (ActionBean) this.request.getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN);
ActionBean bean = (ActionBean) this.request.getAttribute(StripesConstants.REQ_ATTR_LAST_ACTION_BEAN);
return bean.getContext().getValidationErrors();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static synchronized Configuration getDefaultConfiguration() {
public static Map<String, String> getDefaultFilterParams() {
Map<String, String> map = new HashMap<String, String>();
map.put("ActionResolver.Packages", "net.sourceforge.stripes");
map.put("Interceptor.Classes", "net.sourceforge.stripes.test.RecordLastActionBeanInterceptor");
map.put("LocalePicker.Class", "net.sourceforge.stripes.localization.MockLocalePicker");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.sourceforge.stripes.test;

import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.controller.*;

/**
* Created by shane on 23/9/16.
*/
@Intercepts(LifecycleStage.RequestComplete)
public class RecordLastActionBeanInterceptor implements Interceptor {

@Override
public Resolution intercept(ExecutionContext context) throws Exception {
context.getActionBeanContext().getRequest().setAttribute(StripesConstants.REQ_ATTR_LAST_ACTION_BEAN, context.getActionBean());
return null;
}

}