Author: mriou
Date: Fri Aug 17 14:37:15 2007
New Revision: 567153

URL: http://svn.apache.org/viewvc?view=rev&rev=567153
Log:
ODE-154 Fix for WS-Addressing headers contributed by Richard Taylor.

Modified:
    ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
    
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/SessionOutHandler.java
    
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
    ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java

Modified: 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java?view=diff&rev=567153&r1=567152&r2=567153
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java 
(original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ExternalService.java Fri 
Aug 17 14:37:15 2007
@@ -43,6 +43,7 @@
 import org.apache.ode.bpel.iapi.PartnerRoleMessageExchange;
 import org.apache.ode.bpel.iapi.Scheduler;
 import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.Namespaces;
 import org.apache.ode.utils.uuid.UUID;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -108,9 +109,8 @@
             }
 
             Options options = new Options();
+            options.setAction(mctx.getSoapAction());
             options.setTo(axisEPR);
-            String soapAction = 
_converter.getSoapAction(odeMex.getOperationName());
-            options.setAction(soapAction);
             options.setTimeOutInMilliSeconds(60000);
 
             CachedServiceClient cached = _cachedClients.get();
@@ -187,6 +187,23 @@
     }
 
     /**
+     * Extracts the action to be used for the given operation.  It first 
checks to see
+     * if a value is specified using WS-Addressing in the portType, it then 
falls back onto 
+     * getting it from the SOAP Binding.
+     * @param operation the name of the operation to get the Action for
+     * @return The action value for the specified operation
+     */
+    private String getAction(String operation)
+       {
+       String action = _converter.getWSAInputAction(operation);
+        if (action == null || "".equals(action))
+        {
+               action = _converter.getSoapAction(operation);   
+        }
+               return action;
+       }
+
+       /**
      * Extracts endpoint information from ODE message exchange to stuff them 
into Axis MessageContext.
      */
     private void writeHeader(MessageContext ctxt, PartnerRoleMessageExchange 
odeMex) {
@@ -204,9 +221,7 @@
             targetEPR.setSessionId(partnerSessionId);
         }
         options.setProperty("targetSessionEndpoint", targetEPR);
