Clover coverage report - Cactus 1.4 for J2EE API 12
Coverage timestamp: Sun Aug 25 2002 18:00:03 BST
file stats: LOC: 586   Methods: 52
NCLOC: 301   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractHttpServletRequestWrapper.java 50% 67.2% 57.7% 62.1%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus.server;
 3   
 import java.io.BufferedReader;
 4   
 import java.io.File;
 5   
 import java.io.IOException;
 6   
 import java.security.Principal;
 7   
 import java.util.Enumeration;
 8   
 import java.util.Locale;
 9   
 import javax.servlet.RequestDispatcher;
 10   
 import javax.servlet.ServletInputStream;
 11   
 import javax.servlet.http.HttpServletRequest;
 12   
 import javax.servlet.http.HttpSession;
 13   
 import javax.servlet.http.Cookie;
 14   
 import org.apache.cactus.ServletURL;
 15   
 import org.apache.commons.logging.LogFactory;
 16   
 import org.apache.commons.logging.Log;
 17   
 
 18   
 /** 
 19   
  * Abstract wrapper around <code>HttpServletRequest</code>. This class provides 
 20   
  * a common implementation of the wrapper for the different servlet API. 
 21   
  * 
 22   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 23   
  * 
 24   
  * @version $Id: AbstractHttpServletRequestWrapper.java,v 1.5 2002/07/22 12:26:04 vmassol Exp $ 
 25   
  */
 26   
 public abstract class AbstractHttpServletRequestWrapper implements HttpServletRequest {
 27   
   /** 
 28   
        * The real HTTP request 
 29   
        */
 30   
   protected HttpServletRequest request;
 31   
   /** 
 32   
        * The URL to simulate 
 33   
        */
 34   
   protected ServletURL url;
 35   
   /** 
 36   
        * Remote IP address to simulate (if any) 
 37   
        * @see #setRemoteIPAddress(String) 
 38   
        */
 39   
   protected String remoteIPAddress;
 40   
   /** 
 41   
        * Remote Host name to simulate (if any) 
 42   
        * @see #setRemoteHostName(String) 
 43   
        */
 44   
   protected String remoteHostName;
 45   
   /** 
 46   
        * The logger 
 47   
        */
 48   
   private static Log LOGGER;
 49   
   /** 
 50   
        * Construct an <code>HttpServletRequest</code> instance that delegates 
 51   
        * it's method calls to the request object passed as parameter and that 
 52   
        * uses the URL passed as parameter to simulate a URL from which the request 
 53   
        * would come from. 
 54   
        * 
 55   
        * @param theRequest the real HTTP request 
 56   
        * @param theURL     the URL to simulate or <code>null</code> if none 
 57   
        */
 58  177
   public AbstractHttpServletRequestWrapper(HttpServletRequest theRequest, ServletURL theURL) {
 59  177
     super();
 60  177
     this.request = theRequest;
 61  177
     this.url = theURL;
 62   
   } 
 63   
   /** 
 64   
        * @return the original request object 
 65   
        */
 66  15
   public HttpServletRequest getOriginalRequest() {
 67  15
     return this.request;
 68   
   } 
 69   
 
 70   
   /** 
 71   
        * Simulates the remote IP address (i.e. the client IP address). 
 72   
        * 
 73   
        * @param theRemoteIPAddress the simulated IP address in string format. 
 74   
        *        Exemple : "127.0.0.1" 
 75   
        */
 76  3
   public void setRemoteIPAddress(String theRemoteIPAddress) {
 77  3
     this.remoteIPAddress = theRemoteIPAddress;
 78   
   } 
 79   
 
 80   
   /** 
 81   
        * Simulates the remote host name(i.e. the client host name). 
 82   
        * 
 83   
        * @param theRemoteHostName the simulated host name in string format. 
 84   
        *        Exemple : "atlantis" 
 85   
        */
 86  3
   public void setRemoteHostName(String theRemoteHostName) {
 87  3
     this.remoteHostName = theRemoteHostName;
 88   
   } 
 89   
 
 90   
   /** 
 91   
        * @return the context path from the simulated URL or the real context path 
 92   
        *         if a simulation URL has not been defined. 
 93   
        */
 94  36
   public String getContextPath() {
 95  36
     String result;
 96  36
     if ((this.url != null) && (this.url.getContextPath() != null)) {
 97  36
       result = this.url.getContextPath();
 98  36
       AbstractHttpServletRequestWrapper.LOGGER.debug("Using simulated context : [" + result + "]");
 99   
     } else {
 100  0
       result = this.request.getContextPath();
 101   
     } 
 102  36
     return result;
 103   
   } 
 104   
 
 105   
   /** 
 106   
        * @return the path info from the simulated URL or the real path info 
 107   
        *         if a simulation URL has not been defined. 
 108   
        */
 109  39
   public String getPathInfo() {
 110  39
     String result;
 111  39
     if (this.url != null) {
 112  39
       result = this.url.getPathInfo();
 113  39
       AbstractHttpServletRequestWrapper.LOGGER.debug("Using simulated PathInfo : [" + result + 
 114   
           "]");
 115   
     } else {
 116  0
       result = this.request.getPathInfo();
 117   
     } 
 118  39
     return result;
 119   
   } 
 120   
 
 121   
   /** 
 122   
        * @return the server name from the simulated URL or the real server name 
 123   
        *         if a simulation URL has not been defined. 
 124   
        */
 125  18
   public String getServerName() {
 126  18
     String result;
 127  18
     if ((this.url != null) && (this.url.getServerName() != null)) {
 128  18
       result = this.url.getHost();
 129  18
       AbstractHttpServletRequestWrapper.LOGGER.debug("Using simulated server name : [" + result + 
 130   
           "]");
 131   
     } else {
 132  0
       result = this.request.getServerName();
 133   
     } 
 134  18
     return result;
 135   
   } 
 136   
 
 137   
   /** 
 138   
        * @return the server port number from the simulated URL or the real server 
 139   
        *         port number if a simulation URL has not been defined. If not 
 140   
        *         port is defined, then port 80 is returned. 
 141   
        */
 142  18
   public int getServerPort() {
 143  18
     int result;
 144  18
     if (this.url != null) {
 145  18
       result = (this.url.getPort() == -1) ? 80 : this.url.getPort();
 146  18
       AbstractHttpServletRequestWrapper.LOGGER.debug("Using simulated server port : [" + result + 
 147   
           "]");
 148   
     } else {
 149  0
       result = this.request.getServerPort();
 150   
     } 
 151  18
     return result;
 152   
   } 
 153   
 
 154   
   /** 
 155   
        * @return the URI from the simulated URL or the real URI 
 156   
        *         if a simulation URL has not been defined. 
 157   
        */
 158  18
   public String getRequestURI() {
 159  18
     String result;
 160  18
     if (this.url != null) {
 161  18
       result = this.getContextPath() + ((this.getServletPath() == null) ? "" : this.getServletPath(
 162   
           )) + ((this.getPathInfo() == null) ? "" : this.getPathInfo());
 163  18
       AbstractHttpServletRequestWrapper.LOGGER.debug("Using simulated request URI : [" + result + 
 164   
           "]");
 165   
     } else {
 166  0
       result = this.request.getRequestURI();
 167   
     } 
 168  18
     return result;
 169   
   } 
 170   
 
 171   
   /** 
 172   
        * @return the servlet path from the simulated URL or the real servlet path 
 173   
        *         if a simulation URL has not been defined. 
 174   
        */
 175  51
   public String getServletPath() {
 176  51
     String result;
 177  51
     if (this.url != null) {
 178  51
       result = this.url.getServletPath();
 179  51
       AbstractHttpServletRequestWrapper.LOGGER.debug("Using simulated servlet path : [" + result + 
 180   
           "]");
 181   
     } else {
 182  0
       result = this.request.getServletPath();
 183   
     } 
 184  51
     return result;
 185   
   } 
 186   
 
 187   
   /** 
 188   
        * @return any extra path information after the servlet name but 
 189   
        *         before the query string, and translates it to a real path. 
 190   
        *         Takes into account the simulated URL (if any). 
 191   
        */
 192  3
   public String getPathTranslated() {
 193  3
     String pathTranslated;
 194  3
     String pathInfo = this.url.getPathInfo();
 195  3
     if (pathInfo != null) {
 196  3
       if (this.request.getRealPath("/") == null) {
 197  0
         pathTranslated = null;
 198   
       } else {
 199  3
         String newPathInfo = (pathInfo.startsWith("/") ? pathInfo.substring(1) : pathInfo);
 200  3
         if (this.request.getRealPath("/").endsWith("/")) {
 201  0
           pathTranslated = this.request.getRealPath("/") + newPathInfo.replace('/', 
 202   
               File.separatorChar);
 203   
         } else {
 204  3
           pathTranslated = this.request.getRealPath("/") + File.separatorChar + 
 205   
               newPathInfo.replace('/', File.separatorChar);
 206   
         } 
 207   
       } 
 208   
     } else {
 209  0
       pathTranslated = this.request.getPathTranslated();
 210   
     } 
 211  3
     return pathTranslated;
 212   
   } 
 213   
 
 214   
   /** 
 215   
        * @return the query string from the simulated URL or the real query 
 216   
        *         string if a simulation URL has not been defined. 
 217   
        */
 218  3
   public String getQueryString() {
 219  3
     String result;
 220  3
     if (this.url != null) {
 221  3
       result = this.url.getQueryString();
 222  3
       AbstractHttpServletRequestWrapper.LOGGER.debug("Using simulated query string : [" + result + 
 223   
           "]");
 224   
     } else {
 225  0
       result = this.request.getQueryString();
 226   
     } 
 227  3
     return result;
 228   
   } 
 229   
 
 230   
   /** 
 231   
        * @param thePath the path to the resource 
 232   
        * @return a wrapped request dispatcher instead of the real one, so that 
 233   
        *         forward() and include() calls will use the wrapped dispatcher 
 234   
        *         passing it the *original* request [this is needed for some 
 235   
        *         servlet engine like Tomcat 3.x which do not support the new 
 236   
        *         mechanism introduced by Servlet 2.3 Filters]. 
 237   
        * @see HttpServletRequest#getRequestDispatcher(String) 
 238   
        */
 239  6
   public RequestDispatcher getRequestDispatcher(String thePath) {
 240  6
     if (thePath == null) {
 241  0
       return ((RequestDispatcher)(null));
 242   
     } 
 243  6
     RequestDispatcher dispatcher = null;
 244  6
     String fullPath;
 245  6
     if (thePath.startsWith("/")) {
 246  3
       fullPath = thePath;
 247   
     } else {
 248  3
       String pI = this.getPathInfo();
 249  3
       if (pI == null) {
 250  3
         fullPath = this.catPath(this.getServletPath(), thePath);
 251   
       } else {
 252  0
         fullPath = this.catPath(this.getServletPath() + pI, thePath);
 253   
       } 
 254  3
       if (fullPath == null) {
 255  0
         return ((RequestDispatcher)(null));
 256   
       } 
 257   
     } 
 258  6
     AbstractHttpServletRequestWrapper.LOGGER.debug("Computed full path : [" + fullPath + "]");
 259  6
     dispatcher = new RequestDispatcherWrapper(this.request.getRequestDispatcher(fullPath));
 260  6
     return dispatcher;
 261   
   } 
 262   
 
 263   
   /** 
 264   
        * Will concatenate 2 paths, normalising it. For example : 
 265   
        * ( /a/b/c + d = /a/b/d, /a/b/c + ../d = /a/d ). Code borrowed from 
 266   
        * Tomcat 3.2.2 ! 
 267   
        * 
 268   
        * @param theLookupPath the first part of the path 
 269   
        * @param thePath the part to add to the lookup path 
 270   
        * @return the concatenated thePath or null if an error occurs 
 271   
        */
 272  3
   private String catPath(String theLookupPath, String thePath) {
 273  3
     int index = theLookupPath.lastIndexOf("/");
 274  3
     theLookupPath = theLookupPath.substring(0, index);
 275  3
     while (thePath.startsWith("../")){
 276  0
       if (theLookupPath.length() > 0) {
 277  0
         index = theLookupPath.lastIndexOf("/");
 278  0
         theLookupPath = theLookupPath.substring(0, index);
 279   
       } else {
 280  0
         return ((String)(null));
 281   
       } 
 282  0
       index = thePath.indexOf("../") + 3;
 283  0
       thePath = thePath.substring(index);
 284   
     } 
 285  3
     return theLookupPath + "/" + thePath;
 286   
   } 
 287   
 
 288   
   /** 
 289   
        * @return the simulated remote IP address if any or the real one. 
 290   
        * 
 291   
        * @see HttpServletRequest#getRemoteAddr() 
 292   
        */
 293  3
   public String getRemoteAddr() {
 294  3
     String remoteIPAddress;
 295  3
     if (this.remoteIPAddress != null) {
 296  3
       remoteIPAddress = this.remoteIPAddress;
 297   
     } else {
 298  0
       remoteIPAddress = this.request.getRemoteAddr();
 299   
     } 
 300  3
     return remoteIPAddress;
 301   
   } 
 302   
 
 303   
   /** 
 304   
        * @return the simulated remote host name if any or the real one. 
 305   
        * 
 306   
        * @see HttpServletRequest#getRemoteHost() 
 307   
        */
 308  3
   public String getRemoteHost() {
 309  3
     String remoteHostName;
 310  3
     if (this.remoteHostName != null) {
 311  3
       remoteHostName = this.remoteHostName;
 312   
     } else {
 313  0
       remoteHostName = this.request.getRemoteHost();
 314   
     } 
 315  3
     return remoteHostName;
 316   
   } 
 317   
 
 318   
   /** 
 319   
        * @see HttpServletRequest#isRequestedSessionIdFromURL() 
 320   
        */
 321  0
   public boolean isRequestedSessionIdFromURL() {
 322  0
     return this.request.isRequestedSessionIdFromURL();
 323   
   } 
 324   
 
 325   
   /** 
 326   
        * @see HttpServletRequest#isRequestedSessionIdFromUrl() 
 327   
        */
 328  0
   public boolean isRequestedSessionIdFromUrl() {
 329  0
     return this.request.isRequestedSessionIdFromURL();
 330   
   } 
 331   
 
 332   
   /** 
 333   
        * @see HttpServletRequest#isUserInRole(String) 
 334   
        */
 335  3
   public boolean isUserInRole(String theRole) {
 336  3
     return this.request.isUserInRole(theRole);
 337   
   } 
 338   
 
 339   
   /** 
 340   
        * @see HttpServletRequest#isRequestedSessionIdValid() 
 341   
        */
 342  0
   public boolean isRequestedSessionIdValid() {
 343  0
     return this.request.isRequestedSessionIdValid();
 344   
   } 
 345   
 
 346   
   /** 
 347   
        * @see HttpServletRequest#isRequestedSessionIdFromCookie() 
 348   
        */
 349  0
   public boolean isRequestedSessionIdFromCookie() {
 350  0
     return this.request.isRequestedSessionIdFromCookie();
 351   
   } 
 352   
 
 353   
   /** 
 354   
        * @see HttpServletRequest#getLocales() 
 355   
        */
 356  0
   public Enumeration getLocales() {
 357  0
     return this.request.getLocales();
 358   
   } 
 359   
 
 360   
   /** 
 361   
        * @see HttpServletRequest#getHeader(String) 
 362   
        */
 363  6
   public String getHeader(String theName) {
 364  6
     return this.request.getHeader(theName);
 365   
   } 
 366   
 
 367   
   /** 
 368   
        * @see HttpServletRequest#getHeaders(String) 
 369   
        */
 370  0
   public Enumeration getHeaders(String theName) {
 371  0
     return this.request.getHeaders(theName);
 372   
   } 
 373   
 
 374   
   /** 
 375   
        * @see HttpServletRequest#getHeaderNames() 
 376   
        */
 377  0
   public Enumeration getHeaderNames() {
 378  0
     return this.request.getHeaderNames();
 379   
   } 
 380   
 
 381   
   /** 
 382   
        * @see HttpServletRequest#getScheme() 
 383   
        */
 384  0
   public String getScheme() {
 385  0
     return this.request.getScheme();
 386   
   } 
 387   
 
 388   
   /** 
 389   
        * @see HttpServletRequest#getAuthType() 
 390   
        */
 391  0
   public String getAuthType() {
 392  0
     return this.request.getAuthType();
 393   
   } 
 394   
 
 395   
   /** 
 396   
        * @see HttpServletRequest#getRealPath(String) 
 397   
        */
 398  3
   public String getRealPath(String thePath) {
 399  3
     return this.request.getRealPath(thePath);
 400   
   } 
 401   
 
 402   
   /** 
 403   
        * @see HttpServletRequest#getSession() 
 404   
        */
 405  0
   public HttpSession getSession() {
 406  0
     return this.request.getSession();
 407   
   } 
 408   
 
 409   
   /** 
 410   
        * @see HttpServletRequest#getSession(boolean) 
 411   
        */
 412  3
   public HttpSession getSession(boolean isCreate) {
 413  3
     return this.request.getSession(isCreate);
 414   
   } 
 415   
 
 416   
   /** 
 417   
        * @see HttpServletRequest#getReader() 
 418   
        */
 419  6
   public BufferedReader getReader() throws IOException {
 420  6
     return this.request.getReader();
 421   
   } 
 422   
 
 423   
   /** 
 424   
        * @see HttpServletRequest#getContentLength() 
 425   
        */
 426  0
   public int getContentLength() {
 427  0
     return this.request.getContentLength();
 428   
   } 
 429   
 
 430   
   /** 
 431   
        * @see HttpServletRequest#getParameterValues(String) 
 432   
        */
 433  3
   public String[] getParameterValues(String theName) {
 434  3
     return this.request.getParameterValues(theName);
 435   
   } 
 436   
 
 437   
   /** 
 438   
        * @see HttpServletRequest#getContentType() 
 439   
        */
 440  6
   public String getContentType() {
 441  6
     return this.request.getContentType();
 442   
   } 
 443   
 
 444   
   /** 
 445   
        * @see HttpServletRequest#getLocale() 
 446   
        */
 447  0
   public Locale getLocale() {
 448  0
     return this.request.getLocale();
 449   
   } 
 450   
 
 451   
   /** 
 452   
        * @see HttpServletRequest#removeAttribute(String) 
 453   
        */
 454  0
   public void removeAttribute(String theName) {
 455  0
     this.request.removeAttribute(theName);
 456   
   } 
 457   
 
 458   
   /** 
 459   
        * @see HttpServletRequest#getParameter(String) 
 460   
        */
 461  18
   public String getParameter(String theName) {
 462  18
     return this.request.getParameter(theName);
 463   
   } 
 464   
 
 465   
   /** 
 466   
        * @see HttpServletRequest#getInputStream() 
 467   
        */
 468  0
   public ServletInputStream getInputStream() throws IOException {
 469  0
     return this.request.getInputStream();
 470   
   } 
 471   
 
 472   
   /** 
 473   
        * @see HttpServletRequest#getUserPrincipal() 
 474   
        */
 475  3
   public Principal getUserPrincipal() {
 476  3
     return this.request.getUserPrincipal();
 477   
   } 
 478   
 
 479   
   /** 
 480   
        * @see HttpServletRequest#isSecure() 
 481   
        */
 482  0
   public boolean isSecure() {
 483  0
     return this.request.isSecure();
 484   
   } 
 485   
 
 486   
   /** 
 487   
        * @see HttpServletRequest#getCharacterEncoding() 
 488   
        */
 489  0
   public String getCharacterEncoding() {
 490  0
     return this.request.getCharacterEncoding();
 491   
   } 
 492   
 
 493   
   /** 
 494   
        * @see HttpServletRequest#getParameterNames() 
 495   
        */
 496  0
   public Enumeration getParameterNames() {
 497  0
     return this.request.getParameterNames();
 498   
   } 
 499   
 
 500   
   /** 
 501   
        * @see HttpServletRequest#getMethod() 
 502   
        */
 503  6
   public String getMethod() {
 504  6
     return this.request.getMethod();
 505   
   } 
 506   
 
 507   
   /** 
 508   
        * @see HttpServletRequest#setAttribute(String, Object) 
 509   
        */
 510  3
   public void setAttribute(String theName, Object theAttribute) {
 511  3
     this.request.setAttribute(theName, theAttribute);
 512   
   } 
 513   
 
 514   
   /** 
 515   
        * @see HttpServletRequest#getAttribute(String) 
 516   
        */
 517  3
   public Object getAttribute(String theName) {
 518  3
     return this.request.getAttribute(theName);
 519   
   } 
 520   
 
 521   
   /** 
 522   
        * @see HttpServletRequest#getIntHeader(String) 
 523   
        */
 524  0
   public int getIntHeader(String theName) {
 525  0
     return this.request.getIntHeader(theName);
 526   
   } 
 527   
 
 528   
   /** 
 529   
        * @see HttpServletRequest#getDateHeader(String) 
 530   
        */
 531  0
   public long getDateHeader(String theName) {
 532  0
     return this.request.getDateHeader(theName);
 533   
   } 
 534   
 
 535   
   /** 
 536   
        * @see HttpServletRequest#getAttributeNames() 
 537   
        */
 538  0
   public Enumeration getAttributeNames() {
 539  0
     return this.request.getAttributeNames();
 540   
   } 
 541   
 
 542   
   /** 
 543   
        * @see HttpServletRequest#getRemoteUser() 
 544   
        */
 545  3
   public String getRemoteUser() {
 546  3
     return this.request.getRemoteUser();
 547   
   } 
 548   
 
 549   
   /** 
 550   
        * @see HttpServletRequest#getRequestedSessionId() 
 551   
        */
 552  0
   public String getRequestedSessionId() {
 553  0
     return this.request.getRequestedSessionId();
 554   
   } 
 555   
 
 556   
   /** 
 557   
        * @see HttpServletRequest#getCookies() 
 558   
        */
 559  9
   public Cookie[] getCookies() {
 560  9
     return this.request.getCookies();
 561   
   } 
 562   
 
 563   
   /** 
 564   
        * @see HttpServletRequest#getProtocol() 
 565   
        */
 566  0
   public String getProtocol() {
 567  0
     return this.request.getProtocol();
 568   
   } 
 569   
 
 570   
   /** 
 571   
    * Abstract wrapper around <code>HttpServletRequest</code>. This class provides 
 572   
    * a common implementation of the wrapper for the different servlet API. 
 573   
    * 
 574   
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 575   
    * 
 576   
    * @version $Id: AbstractHttpServletRequestWrapper.java,v 1.5 2002/07/22 12:26:04 vmassol Exp $ 
 577   
    */
 578   
   static {
 579   
     /** 
 580   
          * The logger 
 581   
          */
 582  3
     AbstractHttpServletRequestWrapper.LOGGER = LogFactory.getLog(
 583   
         AbstractHttpServletRequestWrapper.class);
 584   
   } 
 585   
 
 586   
 }