Author: markt
Date: Sat Nov  3 20:55:42 2012
New Revision: 1405416

URL: http://svn.apache.org/viewvc?rev=1405416&view=rev
Log:
Move media-type parsing to the new parser and drop the JJTree based parser.

Added:
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java
      - copied, changed from r1405415, 
tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java
      - copied, changed from r1405399, 
tomcat/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java
    
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
      - copied, changed from r1405400, 
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
Removed:
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/AstAttribute.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/AstMediaType.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/AstParameter.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/AstSubType.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/AstType.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/AstValue.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.jjt
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser2.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParserConstants.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParserTokenManager.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParserTreeConstants.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/JJTHttpParserState.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/Node.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/ParseException.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/SimpleCharStream.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/SimpleNode.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/Token.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/TokenMgrError.java
    
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestHttpParser2.java
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/build.xml
    
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/DigestAuthenticator.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/Response.java
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java
    
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1405399-1405400,1405415

Modified: tomcat/tc7.0.x/trunk/build.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/build.xml?rev=1405416&r1=1405415&r2=1405416&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/build.xml (original)
+++ tomcat/tc7.0.x/trunk/build.xml Sat Nov  3 20:55:42 2012
@@ -462,7 +462,6 @@
         <!-- Exclude auto-generated files -->
         <exclude name="java/org/apache/el/parser/ELParser*.java" />
         <exclude name="java/org/apache/el/parser/Node.java" />
-        <exclude 
name="java/org/apache/tomcat/util/http/parser/HttpParser*.java" />
         <exclude name="java/org/apache/**/parser/JJT*ParserState.java" />
         <exclude name="java/org/apache/**/parser/ParseException.java" />
         <exclude name="java/org/apache/**/parser/SimpleCharStream.java" />

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/DigestAuthenticator.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/DigestAuthenticator.java?rev=1405416&r1=1405415&r2=1405416&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/DigestAuthenticator.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/authenticator/DigestAuthenticator.java
 Sat Nov  3 20:55:42 2012
@@ -40,7 +40,7 @@ import org.apache.catalina.util.MD5Encod
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.buf.B2CConverter;
-import org.apache.tomcat.util.http.parser.HttpParser2;
+import org.apache.tomcat.util.http.parser.HttpParser;
 
 
 