-        String soapAction = 
_converter.getSoapAction(odeMex.getOperationName());
-        options.setProperty("soapAction", soapAction);
-
+        
         if (myRoleEPR != null) {
             if (myRoleSessionId != null) {
                 if (__log.isDebugEnabled()) {
@@ -220,12 +235,15 @@
             __log.debug("My-Role EPR not specified, SEP will not be used.");
         }
 
-        if (MessageExchange.MessageExchangePattern.REQUEST_RESPONSE == 
odeMex.getMessageExchangePattern()) {
-            EndpointReference annonEpr =
-                    new 
EndpointReference("http://www.w3.org/2005/08/addressing/anonymous";);
-            ctxt.setReplyTo(annonEpr);
-            ctxt.setMessageID("uuid:"+new UUID().toString());
-        }
+        String action = getAction(odeMex.getOperationName());
+        ctxt.setSoapAction(action);
+        
+           if (MessageExchange.MessageExchangePattern.REQUEST_RESPONSE == 
odeMex.getMessageExchangePattern()) {
+               EndpointReference annonEpr =
+                       new 
EndpointReference(Namespaces.WS_ADDRESSING_ANON_URI);
+               ctxt.setReplyTo(annonEpr);
+               ctxt.setMessageID("uuid:" + new UUID().toString());
+           }
     }
 
     public org.apache.ode.bpel.iapi.EndpointReference 
getInitialEndpointReference() {

Modified: 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/SessionOutHandler.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/SessionOutHandler.java?view=diff&rev=567153&r1=567152&r2=567153
==============================================================================
--- 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/SessionOutHandler.java 
(original)
+++ 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/hooks/SessionOutHandler.java 
Fri Aug 17 14:37:15 2007
@@ -60,19 +60,35 @@
             if (header == null) {
                 header = 
factory.createSOAPHeader(messageContext.getEnvelope());
             }
+            
             if (otargetSession != null && otargetSession instanceof 
MutableEndpoint) {
 
-                WSAEndpoint targetEpr = 
EndpointFactory.convertToWSA((MutableEndpoint) otargetSession);
-
-                OMElement to = factory.createOMElement("To", wsAddrNS);
+               WSAEndpoint targetEpr = 
EndpointFactory.convertToWSA((MutableEndpoint) otargetSession);
+               
+               OMElement to = factory.createOMElement("To", wsAddrNS);
                 header.addChild(to);
                 to.setText(targetEpr.getUrl());
 
-                String soapAction = (String) 
messageContext.getProperty("soapAction");
+                String action = messageContext.getSoapAction(); 
                 OMElement wsaAction = factory.createOMElement("Action", 
wsAddrNS);
                 header.addChild(wsaAction);
-                wsaAction.setText(soapAction);
+                wsaAction.setText(action);
 
+                // we only set the ReplyTo and MessageID headers if doing 
Request-Response
+                org.apache.axis2.addressing.EndpointReference replyToEpr = 
messageContext.getReplyTo();
+                if (replyToEpr != null) {
+                       OMElement replyTo = factory.createOMElement("ReplyTo", 
wsAddrNS);
+                       OMElement address = factory.createOMElement("Address", 
wsAddrNS);
+                       replyTo.addChild(address);
+                    header.addChild(replyTo);
+                    address.setText(replyToEpr.getAddress());
+                    
+                    String messageId = messageContext.getMessageID();
+                    OMElement messageIdElem = 
factory.createOMElement("MessageID", wsAddrNS);
+                    header.addChild(messageIdElem);
+                    messageIdElem.setText(messageId);                
+                }
+                   
                 if (targetEpr.getSessionId() != null) {
                     OMElement session = factory.createOMElement("session", 
intalioSessNS);
                     header.addChild(session);

Modified: 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java?view=diff&rev=567153&r1=567152&r2=567153
==============================================================================
--- 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
 (original)
+++ 
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/SoapMessageConverter.java
 Fri Aug 17 14:37:15 2007
@@ -34,6 +34,7 @@
 import org.apache.ode.axis2.Messages;
 import org.apache.ode.axis2.OdeFault;
 import org.apache.ode.utils.DOMUtils;
+import org.apache.ode.utils.Namespaces;
 import org.apache.ode.utils.stl.CollectionsX;
 import org.w3c.dom.Element;
 
@@ -43,12 +44,14 @@
 import javax.wsdl.BindingOutput;
 import javax.wsdl.Definition;
 import javax.wsdl.Fault;
+import javax.wsdl.Input;
 import javax.wsdl.Message;
 import javax.wsdl.Operation;
 import javax.wsdl.Part;
 import javax.wsdl.Port;
 import javax.wsdl.Service;
 import javax.wsdl.extensions.ElementExtensible;
+import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.soap.SOAPBinding;
 import javax.wsdl.extensions.soap.SOAPBody;
 import javax.wsdl.extensions.soap.SOAPHeader;
@@ -64,7 +67,6 @@
  * representation and vice versa.
  *
  * @author Maciej Szefler ( m s z e f l e r (at) g m a i l . c o m )
- *
  */
 public class SoapMessageConverter {
 
@@ -458,15 +460,33 @@
         return ee.isEmpty() ? null : ee.iterator().next();
 
     }
+    
+    /**
+     * Attempts to extract the WS-Addressing "Action" attribute value from the 
operation definition.
+     * When WS-Addressing is being used by a service provider, the "Action" is 
specified in the 
+     * portType->operation instead of the SOAP binding->operation.  
+     * 
+     * @param operation The name of the operation to extract the SOAP Action 
from
+     * @return the SOAPAction value if one is specified, otherwise empty string
+     */
+    public String getWSAInputAction(String operation) {
+      BindingOperation bop = _binding.getBindingOperation(operation, null, 
null);
+      if (bop == null) return "";
+
+      Input input = bop.getOperation().getInput();
+      if (input != null) {
+        Object actionQName = input.getExtensionAttribute(new 
QName(Namespaces.WS_ADDRESSING_NS, "Action"));
+        if (actionQName != null && actionQName instanceof QName)
+          return ((QName)actionQName).getLocalPart();
+      }
+      return "";
+    }
 
     /**
      * Attempts to extract the SOAP Action is defined in the WSDL document.
      *
-     * @param def
-     * @param service
-     * @param port
-     * @param operation
-     * @return
+     * @param operation The name of the operation to extract the SOAP Action 
from
+     * @return the SOAPAction value if one is specified, otherwise empty string
      */
     public String getSoapAction(String operation) {
         BindingOperation bop = _binding.getBindingOperation(operation, null, 
null);
@@ -478,7 +498,7 @@
 
         return "";
     }
-
+    
     public QName parseSoapFault(Element odeMsgEl, SOAPEnvelope envelope, 
Operation operation) throws AxisFault {
         SOAPFault flt = envelope.getBody().getFault();
         SOAPFaultDetail detail = flt.getDetail();

Modified: ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java
URL: 
http://svn.apache.org/viewvc/ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java?view=diff&rev=567153&r1=567152&r2=567153
==============================================================================
--- ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java 
(original)
+++ ode/trunk/utils/src/main/java/org/apache/ode/utils/Namespaces.java Fri Aug 
17 14:37:15 2007
@@ -42,14 +42,16 @@
     /** Diverse WS-* stuff */
     public static final String WS_ADDRESSING_NS = 
"http://www.w3.org/2005/08/addressing";;
     public static final String WS_ADDRESSING_WSDL_NS = 
"http://www.w3.org/2006/05/addressing/wsdl";;
+    public static final String WS_ADDRESSING_ANON_URI = 
"http://www.w3.org/2005/08/addressing/anonymous";;
     public static final String SOAP_NS = 
"http://schemas.xmlsoap.org/wsdl/soap/";;
     public static final String WSDL_11 = "http://schemas.xmlsoap.org/wsdl/";;
     public static final String WSDL_20 = "http://www.w3.org/2006/01/wsdl";;
     public static final String XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";;
     public static final String JBI_END_POINT_REFERENCE = 
"http://java.sun.com/jbi/end-point-reference";;
     public static final QName WS_ADDRESSING_ENDPOINT = new 
QName(WS_ADDRESSING_NS, "EndpointReference");
+    public static final QName WS_ADDRESSING_USINGADDRESSING = new 
QName(WS_ADDRESSING_WSDL_NS, "UsingAddressing");
 
-/** ODE stuff */
+    /** ODE stuff */
     public static final String ODE_PMAPI = 
"http://www.apache.org/ode/pmapi/types/2006/08/02/";;
     public static final String ODE_EXTENSION_NS = 
"http://www.apache.org/ode/type/extension";;
     public static final String INTALIO_SESSION_NS = 
"http://www.intalio.com/type/session";;


Reply via email to