This is an automated email from the ASF dual-hosted git repository.

veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git


The following commit(s) were added to refs/heads/master by this push:
     new 36ad2bb32 [AXIOM-506] Update the code that ensures blobs are fetched
36ad2bb32 is described below

commit 36ad2bb327554168fbb5f09dc81ccf1204a8ef64
Author: Andreas Veithen <andreas.veit...@gmail.com>
AuthorDate: Sun Nov 13 10:09:55 2022 +0000

    [AXIOM-506] Update the code that ensures blobs are fetched
---
 .../java/org/apache/axiom/om/OMCloneOptions.java   | 25 +++++++++++-----------
 .../java/org/apache/axiom/om/util/CopyUtils.java   |  4 ++--
 .../org/apache/axiom/om/impl/intf/TextContent.java | 15 +++++++------
 .../apache/axiom/om/impl/mixin/AxiomTextMixin.java | 10 ++++-----
 .../apache/axiom/ts/om/text/TestCloneBinary.java   |  2 +-
 .../axiom/ts/soap/envelope/CloneTestCase.java      |  2 +-
 6 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/axiom-api/src/main/java/org/apache/axiom/om/OMCloneOptions.java 
b/axiom-api/src/main/java/org/apache/axiom/om/OMCloneOptions.java
index 7241624c4..0da03c8a1 100644
--- a/axiom-api/src/main/java/org/apache/axiom/om/OMCloneOptions.java
+++ b/axiom-api/src/main/java/org/apache/axiom/om/OMCloneOptions.java
@@ -18,42 +18,41 @@
  */
 package org.apache.axiom.om;
 
