cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: [CXF-5832] Make the attachments map returned from the JAX-WS properties a live "wrapper" over around the List<Attachment> that CXF uses.
Date Thu, 03 Jul 2014 14:00:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/master eafb1dc17 -> 8394d3a8a


[CXF-5832] Make the attachments map returned from the JAX-WS properties a live "wrapper" over
around the List<Attachment> that CXF uses.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/8394d3a8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/8394d3a8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/8394d3a8

Branch: refs/heads/master
Commit: 8394d3a8a3056156074165005c8479b5cccf1c84
Parents: eafb1dc
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu Jul 3 09:42:52 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Thu Jul 3 09:43:43 2014 -0400

----------------------------------------------------------------------
 .../apache/cxf/attachment/AttachmentUtil.java   | 72 ++++++++++++++++++--
 .../cxf/jaxws/AbstractJAXWSMethodInvoker.java   | 19 ------
 .../jaxws/context/WrappedMessageContext.java    |  5 ++
 3 files changed, 71 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/8394d3a8/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
index dc8a68a..37c9b2d 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
@@ -28,10 +28,13 @@ import java.net.URI;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -243,22 +246,79 @@ public final class AttachmentUtil {
         return buffer.toString();
     }
 
-    public static Map<String, DataHandler> getDHMap(Collection<Attachment> attachments)
{
+    public static Map<String, DataHandler> getDHMap(final Collection<Attachment>
attachments) {
         Map<String, DataHandler> dataHandlers = null;
         if (attachments != null) {
             if (attachments instanceof LazyAttachmentCollection) {
                 dataHandlers = ((LazyAttachmentCollection)attachments).createDataHandlerMap();
             } else {
-                //preserve the order of iteration
-                dataHandlers = new LinkedHashMap<String, DataHandler>();
-                for (Attachment attachment : attachments) {
-                    dataHandlers.put(attachment.getId(), attachment.getDataHandler());
-                }
+                dataHandlers = new DHMap(attachments);
             }
         }
         return dataHandlers == null ? new LinkedHashMap<String, DataHandler>() : dataHandlers;
     }
     
+    static class DHMap extends AbstractMap<String, DataHandler> {
+        final Collection<Attachment> list;
+        public DHMap(Collection<Attachment> l) {
+            list = l;
+        }
+        public Set<Map.Entry<String, DataHandler>> entrySet() {
+            return new AbstractSet<Map.Entry<String, DataHandler>>() {
+                @Override
+                public Iterator<Map.Entry<String, DataHandler>> iterator() {
+                    final Iterator<Attachment> it = list.iterator();
+                    return new Iterator<Map.Entry<String, DataHandler>>() {
+                        public boolean hasNext() {
+                            return it.hasNext();
+                        }
+                        public java.util.Map.Entry<String, DataHandler> next() {
+                            final Attachment a = it.next();
+                            return new Map.Entry<String, DataHandler>() {
+                                @Override
+                                public String getKey() {
+                                    return a.getId();
+                                }
+
+                                @Override
+                                public DataHandler getValue() {
+                                    return a.getDataHandler();
+                                }
+
+                                @Override
+                                public DataHandler setValue(DataHandler value) {
+                                    return null;
+                                }
+                            };
+                        }
+                        public void remove() {
+                            it.remove();
+                        }
+                    };
+                }
+
+                @Override
+                public int size() {
+                    return list.size();
+                }
+            };
+        }
+        public DataHandler put(String key, DataHandler value) {
+            Iterator<Attachment> i = list.iterator();
+            DataHandler ret = null;
+            while (i.hasNext()) {
+                Attachment a = i.next();
+                if (a.getId().equals(key)) {
+                    i.remove();
+                    ret = a.getDataHandler();
+                    break;
+                }
+            }
+            list.add(new AttachmentImpl(key, value));
+            return ret;
+        }        
+    }
+    
     public static String cleanContentId(String id) {
         if (id != null) {
             if (id.startsWith("<")) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/8394d3a8/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AbstractJAXWSMethodInvoker.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AbstractJAXWSMethodInvoker.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AbstractJAXWSMethodInvoker.java
index 361294f..fabcdd2 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AbstractJAXWSMethodInvoker.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AbstractJAXWSMethodInvoker.java
@@ -22,15 +22,12 @@ package org.apache.cxf.jaxws;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 
-import javax.activation.DataHandler;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Provider;
 import javax.xml.ws.Response;
@@ -39,7 +36,6 @@ import javax.xml.ws.handler.MessageContext.Scope;
 import javax.xml.ws.soap.SOAPFaultException;
 
 import org.apache.cxf.annotations.UseAsyncMethod;
-import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.continuations.Continuation;
@@ -49,7 +45,6 @@ import org.apache.cxf.headers.Header;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
-import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.FaultMode;
 import org.apache.cxf.message.Message;
@@ -337,20 +332,6 @@ public abstract class AbstractJAXWSMethodInvoker extends FactoryInvoker
{
                     heads.remove("Content-Type");
                 }
             }
-            Map<String, DataHandler> dataHandlers  
-                = CastUtils.cast((Map<?, ?>)out.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS));
-            if (dataHandlers != null && !dataHandlers.isEmpty()) {
-                Collection<Attachment> attachments = out.getAttachments();
-                if (attachments == null) {
-                    attachments = new ArrayList<Attachment>();
-                    out.setAttachments(attachments);
-                }
-                for (Map.Entry<String, DataHandler> entry : dataHandlers.entrySet())
{
-                    Attachment att = new AttachmentImpl(entry.getKey(), entry.getValue());
-                    attachments.add(att);
-                }
-            }
-            out.remove(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/8394d3a8/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
index 0d18ac7..f1d245a 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedMessageContext.java
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxws.context;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -365,6 +366,10 @@ public class WrappedMessageContext implements MessageContext {
         if (attachments instanceof WrappedAttachments) {
             dataHandlers = ((WrappedAttachments) attachments).getAttachments();
         } else {
+            if (attachments == null) {
+                attachments = new ArrayList<Attachment>();
+                mc.put(Message.ATTACHMENTS, attachments);
+            }
             dataHandlers = AttachmentUtil.getDHMap(attachments);
             mc.put(propertyName, 
                    dataHandlers);


Mime
View raw message