You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2008/02/27 05:55:35 UTC

svn commit: r631482 - in /servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc: CxfBcConsumer.java WSAUtils.java interceptors/JbiInInterceptor.java

Author: ffang
Date: Tue Feb 26 20:55:34 2008
New Revision: 631482

URL: http://svn.apache.org/viewvc?rev=631482&view=rev
Log:
[SM-1236]apply patch on behalf of Andrea Zoppello with thanks

Added:
    servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/WSAUtils.java   (with props)
Modified:
    servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
    servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInInterceptor.java

Modified: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java?rev=631482&r1=631481&r2=631482&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java (original)
+++ servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java Tue Feb 26 20:55:34 2008
@@ -44,6 +44,7 @@
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.binding.AbstractBindingFactory;
 import org.apache.cxf.binding.jbi.JBIFault;
+import org.apache.cxf.binding.soap.SoapMessage;
 import org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
 import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
 import org.apache.cxf.binding.soap.interceptor.SoapActionOutInterceptor;
@@ -76,6 +77,7 @@
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.transport.ChainInitiationObserver;
+import org.apache.cxf.ws.addressing.AddressingProperties;
 import org.apache.cxf.ws.rm.Servant;
 import org.apache.cxf.wsdl.WSDLManager;
 import org.apache.cxf.wsdl11.WSDLServiceFactory;
@@ -125,9 +127,9 @@
     private BindingFaultInfo faultWanted;
 
     private Bus bus;
-    
+
     private boolean mtomEnabled;
