JAL_1426 JAL-3066 update Apache James mime parser and fix deprecation warnings with...
authorJim Procter <jprocter@issues.jalview.org>
Fri, 6 Sep 2019 16:04:13 +0000 (17:04 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 6 Sep 2019 16:04:13 +0000 (17:04 +0100)
j11lib/apache-mime4j-core-0.8.3.jar [new file with mode: 0644]
j11lib/apache-mime4j-dom-0.8.3.jar [new file with mode: 0644]
j8lib/apache-mime4j-core-0.8.3.jar [new file with mode: 0644]
j8lib/apache-mime4j-dom-0.8.3.jar [new file with mode: 0644]
src/jalview/ws/io/mime/JalviewMimeContentHandler.java
src/jalview/ws/rest/HttpResultSet.java

diff --git a/j11lib/apache-mime4j-core-0.8.3.jar b/j11lib/apache-mime4j-core-0.8.3.jar
new file mode 100644 (file)
index 0000000..448cf92
Binary files /dev/null and b/j11lib/apache-mime4j-core-0.8.3.jar differ
diff --git a/j11lib/apache-mime4j-dom-0.8.3.jar b/j11lib/apache-mime4j-dom-0.8.3.jar
new file mode 100644 (file)
index 0000000..938c215
Binary files /dev/null and b/j11lib/apache-mime4j-dom-0.8.3.jar differ
diff --git a/j8lib/apache-mime4j-core-0.8.3.jar b/j8lib/apache-mime4j-core-0.8.3.jar
new file mode 100644 (file)
index 0000000..448cf92
Binary files /dev/null and b/j8lib/apache-mime4j-core-0.8.3.jar differ
diff --git a/j8lib/apache-mime4j-dom-0.8.3.jar b/j8lib/apache-mime4j-dom-0.8.3.jar
new file mode 100644 (file)
index 0000000..938c215
Binary files /dev/null and b/j8lib/apache-mime4j-dom-0.8.3.jar differ
index 66569af..7d1b0f5 100644 (file)
@@ -29,9 +29,9 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.descriptor.BodyDescriptor;
 import org.apache.james.mime4j.parser.ContentHandler;
-import org.apache.james.mime4j.parser.Field;
+import org.apache.james.mime4j.stream.BodyDescriptor;
+import org.apache.james.mime4j.stream.Field;
 
 /**
  * ContentHandler for parsing mime encoded messages into Jalview objects. TODO:
@@ -71,7 +71,7 @@ public class JalviewMimeContentHandler implements ContentHandler
   /**
    * sources for data to be parsed
    */
-  List<DataProvider> dataItems = new ArrayList<DataProvider>();
+  List<DataProvider> dataItems = new ArrayList<>();
 
   @Override
   public void body(BodyDescriptor arg0, InputStream arg1)
@@ -176,5 +176,4 @@ public class JalviewMimeContentHandler implements ContentHandler
     // TODO Auto-generated method stub
     return null;
   }
-
 }
index 5bfe3b5..8414da5 100644 (file)
@@ -40,9 +40,9 @@ import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpRequestBase;
 import org.apache.http.entity.mime.MultipartEntity;
+import org.apache.http.util.EntityUtils;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.parser.MimeStreamParser;
-
 /**
  * data source instantiated from the response of an httpclient request.
  * 
@@ -116,23 +116,22 @@ public class HttpResultSet extends FileParse implements AutoCloseable
     }
     jalview.io.packed.JalviewDataset ds = restJob.newJalviewDataset();
     // Decide how we deal with content.
-    if (en instanceof MultipartEntity)
+    // TODO : verify we are detecting a multipart response correctly
+    if (en.getContentType().getValue().startsWith("multipart/form-data"))
     {
       // Multipart messages should be properly typed, so we parse them as we go.
-      MultipartEntity mpe = (MultipartEntity) en;
-      // multipart
       JalviewMimeContentHandler handler = new JalviewMimeContentHandler(ds);
       MimeStreamParser parser = new MimeStreamParser();
       parser.setContentHandler(handler);
       try
       {
-        parser.parse(mpe.getContent());
+        parser.parse(en.getContent());
       } catch (MimeException me)
       {
         error = true;
         errormessage = "Couldn't parse message from web service.";
         Cache.log.warn("Failed to parse MIME multipart content", me);
-        en.consumeContent();
+        EntityUtils.consume(en);
       }
       return new ParsePackedSet().getAlignment(ds,
               handler.getJalviewDataProviders());
@@ -186,7 +185,7 @@ public class HttpResultSet extends FileParse implements AutoCloseable
       {
         Cache.log.error("Can't handle encoding '" + enc
                 + "' for response from webservice.", e);
-        en.consumeContent();
+        EntityUtils.consume(en);
         error = true;
         errormessage = "Can't handle encoding for response from webservice";
         return;