本文整理汇总了Java中net.sourceforge.stripes.action.ActionBeanContext.getRequest方法的典型用法代码示例。如果您正苦于以下问题:Java ActionBeanContext.getRequest方法的具体用法?Java ActionBeanContext.getRequest怎么用?Java ActionBeanContext.getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sourceforge.stripes.action.ActionBeanContext
的用法示例。
在下文中一共展示了ActionBeanContext.getRequest方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: intercept
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
logger.debug("Retrieving Stripes objects");
ActionBeanContext actionContext = context.getActionBeanContext();
ActionBean actionBean = context.getActionBean();
Method handler = context.getHandler();
logger.debug("Retrieving Servlet API objects");
HttpServletRequest request = actionContext.getRequest();
Dispatch dispatch = DispatcherUtil.getDispatch(request);
if(SecurityLogic.isAllowed(request, dispatch, actionBean, handler)) {
logger.debug("Security check passed.");
return context.proceed();
} else {
return new ForbiddenAccessResolution();
}
}
示例2: intercept
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
logger.debug("Retrieving Stripes objects");
ActionBeanContext actionContext = context.getActionBeanContext();
logger.debug("Retrieving Servlet API objects");
HttpServletRequest request = actionContext.getRequest();
if (request.getDispatcherType() == DispatcherType.REQUEST) {
logger.debug("Starting page response timer");
StopWatch stopWatch = new StopWatch();
// There is no need to stop this timer.
stopWatch.start();
request.setAttribute(RequestAttributes.STOP_WATCH, stopWatch);
}
Resolution resolution = dispatch(actionContext);
return resolution != null ? resolution : context.proceed();
}
示例3: getDispatch
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
public static Dispatch getDispatch(ActionBeanContext context) {
HttpServletRequest request = context.getRequest();
Dispatcher dispatcher = get(request);
if(context instanceof ElementsActionBeanContext) {
String actionPath = ((ElementsActionBeanContext) context).getActionPath();
return dispatcher.getDispatch(actionPath);
} else {
return getDispatch(request);
}
}
示例4: intercept
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
logger.debug("Retrieving Stripes objects");
Object action = context.getActionBean();
ActionBeanContext actionContext = context.getActionBeanContext();
logger.debug("Retrieving Servlet API objects");
HttpServletRequest request = actionContext.getRequest();
ServletContext servletContext = actionContext.getServletContext();
Injections.inject(action, servletContext, request);
return context.proceed();
}
示例5: intercept
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
logger.debug("Retrieving Stripes objects");
ActionBeanContext actionContext = context.getActionBeanContext();
ActionBean actionBean = context.getActionBean();
Method handler = context.getHandler();
logger.debug("Retrieving Servlet API objects");
HttpServletRequest request = actionContext.getRequest();
Subject subject = SecurityUtils.getSubject();
if (!SecurityLogic.satisfiesRequiresAdministrator(request, actionBean, handler)) {
return new ForbiddenAccessResolution();
}
logger.debug("Checking page permissions");
boolean isNotAdmin = !SecurityLogic.isAdministrator(request);
if (isNotAdmin) {
ServletContext servletContext = context.getActionBeanContext().getServletContext();
Configuration configuration = (Configuration) servletContext.getAttribute(BaseModule.PORTOFINO_CONFIGURATION);
Permissions permissions;
Dispatch dispatch = DispatcherUtil.getDispatch(request);
String resource;
boolean allowed;
if(dispatch != null) {
logger.debug("The protected resource is a page action");
resource = dispatch.getLastPageInstance().getPath();
allowed = SecurityLogic.hasPermissions(configuration, dispatch, subject, handler);
} else {
logger.debug("The protected resource is a plain Stripes ActionBean");
resource = request.getRequestURI();
permissions = new Permissions();
allowed = SecurityLogic.hasPermissions
(configuration, permissions, subject, handler, actionBean.getClass());
}
if(!allowed) {
logger.info("Access to {} is forbidden", resource);
return new ForbiddenAccessResolution();
}
}
logger.debug("Security check passed.");
return context.proceed();
}
示例6: intercept
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
public Resolution intercept(ExecutionContext context) throws Exception {
logger.debug("Retrieving Stripes objects");
ActionBeanContext actionContext = context.getActionBeanContext();
logger.debug("Retrieving Servlet API objects");
HttpServletRequest request = actionContext.getRequest();
logger.debug("Starting page response timer");
StopWatch stopWatch = new StopWatch();
// There is no need to stop this timer.
stopWatch.start();
request.setAttribute(RequestAttributes.STOP_WATCH, stopWatch);
Dispatch dispatch = DispatcherUtil.getDispatch(request);
if (dispatch != null) {
logger.debug("Preparing PageActions");
for(PageInstance page : dispatch.getPageInstancePath()) {
if(page.getParent() == null) {
logger.debug("Not preparing root");
continue;
}
if(page.isPrepared()) {
continue;
}
logger.debug("Preparing PageAction {}", page);
PageAction actionBean = ensureActionBean(page);
configureActionBean(actionBean, page, request);
try {
actionBean.setContext(actionContext);
actionBean.setPageInstance(page);
Resolution resolution = actionBean.preparePage();
if(resolution != null) {
logger.debug("PageAction prepare returned a resolution: {}", resolution);
request.setAttribute(INVALID_PAGE_INSTANCE, page);
return resolution;
}
page.setPrepared(true);
} catch (Throwable t) {
request.setAttribute(INVALID_PAGE_INSTANCE, page);
logger.error("PageAction prepare failed for " + page, t);
if(!PageActionLogic.isEmbedded(actionBean)) {
String msg = MessageFormat.format
(ElementsThreadLocals.getText("this.page.has.thrown.an.exception.during.execution"), ExceptionUtils.getRootCause(t));
SessionMessages.addErrorMessage(msg);
}
return new ForwardResolution("/m/pageactions/redirect-to-last-working-page.jsp");
}
}
PageInstance pageInstance = dispatch.getLastPageInstance();
request.setAttribute(RequestAttributes.PAGE_INSTANCE, pageInstance);
}
return context.proceed();
}
示例7: getActionBean
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
/**
* Returns the ActionBean class that is bound to the UrlBinding supplied. If the action
* bean already exists in the appropriate scope (request or session) then the existing
* instance will be supplied. If not, then a new instance will be manufactured and have
* the supplied ActionBeanContext set on it.
*
* @param path a URL to which an ActionBean is bound, or a path starting with the URL
* to which an ActionBean has been bound.
* @param context the current ActionBeanContext
* @return a Class<ActionBean> for the ActionBean requested
* @throws StripesServletException if the UrlBinding does not match an ActionBean binding
*/
public ActionBean getActionBean(ActionBeanContext context, String path) throws StripesServletException {
Class<? extends ActionBean> beanClass = getActionBeanType(path);
ActionBean bean;
if (beanClass == null) {
throw new ActionBeanNotFoundException(path, getUrlBindingFactory().getPathMap());
}
String bindingPath = getUrlBinding(beanClass);
try {
HttpServletRequest request = context.getRequest();
if (beanClass.isAnnotationPresent(SessionScope.class)) {
bean = (ActionBean) request.getSession().getAttribute(bindingPath);
if (bean == null) {
bean = makeNewActionBean(beanClass, context);
request.getSession().setAttribute(bindingPath, bean);
}
}
else {
bean = (ActionBean) request.getAttribute(bindingPath);
if (bean == null) {
bean = makeNewActionBean(beanClass, context);
request.setAttribute(bindingPath, bean);
}
}
setActionBeanContext(bean, context);
}
catch (Exception e) {
StripesServletException sse = new StripesServletException(
"Could not create instance of ActionBean type [" + beanClass.getName() + "].", e);
log.error(sse);
throw sse;
}
assertGetContextWorks(bean);
return bean;
}
示例8: positiveCase
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
@Test(groups="fast")
public void positiveCase() throws Exception {
MockServletContext ctx = StripesTestFixture.createServletContext();
try {
MockRoundtrip trip = new MockRoundtrip(ctx, FlashScopeTests.class);
trip.addParameter("foo", "foo123");
trip.execute();
String url = trip.getDestination();
Matcher matcher = FLASH_ID_REGEX.matcher(url);
Assert.assertTrue(matcher.matches(),
"Redirect URL should contain request parameter for flash scope id.");
Assert.assertEquals("foo123", trip.getRequest().getAttribute("foo"),
"FlashScope should have inserted 'foo' into a request attribute.");
MockRoundtrip trip2 = new MockRoundtrip
(ctx, FlashScopeTests.class, (MockHttpSession) trip.getRequest().getSession());
// Get the flash scope ID from the redirect URL and add it back as a parameter
String id = matcher.group(1);
trip2.addParameter(StripesConstants.URL_KEY_FLASH_SCOPE_ID, id);
Assert.assertNull(trip2.getRequest().getAttribute("foo"),
"Request attribute 'foo' should not exist prior to request.");
trip2.execute("DoNothing");
Assert.assertEquals("foo123", trip2.getRequest().getAttribute("foo"),
"Request attribute 'foo' should have been set by FlashScope.");
Assert.assertEquals(FlashScope.getAllFlashScopes(trip2.getRequest()).size(), 0,
"FlashScope should have been removed from session after use.");
// Test flashing an ActionBean
MockRoundtrip trip3 = new MockRoundtrip(ctx, FlashScopeTests.class, (MockHttpSession) trip
.getRequest().getSession());
// Get the flash scope ID from the redirect URL and add it back as a parameter
trip3.addParameter(StripesConstants.URL_KEY_FLASH_SCOPE_ID, id);
trip3.execute("FlashBean");
try {
ActionBeanContext tmp = trip3.getActionBean(getClass()).getContext();
HttpServletResponse response = tmp.getResponse();
HttpServletRequest request = tmp.getRequest();
Assert.assertNotNull(request);
Assert.assertNotNull(response);
Assert.assertTrue(Proxy.class.isAssignableFrom(response.getClass()));
Assert.assertEquals(StripesRequestWrapper.class, request.getClass());
response.isCommitted();
Assert.fail(
"Response should have thrown IllegalStateException after request cycle complete");
}
catch (IllegalStateException e) {
}
} finally {
ctx.close();
}
}
示例9: getActionBean
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
/**
* Gets the logical name of the ActionBean that should handle the request. Implemented to look
* up the name of the form based on the name assigned to the form in the form tag, and
* encoded in a hidden field.
*
* @param context the ActionBeanContext for the current request
* @return the name of the form to be used for this request
*/
public ActionBean getActionBean(ActionBeanContext context) throws StripesServletException {
HttpServletRequest request = context.getRequest();
String path = HttpUtil.getRequestedPath(request);
ActionBean bean = getActionBean(context, path);
request.setAttribute(RESOLVED_ACTION, getUrlBindingFromPath(path));
return bean;
}
示例10: getActionBean
import net.sourceforge.stripes.action.ActionBeanContext; //导入方法依赖的package包/类
/**
* Gets the logical name of the ActionBean that should handle the request.
* Implemented to look up the name of the form based on the name assigned to
* the form in the form tag, and encoded in a hidden field.
*
* @param context
* the ActionBeanContext for the current request
* @return the name of the form to be used for this request
*/
public ActionBean getActionBean(ActionBeanContext context) throws StripesServletException {
HttpServletRequest request = context.getRequest();
String path = HttpUtil.getRequestedPath(request);
ActionBean bean = getActionBean(context, path);
request.setAttribute(RESOLVED_ACTION, getUrlBindingFromPath(path));
return bean;
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:17,代码来源:AnnotatedClassActionResolver.java