Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.picketbox.http.authentication;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 

This class is a representation of the state of a previous javax.servlet.http.HttpServletRequest instance.

Author(s):
Pedro Silva
 
 public class SavedRequest {
 
     private List<Cookiecookies = new ArrayList<Cookie>();
     private Map<StringStringheaders = new HashMap<StringString>();
     private Map<StringString[]> parameters = new HashMap<StringString[]>();
     private String method;
     private String queryString;
     private String requestURI;
     private String scheme;
     private String contextPath;

    

Create a new instance copying the state from the request passed as argument.

 
     public SavedRequest(HttpServletRequest request) {
         copyCookies(request);
         copyHeaders(request);
         copyParameters(request);
 
         // copy general properties from the original request
         this. = request.getMethod();
         this. = request.getQueryString();
         this. = request.getRequestURI();
         this. = request.getScheme();
         this. = request.getContextPath();
     }

    

Returns the parameters copied from the original request.

 
     public Map<StringString[]> getParameters() {
         return this.;
     }

    

Returns the headers copied from the original request.

 
     public Map<StringStringgetHeaders() {
         return this.;
     }

    

Returns the cookies copied from the original request.

 
     public List<CookiegetCookies() {
         return this.;
     }

    

Returns the original HTTP method used by the original request.

    public String getMethod() {
        return ;
    }

    

Returns the querystring used by the original request.

    public String getQueryString() {
        return ;
    }

    

Returns the requestURI used by the original request.

    public String getRequestURI() {
        return ;
    }

    

Returns the original scheme used by the original request.

    public String getScheme() {
        return ;
    }

    

Returns the original context path used by the original request.

    public String getContextPath() {
        return ;
    }

    

Copy the parameters from the original javax.servlet.http.HttpServletRequest.

    private void copyParameters(HttpServletRequest request) {
        Set<Entry<StringString[]>> parametersEntries = request.getParameterMap().entrySet();
        for (Entry<StringString[]> parameter : parametersEntries) {
            this.getParameters().put(parameter.getKey(), (String[]) parameter.getValue());
        }
    }

    

Copy the headers from the original javax.servlet.http.HttpServletRequest.

    private void copyHeaders(HttpServletRequest request) {
        Enumeration<StringheaderNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String headerName = (StringheaderNames.nextElement();
            String headerValue = request.getHeader(headerName);
            this.getHeaders().put(headerNameheaderValue);
        }
    }

    

Copy the cookies from the original javax.servlet.http.HttpServletRequest.

    private void copyCookies(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        if (cookies == null) {
            return;
        }
        for (Cookie cookie : cookies) {
            this.getCookies().add(cookie);
        }
    }
New to GrepCode? Check out our FAQ X