From: Jim Procter Date: Fri, 6 Sep 2019 16:04:13 +0000 (+0100) Subject: JAL_1426 JAL-3066 update Apache James mime parser and fix deprecation warnings with... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=80238b0ded8d29f9f50399c51bc550bc1df9c426;p=jalview.git JAL_1426 JAL-3066 update Apache James mime parser and fix deprecation warnings with HttpMultiPartEntity
 --- diff --git a/j11lib/apache-mime4j-core-0.8.3.jar b/j11lib/apache-mime4j-core-0.8.3.jar new file mode 100644 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 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 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 index 0000000..938c215 Binary files /dev/null and b/j8lib/apache-mime4j-dom-0.8.3.jar differ diff --git a/src/jalview/ws/io/mime/JalviewMimeContentHandler.java b/src/jalview/ws/io/mime/JalviewMimeContentHandler.java index 66569af..7d1b0f5 100644 --- a/src/jalview/ws/io/mime/JalviewMimeContentHandler.java +++ b/src/jalview/ws/io/mime/JalviewMimeContentHandler.java @@ -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 dataItems = new ArrayList(); + List 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; } - } diff --git a/src/jalview/ws/rest/HttpResultSet.java b/src/jalview/ws/rest/HttpResultSet.java index 5bfe3b5..8414da5 100644 --- a/src/jalview/ws/rest/HttpResultSet.java +++ b/src/jalview/ws/rest/HttpResultSet.java @@ -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;