MCPcopy Index your code
hub / github.com/apache/tomcat / ServletRequestWrapper

Class ServletRequestWrapper

java/jakarta/servlet/ServletRequestWrapper.java:36–489  ·  view source on GitHub ↗

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.Servlet

Source from the content-addressed store, hash-verified

34 * @since Servlet 2.3
35 */
36public class ServletRequestWrapper implements ServletRequest {
37 private static final String LSTRING_FILE = "jakarta.servlet.LocalStrings";
38 private static final ResourceBundle lStrings = ResourceBundle.getBundle(LSTRING_FILE);
39
40 private ServletRequest request;
41
42 /**
43 * Creates a ServletRequest adaptor wrapping the given request object.
44 *
45 * @param request The request to wrap
46 *
47 * @throws IllegalArgumentException if the request is null
48 */
49 public ServletRequestWrapper(ServletRequest request) {
50 if (request == null) {
51 throw new IllegalArgumentException(lStrings.getString("wrapper.nullRequest"));
52 }
53 this.request = request;
54 }
55
56 /**
57 * Get the wrapped request.
58 *
59 * @return the wrapped request object
60 */
61 public ServletRequest getRequest() {
62 return this.request;
63 }
64
65 /**
66 * Sets the request object being wrapped.
67 *
68 * @param request The new wrapped request.
69 *
70 * @throws IllegalArgumentException if the request is null.
71 */
72 public void setRequest(ServletRequest request) {
73 if (request == null) {
74 throw new IllegalArgumentException(lStrings.getString("wrapper.nullRequest"));
75 }
76 this.request = request;
77 }
78
79 /**
80 * The default behavior of this method is to call getAttribute(String name) on the wrapped request object.
81 */
82 @Override
83 public Object getAttribute(String name) {
84 return this.request.getAttribute(name);
85 }
86
87 /**
88 * The default behavior of this method is to return getAttributeNames() on the wrapped request object.
89 */
90 @Override
91 public Enumeration<String> getAttributeNames() {
92 return this.request.getAttributeNames();
93 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected