You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/10/14 22:12:26 UTC

svn commit: r1183482 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src: main/java/org/apache/axiom/attachments/ test/java/org/apache/axiom/attachments/

Author: veithen
Date: Fri Oct 14 20:12:26 2011
New Revision: 1183482

URL: http://svn.apache.org/viewvc?rev=1183482&view=rev
Log:
Use a simple List instead of a Hashtable to store MIME part headers. A typical MIME part has 3 headers, so that a List may actually be more efficient than a Hashtable, especially if we normalize keys to lower case. This also solves AXIOM-389 because String#equalsIgnoreCase is not locale aware (in contrast to String#toLowerCase).

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Header.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java

Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Header.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Header.java?rev=1183482&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Header.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Header.java Fri Oct 14 20:12:26 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.attachments;
+
+final class Header {
+    private final String name;
+    private final String value;
+
+    /**
+     * Constructor.
+     * 
+     * @param name
+     *            the name of the header
+     * @param value
+     *            the value of the header
+     */
+    public Header(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    /**
+     * Get the name of this header.
+     * 
+     * @return the name of this header
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Get the value of this header.
+     * 
+     * @return the value of this header
+     */
+    public String getValue() {
+        return value;
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Header.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java?rev=1183482&r1=1183481&r2=1183482&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/MIMEMessage.java Fri Oct 14 20:12:26 2011
@@ -20,14 +20,14 @@ package org.apache.axiom.attachments;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Hashtable;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import javax.activation.DataHandler;
-import javax.mail.Header;
 import javax.mail.internet.ContentType;
 import javax.mail.internet.ParseException;
 
@@ -344,7 +344,7 @@ class MIMEMessage extends AttachmentsImp
         boolean isSOAPPart = (partIndex == 0);
 
         try {
-            Hashtable headers = readHeaders();
+            List headers = readHeaders();
             
             partIndex++;
             currentPart = new PartImpl(this, isSOAPPart, headers, parser);
@@ -368,14 +368,14 @@ class MIMEMessage extends AttachmentsImp
         return contentLength;
     }
     
-    private Hashtable readHeaders() throws IOException, MimeException {
+    private List readHeaders() throws IOException, MimeException {
         if(log.isDebugEnabled()){
-            log.debug("initHeaders");
+            log.debug("readHeaders");
         }
         
         checkParserState(parser.next(), EntityState.T_START_HEADER);
         
-        Hashtable headers = new Hashtable();
+        List headers = new ArrayList();
         while (parser.next() == EntityState.T_FIELD) {
             Field field = parser.getField();
             String name = field.getName();
@@ -384,11 +384,7 @@ class MIMEMessage extends AttachmentsImp
             if (log.isDebugEnabled()){
                 log.debug("addHeader: (" + name + ") value=(" + value +")");
             }
-            Header headerObj = new Header(name, value);
-            
-            // Use the lower case name as the key
-            String key = name.toLowerCase();
-            headers.put(key, headerObj);
+            headers.add(new Header(name, value));
         }
         
         checkParserState(parser.next(), EntityState.T_BODY);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java?rev=1183482&r1=1183481&r2=1183482&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/PartImpl.java Fri Oct 14 20:12:26 2011
@@ -29,14 +29,13 @@ import org.apache.james.mime4j.stream.Mi
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
-import javax.mail.Header;
 import javax.mail.MessagingException;
 import javax.mail.internet.HeaderTokenizer;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.Hashtable;
+import java.util.List;
 
 /**
  * Actual implementation of the {@link Part} interface.
@@ -70,9 +69,7 @@ final class PartImpl implements Part {
     private final MIMEMessage message;
     private final boolean isSOAPPart;
     
-    // Key is the lower-case name.
-    // Value is a javax.mail.Header object
-    private Hashtable headers;
+    private List/*<Header>*/ headers;
     
     private int state = STATE_UNREAD;
     
@@ -94,21 +91,23 @@ final class PartImpl implements Part {
      * @see org.apache.axiom.attachments.ContentStoreFactory
      * @param headers
      */
-    PartImpl(MIMEMessage message, boolean isSOAPPart, Hashtable in, MimeTokenStream parser) {
+    PartImpl(MIMEMessage message, boolean isSOAPPart, List headers, MimeTokenStream parser) {
         this.message = message;
         this.isSOAPPart = isSOAPPart;
-        headers = in;
-        if (headers == null) {
-            headers = new Hashtable();
-        }
+        this.headers = headers;
         this.parser = parser;
         this.dataHandler = new PartDataHandler(this);
     }
     
     public String getHeader(String name) {
-        String key = name.toLowerCase();
-        Header header = (Header) headers.get(key);
-        String value = header == null ? null : header.getValue();
+        String value = null;
+        for (int i=0, l=headers.size(); i<l; i++) {
+            Header header = (Header)headers.get(i);
+            if (header.getName().equalsIgnoreCase(name)) {
+                value = header.getValue();
+                break;
+            }
+        }
         if(log.isDebugEnabled()){
             log.debug("getHeader name=(" + name + ") value=(" + value +")");
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java?rev=1183482&r1=1183481&r2=1183482&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java Fri Oct 14 20:12:26 2011
@@ -653,7 +653,7 @@ public class AttachmentsTest extends Abs
     }
 
     // Regression test for AXIOM-389
-    public void _testTurkishLocale1() throws Exception {
+    public void testTurkishLocale1() throws Exception {
         testTurkishLocale("Content-ID");
     }