@@ -559,7 +559,7 @@ public class DigestAuthenticator extends
 
             Map<String,String> directives;
             try {
-                directives = HttpParser2.parseAuthorizationDigest(
+                directives = HttpParser.parseAuthorizationDigest(
                         new StringReader(authorization));
             } catch (IOException e) {
                 return false;

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java?rev=1405416&r1=1405415&r2=1405416&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Response.java Sat 
Nov  3 20:55:42 2012
@@ -54,7 +54,6 @@ import org.apache.tomcat.util.http.FastH
 import org.apache.tomcat.util.http.MimeHeaders;
 import org.apache.tomcat.util.http.ServerCookie;
 import org.apache.tomcat.util.http.parser.MediaTypeCache;
-import org.apache.tomcat.util.http.parser.ParseException;
 import org.apache.tomcat.util.net.URL;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -804,10 +803,8 @@ public class Response
             return;
         }
 
-        String[] m = null;
-        try {
-             m = MEDIA_TYPE_CACHE.parse(type);
-        } catch (ParseException e) {
+        String[] m = MEDIA_TYPE_CACHE.parse(type);
+        if (m == null) {
             // Invalid - Assume no charset and just pass through whatever
             // the user provided.
             coyoteResponse.setContentTypeNoCharset(type);

Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/Response.java?rev=1405416&r1=1405415&r2=1405416&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/Response.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/Response.java Sat Nov  3 
20:55:42 2012
@@ -23,9 +23,8 @@ import java.util.Locale;
 
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.http.parser.AstMediaType;
 import org.apache.tomcat.util.http.parser.HttpParser;
-import org.apache.tomcat.util.http.parser.ParseException;
+import org.apache.tomcat.util.http.parser.MediaType;
 
 /**
  * Response object.
@@ -435,11 +434,13 @@ public final class Response {
             return;
         }
 
-        AstMediaType m = null;
-        HttpParser hp = new HttpParser(new StringReader(type));
+        MediaType m = null;
         try {
-             m = hp.MediaType();
-        } catch (ParseException e) {
+             m = HttpParser.parseMediaType(new StringReader(type));
+        } catch (IOException e) {
+            // Ignore - null test below handles this
+        }
+        if (m == null) {
             // Invalid - Assume no charset and just pass through whatever
             // the user provided.
             this.contentType = type;

Copied: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java 
(from r1405415, 
tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java)
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java?p2=tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java&p1=tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java&r1=1405415&r2=1405416&rev=1405416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java 
Sat Nov  3 20:55:42 2012
@@ -49,7 +49,8 @@ public class HttpParser {
     private static final Integer FIELD_TYPE_LHEX = Integer.valueOf(3);
     private static final Integer FIELD_TYPE_QUOTED_LHEX = Integer.valueOf(4);
 
-    private static final Map<String,Integer> fieldTypes = new HashMap<>();
+    private static final Map<String,Integer> fieldTypes =
+            new HashMap<String,Integer>();
 
     private static final boolean isToken[] = new boolean[128];
     private static final boolean isHex[] = new boolean[128];
@@ -107,7 +108,7 @@ public class HttpParser {
     public static Map<String,String> parseAuthorizationDigest (
             StringReader input) throws IllegalArgumentException, IOException {
 
-        Map<String,String> result = new HashMap<>();
+        Map<String,String> result = new HashMap<String,String>();
 
         if (skipConstant(input, "Digest") != SkipConstantResult.FOUND) {
             return null;
@@ -190,7 +191,8 @@ public class HttpParser {
             return null;
         }
 
-        LinkedHashMap<String,String> parameters = new LinkedHashMap<>();
+        LinkedHashMap<String,String> parameters =
+                new LinkedHashMap<String,String>();
 
         SkipConstantResult lookForSemiColon = skipConstant(input, ";");
         if (lookForSemiColon == SkipConstantResult.NOT_FOUND) {

Copied: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java 
(from r1405399, 
tomcat/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java)
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java?p2=tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java&p1=tomcat/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java&r1=1405399&r2=1405416&rev=1405416&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaType.java 
Sat Nov  3 20:55:42 2012
@@ -16,21 +16,109 @@
  */
 package org.apache.tomcat.util.http.parser;
 
+import java.util.LinkedHashMap;
+import java.util.Map;
+
 public class MediaType {
 
-    private final String noCharset;
+    private final String type;
+    private final String subtype;
+    private final LinkedHashMap<String,String> parameters;
     private final String charset;
+    private volatile String noCharset;
+    private volatile String withCharset;
+
+    protected MediaType(String type, String subtype,
+            LinkedHashMap<String,String> parameters) {
+        this.type = type;
+        this.subtype = subtype;
+        this.parameters = parameters;
 
-    protected MediaType(String noCharset, String charset) {
-        this.noCharset = noCharset;
-        this.charset = charset;
+        String cs = parameters.get("charset");
+        if (cs != null && cs.length() > 0 &&
+                cs.charAt(0) == '"') {
+            cs = HttpParser.unquote(cs);
+        }
+        this.charset = cs;
     }
 
-    public String toStringNoCharset() {
-        return noCharset;
+    public String getType() {
+        return type;
     }
 
-    public String getCharSet() {
+    public String getSubtype() {
+        return subtype;
+    }
+
+    public String getCharset() {
         return charset;
     }
+
+    public int getParameterCount() {
+        return parameters.size();
+    }
+
+    public String getParameterValue(String parameter) {
+        return parameters.get(parameter);
+    }
+
+    @Override
+    public String toString() {
+        if (withCharset == null) {
+            synchronized (this) {
+                if (withCharset == null) {
+                    StringBuilder result = new StringBuilder();
+                    result.append(type);
+                    result.append('/');
+                    result.append(subtype);
+                    for (Map.Entry<String, String> entry : 
parameters.entrySet()) {
+                        String value = entry.getValue();
+                        if (value == null || value.length() == 0) {
+                            continue;
+                        }
+                        result.append(';');
+                        // Workaround for Adobe Read 9 plug-in on IE bug
+                        // Can be removed after 26 June 2013 (EOL of Reader 9)
+                        // See BZ 53814
+                        result.append(' ');
+                        result.append(entry.getKey());
+                        result.append('=');
+                        result.append(value);
+                    }
+
+                    withCharset = result.toString();
+                }
+            }
+        }
+        return withCharset;
+    }
+
+    public String toStringNoCharset() {
+        if (noCharset == null) {
+            synchronized (this) {
+                if (noCharset == null) {
+                    StringBuilder result = new StringBuilder();
+                    result.append(type);
+                    result.append('/');
+                    result.append(subtype);
+                    for (Map.Entry<String, String> entry : 
parameters.entrySet()) {
+                        if (entry.getKey().equalsIgnoreCase("charset")) {
+                            continue;
+                        }
+                        result.append(';');
+                        // Workaround for Adobe Read 9 plug-in on IE bug
+                        // Can be removed after 26 June 2013 (EOL of Reader 9)
+                        // See BZ 53814
+                        result.append(' ');
+                        result.append(entry.getKey());
+                        result.append('=');
+                        result.append(entry.getValue());
+                    }
+
+                    noCharset = result.toString();
+                }
+            }
+        }
+        return noCharset;
+    }
 }

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java?rev=1405416&r1=1405415&r2=1405416&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java
 Sat Nov  3 20:55:42 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.tomcat.util.http.parser;
 
+import java.io.IOException;
 import java.io.StringReader;
 
 import org.apache.tomcat.util.collections.ConcurrentCache;
@@ -40,21 +41,24 @@ public class MediaTypeCache {
      * @return      The results are provided as a two element String array. The
      *                  first element is the media type less the charset and
      *                  the second element is the charset
-     *
-     * @throws ParseException if the input cannot be parsed
      */
-    public String[] parse(String input) throws ParseException {
+    public String[] parse(String input) {
         String[] result = cache.get(input);
 
         if (result != null) {
             return result;
         }
 
-        HttpParser hp = new HttpParser(new StringReader(input));
-        AstMediaType m = hp.MediaType();
-
-        result = new String[] {m.toStringNoCharset(), m.getCharset()};
-        cache.put(input, result);
+        MediaType m = null;
+        try {
+            m = HttpParser.parseMediaType(new StringReader(input));
+        } catch (IOException e) {
+            // Ignore - return null
+        }
+        if (m != null) {
+            result = new String[] {m.toStringNoCharset(), m.getCharset()};
+            cache.put(input, result);
+        }
 
         return result;
     }

Copied: 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
 (from r1405400, 
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java)
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java?p2=tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java&p1=tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java&r1=1405400&r2=1405416&rev=1405416&view=diff
==============================================================================
--- 
tomcat/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestAuthorizationDigest.java
 Sat Nov  3 20:55:42 2012
@@ -38,7 +38,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
 
         Assert.assertEquals("mthornton", result.get("username"));
         Assert.assertEquals("optrak.com", result.get("realm"));
@@ -69,7 +69,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
 
         Assert.assertEquals("mthornton", result.get("username"));
         Assert.assertEquals("optrak.com", result.get("realm"));
@@ -93,7 +93,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
 
         Assert.assertEquals("mthornton", result.get("username"));
         Assert.assertEquals("auth", result.get("qop"));
@@ -107,7 +107,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
 
         Assert.assertEquals("mthornton", result.get("username"));
         Assert.assertEquals("auth", result.get("qop"));
@@ -120,7 +120,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
 
         Assert.assertEquals("00000001", result.get("nc"));
     }
@@ -131,7 +131,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
         Assert.assertNull(result);
     }
 
@@ -141,7 +141,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
         Assert.assertNull(result);
     }
 
@@ -151,7 +151,7 @@ public class TestAuthorizationDigest {
 
         StringReader input = new StringReader(header);
 
-        Map<String,String> result = 
HttpParser2.parseAuthorizationDigest(input);
+        Map<String,String> result = HttpParser.parseAuthorizationDigest(input);
         Assert.assertNull(result);
     }
 

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java?rev=1405416&r1=1405415&r2=1405416&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java 
Sat Nov  3 20:55:42 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.tomcat.util.http.parser;
 
+import java.io.IOException;
 import java.io.StringReader;
 
 import static org.junit.Assert.assertEquals;
@@ -60,93 +61,90 @@ public class TestMediaType {
 
 
     @Test
-    public void testSimple() throws ParseException {
+    public void testSimple() throws IOException {
         doTest();
     }
 
 
     @Test
-    public void testSimpleWithToken() throws ParseException {
+    public void testSimpleWithToken() throws IOException {
         doTest(PARAM_TOKEN);
     }
 
 
     @Test
-    public void testSimpleWithQuotedString() throws ParseException {
+    public void testSimpleWithQuotedString() throws IOException {
         doTest(PARAM_QUOTED);
     }
 
 
     @Test
-    public void testSimpleWithEmptyQuotedString() throws ParseException {
+    public void testSimpleWithEmptyQuotedString() throws IOException {
         doTest(PARAM_EMPTY_QUOTED);
     }
 
 
     @Test
-    public void testSimpleWithComplesQuotedString() throws ParseException {
+    public void testSimpleWithComplesQuotedString() throws IOException {
         doTest(PARAM_COMPLEX_QUOTED);
     }
 
 
     @Test
-    public void testSimpleWithCharset() throws ParseException {
+    public void testSimpleWithCharset() throws IOException {
         doTest(PARAM_CHARSET);
     }
 
 
     @Test
-    public void testSimpleWithCharsetWhitespaceBefore() throws ParseException {
+    public void testSimpleWithCharsetWhitespaceBefore() throws IOException {
         doTest(PARAM_WS_CHARSET);
     }
 
 
     @Test
-    public void testSimpleWithCharsetWhitespaceAfter() throws ParseException {
+    public void testSimpleWithCharsetWhitespaceAfter() throws IOException {
         doTest(PARAM_CHARSET_WS);
     }
 
 
     @Test
-    public void testSimpleWithCharsetQuoted() throws ParseException {
+    public void testSimpleWithCharsetQuoted() throws IOException {
         doTest(PARAM_CHARSET_QUOTED);
     }
 
 
     @Test
-    public void testSimpleWithAll() throws ParseException {
+    public void testSimpleWithAll() throws IOException {
         doTest(PARAM_COMPLEX_QUOTED, PARAM_EMPTY_QUOTED, PARAM_QUOTED,
                 PARAM_TOKEN, PARAM_CHARSET);
     }
 
 
     @Test
-    public void testCharset() throws ParseException {
+    public void testCharset() throws IOException {
         StringBuilder sb = new StringBuilder();
         sb.append(TYPES);
         sb.append(PARAM_CHARSET);
         sb.append(PARAM_TOKEN);
 
         StringReader sr = new StringReader(sb.toString());
-        HttpParser hp = new HttpParser(sr);
-        AstMediaType m = hp.MediaType();
+        MediaType m = HttpParser.parseMediaType(sr);
 
-        assertEquals(sb.toString().replaceAll(" ", ""), m.toString());
+        assertEquals("foo/bar; charset=UTF-8; a=b", m.toString());
         assertEquals(CHARSET, m.getCharset());
-        assertEquals(TYPES.replaceAll(" ", "") + PARAM_TOKEN,
-                m.toStringNoCharset());
+        assertEquals("foo/bar; a=b", m.toStringNoCharset());
     }
 
 
     @Test
-    public void testCharsetQuoted() throws ParseException {
+    public void testCharsetQuoted() throws IOException {
         StringBuilder sb = new StringBuilder();
         sb.append(TYPES);
         sb.append(PARAM_CHARSET_QUOTED);
 
         StringReader sr = new StringReader(sb.toString());
-        HttpParser hp = new HttpParser(sr);
-        AstMediaType m = hp.MediaType();
+        MediaType m = HttpParser.parseMediaType(sr);
 
         assertEquals(CHARSET_WS, m.getCharset());
         assertEquals(TYPES.replaceAll(" ", ""),
@@ -155,88 +153,59 @@ public class TestMediaType {
 
 
     @Test
-    public void testBug52811() throws ParseException {
+    public void testBug52811() throws IOException {
         String input = "multipart/related;boundary=1_4F50BD36_CDF8C28;" +
                 "Start=\"<31671603.smil>\";" +
                 "Type=\"application/smil;charset=UTF-8\"";
 
         StringReader sr = new StringReader(input);
-        HttpParser hp = new HttpParser(sr);
-        AstMediaType m = hp.MediaType();
-
-        assertTrue(m.children.length == 5);
+        MediaType m = HttpParser.parseMediaType(sr);
 
         // Check the types
-        assertTrue(m.children[0] instanceof AstType);
-        assertTrue(m.children[1] instanceof AstSubType);
-        assertEquals("multipart", m.children[0].toString());
-        assertEquals("related", m.children[1].toString());
+        assertEquals("multipart", m.getType());
+        assertEquals("related", m.getSubtype());
 
         // Check the parameters
-        AstParameter p = (AstParameter) m.children[2];
-        assertTrue(p.children.length == 2);
-        assertTrue(p.children[0] instanceof AstAttribute);
-        assertTrue(p.children[1] instanceof AstValue);
-        assertEquals("boundary", p.children[0].toString());
-        assertEquals("1_4F50BD36_CDF8C28", p.children[1].toString());
-
-        p = (AstParameter) m.children[3];
-        assertTrue(p.children.length == 2);
-        assertTrue(p.children[0] instanceof AstAttribute);
-        assertTrue(p.children[1] instanceof AstValue);
-        assertEquals("Start", p.children[0].toString());
-        assertEquals("\"<31671603.smil>\"", p.children[1].toString());
-
-        p = (AstParameter) m.children[4];
-        assertTrue(p.children.length == 2);
-        assertTrue(p.children[0] instanceof AstAttribute);
-        assertTrue(p.children[1] instanceof AstValue);
-        assertEquals("Type", p.children[0].toString());
+        assertTrue(m.getParameterCount() == 3);
+
+        assertEquals("1_4F50BD36_CDF8C28", m.getParameterValue("boundary"));
+        assertEquals("\"<31671603.smil>\"", m.getParameterValue("Start"));
         assertEquals("\"application/smil;charset=UTF-8\"",
-                p.children[1].toString());
+                m.getParameterValue("Type"));
 
-        assertEquals(input, m.toString());
-        assertEquals(input, m.toStringNoCharset());
+        String expected = "multipart/related; boundary=1_4F50BD36_CDF8C28; " +
+                "Start=\"<31671603.smil>\"; " +
+                "Type=\"application/smil;charset=UTF-8\"";
+        assertEquals(expected, m.toString());
+        assertEquals(expected, m.toStringNoCharset());
         assertNull(m.getCharset());
     }
 
 
     @Test
-    public void testBug53353() throws ParseException {
+    public void testBug53353() throws IOException {
         String input = "text/html; UTF-8;charset=UTF-8";
 
         StringReader sr = new StringReader(input);
-        HttpParser hp = new HttpParser(sr);
-        AstMediaType m = hp.MediaType();
-
-        assertTrue(m.children.length == 4);
+        MediaType m = HttpParser.parseMediaType(sr);
 
         // Check the types
-        assertTrue(m.children[0] instanceof AstType);
-        assertTrue(m.children[1] instanceof AstSubType);
-        assertEquals("text", m.children[0].toString());
-        assertEquals("html", m.children[1].toString());
+        assertEquals("text", m.getType());
+        assertEquals("html", m.getSubtype());
 
         // Check the parameters
-        AstParameter p = (AstParameter) m.children[2];
-        assertTrue(p.children.length == 1);
-        assertTrue(p.children[0] instanceof AstAttribute);
-        assertEquals("UTF-8", p.children[0].toString());
-
-        p = (AstParameter) m.children[3];
-        assertTrue(p.children.length == 2);
-        assertTrue(p.children[0] instanceof AstAttribute);
-        assertTrue(p.children[1] instanceof AstValue);
-        assertEquals("charset", p.children[0].toString());
-        assertEquals("UTF-8", p.children[1].toString());
+        assertTrue(m.getParameterCount() == 2);
+
+        assertEquals("", m.getParameterValue("UTF-8"));
+        assertEquals("UTF-8", m.getCharset());
 
         // Note: Invalid input is filtered out
-        assertEquals("text/html;charset=UTF-8", m.toString());
+        assertEquals("text/html; charset=UTF-8", m.toString());
         assertEquals("UTF-8", m.getCharset());
     }
 
 
-    private void doTest(Parameter... parameters) throws ParseException {
+    private void doTest(Parameter... parameters) throws IOException {
         StringBuilder sb = new StringBuilder();
         sb.append(TYPES);
         for (Parameter p : parameters) {
@@ -244,27 +213,19 @@ public class TestMediaType {
         }
 
         StringReader sr = new StringReader(sb.toString());
-        HttpParser hp = new HttpParser(sr);
-        AstMediaType m = hp.MediaType();
+        MediaType m = HttpParser.parseMediaType(sr);
 
-        // Check all expected children are present
-        assertTrue(m.children.length == 2 + parameters.length);
+        // Check all expected parameters are present
+        assertTrue(m.getParameterCount() == parameters.length);
 
         // Check the types
-        assertTrue(m.children[0] instanceof AstType);
-        assertTrue(m.children[1] instanceof AstSubType);
-        assertEquals(TYPE.trim(), m.children[0].toString());
-        assertEquals(SUBTYPE.trim(), m.children[1].toString());
+        assertEquals(TYPE.trim(), m.getType());
+        assertEquals(SUBTYPE.trim(), m.getSubtype());
 
         // Check the parameters
         for (int i = 0; i <  parameters.length; i++) {
-            assertTrue(m.children[i + 2] instanceof AstParameter);
-            AstParameter p = (AstParameter) m.children[i + 2];
-            assertTrue(p.children.length == 2);
-            assertTrue(p.children[0] instanceof AstAttribute);
-            assertTrue(p.children[1] instanceof AstValue);
-            assertEquals(parameters[i].getName().trim(), 
p.children[0].toString());
-            assertEquals(parameters[i].getValue().trim(), 
p.children[1].toString());
+            assertEquals(parameters[i].getValue().trim(),
+                    m.getParameterValue(parameters[i].getName().trim()));
         }
     }
 

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1405416&r1=1405415&r2=1405416&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sat Nov  3 20:55:42 2012
@@ -92,6 +92,14 @@
         multiple issues that resulted in incorrect ordering or failure to find
         a correct, valid order. (markt)
       </fix>
+      <update>
+        The HTTP header parser added to address <bug>52811</bug> has been
+        removed and replaced with the light-weight HTTP header parser created 
to
+        address <bug>54060</bug>. The new parser includes a work-around has for
+        a bug in the Adobe Acrobat Reader 9.x plug-in for Microsoft Internet
+        Explorer that was identified when the old parser was introduced
+        (<bug>53814</bug>).  
+      </update>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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

Reply via email to