Package org.ocpsoft.rewrite.servlet.http.event

Examples of org.ocpsoft.rewrite.servlet.http.event.HttpInboundServletRewrite


   @Override
   public void perform(final Rewrite event, final EvaluationContext context)
   {
      if ((event instanceof HttpInboundServletRewrite) && DispatchType.isRequest().evaluate(event, context))
      {
         HttpInboundServletRewrite in = (HttpInboundServletRewrite) event;

         QueryStringBuilder query = QueryStringBuilder.createNew();
         query.addParameters(in.getInboundAddress().getQuery());

         String token = query.decode().getParameter(tokenName);
         if (token != null)
         {
            String decoded = encodingStrategy.decode(token);

            if (checksumStrategy.checksumValid(decoded))
            {
               decoded = checksumStrategy.removeChecksum(decoded);
               query.removeParameter(tokenName);
               QueryStringBuilder queryParams = QueryStringBuilder.createFromEncoded(decoded);
               RewriteWrappedRequest request = RewriteWrappedRequest.getCurrentInstance(in.getRequest());
               for (Entry<String, List<String>> param : queryParams.getParameterMap().entrySet()) {
                  for (String value : param.getValue()) {
                     Maps.addArrayValue(request.getModifiableParameters(), param.getKey(), value);
                  }
               }
            }
            else if (onfailure != null)
            {
               onfailure.perform(event, context);
            }
         }
         else if (!query.isEmpty() && inboundCorrection)
         {
            in.redirectTemporary(in.getAddress().getPathAndQuery());
         }
      }

      else if (event instanceof HttpOutboundServletRewrite)
      {
View Full Code Here


   }

   @Override
   public void handleResult(Rewrite event) throws ServletException, IOException
   {
      HttpInboundServletRewrite servletRewrite = (HttpInboundServletRewrite) event;
      String dispatchResource = servletRewrite.getDispatchResource();

      if (servletRewrite.getFlow().is(BaseRewrite.ServletRewriteFlow.ABORT_REQUEST))
      {
         if (servletRewrite.getFlow().is(BaseRewrite.ServletRewriteFlow.FORWARD))
         {
            log.debug("Issuing internal FORWARD to [{}].", dispatchResource);
            servletRewrite.getRequest().getRequestDispatcher(dispatchResource)
                     .forward(servletRewrite.getRequest(), servletRewrite.getResponse());
         }
         else if (servletRewrite.getFlow().is(BaseRewrite.ServletRewriteFlow.REDIRECT_PERMANENT))
         {
            log.debug("Issuing 301 permanent REDIRECT to [{}].", dispatchResource);
            HttpServletResponse response = (HttpServletResponse) servletRewrite.getResponse();
            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            response.setHeader("Location", dispatchResource);
            response.flushBuffer();
         }
         else if (servletRewrite.getFlow().is(BaseRewrite.ServletRewriteFlow.REDIRECT_TEMPORARY))
         {
            log.debug("Issuing 302 temporary REDIRECT to [{}].", dispatchResource);
            HttpServletResponse response = (HttpServletResponse) servletRewrite.getResponse();
            response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
            response.setHeader("Location", dispatchResource);
            response.flushBuffer();
         }
         else
         {
            log.debug("ABORT requested. Terminating request NOW.");
         }
      }
      else if (servletRewrite.getFlow().is(BaseRewrite.ServletRewriteFlow.INCLUDE))
      {
         log.debug("Issuing internal INCLUDE to [{}].", dispatchResource);
         servletRewrite.getRequest().getRequestDispatcher(dispatchResource)
                  .include(servletRewrite.getRequest(), servletRewrite.getResponse());
      }
   }
View Full Code Here

TOP

Related Classes of org.ocpsoft.rewrite.servlet.http.event.HttpInboundServletRewrite

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.