Package webwork.dispatcher

Examples of webwork.dispatcher.GenericDispatcher


         servletPath = aRequest.getServletPath();
     
       //logger.info("servletPath:" + servletPath);
     
       String actionName = getActionName(servletPath);
       GenericDispatcher gd = new GenericDispatcher(actionName, false);
       ActionContext context = gd.prepareContext();
      
       //logger.info("actionName:" + actionName);

       InfoGluePrincipal principal = (InfoGluePrincipal)aRequest.getSession().getAttribute("infogluePrincipal");
       if(principal != null)
         aRequest.setAttribute("infoglueRemoteUser", principal.getName());

       aRequest.setAttribute("webwork.request_url", aRequest.getRequestURL());

       ServletActionContext.setContext(aRequest, aResponse, getServletContext(), actionName);

       gd.prepareValueStack();
       ActionResult ar = null;
       try
       {
           gd.executeAction();
           ar = gd.finish();
       }
       catch (Throwable e)
       {
           log.warn("Could not execute action:" + e.getMessage());
            try
            {
                aResponse.sendError(404, "Could not execute action [" + actionName + "]:" + e.getMessage() + getHTMLErrorMessage(e));
            }
            catch (IOException e1)
            {
            }
       }

       if (ar != null && ar.getActionException() != null)
       {
         log.warn("Could not execute action:" + ar.getActionException().getMessage());
         //log.error("Could not execute action", ar.getActionException());
         try
         {
           aResponse.sendError(500, ar.getActionException().getMessage() + getHTMLErrorMessage(ar.getActionException()));
         }
         catch (IOException e1)
         {
         }
       }

      // check if no view exists
      if (ar != null && ar.getResult() != null && ar.getView() == null && !ar.getResult().equals(Action.NONE)) {
          try
          {
              aResponse.sendError(404, "No view for result [" + ar.getResult() + "] exists for action [" + actionName + "]");
          }
          catch (IOException e)
          {
          }
      }

      if (ar != null && ar.getView() != null && ar.getActionException() == null)
      {
          String view = ar.getView().toString();
          log.debug("Result:" + view);

          RequestDispatcher dispatcher = null;
          try
          {
               dispatcher = aRequest.getRequestDispatcher(view);
          }
          catch (Throwable e)
          {
              // Ignore
          }

          if (dispatcher == null)
              throw new ServletException("No presentation file with name '" + view + "' found!");

          try
          {
              // If we're included, then include the view
              // Otherwise do forward
              // This allow the page to, for example, set content type
              if (aRequest.getAttribute("javax.servlet.include.servlet_path") == null)
              {
                   aRequest.setAttribute("webwork.view_uri", view);
                   aRequest.setAttribute("webwork.request_uri", aRequest.getRequestURI());
                   aRequest.setAttribute("webwork.request_url", aRequest.getRequestURL());
                   //aRequest.setAttribute("webwork.contextPath",aRequest.getContextPath());

                   dispatcher.forward(aRequest, aResponse);
              }
              else
              {
                   //aRequest.setAttribute("webwork.request_uri",aRequest.getAttribute("javax.servlet.include.request_uri"));
                   //aRequest.setAttribute("webwork.contextPath",aRequest.getAttribute("javax.servlet.include.context_path"));
                   dispatcher.include(aRequest, aResponse);
              }
          }
          catch (IOException e)
          {
            e.printStackTrace();
              throw new ServletException(e);
          }
          catch (Exception e)
          {
            e.printStackTrace();
            throw new ServletException(e);
          }
          finally
          {
              // Get last action from stack and and store it in request attribute STACK_HEAD
              // It is then popped from the stack.
              aRequest.setAttribute(STACK_HEAD, ServletValueStack.getStack(aRequest).popValue());
          }
      }

      gd.finalizeContext();
   }
View Full Code Here


    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException
    {
        final WorkflowContext wfContext = (WorkflowContext) transientVars.get("context");

        String actionName = (String) args.get("action.name");
        GenericDispatcher gd = new GenericDispatcher(actionName);
        gd.prepareContext();
       
        ActionContext.setPrincipal(new Principal() {
                public String getName() {
                    return wfContext.getCaller();
                }
            });
        ActionContext.setApplication(args);
        ActionContext.setSession(ps.getProperties(""));
        ActionContext.setLocale(Locale.getDefault());

        Map params = new HashMap(transientVars);
        params.putAll(args);
        ActionContext.setParameters(Collections.unmodifiableMap(params));

        try {
            gd.prepareContext();
            gd.prepareValueStack();
            gd.executeAction();
            gd.finish();
            gd.finalizeContext();
        } catch (Exception e) {
            throw new WorkflowException("Could not execute action " + actionName, e);
        }
    }
View Full Code Here

TOP

Related Classes of webwork.dispatcher.GenericDispatcher

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.