You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2012/11/13 01:33:25 UTC

svn commit: r1408517 - /tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java

Author: kkolinko
Date: Tue Nov 13 00:33:25 2012
New Revision: 1408517

URL: http://svn.apache.org/viewvc?rev=1408517&view=rev
Log:
For https://issues.apache.org/bugzilla/show_bug.cgi?id=53960
Review of r1402846:
If someone needs the extractUriElements() method, one has to call it explicitly.
So that
a) we do not waste time in 90% of tests where this info is not needed,
b) we do not waste time if the response is not HTML.

Modified:
    tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java

Modified: tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java?rev=1408517&r1=1408516&r2=1408517&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java Tue Nov 13 00:33:25 2012
@@ -93,7 +93,7 @@ public abstract class SimpleHttpClient {
     private String redirectUri;
 
     private String responseBody;
-    private List<String> bodyUriElements = new ArrayList<>();
+    private List<String> bodyUriElements = null;
 
     protected void setPort(int thePort) {
         port = thePort;
@@ -138,6 +138,17 @@ public abstract class SimpleHttpClient {
         return responseBody;
     }
 
+    /**
+     * Return opening tags of HTML elements that were extracted by the
+     * {@link #extractUriElements()} method.
+     *
+     * <p>
+     * Note, that {@link #extractUriElements()} method has to be called
+     * explicitly.
+     *
+     * @return List of HTML tags, accumulated by {@link #extractUriElements()}
+     *         method, or {@code null} if the method has not been called yet.
+     */
     public List<String> getResponseBodyUriElements() {
         return bodyUriElements;
     }
@@ -292,20 +303,29 @@ public abstract class SimpleHttpClient {
             }
         }
         responseBody = builder.toString();
-        extractUriElements(responseBody);
     }
 
-    /*
-     * Scan an html body for useful html uri elements. If any are found,
-     * then accumulate them. Test classes might not use them, but they
-     * are collected anyway.
+    /**
+     * Scan the response body for opening tags of certain HTML elements
+     * (&lt;a&gt;, &lt;form&gt;). If any are found, then accumulate them.
+     *
+     * <p>
+     * Note: This method has the following limitations: a) It assumes that the
+     * response is HTML. b) It searches for lowercase tags only. 
+     *
+     * @see #getResponseBodyUriElements()
      */
-    private void extractUriElements(String body) {
-        if (body.length() > 0) {
+    public void extractUriElements() {
+        bodyUriElements = new ArrayList<>();
+        if (responseBody.length() > 0) {
             int ix = 0;
-            while ((ix = extractUriElement(body, ix, RESOURCE_TAG)) > 0){}
+            while ((ix = extractUriElement(responseBody, ix, RESOURCE_TAG)) > 0){
+                // loop
+            }
             ix = 0;
-            while ((ix = extractUriElement(body, ix, LOGIN_TAG)) > 0){}
+            while ((ix = extractUriElement(responseBody, ix, LOGIN_TAG)) > 0){
+                // loop
+            }
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org