/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 jakarta.servlet;
/** * 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. * * @see jakarta.servlet.ServletRequest * * @since Servlet 2.3
*/ publicclass ServletRequestWrapper implements ServletRequest { privatestaticfinal String LSTRING_FILE = "jakarta.servlet.LocalStrings"; privatestaticfinal ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE);
private ServletRequest request;
/** * Creates a ServletRequest adaptor wrapping the given request object. * * @param request The request to wrap * * @throws IllegalArgumentException if the request is null
*/ public ServletRequestWrapper(ServletRequest request) { if (request == null) { thrownew IllegalArgumentException(lStrings.getString("wrapper.nullRequest"));
} this.request = request;
}
/** * Get the wrapped request. * * @return the wrapped request object
*/ public ServletRequest getRequest() { returnthis.request;
}
/** * Sets the request object being wrapped. * * @param request The new wrapped request. * * @throws IllegalArgumentException if the request is null.
*/ publicvoid setRequest(ServletRequest request) { if (request == null) { thrownew IllegalArgumentException(lStrings.getString("wrapper.nullRequest"));
} this.request = request;
}
/** * The default behavior of this method is to call getAttribute(String name) on the wrapped request object.
*/
@Override public Object getAttribute(String name) { returnthis.request.getAttribute(name);
}
/** * The default behavior of this method is to return getAttributeNames() on the wrapped request object.
*/
@Override public Enumeration<String> getAttributeNames() { returnthis.request.getAttributeNames();
}
/** * The default behavior of this method is to return getCharacterEncoding() on the wrapped request object.
*/
@Override public String getCharacterEncoding() { returnthis.request.getCharacterEncoding();
}
/** * The default behavior of this method is to set the character encoding on the wrapped request object.
*/
@Override publicvoid setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException { this.request.setCharacterEncoding(enc);
}
/** * The default behavior of this method is to return getContentLength() on the wrapped request object.
*/
@Override publicint getContentLength() { returnthis.request.getContentLength();
}
/** * The default behavior of this method is to return getContentLengthLong() on the wrapped request object. * * @since Servlet 3.1
*/
@Override publiclong getContentLengthLong() { returnthis.request.getContentLengthLong();
}
/** * The default behavior of this method is to return getContentType() on the wrapped request object.
*/
@Override public String getContentType() { returnthis.request.getContentType();
}
/** * The default behavior of this method is to return getInputStream() on the wrapped request object.
*/
@Override public ServletInputStream getInputStream() throws IOException { returnthis.request.getInputStream();
}
/** * The default behavior of this method is to return getParameter(String name) on the wrapped request object.
*/
@Override public String getParameter(String name) { returnthis.request.getParameter(name);
}
/** * The default behavior of this method is to return getParameterMap() on the wrapped request object.
*/
@Override public Map<String,String[]> getParameterMap() { returnthis.request.getParameterMap();
}
/** * The default behavior of this method is to return getParameterNames() on the wrapped request object.
*/
@Override public Enumeration<String> getParameterNames() { returnthis.request.getParameterNames();
}
/** * The default behavior of this method is to return getParameterValues(String name) on the wrapped request object.
*/
@Override public String[] getParameterValues(String name) { returnthis.request.getParameterValues(name);
}
/** * The default behavior of this method is to return getProtocol() on the wrapped request object.
*/
@Override public String getProtocol() { returnthis.request.getProtocol();
}
/** * The default behavior of this method is to return getScheme() on the wrapped request object.
*/
@Override public String getScheme() { returnthis.request.getScheme();
}
/** * The default behavior of this method is to return getServerName() on the wrapped request object.
*/
@Override public String getServerName() { returnthis.request.getServerName();
}
/** * The default behavior of this method is to return getServerPort() on the wrapped request object.
*/
@Override publicint getServerPort() { returnthis.request.getServerPort();
}
/** * The default behavior of this method is to return getReader() on the wrapped request object.
*/
@Override public BufferedReader getReader() throws IOException { returnthis.request.getReader();
}
/** * The default behavior of this method is to return getRemoteAddr() on the wrapped request object.
*/
@Override public String getRemoteAddr() { returnthis.request.getRemoteAddr();
}
/** * The default behavior of this method is to return getRemoteHost() on the wrapped request object.
*/
@Override public String getRemoteHost() { returnthis.request.getRemoteHost();
}
/** * The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request * object.
*/
@Override publicvoid setAttribute(String name, Object o) { this.request.setAttribute(name, o);
}
/** * The default behavior of this method is to call removeAttribute(String name) on the wrapped request object.
*/
@Override publicvoid removeAttribute(String name) { this.request.removeAttribute(name);
}
/** * The default behavior of this method is to return getLocale() on the wrapped request object.
*/
@Override public Locale getLocale() { returnthis.request.getLocale();
}
/** * The default behavior of this method is to return getLocales() on the wrapped request object.
*/
@Override public Enumeration<Locale> getLocales() { returnthis.request.getLocales();
}
/** * The default behavior of this method is to return isSecure() on the wrapped request object.
*/
@Override publicboolean isSecure() { returnthis.request.isSecure();
}
/** * The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.
*/
@Override public RequestDispatcher getRequestDispatcher(String path) { returnthis.request.getRequestDispatcher(path);
}
/** * The default behavior of this method is to return getRemotePort() on the wrapped request object. * * @since Servlet 2.4
*/
@Override publicint getRemotePort() { returnthis.request.getRemotePort();
}
/** * The default behavior of this method is to return getLocalName() on the wrapped request object. * * @since Servlet 2.4
*/
@Override public String getLocalName() { returnthis.request.getLocalName();
}
/** * The default behavior of this method is to return getLocalAddr() on the wrapped request object. * * @since Servlet 2.4
*/
@Override public String getLocalAddr() { returnthis.request.getLocalAddr();
}
/** * The default behavior of this method is to return getLocalPort() on the wrapped request object. * * @since Servlet 2.4
*/
@Override publicint getLocalPort() { returnthis.request.getLocalPort();
}
/** * The default behavior of this method is to return getServletContext() on the wrapped request object. * * @since Servlet 3.0
*/
@Override public ServletContext getServletContext() { return request.getServletContext();
}
/** * The default behavior of this method is to return startAsync() on the wrapped request object. * * @throws IllegalStateException If asynchronous processing is not supported for this request or if the request is * already in asynchronous mode * * @since Servlet 3.0
*/
@Override public AsyncContext startAsync() throws IllegalStateException { return request.startAsync();
}
/** * The default behavior of this method is to return startAsync(Runnable) on the wrapped request object. * * @param servletRequest The ServletRequest with which to initialise the asynchronous context * @param servletResponse The ServletResponse with which to initialise the asynchronous context * * @throws IllegalStateException If asynchronous processing is not supported for this request or if the request is * already in asynchronous mode * * @since Servlet 3.0
*/
@Override public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { return request.startAsync(servletRequest, servletResponse);
}
/** * The default behavior of this method is to return isAsyncStarted() on the wrapped request object. * * @since Servlet 3.0
*/
@Override publicboolean isAsyncStarted() { return request.isAsyncStarted();
}
/** * The default behavior of this method is to return isAsyncSupported() on the wrapped request object. * * @since Servlet 3.0
*/
@Override publicboolean isAsyncSupported() { return request.isAsyncSupported();
}
/** * The default behavior of this method is to return getAsyncContext() on the wrapped request object. * * @since Servlet 3.0
*/
@Override public AsyncContext getAsyncContext() { return request.getAsyncContext();
}
/** * TODO SERVLET3 - Add comments * * @param wrapped The request to compare to the wrapped request * * @return <code>true</code> if the request wrapped by this wrapper (or series of wrappers) is the same as the * supplied request, otherwise <code>false</code> * * @since Servlet 3.0
*/ publicboolean isWrapperFor(ServletRequest wrapped) { if (request == wrapped) { returntrue;
} if (request instanceof ServletRequestWrapper) { return ((ServletRequestWrapper) request).isWrapperFor(wrapped);
} returnfalse;
}
/** * TODO SERVLET3 - Add comments * * @param wrappedType The class to compare to the class of the wrapped request * * @return <code>true</code> if the request wrapped by this wrapper (or series of wrappers) is the same type as the * supplied type, otherwise <code>false</code> * * @since Servlet 3.0
*/ publicboolean isWrapperFor(Class<?> wrappedType) { if (wrappedType.isAssignableFrom(request.getClass())) { returntrue;
} if (request instanceof ServletRequestWrapper) { return ((ServletRequestWrapper) request).isWrapperFor(wrappedType);
} returnfalse;
}
/** * The default behavior of this method is to call getDispatcherType() on the wrapped request object. * * @since Servlet 3.0
*/
@Override public DispatcherType getDispatcherType() { returnthis.request.getDispatcherType();
}
/** * Gets the request ID for the wrapped request. * * @return the request ID for the wrapped request * * @since Servlet 6.0
*/
@Override public String getRequestId() { return request.getRequestId();
}
/** * Gets the protocol defined request ID, if any, for the wrapped request. * * @return the protocol defined request ID, if any, for the wrapped request * * @since Servlet 6.0
*/
@Override public String getProtocolRequestId() { return request.getProtocolRequestId();
}
/** * Gets the connection information for the wrapped request. * * @return the connection information for the wrapped request * * @since Servlet 6.0
*/
@Override public ServletConnection getServletConnection() { return request.getServletConnection();
}
}
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.