Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  *
  *
  * This file incorporates work covered by the following copyright and
  * permission notice:
  *
  * Copyright 2004 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package javax.servlet;
 
 import java.util.Map;

Provides a convenient implementation of the ServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object.

Since:
Servlet 2.3
See also:
ServletRequest
 
 
 public class ServletRequestWrapper implements ServletRequest {
 
     private ServletRequest request;

    
Creates a ServletRequest adaptor wrapping the given request object.

Throws:
java.lang.IllegalArgumentException if the request is null
 
     public ServletRequestWrapper(ServletRequest request) {
         if (request == null) {
             throw new IllegalArgumentException("Request cannot be null");   
         }
         this. = request;
     }


    
Return the wrapped request object.
 
     public ServletRequest getRequest() {
         return this.;
    }


    
Sets the request object being wrapped.

Throws:
java.lang.IllegalArgumentException if the request is null.
    public void setRequest(ServletRequest request) {
        if (request == null) {
            throw new IllegalArgumentException("Request cannot be null");
        }
        this. = request;
    }


    
The default behavior of this method is to call getAttribute(String name) on the wrapped request object.
    public Object getAttribute(String name) {
        return this..getAttribute(name);
    }


    
The default behavior of this method is to return getAttributeNames() on the wrapped request object.
    public Enumeration<StringgetAttributeNames() {
        return this..getAttributeNames();
    }    


    
The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.
    public String getCharacterEncoding() {
        return this..getCharacterEncoding();
    }


    
The default behavior of this method is to set the character encoding on the wrapped request object.
    public void setCharacterEncoding(String enc)
            throws UnsupportedEncodingException {
        this..setCharacterEncoding(enc);
    }


    
The default behavior of this method is to return getContentLength() on the wrapped request object.
    public int getContentLength() {
        return this..getContentLength();
    }


    
The default behavior of this method is to return getContentType() on the wrapped request object.
    public String getContentType() {
        return this..getContentType();
    }


    
The default behavior of this method is to return getInputStream() on the wrapped request object.
    public ServletInputStream getInputStream() throws IOException {
        return this..getInputStream();
    }


    
The default behavior of this method is to return getParameter(String name) on the wrapped request object.
    public String getParameter(String name) {
        return this..getParameter(name);
    }


    
The default behavior of this method is to return getParameterMap() on the wrapped request object.
    public Map<StringString[]> getParameterMap() {
        return this..getParameterMap();
    }


    
The default behavior of this method is to return getParameterNames() on the wrapped request object.
    public Enumeration<StringgetParameterNames() {
        return this..getParameterNames();
    }


    
The default behavior of this method is to return getParameterValues(String name) on the wrapped request object.
    public String[] getParameterValues(String name) {
        return this..getParameterValues(name);
    }


    
The default behavior of this method is to return getProtocol() on the wrapped request object.
    public String getProtocol() {
        return this..getProtocol();
    }


    
The default behavior of this method is to return getScheme() on the wrapped request object.
    public String getScheme() {
        return this..getScheme();
    }


    
The default behavior of this method is to return getServerName() on the wrapped request object.
    public String getServerName() {
        return this..getServerName();
    }


    
The default behavior of this method is to return getServerPort() on the wrapped request object.
    public int getServerPort() {
        return this..getServerPort();
    }


    
The default behavior of this method is to return getReader() on the wrapped request object.
    public BufferedReader getReader() throws IOException {
        return this..getReader();
    }


    
The default behavior of this method is to return getRemoteAddr() on the wrapped request object.
    public String getRemoteAddr() {
        return this..getRemoteAddr();
    }


    
The default behavior of this method is to return getRemoteHost() on the wrapped request object.
    public String getRemoteHost() {
        return this..getRemoteHost();
    }


    
The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.
    public void setAttribute(String nameObject o) {
        this..setAttribute(nameo);
    }


    
The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.
    public void removeAttribute(String name) {
        this..removeAttribute(name);
    }


    
The default behavior of this method is to return getLocale() on the wrapped request object.
    public Locale getLocale() {
        return this..getLocale();
    }


    
The default behavior of this method is to return getLocales() on the wrapped request object.
    public Enumeration<LocalegetLocales() {
        return this..getLocales();
    }


    
The default behavior of this method is to return isSecure() on the wrapped request object.
    public boolean isSecure() {
        return this..isSecure();
    }


    
The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.
        return this..getRequestDispatcher(path);
    }


    
The default behavior of this method is to return getRealPath(String path) on the wrapped request object.

Deprecated:
As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead
    public String getRealPath(String path) {
        return this..getRealPath(path);
    }

    
    
The default behavior of this method is to return getRemotePort() on the wrapped request object.

Since:
Servlet 2.4
    
    public int getRemotePort(){
        return this..getRemotePort();
    }


    
The default behavior of this method is to return getLocalName() on the wrapped request object.

Since:
Servlet 2.4
    public String getLocalName(){
        return this..getLocalName();
    }


    
The default behavior of this method is to return getLocalAddr() on the wrapped request object.

Since:
Servlet 2.4
       
    public String getLocalAddr(){
        return this..getLocalAddr();
    }


    
The default behavior of this method is to return getLocalPort() on the wrapped request object.

Since:
Servlet 2.4
    public int getLocalPort(){
        return this..getLocalPort();
    }


    
Gets the servlet context to which the wrapped servlet request was last dispatched.

Returns:
the servlet context to which the wrapped servlet request was last dispatched
Since:
Servlet 3.0
    public ServletContext getServletContext() {
        return .getServletContext();
    }


    
The default behavior of this method is to invoke ServletRequest.startAsync() on the wrapped request object.

Returns:
the (re)initialized AsyncContext
Throws:
java.lang.IllegalStateException if the request is within the scope of a filter or servlet that does not support asynchronous operations (that is, isAsyncSupported() returns false), or if this method is called again without any asynchronous dispatch (resulting from one of the AsyncContext.dispatch() methods), is called outside the scope of any such dispatch, or is called again within the scope of the same dispatch, or if the response has already been closed
Since:
Servlet 3.0
See also:
ServletRequest.startAsync()
    public AsyncContext startAsync() throws IllegalStateException {
        return .startAsync();
    }
    

    
The default behavior of this method is to invoke ServletRequest.startAsync(javax.servlet.ServletRequest,javax.servlet.ServletResponse) on the wrapped request object.

Parameters:
servletRequest the ServletRequest used to initialize the AsyncContext
servletResponse the ServletResponse used to initialize the AsyncContext
Returns:
the (re)initialized AsyncContext
Throws:
java.lang.IllegalStateException if the request is within the scope of a filter or servlet that does not support asynchronous operations (that is, isAsyncSupported() returns false), or if this method is called again without any asynchronous dispatch (resulting from one of the AsyncContext.dispatch() methods), is called outside the scope of any such dispatch, or is called again within the scope of the same dispatch, or if the response has already been closed
Since:
Servlet 3.0
See also:
ServletRequest.startAsync(javax.servlet.ServletRequest,javax.servlet.ServletResponse)
    public AsyncContext startAsync(ServletRequest servletRequest,
                                   ServletResponse servletResponse)
            throws IllegalStateException {
        return .startAsync(servletRequestservletResponse);
    }


    
Checks if the wrapped request has been put into asynchronous mode.

Returns:
true if this request has been put into asynchronous mode, false otherwise
Since:
Servlet 3.0
See also:
ServletRequest.isAsyncStarted()
    public boolean isAsyncStarted() {
        return .isAsyncStarted();
    }


    
Checks if the wrapped request supports asynchronous operation.

Returns:
true if this request supports asynchronous operation, false otherwise
Since:
Servlet 3.0
See also:
ServletRequest.isAsyncSupported()
    public boolean isAsyncSupported() {
        return .isAsyncSupported();
    }


    
Gets the AsyncContext that was created or reinitialized by the most recent invocation of startAsync() or startAsync(javax.servlet.ServletRequest,javax.servlet.ServletResponse) on the wrapped request.

Returns:
the AsyncContext that was created or reinitialized by the most recent invocation of startAsync() or startAsync(javax.servlet.ServletRequest,javax.servlet.ServletResponse) on the wrapped request
Throws:
java.lang.IllegalStateException if this request has not been put into asynchronous mode, i.e., if neither startAsync() nor startAsync(javax.servlet.ServletRequest,javax.servlet.ServletResponse) has been called
Since:
Servlet 3.0
See also:
ServletRequest.getAsyncContext()
    public AsyncContext getAsyncContext() {
        return .getAsyncContext();
    }


    
Checks (recursively) if this ServletRequestWrapper wraps the given ServletRequest instance.

Parameters:
wrapped the ServletRequest instance to search for
Returns:
true if this ServletRequestWrapper wraps the given ServletRequest instance, false otherwise
Since:
Servlet 3.0
    public boolean isWrapperFor(ServletRequest wrapped) {
        if ( == wrapped) {
            return true;
        } else if ( instanceof ServletRequestWrapper) {
            return ((ServletRequestWrapper).isWrapperFor(wrapped);
        } else {
            return false;
        }
    }


    
Checks (recursively) if this ServletRequestWrapper wraps a ServletRequest of the given class type.

Parameters:
wrappedType the ServletRequest class type to search for
Returns:
true if this ServletRequestWrapper wraps a ServletRequest of the given class type, false otherwise
Throws:
java.lang.IllegalArgumentException if the given class does not implement ServletRequest
Since:
Servlet 3.0
    public boolean isWrapperFor(Class wrappedType) {
        if (!ServletRequest.class.isAssignableFrom(wrappedType)) {
            throw new IllegalArgumentException("Given class " +
                wrappedType.getName() + " not a subinterface of " +
                ServletRequest.class.getName());
        }
        if (wrappedType.isAssignableFrom(.getClass())) {
            return true;
        } else if ( instanceof ServletRequestWrapper) {
            return ((ServletRequestWrapper).isWrapperFor(wrappedType);
        } else {
            return false;
        }
    }


    
Gets the dispatcher type of the wrapped request.

Returns:
the dispatcher type of the wrapped request
Since:
Servlet 3.0
See also:
ServletRequest.getDispatcherType()
    public DispatcherType getDispatcherType() {
        return .getDispatcherType();
    }
New to GrepCode? Check out our FAQ X