-    
+
     private String locationURI;
 
     /**
@@ -177,8 +179,6 @@
         outFault = interceptors;
     }
 
-   
-
     public void process(MessageExchange exchange) throws Exception {
         Message message = messages.remove(exchange.getExchangeId());
         message.getInterceptorChain().resume();
@@ -212,13 +212,15 @@
                 WSDLFactory wsdlFactory = WSDLFactory.newInstance();
                 WSDLReader reader = wsdlFactory.newWSDLReader();
                 reader.setFeature(Constants.FEATURE_VERBOSE, false);
-                //definition = reader.readWSDL(wsdl.getURL().toString(),
-                 //       description);
+                // definition = reader.readWSDL(wsdl.getURL().toString(),
+                // description);
                 try {
                     // use wsdl manager to parse wsdl or get cached definition
-                    definition = getBus().getExtension(WSDLManager.class).getDefinition(wsdl.getURL());
+                    definition = getBus().getExtension(WSDLManager.class)
+                            .getDefinition(wsdl.getURL());
                 } catch (WSDLException ex) {
-                    //throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
+                    // throw new ServiceConstructionException(new
+                    // Message("SERVICE_CREATION_MSG", LOG), ex);
                 }
             }
             if (service == null) {
@@ -239,28 +241,26 @@
                     .getEndpoints().iterator().next();
             for (ServiceInfo serviceInfo : cxfService.getServiceInfos()) {
                 if (serviceInfo.getName().equals(service)
-                    && getEndpoint() != null 
-                    && serviceInfo.getEndpoint(new QName(
-                            serviceInfo.getName().getNamespaceURI(), getEndpoint())) != null) {
-                    ei = serviceInfo.getEndpoint(new QName(
-                                serviceInfo.getName().getNamespaceURI(), getEndpoint()));
-             
+                        && getEndpoint() != null
+                        && serviceInfo.getEndpoint(new QName(serviceInfo
+                                .getName().getNamespaceURI(), getEndpoint())) != null) {
+                    ei = serviceInfo.getEndpoint(new QName(serviceInfo
+                            .getName().getNamespaceURI(), getEndpoint()));
+
                 }
             }
-            
 
             if (endpoint == null) {
                 endpoint = ei.getName().getLocalPart();
             }
-            
+
             if (locationURI != null) {
                 ei.setAddress(locationURI);
             }
-            
+
             ei.getBinding().setProperty(
                     AbstractBindingFactory.DATABINDING_DISABLED, Boolean.TRUE);
-            
-            
+
             cxfService.getInInterceptors().add(
                     new ReadHeadersInterceptor(getBus()));
             cxfService.getInInterceptors().add(new MustUnderstandInterceptor());
@@ -277,7 +277,8 @@
             cxfService.getOutInterceptors().add(new JbiOutWsdl1Interceptor());
             cxfService.getOutInterceptors().add(new SoapActionOutInterceptor());
             cxfService.getOutInterceptors().add(new AttachmentOutInterceptor());
-            cxfService.getOutInterceptors().add(new MtomCheckInterceptor(isMtomEnabled()));
+            cxfService.getOutInterceptors().add(
+                    new MtomCheckInterceptor(isMtomEnabled()));
             cxfService.getOutInterceptors().add(new StaxOutInterceptor());
             cxfService.getOutInterceptors().add(
                     new SoapPreProtocolOutInterceptor());
@@ -316,8 +317,7 @@
                     getBus().getOutInterceptors());
             cxfService.getOutFaultInterceptors().addAll(
                     getBus().getOutFaultInterceptors());
-            
-            
+
             chain = new JbiChainInitiationObserver(ep, getBus());
             server = new ServerImpl(getBus(), ep, null, chain);
 
@@ -348,7 +348,7 @@
     public String getLocationURI() {
         return locationURI;
     }
-    
+
     protected class JbiChainInitiationObserver extends ChainInitiationObserver {
 
         public JbiChainInitiationObserver(Endpoint endpoint, Bus bus) {
@@ -391,6 +391,7 @@
         }
 
         public void handleMessage(final Message message) throws Fault {
+
             final Exchange cxfExchange = message.getExchange();
             final Endpoint endpoint = cxfExchange.get(Endpoint.class);
             final Service service = endpoint.getService();
@@ -440,7 +441,6 @@
             CxfBcConsumer.this.isOneway = message.getExchange().get(
                     BindingOperationInfo.class).getOperationInfo().isOneWay();
             message.getExchange().setOneWay(CxfBcConsumer.this.isOneway);
-            
 
             try {
                 if (CxfBcConsumer.this.synchronous
@@ -450,7 +450,7 @@
                     process(exchange);
                 } else {
                     context.getDeliveryChannel().send(exchange);
-                    
+
                 }
             } catch (Exception e) {
                 throw new Fault(e);
@@ -475,10 +475,12 @@
             }
             if (!ex.isOneWay()) {
                 if (exchange.getFault() != null) {
-                    Fault f = new JBIFault(new org.apache.cxf.common.i18n.Message(
-                            "Fault occured", (ResourceBundle) null));
+                    Fault f = new JBIFault(
+                            new org.apache.cxf.common.i18n.Message(
+                                    "Fault occured", (ResourceBundle) null));
 
-                    Element details = toElement(exchange.getFault().getContent());
+                    Element details = toElement(exchange.getFault()
+                            .getContent());
                     f.setDetail(details);
                     processFaultDetail(f, message);
                     message.put(BindingFaultInfo.class, faultWanted);
@@ -490,8 +492,17 @@
                         outMessage = endpoint.getBinding().createMessage();
                         ex.setOutMessage(outMessage);
                     }
-                    NormalizedMessageImpl norMessage = 
-                        (NormalizedMessageImpl) exchange.getMessage("out");
+                    NormalizedMessageImpl norMessage = (NormalizedMessageImpl) exchange
+                            .getMessage("out");
+
+                    // -- MODIFIED
+                    if (outMessage instanceof SoapMessage) {
+                        AddressingProperties addressingProperties = WSAUtils
+                                .getCXFAddressingPropertiesFromMap((Map<String, String>) norMessage
+                                        .getProperty(WSAUtils.WSA_HEADERS_OUTBOUND));
+                        outMessage.put(WSAUtils.WSA_HEADERS_OUTBOUND,
+                                addressingProperties);
+                    }
                     List<Attachment> attachmentList = new ArrayList<Attachment>();
                     outMessage.setContent(Source.class, exchange.getMessage(
                             "out").getContent());
@@ -501,7 +512,7 @@
                         DataHandler dh = norMessage.getAttachment(id);
                         attachmentList.add(new AttachmentImpl(id, dh));
                     }
-                    
+
                     outMessage.setAttachments(attachmentList);
                 }
             }
@@ -550,17 +561,17 @@
     }
 
     private static Element removeEmptyDefaultTns(Element ret) {
-        //to make unquailied fault work
-        if (ret.hasAttribute("xmlns") 
+        // to make unquailied fault work
+        if (ret.hasAttribute("xmlns")
                 && ret.getAttribute("xmlns").length() == 0) {
             ret.removeAttribute("xmlns");
         }
         NodeList nodes = ret.getChildNodes();
         for (int i = 0; i < nodes.getLength(); i++) {
             if (nodes.item(i) instanceof Element) {
-                Element ele = (Element)nodes.item(i);
+                Element ele = (Element) nodes.item(i);
                 ele = removeEmptyDefaultTns(ele);
-                
+
             }
         }
         return ret;

Added: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/WSAUtils.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/WSAUtils.java?rev=631482&view=auto
==============================================================================
--- servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/WSAUtils.java (added)
+++ servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/WSAUtils.java Tue Feb 26 20:55:34 2008
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.cxfbc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cxf.ws.addressing.AddressingProperties;
+import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
+import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.Names;
+import org.apache.cxf.ws.addressing.RelatesToType;
+import org.apache.cxf.wsdl.EndpointReferenceUtils;
+
+public final class WSAUtils {
+
+    public static final String WSA_HEADERS_INBOUND = "javax.xml.ws.addressing.context.inbound";
+
+    public static final String WSA_HEADERS_OUTBOUND = "javax.xml.ws.addressing.context.outbound";
+
+    private static final org.apache.cxf.ws.addressing.ObjectFactory WSA_OBJECT_FACTORY = new org.apache.cxf.ws.addressing.ObjectFactory();
+
+    private WSAUtils() {
+        
+    }
+    
+    public static AddressingProperties getCXFAddressingPropertiesFromMap(
+            Map<String, String> wsAddressingAsMap) {
+
+        
+        AddressingProperties maps = new AddressingPropertiesImpl();
+        if (wsAddressingAsMap == null) {
+            return maps;
+        }
+        for (String wsaHeaderKey : wsAddressingAsMap.keySet()) {
+
+            String wsaHeaderValue = wsAddressingAsMap.get(wsaHeaderKey);
+            System.out.println(" WSA HEADER KEY -> " + wsaHeaderKey);
+            System.out.println(" WSA HEADER VALUE -> " + wsaHeaderKey);
+            if (Names.WSA_MESSAGEID_NAME.equals(wsaHeaderKey)) {
+                AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
+                        .createAttributedURIType();
+                aAttributedURIType.setValue(wsaHeaderValue);
+                maps.setMessageID(aAttributedURIType);
+            } else if (Names.WSA_TO_NAME.equals(wsaHeaderKey)) {
+                maps.setTo(EndpointReferenceUtils
+                        .getEndpointReference(wsaHeaderValue));
+            } else if (Names.WSA_FROM_NAME.equals(wsaHeaderKey)) {
+                maps.setTo(EndpointReferenceUtils
+                        .getEndpointReference(wsaHeaderValue));
+            } else if (Names.WSA_REPLYTO_NAME.equals(wsaHeaderKey)) {
+                maps.setReplyTo(EndpointReferenceUtils
+                        .getEndpointReference(wsaHeaderValue));
+            } else if (Names.WSA_FAULTTO_NAME.equals(wsaHeaderKey)) {
+                // System.out.println( " **WSA_FAULTTO_NAME**");
+                maps.setFaultTo(EndpointReferenceUtils
+                        .getEndpointReference(wsaHeaderValue));
+            } else if (Names.WSA_RELATESTO_NAME.equals(wsaHeaderKey)) {
+                RelatesToType aRelatesToType = WSA_OBJECT_FACTORY
+                        .createRelatesToType();
+                aRelatesToType.setValue(wsaHeaderValue);
+                maps.setRelatesTo(aRelatesToType);
+            } else if (Names.WSA_ACTION_NAME.equals(wsaHeaderKey)) {
+                AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
+                        .createAttributedURIType();
+                aAttributedURIType.setValue(wsaHeaderValue);
+                maps.setAction(aAttributedURIType);
+            }
+        }
+        return maps;
+    }
+
+    public static Map<String, String> getAsMap(AddressingProperties maps) {
+
+        Map<String, String> returnMap = new HashMap<String, String>();
+
+        if (maps.getMessageID() != null) {
+            returnMap.put(Names.WSA_MESSAGEID_NAME, maps.getMessageID()
+                    .getValue());
+        }
+        if (maps.getTo() != null) {
+            returnMap.put(Names.WSA_TO_NAME, maps.getTo().getValue());
+        }
+        if (maps.getFrom() != null) {
+            returnMap.put(Names.WSA_FROM_NAME, maps.getFrom().getAddress()
+                    .getValue());
+        }
+        if (maps.getReplyTo() != null) {
+            returnMap.put(Names.WSA_REPLYTO_NAME, maps.getReplyTo()
+                    .getAddress().getValue());
+        }
+        if (maps.getFaultTo() != null) {
+            returnMap.put(Names.WSA_FAULTTO_NAME, maps.getFaultTo()
+                    .getAddress().getValue());
+        }
+        if (maps.getRelatesTo() != null) {
+            returnMap.put(Names.WSA_RELATESTO_NAME, maps.getRelatesTo()
+                    .getValue());
+        }
+        if (maps.getAction() != null) {
+            returnMap.put(Names.WSA_ACTION_NAME, maps.getAction().getValue());
+        }
+        return returnMap;
+    }
+}

Propchange: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/WSAUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/WSAUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInInterceptor.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInInterceptor.java?rev=631482&r1=631481&r2=631482&view=diff
==============================================================================
--- servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInInterceptor.java (original)
+++ servicemix/smx3/trunk/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInInterceptor.java Tue Feb 26 20:55:34 2008
@@ -38,6 +38,8 @@
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.ws.addressing.AddressingProperties;
+import org.apache.servicemix.cxfbc.WSAUtils;
 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
 import org.apache.servicemix.soap.util.QNameUtil;
 
@@ -78,6 +80,10 @@
             }
             // Put headers
             toNMSHeaders(nm, message);
+
+            // copy wsa headers if present
+            toNMSWSAHeaders(nm, message);
+
             // Put attachments
             toNMSAttachments(nm, message);
             // Put subject
@@ -133,6 +139,23 @@
         MessageExchange me = mef.createExchange(mep);
         me.setOperation(operation.getName());
         return me;
+    }
+
+    private void toNMSWSAHeaders(NormalizedMessage normalizedMessage,
+            Message soapMessage) {
+        SoapMessage message = null;
+        if (!(soapMessage instanceof SoapMessage)) {
+            return;
+        } else {
+            message = (SoapMessage) soapMessage;
+        }
+
+        if (message.get(WSAUtils.WSA_HEADERS_INBOUND) != null) {
+            normalizedMessage.setProperty(WSAUtils.WSA_HEADERS_INBOUND,
+                    WSAUtils.getAsMap((AddressingProperties) message
+                            .get(WSAUtils.WSA_HEADERS_INBOUND)));
+        }
+
     }
 
     /**