Complex classes like HttpServletRequestWrapper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use HttpServletRequestWrapper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
36 | class HttpServletRequestWrapper extends ServletRequestWrapper implements HttpServletRequestInterface |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * Injects the passed request instance into this servlet request. |
||
41 | * |
||
42 | * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $request The request instance used for initialization |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | 1 | public function injectHttpRequest(HttpServletRequestInterface $request) |
|
50 | |||
51 | /** |
||
52 | * Returns the base modifier which allows for base path generation within rewritten URL environments |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getBaseModifier() |
||
60 | |||
61 | /** |
||
62 | * Returns the application context name (application name prefixed with a slash) for the actual request. |
||
63 | * |
||
64 | * @return string The application context name |
||
65 | */ |
||
66 | public function getContextPath() |
||
70 | |||
71 | /** |
||
72 | * @return \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface |
||
73 | */ |
||
74 | 1 | public function getRequest() |
|
78 | |||
79 | /** |
||
80 | * Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getRequestUri() |
||
88 | |||
89 | /** |
||
90 | * Returns an part instance |
||
91 | * |
||
92 | * @return \AppserverIo\Psr\HttpMessage\PartInterface |
||
93 | */ |
||
94 | public function getHttpPartInstance() |
||
98 | |||
99 | /** |
||
100 | * Returns the URL the client used to make the request. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getRequestUrl() |
||
108 | |||
109 | /** |
||
110 | * Returns the path to the servlet used to handle this request. |
||
111 | * |
||
112 | * @return string The relative path to the servlet |
||
113 | */ |
||
114 | public function getServletPath() |
||
118 | |||
119 | /** |
||
120 | * Return the session identifier proposed by the actual configuration and request state. |
||
121 | * |
||
122 | * @return string The session identifier proposed for this request |
||
123 | */ |
||
124 | public function getProposedSessionId() |
||
128 | |||
129 | /** |
||
130 | * Returns the session for this request. |
||
131 | * |
||
132 | * @param boolean $create TRUE to create a new session, else FALSE |
||
133 | * |
||
134 | * @return \AppserverIo\Psr\Servlet\Http\HttpSessionInterface The session instance |
||
135 | */ |
||
136 | public function getSession($create = false) |
||
140 | |||
141 | /** |
||
142 | * Returns the absolute path info started from the context path. |
||
143 | * |
||
144 | * @return string the absolute path info |
||
145 | */ |
||
146 | public function getPathInfo() |
||
150 | |||
151 | /** |
||
152 | * Returns the server name. |
||
153 | * |
||
154 | * @return string The server name |
||
155 | */ |
||
156 | public function getServerName() |
||
160 | |||
161 | /** |
||
162 | * Returns query string of the actual request. |
||
163 | * |
||
164 | * @return string|null The query string of the actual request |
||
165 | */ |
||
166 | 1 | public function getQueryString() |
|
170 | |||
171 | /** |
||
172 | * Returns header info by given key |
||
173 | * |
||
174 | * @param string $key The header key to get |
||
175 | * |
||
176 | * @return string|null |
||
177 | */ |
||
178 | public function getHeader($key) |
||
182 | |||
183 | /** |
||
184 | * Returns headers data. |
||
185 | * |
||
186 | * @return array |
||
187 | */ |
||
188 | public function getHeaders() |
||
192 | |||
193 | /** |
||
194 | * Returns request method |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getMethod() |
||
202 | |||
203 | /** |
||
204 | * Sets the method to be performed on the resource identified by the |
||
205 | * Request-URI. |
||
206 | * |
||
207 | * While HTTP method names are typically all uppercase characters, HTTP |
||
208 | * method names are case-sensitive and thus implementations SHOULD NOT |
||
209 | * modify the given string. |
||
210 | * |
||
211 | * @param string $method Case-insensitive method |
||
212 | * |
||
213 | * @return void |
||
214 | */ |
||
215 | public function setMethod($method) |
||
219 | |||
220 | /** |
||
221 | * Returns true if the request has a cookie header with the passed |
||
222 | * name, else false. |
||
223 | * |
||
224 | * @param string $cookieName Name of the cookie header to be checked |
||
225 | * |
||
226 | * @return boolean true if the request has the cookie, else false |
||
227 | */ |
||
228 | public function hasCookie($cookieName) |
||
232 | |||
233 | /** |
||
234 | * Returns the value of the cookie with the passed name. |
||
235 | * |
||
236 | * @param string $cookieName The name of the cookie to return |
||
237 | * |
||
238 | * @return \AppserverIo\Psr\HttpMessage\CookieInterface The cookie instance |
||
239 | */ |
||
240 | public function getCookie($cookieName) |
||
244 | |||
245 | /** |
||
246 | * Adds the passed cookie to this request. |
||
247 | * |
||
248 | * @param \AppserverIo\Psr\HttpMessage\CookieInterface $cookie The cookie to add |
||
249 | * |
||
250 | * @return void |
||
251 | */ |
||
252 | public function addCookie(CookieInterface $cookie) |
||
256 | |||
257 | /** |
||
258 | * Adds a header information got from connection. |
||
259 | * |
||
260 | * @param string $name The header name |
||
261 | * @param string $value The headers value |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | public function addHeader($name, $value) |
||
269 | |||
270 | /** |
||
271 | * Adds a part to the parts collection. |
||
272 | * |
||
273 | * @param \AppserverIo\Psr\HttpMessage\PartInterface $part A form part object |
||
274 | * @param string $name A manually defined name |
||
275 | * |
||
276 | * @return void |
||
277 | */ |
||
278 | public function addPart(PartInterface $part, $name = null) |
||
282 | |||
283 | /** |
||
284 | * Returns the body content as string. |
||
285 | * |
||
286 | * @return string The body content |
||
287 | */ |
||
288 | public function getBodyContent() |
||
292 | |||
293 | /** |
||
294 | * Returns the body stream as a resource. |
||
295 | * |
||
296 | * @return resource The body stream |
||
297 | */ |
||
298 | public function getBodyStream() |
||
302 | |||
303 | /** |
||
304 | * Returns the Http request instance. |
||
305 | * |
||
306 | * @return \AppserverIo\Psr\HttpMessage\RequestInterface The Http request instance |
||
307 | */ |
||
308 | public function getHttpRequest() |
||
312 | |||
313 | /** |
||
314 | * Returns an array with all request parameters. |
||
315 | * |
||
316 | * @return array The array with the request parameters |
||
317 | */ |
||
318 | public function getParameterMap() |
||
322 | |||
323 | /** |
||
324 | * Returns the parameter with the passed name if available or null |
||
325 | * if the parameter not exists. |
||
326 | * |
||
327 | * @param string $name The name of the parameter to return |
||
328 | * @param integer $filter The filter to use |
||
329 | * |
||
330 | * @return string|null |
||
331 | */ |
||
332 | public function getParameter($name, $filter = FILTER_SANITIZE_STRING) |
||
336 | |||
337 | /** |
||
338 | * Returns a part object by given name |
||
339 | * |
||
340 | * @param string $name The name of the form part |
||
341 | * |
||
342 | * @return \AppserverIo\Psr\HttpMessage\PartInterface The part instance |
||
343 | */ |
||
344 | public function getPart($name) |
||
348 | |||
349 | /** |
||
350 | * Returns the parts collection as array |
||
351 | * |
||
352 | * @return array A collection of HttpPart objects |
||
353 | */ |
||
354 | public function getParts() |
||
358 | |||
359 | /** |
||
360 | * Return the session identifier included in this request, if any. |
||
361 | * |
||
362 | * @return string The session identifier included in this request |
||
363 | */ |
||
364 | public function getRequestedSessionId() |
||
368 | |||
369 | /** |
||
370 | * Return the session name included in this request, if any. |
||
371 | * |
||
372 | * @return string The session name included in this request |
||
373 | */ |
||
374 | public function getRequestedSessionName() |
||
378 | |||
379 | /** |
||
380 | * Returns the servlet response bound to this request. |
||
381 | * |
||
382 | * @return \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface The response instance |
||
383 | */ |
||
384 | public function getResponse() |
||
388 | |||
389 | /** |
||
390 | * Returns the server variable with the requested name. |
||
391 | * |
||
392 | * @param string $name The name of the server variable to be returned |
||
393 | * |
||
394 | * @return mixed The requested server variable |
||
395 | */ |
||
396 | public function getServerVar($name) |
||
400 | |||
401 | /** |
||
402 | * Returns the array with the server variables. |
||
403 | * |
||
404 | * @return array The array with the server variables |
||
405 | */ |
||
406 | public function getServerVars() |
||
410 | |||
411 | /** |
||
412 | * Returns the request URI. |
||
413 | * |
||
414 | * @return string The request URI |
||
415 | */ |
||
416 | public function getUri() |
||
420 | |||
421 | /** |
||
422 | * Returns the protocol version. |
||
423 | * |
||
424 | * @return string The protocol version |
||
425 | */ |
||
426 | public function getVersion() |
||
430 | |||
431 | /** |
||
432 | * Checks if header exists by given name. |
||
433 | * |
||
434 | * @param string $name The header name to check |
||
435 | * |
||
436 | * @return boolean |
||
437 | */ |
||
438 | public function hasHeader($name) |
||
442 | |||
443 | /** |
||
444 | * Queries whether the request contains a parameter or not. |
||
445 | * |
||
446 | * @param string $name The name of the param we're query for |
||
447 | * |
||
448 | * @return boolean TRUE if the parameter is available, else FALSE |
||
449 | */ |
||
450 | public function hasParameter($name) |
||
454 | |||
455 | /** |
||
456 | * Sets the flag that shows if the request has already been dispatched. |
||
457 | * |
||
458 | * @return boolean TRUE if the request has already been dispatched, else FALSE |
||
459 | */ |
||
460 | public function isDispatched() |
||
464 | |||
465 | /** |
||
466 | * Set Base modifier which allows for base path generation within rewritten URL environments. |
||
467 | * |
||
468 | * @param string $baseModifier The base modifier |
||
469 | * |
||
470 | * @return void |
||
471 | */ |
||
472 | public function setBaseModifier($baseModifier) |
||
476 | |||
477 | /** |
||
478 | * Resets the stream resource pointing to body content. |
||
479 | * |
||
480 | * @param resource $bodyStream The body content stream resource |
||
481 | * |
||
482 | * @return void |
||
483 | */ |
||
484 | public function setBodyStream($bodyStream) |
||
488 | |||
489 | /** |
||
490 | * Sets the application context name (application name prefixed with a slash) for the actual request. |
||
491 | * |
||
492 | * @param string $contextPath The application context name |
||
493 | * |
||
494 | * @return void |
||
495 | */ |
||
496 | public function setContextPath($contextPath) |
||
500 | |||
501 | /** |
||
502 | * Sets the flag to mark the request dispatched. |
||
503 | * |
||
504 | * @param boolean $dispatched TRUE if the request has already been dispatched, else FALSE |
||
505 | * |
||
506 | * @return void |
||
507 | */ |
||
508 | public function setDispatched($dispatched = true) |
||
512 | |||
513 | /** |
||
514 | * Set headers data. |
||
515 | * |
||
516 | * @param array $headers The headers array to set |
||
517 | * |
||
518 | * @return void |
||
519 | */ |
||
520 | public function setHeaders(array $headers) |
||
524 | |||
525 | /** |
||
526 | * Sets an array with all request parameters. |
||
527 | * |
||
528 | * @param array $parameterMap The parameter map |
||
529 | * |
||
530 | * @return void |
||
531 | */ |
||
532 | public function setParameterMap(array $parameterMap) |
||
536 | |||
537 | /** |
||
538 | * Sets the absolute path info started from the context path. |
||
539 | * |
||
540 | * @param string $pathInfo The path info |
||
541 | * |
||
542 | * @return void |
||
543 | */ |
||
544 | public function setPathInfo($pathInfo) |
||
548 | |||
549 | /** |
||
550 | * Set the requested session ID for this request. This is normally called by |
||
551 | * the HTTP Connector, when it parses the request headers. |
||
552 | * |
||
553 | * @param string $requestedSessionId The requested session ID |
||
554 | * |
||
555 | * @return void |
||
556 | */ |
||
557 | public function setRequestedSessionId($requestedSessionId) |
||
561 | |||
562 | /** |
||
563 | * Set the requested session name for this request. |
||
564 | * |
||
565 | * @param string $requestedSessionName The requested session name |
||
566 | * |
||
567 | * @return void |
||
568 | */ |
||
569 | public function setRequestedSessionName($requestedSessionName) |
||
573 | |||
574 | /** |
||
575 | * Sets the path to the servlet used to handle this request. |
||
576 | * |
||
577 | * @param string $servletPath The path to the servlet |
||
578 | * |
||
579 | * @return void |
||
580 | */ |
||
581 | public function setServletPath($servletPath) |
||
585 | |||
586 | /** |
||
587 | * Sets the URI. |
||
588 | * |
||
589 | * @param string $uri The request URI |
||
590 | * |
||
591 | * @return void |
||
592 | */ |
||
593 | public function setUri($uri) |
||
597 | |||
598 | /** |
||
599 | * Set the protocol version. |
||
600 | * |
||
601 | * @param string $version The protocol version |
||
602 | * |
||
603 | * @return void |
||
604 | */ |
||
605 | public function setVersion($version) |
||
609 | } |
||
610 |