cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [1/5] git commit: [CXF-5871] Fix dispatch.invokeAsync not sending proper Action
Date Fri, 11 Jul 2014 18:30:27 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 9be6ef67c -> a4e4ea126


[CXF-5871] Fix dispatch.invokeAsync not sending proper Action


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

Branch: refs/heads/master
Commit: 1b3b938b02d491520377aa5fa020baa971025782
Parents: 388ee56
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Jul 11 12:44:03 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Jul 11 14:29:30 2014 -0400

----------------------------------------------------------------------
 .../java/org/apache/cxf/jaxws/DispatchImpl.java | 178 +++++++++++--------
 1 file changed, 99 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1b3b938b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
index 9c7d68e..968888c 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/DispatchImpl.java
@@ -40,11 +40,13 @@ import javax.xml.soap.SOAPMessage;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
 import javax.xml.ws.AsyncHandler;
 import javax.xml.ws.Binding;
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.EndpointReference;
+import javax.xml.ws.Holder;
 import javax.xml.ws.Response;
 import javax.xml.ws.Service;
 import javax.xml.ws.WebServiceException;
@@ -54,6 +56,7 @@ import javax.xml.ws.http.HTTPBinding;
 import javax.xml.ws.http.HTTPException;
 import javax.xml.ws.soap.SOAPBinding;
 import javax.xml.ws.soap.SOAPFaultException;
+
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -306,7 +309,6 @@ public class DispatchImpl<T> implements Dispatch<T>, BindingProvider,
Closeable
                 getRequestContext().put("unwrap.jaxb.element", unwrapProperty);
             }
             QName opName = (QName)getRequestContext().get(MessageContext.WSDL_OPERATION);
-            boolean findDispatchOp = Boolean.TRUE.equals(getRequestContext().get("find.dispatch.operation"));
             
             boolean hasOpName;
             if (opName == null) {
@@ -320,95 +322,106 @@ public class DispatchImpl<T> implements Dispatch<T>, BindingProvider,
Closeable
                     addInvokeOperation(opName, isOneWay);
                 }
             }
+            Holder<T> holder = new Holder<T>(obj);
+            opName = calculateOpName(holder, opName, hasOpName);
             