-import javax.activation.DataHandler;
-
+import org.apache.axiom.blob.Blob;
 import org.apache.axiom.ext.stax.BlobProvider;
 
 public class OMCloneOptions {
-    private boolean fetchDataHandlers;
+    private boolean fetchBlobs;
     private boolean copyOMDataSources;
     private boolean preserveModel;
 
     /**
-     * Determine whether {@link DataHandler} objects should be fetched when 
cloning {@link OMText}
-     * nodes. See {@link #setFetchDataHandlers(boolean)} for more information 
about this option.
+     * Determine whether {@link Blob} objects should be fetched when cloning 
{@link OMText}
+     * nodes. See {@link #setFetchBlobs(boolean)} for more information about 
this option.
      * 
      * @return the current value of this option
      */
-    public boolean isFetchDataHandlers() {
-        return fetchDataHandlers;
+    public boolean isFetchBlobs() {
+        return fetchBlobs;
     }
 
     /**
-     * Specify whether {@link DataHandler} objects should be fetched when 
cloning {@link OMText}
+     * Specify whether {@link Blob} objects should be fetched when cloning 
{@link OMText}
      * nodes. If this option is set to <code>false</code> (default) then an 
{@link OMText} node
      * backed by a {@link BlobProvider} will be cloned by copying the 
reference to that
      * {@link BlobProvider} to the cloned {@link OMText} node. This implies 
that if the
      * original tree was constructed from an XOP encoded stream, then the 
clone may become unusable
      * if that stream is closed. If this option is set to <code>true</code>, 
then
-     * {@link BlobProvider} references will be replaced by {@link DataHandler} 
references. In
+     * {@link BlobProvider} references will be replaced by {@link Blob} 
references. In
      * addition, the necessary actions are taken to ensure that the content of 
these
-     * {@link DataHandler} instances is fetched into memory or temporary 
storage, so that the clones
+     * {@link Blob} instances is fetched into memory or temporary storage, so 
that the clones
      * remain usable even after the underlying stream is closed.
      * 
-     * @param fetchDataHandlers
+     * @param fetchBlobs
      *            the value to set for this option
      */
-    public void setFetchDataHandlers(boolean fetchDataHandlers) {
-        this.fetchDataHandlers = fetchDataHandlers;
+    public void setFetchBlobs(boolean fetchBlobs) {
+        this.fetchBlobs = fetchBlobs;
     }
 
     /**
diff --git a/axiom-compat/src/main/java/org/apache/axiom/om/util/CopyUtils.java 
b/axiom-compat/src/main/java/org/apache/axiom/om/util/CopyUtils.java
index 924cdb9e9..b972e967f 100644
--- a/axiom-compat/src/main/java/org/apache/axiom/om/util/CopyUtils.java
+++ b/axiom-compat/src/main/java/org/apache/axiom/om/util/CopyUtils.java
@@ -55,7 +55,7 @@ public class CopyUtils {
      *             {@link OMInformationItem#clone(OMCloneOptions)} on the 
source
      *             {@link SOAPEnvelope} with the following options enabled:
      *             <ul>
-     *             <li>{@link OMCloneOptions#setFetchDataHandlers(boolean)}
+     *             <li>{@link OMCloneOptions#setFetchBlobs(boolean)}
      *             <li>{@link OMCloneOptions#setPreserveModel(boolean)}
      *             <li>{@link OMCloneOptions#setCopyOMDataSources(boolean)}
      *             </ul>
@@ -65,7 +65,7 @@ public class CopyUtils {
      */
     public static SOAPEnvelope copy(SOAPEnvelope sourceEnv) {
         SOAPCloneOptions options = new SOAPCloneOptions();
-        options.setFetchDataHandlers(true);
+        options.setFetchBlobs(true);
         options.setPreserveModel(true);
         options.setCopyOMDataSources(true);
         return (SOAPEnvelope)sourceEnv.clone(options);
diff --git 
a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java 
b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java
index e572f5e02..7afaf461f 100644
--- 
a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java
+++ 
b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/intf/TextContent.java
@@ -27,10 +27,10 @@ import org.apache.axiom.core.CloneableCharacterData;
 import org.apache.axiom.core.stream.CharacterData;
 import org.apache.axiom.core.stream.CharacterDataSink;
 import org.apache.axiom.ext.stax.BlobProvider;
+import org.apache.axiom.mime.PartBlob;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.util.UIDGenerator;
-import org.apache.axiom.util.activation.DataHandlerUtils;
 import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
 import org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream;
 import org.apache.axiom.util.base64.Base64Utils;
@@ -162,11 +162,14 @@ public final class TextContent implements 
CloneableCharacterData {
     public <T> CharacterData clone(ClonePolicy<T> policy, T options) {
         if (binary
                 && options instanceof OMCloneOptions
-                && ((OMCloneOptions) options).isFetchDataHandlers()) {
-            // Force loading of the reference to the DataHandler and ensure 
that its content is
-            // completely fetched into memory (or temporary storage).
-            // TODO(AXIOM-506): review this
-            DataHandlerUtils.toDataHandler(getBlob()).getDataSource();
+                && ((OMCloneOptions) options).isFetchBlobs()) {
+            // This will fetch the Blob from the BlobProvider if applicable.
+            Blob blob = getBlob();
+            // If the blob refers to a MIME part of an XOP encoded message, 
ensure that the part is
+            // fetched.
+            if (blob instanceof PartBlob) {
+                ((PartBlob) blob).getPart().fetch();
+            }
         }
         return new TextContent(this);
     }
diff --git 
a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/mixin/AxiomTextMixin.java
 
b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/mixin/AxiomTextMixin.java
index ff776a645..ea3255252 100644
--- 
a/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/mixin/AxiomTextMixin.java
+++ 
b/mixins/om-mixins/src/main/java/org/apache/axiom/om/impl/mixin/AxiomTextMixin.java
@@ -18,12 +18,11 @@
  */
 package org.apache.axiom.om.impl.mixin;
 
-import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.blob.Blob;
 import org.apache.axiom.core.CoreModelException;
-import org.apache.axiom.mime.activation.PartDataHandler;
+import org.apache.axiom.mime.PartBlob;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMNamespace;
@@ -32,7 +31,6 @@ import org.apache.axiom.om.impl.common.AxiomSemantics;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.intf.AxiomText;
 import org.apache.axiom.om.impl.intf.TextContent;
-import org.apache.axiom.util.activation.DataHandlerUtils;
 import org.apache.axiom.weaver.annotation.Mixin;
 
 @Mixin
@@ -151,9 +149,9 @@ public abstract class AxiomTextMixin implements AxiomText {
     @Override
     public final void buildWithAttachments() {
         if (isOptimized()) {
-            DataHandler dataHandler = 
DataHandlerUtils.getDataHandler(getBlob());
-            if (dataHandler instanceof PartDataHandler) {
-                ((PartDataHandler) dataHandler).getPart().fetch();
+            Blob blob = getBlob();
+            if (blob instanceof PartBlob) {
+                ((PartBlob) blob).getPart().fetch();
             }
         }
     }
diff --git 
a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/text/TestCloneBinary.java
 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/text/TestCloneBinary.java
index 828c9ea70..2db4e679e 100644
--- 
a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/text/TestCloneBinary.java
+++ 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/text/TestCloneBinary.java
@@ -56,7 +56,7 @@ public class TestCloneBinary extends AxiomTestCase {
                         .getDocumentElement();
         OMText text = (OMText) root.getFirstOMChild();
         OMCloneOptions options = new OMCloneOptions();
-        options.setFetchDataHandlers(fetch);
+        options.setFetchBlobs(fetch);
         OMText clone = (OMText) text.clone(options);
         assertTrue(clone.isBinary());
         assertEquals(fetch, attachmentAccessor.isLoaded());
diff --git 
a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/CloneTestCase.java
 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/CloneTestCase.java
index 4c491b8bc..1df5f22b4 100644
--- 
a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/CloneTestCase.java
+++ 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/envelope/CloneTestCase.java
@@ -46,7 +46,7 @@ public abstract class CloneTestCase extends SOAPTestCase {
     protected void copyAndCheck(SOAPEnvelope sourceEnv) throws Exception {
 
         SOAPCloneOptions options = new SOAPCloneOptions();
-        options.setFetchDataHandlers(true);
+        options.setFetchBlobs(true);
         options.setPreserveModel(true);
         options.setCopyOMDataSources(true);
         SOAPEnvelope targetEnv = (SOAPEnvelope) sourceEnv.clone(options);

Reply via email to