Package com.opensymphony.xwork2

Examples of com.opensymphony.xwork2.ActionContext


     * @see com.opensymphony.xwork2.interceptor.MethodFilterInterceptor#doIntercept(com.opensymphony.xwork2.ActionInvocation)
     */
    protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
        ActionProxy proxy = actionInvocation.getProxy();
        String name = getBackgroundProcessName(proxy);
        ActionContext context = actionInvocation.getInvocationContext();
        Map session = context.getSession();
        HttpSession httpSession = ServletActionContext.getRequest().getSession(true);

        Boolean secondTime  = true;
        if (executeAfterValidationPass) {
            secondTime = (Boolean) context.get(KEY);
            if (secondTime == null) {
                context.put(KEY, true);
                secondTime = false;
            } else {
                secondTime = true;
                context.put(KEY, null);
            }
        }

        //sync on the real HttpSession as the session from the context is a wrap that is created
        //on every request
View Full Code Here


        session = new HashMap();
        Map params = new TreeMap();
        Map ctxMap = new TreeMap();
        ctxMap.put(ActionContext.SESSION, session);
        ctxMap.put(ActionContext.PARAMETERS, params);
        ActionContext ctx = new ActionContext(ctxMap);
        ActionContext.setContext(ctx);
    }
View Full Code Here

    @Override
    public String doIntercept(ActionInvocation invocation) throws Exception {
        Object action = invocation.getAction();
        if (!(action instanceof NoParameters)) {
            ActionContext ac = invocation.getInvocationContext();
            final Map<String, Object> parameters = retrieveParameters(ac);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Setting params " + getParameterLogMap(parameters));
            }

            if (parameters != null) {
                Map<String, Object> contextMap = ac.getContextMap();
                try {
                    ReflectionContextState.setCreatingNullObjects(contextMap, true);
                    ReflectionContextState.setDenyMethodExecution(contextMap, true);
                    ReflectionContextState.setReportingConversionErrors(contextMap, true);

                    ValueStack stack = ac.getValueStack();
                    setParameters(action, stack, parameters);
                } finally {
                    ReflectionContextState.setCreatingNullObjects(contextMap, false);
                    ReflectionContextState.setDenyMethodExecution(contextMap, false);
                    ReflectionContextState.setReportingConversionErrors(contextMap, false);
View Full Code Here

    }

    protected String lookupExtension(String extension) {
        if (extension == null) {
            // Look for the current extension, if available
            ActionContext context = ActionContext.getContext();
            if (context != null) {
                ActionMapping orig = (ActionMapping) context.get(ServletActionContext.ACTION_MAPPING);
                if (orig != null) {
                    extension = orig.getExtension();
                }
            }
            if (extension == null) {
View Full Code Here

        assertNotNull(result);
        assertTrue(result instanceof ServletRedirectResult);

        Mock invMock = new Mock(ActionInvocation.class);
        ActionInvocation inv = (ActionInvocation) invMock.proxy();
        ActionContext ctx = ActionContext.getContext();
        ctx.put(ServletActionContext.HTTP_REQUEST, request);
        StrutsMockHttpServletResponse response = new StrutsMockHttpServletResponse();
        ctx.put(ServletActionContext.HTTP_RESPONSE, response);
        invMock.expectAndReturn("getInvocationContext", ctx);
        invMock.expectAndReturn("getStack", ctx.getValueStack());
        result.execute(inv);
        assertEquals("http://www.google.com", response.getRedirectURL());
        //TODO: need to test location but there's noaccess to the property/method, unless we use reflection
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public String intercept(ActionInvocation invocation) throws Exception {
    logger.debug("Start AuthenticationInterceptor");
    final Object action = invocation.getAction();
    final ActionContext context = invocation.getInvocationContext();
    WebApplicationContext ctx = WebApplicationContextUtils.
      getWebApplicationContext((ServletContext) context.get(SERVLET_CONTEXT));
    HttpServletRequest request = (HttpServletRequest)context.get(HTTP_REQUEST);
    HttpServletResponse response = (HttpServletResponse)context.get(HTTP_RESPONSE);
   
    OperatingUnitDao operatingUnitDao = (OperatingUnitDao)ctx.getBean("loxiaOperatingUnitDao");
   
    String strMethod = invocation.getProxy().getMethod();
    Method m = getActionMethod(action.getClass(), strMethod);
View Full Code Here

  private boolean debug = false;

  @SuppressWarnings("unchecked")
  @Override
  public String intercept(ActionInvocation invocation) throws Exception {
    final ActionContext context = invocation.getInvocationContext();
    HttpServletRequest request = (HttpServletRequest)context.get(StrutsStatics.HTTP_REQUEST);
    boolean isXhr = (request.getHeader("X-Requested-With") != null);
    String result = super.intercept(invocation);
    if(isXhr){
      logger.debug("This is one xhrequest.");
      if(TokenInterceptor.INVALID_TOKEN_CODE.equals(result)){
        //duplicate submit error here
        //construct one exception for jsonresult
        String errorMessage = LocalizedTextUtil.findText(this.getClass(), "struts.messages.invalid.token",
                    invocation.getInvocationContext().getLocale(),
                    "The form has already been processed or no token was supplied, please try again.", new Object[0]);
       
        Map req  = (Map)context.get("request");
        Map session = context.getSession();
        Map<String,Object> exceptionMap = new HashMap<String, Object>();
        exceptionMap.put("invalidToken", true);
        exceptionMap.put("errorMessages", Arrays.asList(errorMessage));
        synchronized (session) {
          exceptionMap.put("token", TokenHelper.setToken());
View Full Code Here

          ServletContext servletContext) throws Exception
    {
        // BEGIN: Change for Struts 2.1.6
        Container container = dispatcher.getContainer();
        ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
        ActionContext.setContext(new ActionContext(stack.getContext()));
        // END: Change for Struts 2.1.6

        ServletActionContext.setRequest(request);
        ServletActionContext.setResponse(response);
        ServletActionContext.setServletContext(servletContext);
View Full Code Here

  @Override
  public String intercept(ActionInvocation invocation) throws Exception {
    // Get the action context from the invocation so we can access the
      // HttpServletRequest and HttpSession objects.
      final ActionContext context = invocation.getInvocationContext ();
      HttpServletRequest request = (HttpServletRequest) context.get(StrutsStatics.HTTP_REQUEST);
      HttpSession session =  request.getSession (true);

      // Is there a "user" object stored in the user's HttpSession?
      Object user = session.getAttribute (SessionConstants.USER_HANDLE);
      if (user == null) {
          // The user has not logged in yet.

          // Is the user attempting to log in right now?
          String loginAttempt = request.getParameter (LOGIN_ATTEMPT);
          if (! StringUtils.isBlank (loginAttempt) ) { // The user is attempting to log in.

              // Process the user's login attempt.
            String loginError = processLoginAttempt (request, session);
              if ("".equals(loginError) ) {
                  // The login succeeded send them the login-success page.
               
                log.info(String.format("User %s login [%s]", request.getParameter(LOGIN_EMAIL), request.getRemoteAddr()));
               
                // If they were originally going somewhere else, try and send them there again
                String intendedUri = (String) session.getAttribute(SessionConstants.LOGIN_REDIRECT);
                if( intendedUri != null)
                {
                  session.removeAttribute(SessionConstants.LOGIN_REDIRECT);
                  ((HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE)).sendRedirect(intendedUri);
                }
               
                // Otherwise, go to the default
                  return "login-success";
              } else {
View Full Code Here

    return (currentUser(false) != null);
  }
 
  public static User currentUser(boolean throwIfNotSignedIn)
  {
    ActionContext context = ActionContext.getContext();
    User user = null;
   
    // Fetch it from the session
    if(context != null)
      user = (User) ActionContext.getContext().getSession().get(SessionConstants.USER_HANDLE);
View Full Code Here

TOP

Related Classes of com.opensymphony.xwork2.ActionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.