-            //CXF-2836 : find the operation for the dispatched object
-            // if findDispatchOp is already true, skip the addressing feature lookup.
-            // if the addressing feature is enabled, set findDispatchOp to true
-            if (!findDispatchOp) {
-                // the feature list to be searched is the endpoint and the bus's lists
-                List<Feature> endpointFeatures 
-                    = ((JaxWsClientEndpointImpl)client.getEndpoint()).getFeatures();
-                List<Feature> allFeatures;
-                if (client.getBus().getFeatures() != null) {
-                    allFeatures = new ArrayList<Feature>(endpointFeatures.size() 
-                        + client.getBus().getFeatures().size());
-                    allFeatures.addAll(endpointFeatures);
-                    allFeatures.addAll(client.getBus().getFeatures());
-                } else {
-                    allFeatures = endpointFeatures;
-                }
-                for (Feature feature : allFeatures) {
-                    if (feature instanceof WSAddressingFeature) {
-                        findDispatchOp = true; 
-                    }
+            Object ret[] = client.invokeWrapped(opName,
+                                                holder.value);
+            if (isOneWay || ret == null || ret.length == 0) {
+                return null;
+            }
+            return (T)ret[0];
+        } catch (Exception ex) {
+            throw mapException(ex);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private QName calculateOpName(Holder<T> holder, QName opName, boolean hasOpName)
throws XMLStreamException {
+        boolean findDispatchOp = Boolean.TRUE.equals(getRequestContext().get("find.dispatch.operation"));
+
+        //CXF-2836 : find the operation for the dispatched object
+        // if findDispatchOp is already true, skip the addressing feature lookup.
+        // if the addressing feature is enabled, set findDispatchOp to true
+        if (!findDispatchOp) {
+            // the feature list to be searched is the endpoint and the bus's lists
+            List<Feature> endpointFeatures 
+                = ((JaxWsClientEndpointImpl)client.getEndpoint()).getFeatures();
+            List<Feature> allFeatures;
+            if (client.getBus().getFeatures() != null) {
+                allFeatures = new ArrayList<Feature>(endpointFeatures.size() 
+                    + client.getBus().getFeatures().size());
+                allFeatures.addAll(endpointFeatures);
+                allFeatures.addAll(client.getBus().getFeatures());
+            } else {
+                allFeatures = endpointFeatures;
+            }
+            for (Feature feature : allFeatures) {
+                if (feature instanceof WSAddressingFeature) {
+                    findDispatchOp = true; 
                 }
             }
-            Map<String, QName> payloadOPMap = createPayloadEleOpNameMap(
-                    client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
-            if (findDispatchOp && !payloadOPMap.isEmpty()) {
-                QName payloadElementName = null;
-                if (obj instanceof javax.xml.transform.Source) {
-                    XMLStreamReader reader = null;
-                    try {
-                        reader = StaxUtils.createXMLStreamReader((javax.xml.transform.Source)obj);
-                        Document document = StaxUtils.read(reader);
-                        createdSource = new StaxSource(StaxUtils.createXMLStreamReader(document));
-                        payloadElementName = getPayloadElementName(document.getDocumentElement());
-                    } catch (Exception e) {                        
-                        // ignore, we are trying to get the operation name
-                    } finally {
-                        StaxUtils.close(reader);
-                    }
+        }
+        Source createdSource = null;
+        Map<String, QName> payloadOPMap = createPayloadEleOpNameMap(
+                client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
+        if (findDispatchOp && !payloadOPMap.isEmpty()) {
+            QName payloadElementName = null;
+            if (holder.value instanceof javax.xml.transform.Source) {
+                XMLStreamReader reader = null;
+                try {
+                    reader = StaxUtils.createXMLStreamReader((javax.xml.transform.Source)holder.value);
+                    Document document = StaxUtils.read(reader);
+                    createdSource = new StaxSource(StaxUtils.createXMLStreamReader(document));
+                    payloadElementName = getPayloadElementName(document.getDocumentElement());
+                } catch (Exception e) {                        
+                    // ignore, we are trying to get the operation name
+                } finally {
+                    StaxUtils.close(reader);
                 }
-                if (obj instanceof SOAPMessage) {
-                    payloadElementName = getPayloadElementName((SOAPMessage)obj);
+            }
+            if (holder.value instanceof SOAPMessage) {
+                payloadElementName = getPayloadElementName((SOAPMessage)holder.value);
 
-                }
+            }
 
-                if (this.context != null) {
-                    payloadElementName = getPayloadElementName(obj);
-                }
+            if (this.context != null) {
+                payloadElementName = getPayloadElementName(holder.value);
+            }
 
-                if (payloadElementName != null) {
-                    if (hasOpName) {
-                        // Verify the payload element against the given operation name.
-                        // This allows graceful handling of non-standard WSDL definitions
-                        // where different operations have the same payload element.
-                        QName expectedElementName = payloadOPMap.get(opName.toString());
-                        if (expectedElementName == null || !expectedElementName.toString().equals(
-                                payloadElementName.toString())) {
-                            // Verification of the provided operation name failed.
-                            // Resolve the operation name from the payload element.
-                            hasOpName = false;
-                            payloadOPMap = createPayloadEleOpNameMap(
-                                    client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
-                        }
+            if (payloadElementName != null) {
+                if (hasOpName) {
+                    // Verify the payload element against the given operation name.
+                    // This allows graceful handling of non-standard WSDL definitions
+                    // where different operations have the same payload element.
+                    QName expectedElementName = payloadOPMap.get(opName.toString());
+                    if (expectedElementName == null || !expectedElementName.toString().equals(
+                            payloadElementName.toString())) {
+                        // Verification of the provided operation name failed.
+                        // Resolve the operation name from the payload element.
+                        hasOpName = false;
+                        payloadOPMap = createPayloadEleOpNameMap(
+                                client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
                     }
-                    QName dispatchedOpName = null;
-                    if (!hasOpName) {
-                        dispatchedOpName = payloadOPMap.get(payloadElementName.toString());
-                    }
-                    if (null != dispatchedOpName) {
-                        BindingOperationInfo dbop = client.getEndpoint().getBinding().getBindingInfo()
-                            .getOperation(dispatchedOpName);
-                        if (dbop != null) {
-                            opName = dispatchedOpName;
-                        }
+                }
+                QName dispatchedOpName = null;
+                if (!hasOpName) {
+                    dispatchedOpName = payloadOPMap.get(payloadElementName.toString());
+                }
+                if (null != dispatchedOpName) {
+                    BindingOperationInfo dbop = client.getEndpoint().getBinding().getBindingInfo()
+                        .getOperation(dispatchedOpName);
+                    if (dbop != null) {
+                        opName = dispatchedOpName;
                     }
                 }
-            } 
-            
-            Object ret[] = client.invokeWrapped(opName,
-                                                createdSource == null ? obj : createdSource);
-            if (isOneWay || ret == null || ret.length == 0) {
-                return null;
             }
-            return (T)ret[0];
-        } catch (Exception ex) {
-            throw mapException(ex);
         }
+        if (createdSource != null) {
+            holder.value = (T)createdSource;
+        }
+        return opName;
     }
-
   
     public Future<?> invokeAsync(T obj, AsyncHandler<T> asyncHandler) {
         checkError();
@@ -417,11 +430,15 @@ public class DispatchImpl<T> implements Dispatch<T>, BindingProvider,
Closeable
         ClientCallback callback = new JaxwsClientCallback<T>(asyncHandler, this);
              
         Response<T> ret = new JaxwsResponseCallback<T>(callback);
-        try {
+        try {           
+            boolean hasOpName;
+            
             QName opName = (QName)getRequestContext().get(MessageContext.WSDL_OPERATION);
             if (opName == null) {
+                hasOpName = false;
                 opName = INVOKE_QNAME;
             } else {
+                hasOpName = true;
                 BindingOperationInfo bop = client.getEndpoint().getBinding()
                     .getBindingInfo().getOperation(opName);
                 if (bop == null) {
@@ -429,9 +446,12 @@ public class DispatchImpl<T> implements Dispatch<T>, BindingProvider,
Closeable
                 }
             }
 
+            Holder<T> holder = new Holder<T>(obj);
+            opName = calculateOpName(holder, opName, hasOpName);
+            
             client.invokeWrapped(callback, 
                                  opName,
-                                 obj);
+                                 holder.value);
             
             return ret;
         } catch (Exception ex) {


Mime
View raw message