servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r389472 - in /incubator/servicemix/trunk: servicemix-http/src/main/java/org/apache/servicemix/http/processors/ servicemix-http/src/test/java/org/apache/servicemix/http/ servicemix-http/src/test/resources/org/apache/servicemix/http/ servicem...
Date Tue, 28 Mar 2006 10:46:57 GMT
Author: gnodet
Date: Tue Mar 28 02:46:44 2006
New Revision: 389472

URL: http://svn.apache.org/viewcvs?rev=389472&view=rev
Log:
SM-370: wsa:MessageID is not implemented for WS-Addressing

Added:
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingHandler.java
      - copied, changed from r387168, incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java
Removed:
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java
Modified:
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpAddressingTest.java
    incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/addressing-request.xml
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
    incubator/servicemix/trunk/servicemix-soap/project.xml
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Context.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
Tue Mar 28 02:46:44 2006
@@ -39,10 +39,10 @@
 import org.apache.servicemix.http.HttpLifeCycle;
 import org.apache.servicemix.http.HttpProcessor;
 import org.apache.servicemix.http.ServerManager;
+import org.apache.servicemix.soap.Context;
 import org.apache.servicemix.soap.SoapFault;
 import org.apache.servicemix.soap.SoapHelper;
-import org.apache.servicemix.soap.handlers.AddressingInHandler;
-import org.apache.servicemix.soap.marshalers.JBIMarshaler;
+import org.apache.servicemix.soap.handlers.AddressingHandler;
 import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
@@ -64,7 +64,6 @@
     protected ComponentContext context;
     protected DeliveryChannel channel;
     protected SoapMarshaler soapMarshaler;
-    protected JBIMarshaler jbiMarshaler;
     protected SoapHelper soapHelper;
     protected Map locks;
         
@@ -75,8 +74,7 @@
             this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
         }
         this.soapHelper = new SoapHelper(endpoint);
-        this.soapHelper.addPolicy(new AddressingInHandler());
-        this.jbiMarshaler = new JBIMarshaler();
+        this.soapHelper.addPolicy(new AddressingHandler());
         this.locks = new ConcurrentHashMap();
     }
     
@@ -123,11 +121,12 @@
             try {
                 SoapMessage message = soapMarshaler.createReader().read(request.getInputStream(),

                                                                         request.getHeader("Content-Type"));
-                exchange = soapHelper.createExchange(message);
+                Context context = soapHelper.createContext(message);
+                request.setAttribute(Context.class.getName(), context);
+                exchange = soapHelper.onReceive(context);
                 NormalizedMessage inMessage = exchange.getMessage("in");
                 inMessage.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(request));
                 locks.put(exchange.getExchangeId(), cont);
-                request.setAttribute(SoapMessage.class.getName(), message);
                 request.setAttribute(MessageExchange.class.getName(), exchange);
                 ((BaseLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle()).sendConsumerExchange(exchange,
this);
                 // TODO: make this timeout configurable
@@ -165,8 +164,8 @@
                 } else {
                     NormalizedMessage outMsg = exchange.getMessage("out");
                     if (outMsg != null) {
-                        SoapMessage out = new SoapMessage();
-                        jbiMarshaler.fromNMS(out, outMsg);
+                        Context context = (Context) request.getAttribute(Context.class.getName());
+                        SoapMessage out = soapHelper.onReply(context, outMsg);
                         SoapWriter writer = soapMarshaler.createWriter(out);
                         response.setContentType(writer.getContentType());
                         writer.write(response.getOutputStream());
@@ -185,12 +184,8 @@
         } else {
             response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
         }
-        SoapMessage in = (SoapMessage) request.getAttribute(SoapMessage.class.getName());
-        SoapMessage soapFault = new SoapMessage();
-        soapFault.setFault(fault);
-        if (in != null) {
-            soapFault.setEnvelopeName(in.getEnvelopeName());
-        }
+        Context context = (Context) request.getAttribute(Context.class.getName());
+        SoapMessage soapFault = soapHelper.onFault(context, fault);
         SoapWriter writer = soapMarshaler.createWriter(soapFault);
         response.setContentType(writer.getContentType());
         writer.write(response.getOutputStream());

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpAddressingTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpAddressingTest.java?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpAddressingTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpAddressingTest.java
Tue Mar 28 02:46:44 2006
@@ -28,6 +28,7 @@
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.tck.SpringTestSupport;
 import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.Node;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 
 public class HttpAddressingTest extends SpringTestSupport {
@@ -50,7 +51,10 @@
                 fail("Received ERROR status");
             }
         } else {
-            logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
+            Node node = new SourceTransformer().toDOMNode(me.getOutMessage());
+            logger.info(new SourceTransformer().toString(node));
+            assertEquals("myid", textValueOfXPath(node, "//*[local-name()='RelatesTo']"));
+            assertNotNull(textValueOfXPath(node, "//*[local-name()='MessageID']"));
         }
     }
     

Modified: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/addressing-request.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/addressing-request.xml?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/addressing-request.xml
(original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/addressing-request.xml
Tue Mar 28 02:46:44 2006
@@ -1,10 +1,11 @@
 <soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'
-               xmlns:wsa='http://schemas.xmlsoap.org/ws/2003/03/addressing'
+               xmlns:wsa='http://www.w3.org/2005/08/addressing'
                xmlns:test='http://test'>
   <soap:Header>
+    <wsa:MessageID>myid</wsa:MessageID>
     <wsa:To>http://test/MyConsumerService/myConsumer</wsa:To>
     <wsa:ReplyTo>
-      <wsa:ServiceName>test:MyConsumerService</wsa:ServiceName>
+      <wsa:Address>test:MyConsumerService</wsa:Address>
     </wsa:ReplyTo>
   </soap:Header>
   <soap:Body>

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
Tue Mar 28 02:46:44 2006
@@ -39,10 +39,10 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.common.BaseLifeCycle;
+import org.apache.servicemix.soap.Context;
 import org.apache.servicemix.soap.SoapFault;
 import org.apache.servicemix.soap.SoapHelper;
-import org.apache.servicemix.soap.handlers.AddressingInHandler;
-import org.apache.servicemix.soap.marshalers.JBIMarshaler;
+import org.apache.servicemix.soap.handlers.AddressingHandler;
 import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
@@ -60,7 +60,6 @@
     protected DeliveryChannel channel;
     protected SoapHelper soapHelper;
     protected SoapMarshaler soapMarshaler;
-    protected JBIMarshaler jbiMarshaler;
     
     public MultiplexingConsumerProcessor(JmsEndpoint endpoint) {
         super(endpoint);
@@ -69,8 +68,7 @@
             this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
         }
         this.soapHelper = new SoapHelper(endpoint);
-        this.soapHelper.addPolicy(new AddressingInHandler());
-        this.jbiMarshaler = new JBIMarshaler();
+        this.soapHelper.addPolicy(new AddressingHandler());
     }
 
     protected void doStart(InitialContext ctx) throws Exception {
@@ -125,10 +123,12 @@
                         }
                         String contentType = message.getStringProperty("Content-Type");
                         SoapMessage soap = soapMarshaler.createReader().read(is, contentType);
-                        MessageExchange exchange = soapHelper.createExchange(soap);
+                        Context context = soapHelper.createContext(soap);
+                        MessageExchange exchange = soapHelper.onReceive(context);
+                        context.setProperty(Message.class.getName(), message);
                         // TODO: copy protocol messages
                         //inMessage.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(message));
-                        pendingMessages.put(exchange.getExchangeId(), message);
+                        pendingMessages.put(exchange.getExchangeId(), context);
                         BaseLifeCycle lf = (BaseLifeCycle) endpoint.getServiceUnit().getComponent().getLifeCycle();
                         lf.sendConsumerExchange(exchange, MultiplexingConsumerProcessor.this);
                     } catch (Throwable e) {
@@ -142,7 +142,8 @@
     }
 
     public void process(MessageExchange exchange) throws Exception {
-        Message message = (Message) pendingMessages.remove(exchange.getExchangeId());
+        Context context = (Context) pendingMessages.remove(exchange.getExchangeId());
+        Message message = (Message) context.getProperty(Message.class.getName());
         MessageProducer producer = null;
         Message response = null;
         try {
@@ -155,13 +156,7 @@
             } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
                 if (exchange.getFault() != null) {
                     SoapFault fault = new SoapFault(SoapFault.RECEIVER, null, null, null,
exchange.getFault().getContent());
-                    SoapMessage soapFault = new SoapMessage();
-                    soapFault.setFault(fault);
-                    // TODO: retrieve input soap message
-                    SoapMessage in = null;
-                    if (in != null) {
-                        soapFault.setEnvelopeName(in.getEnvelopeName());
-                    }
+                    SoapMessage soapFault = soapHelper.onFault(context, fault);
                     ByteArrayOutputStream baos = new ByteArrayOutputStream();
                     SoapWriter writer = soapMarshaler.createWriter(soapFault);
                     writer.write(baos);
@@ -171,8 +166,7 @@
                 } else {
                     NormalizedMessage outMsg = exchange.getMessage("out");
                     if (outMsg != null) {
-                        SoapMessage out = new SoapMessage();
-                        jbiMarshaler.fromNMS(out, outMsg);
+                        SoapMessage out = soapHelper.onReply(context, outMsg);
                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
                         SoapWriter writer = soapMarshaler.createWriter(out);
                         writer.write(baos);

Modified: incubator/servicemix/trunk/servicemix-soap/project.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/project.xml?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/project.xml (original)
+++ incubator/servicemix/trunk/servicemix-soap/project.xml Tue Mar 28 02:46:44 2006
@@ -85,6 +85,11 @@
         <artifactId>spring</artifactId>
         <version>${spring_version}</version>
       </dependency>
+      <dependency>
+        <groupId>incubator-activemq</groupId>
+        <artifactId>activemq-core</artifactId>
+        <version>${activemq_version}</version>
+      </dependency>
       
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Context.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Context.java?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Context.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Context.java
Tue Mar 28 02:46:44 2006
@@ -18,6 +18,8 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+
 /**
  * 
  * @author Guillaume Nodet
@@ -26,7 +28,9 @@
  */
 public class Context {
 
-	public static final String SOAP_MESSAGE = "org.apache.servicemix.SoapMessage";
+    public static final String SOAP_IN = "org.apache.servicemix.SoapIn";
+    public static final String SOAP_OUT = "org.apache.servicemix.SoapOut";
+    public static final String SOAP_FAULT = "org.apache.servicemix.SoapFault";
 	public static final String INTERFACE = "org.apache.servicemix.Interface";
 	public static final String OPERATION = "org.apache.servicemix.Operation";
 	public static final String SERVICE = "org.apache.servicemix.Service";
@@ -37,7 +41,31 @@
 	public Context() {
 		this.properties = new HashMap();
 	}
-	
+    
+    public SoapMessage getInMessage() {
+        return (SoapMessage) getProperty(SOAP_IN);
+    }
+    
+    public SoapMessage getOutMessage() {
+        return (SoapMessage) getProperty(SOAP_OUT);
+    }
+    
+    public SoapMessage getFaultMessage() {
+        return (SoapMessage) getProperty(SOAP_FAULT);
+    }
+    
+    public void setInMessage(SoapMessage message) {
+        setProperty(SOAP_IN, message);
+    }
+    
+    public void setOutMessage(SoapMessage message) {
+        setProperty(SOAP_OUT, message);
+    }
+    
+    public void setFaultMessage(SoapMessage message) {
+        setProperty(SOAP_FAULT, message);
+    }
+    
 	public Object getProperty(String name) {
 		return properties.get(name);
 	}

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java
Tue Mar 28 02:46:44 2006
@@ -23,8 +23,12 @@
  */
 public interface Handler {
 
-	public void process(Context context) throws Exception;
+	public void onReceive(Context context) throws Exception;
+    
+    public void onReply(Context context) throws Exception;
 	
+    public void onFault(Context context) throws Exception;
+    
 	public void onComplete(Context context);
 	
 	public void onException(Context context, Exception e);

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java
Tue Mar 28 02:46:44 2006
@@ -74,34 +74,11 @@
     	policies.add(policy);
     }
 
-	public Context createContext(SoapMessage message) {
-		Context context = new Context();
-		context.setProperty(Context.SOAP_MESSAGE, message);
-        if (message.getBodyName() == null) {
-            context.setProperty(Context.OPERATION, endpoint.getDefaultOperation());
-        } else {
-            context.setProperty(Context.OPERATION, message.getBodyName());
-        }
-        // If no target endpoint / service / interface is defined
-        // we assume we use the same informations has defined on the
-        // external endpoint
-        if (endpoint.getTargetInterfaceName() == null && 
-            endpoint.getTargetService() == null &&
-            endpoint.getTargetEndpoint() == null) {
-    		context.setProperty(Context.INTERFACE, endpoint.getInterfaceName());
-    		context.setProperty(Context.SERVICE, endpoint.getService());
-    		context.setProperty(Context.ENDPOINT, endpoint.getEndpoint());
-        } else {
-            context.setProperty(Context.INTERFACE, endpoint.getTargetInterfaceName());
-            context.setProperty(Context.SERVICE, endpoint.getTargetService());
-            context.setProperty(Context.ENDPOINT, endpoint.getTargetEndpoint());
+	public MessageExchange onReceive(Context context) throws Exception {
+        for (Iterator it = policies.iterator(); it.hasNext();) {
+            Handler policy = (Handler) it.next();
+            policy.onReceive(context);
         }
-		return context;
-	}
-	
-	public MessageExchange createExchange(SoapMessage message) throws Exception {
-		Context context = createContext(message);
-		analyzeHeaders(context);
 		URI mep = findMep(context);
 		if (mep == null) {
 			mep = endpoint.getDefaultMep();
@@ -120,19 +97,68 @@
     		}
         }
         NormalizedMessage inMessage = exchange.createMessage();
-        jbiMarshaler.toNMS(inMessage, message);
+        jbiMarshaler.toNMS(inMessage, context.getInMessage());
         exchange.setMessage(inMessage, "in");
         return exchange;
 	}
-	
-    public void analyzeHeaders(Context context) throws Exception {
-    	for (Iterator it = policies.iterator(); it.hasNext();) {
-    		Handler policy = (Handler) it.next();
-    		policy.process(context);
-    	}
+    
+    public SoapMessage onReply(Context context, NormalizedMessage outMsg) throws Exception
{
+        SoapMessage out = new SoapMessage();
+        if (context.getInMessage() != null) {
+            out.setEnvelopeName(context.getInMessage().getEnvelopeName());
+        }
+        jbiMarshaler.fromNMS(out, outMsg);
+        context.setOutMessage(out);
+        for (Iterator it = policies.iterator(); it.hasNext();) {
+            Handler policy = (Handler) it.next();
+            policy.onReply(context);
+        }
+        return out;
     }
-	
-    public MessageExchange createExchange(URI mep) throws MessagingException {
+    
+    public SoapMessage onFault(Context context, SoapFault fault) throws Exception {
+        SoapMessage soapFault = new SoapMessage();
+        soapFault.setFault(fault);
+        if (context == null) {
+            context = new Context();
+        }
+        if (context.getInMessage() != null) {
+            soapFault.setEnvelopeName(context.getInMessage().getEnvelopeName());
+        }
+        context.setFaultMessage(soapFault);
+        for (Iterator it = policies.iterator(); it.hasNext();) {
+            Handler policy = (Handler) it.next();
+            policy.onFault(context);
+        }
+        return soapFault;
+    }
+    
+    public Context createContext(SoapMessage message) {
+        Context context = new Context();
+        context.setInMessage(message);
+        if (message.getBodyName() == null) {
+            context.setProperty(Context.OPERATION, endpoint.getDefaultOperation());
+        } else {
+            context.setProperty(Context.OPERATION, message.getBodyName());
+        }
+        // If no target endpoint / service / interface is defined
+        // we assume we use the same informations has defined on the
+        // external endpoint
+        if (endpoint.getTargetInterfaceName() == null && 
+            endpoint.getTargetService() == null &&
+            endpoint.getTargetEndpoint() == null) {
+            context.setProperty(Context.INTERFACE, endpoint.getInterfaceName());
+            context.setProperty(Context.SERVICE, endpoint.getService());
+            context.setProperty(Context.ENDPOINT, endpoint.getEndpoint());
+        } else {
+            context.setProperty(Context.INTERFACE, endpoint.getTargetInterfaceName());
+            context.setProperty(Context.SERVICE, endpoint.getTargetService());
+            context.setProperty(Context.ENDPOINT, endpoint.getTargetEndpoint());
+        }
+        return context;
+    }
+    
+    protected MessageExchange createExchange(URI mep) throws MessagingException {
         ComponentContext context = endpoint.getServiceUnit().getComponent().getComponentContext();
         DeliveryChannel channel = context.getDeliveryChannel();
         MessageExchangeFactory factory = channel.createExchangeFactory();
@@ -140,7 +166,7 @@
         return exchange;
     }
     
-    public URI findMep(Context context) throws Exception {
+    protected URI findMep(Context context) throws Exception {
 		QName interfaceName = (QName) context.getProperty(Context.INTERFACE);
 		QName serviceName = (QName) context.getProperty(Context.SERVICE);
 		QName operationName = (QName) context.getProperty(Context.OPERATION);

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java?rev=389472&r1=389471&r2=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java
Tue Mar 28 02:46:44 2006
@@ -24,7 +24,16 @@
  * @version $Revision: 1.5 $
  * @since 3.0
  */
-public abstract class AbstractHandler implements Handler {
+public class AbstractHandler implements Handler {
+
+    public void onReceive(Context context) throws Exception {
+    }
+
+    public void onReply(Context context) throws Exception {
+    }
+
+    public void onFault(Context context) throws Exception {
+    }
 
 	public void onComplete(Context context) {
 	}

Copied: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingHandler.java
(from r387168, incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java)
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingHandler.java?p2=incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingHandler.java&p1=incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java&r1=387168&r2=389472&rev=389472&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingInHandler.java
(original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingHandler.java
Tue Mar 28 02:46:44 2006
@@ -20,10 +20,13 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.activemq.util.IdGenerator;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.util.DOMUtil;
 import org.apache.servicemix.soap.Context;
 import org.apache.servicemix.soap.SoapFault;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 
@@ -33,12 +36,14 @@
  * @version $Revision: 1.5 $
  * @since 3.0
  */
-public class AddressingInHandler extends AbstractHandler {
+public class AddressingHandler extends AbstractHandler {
 
     public static final String WSA_NAMESPACE_200303 = "http://schemas.xmlsoap.org/ws/2003/03/addressing";
     public static final String WSA_NAMESPACE_200408 = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
     public static final String WSA_NAMESPACE_200508 = "http://www.w3.org/2005/08/addressing";
     
+    public static final String WSA_PREFIX = "wsa";
+    
     public static final String EL_ACTION = "Action";
     public static final String EL_ADDRESS = "Address";
     public static final String EL_FAULT_TO = "FaultTo";
@@ -50,8 +55,11 @@
     public static final String EL_REPLY_TO = "ReplyTo";
     public static final String EL_TO = "To";
     
-	public void process(Context context) throws Exception {
-		SoapMessage message = (SoapMessage) context.getProperty(Context.SOAP_MESSAGE);
+    protected final SourceTransformer sourceTransformer = new SourceTransformer();
+    protected final IdGenerator idGenerator = new IdGenerator();
+    
+	public void onReceive(Context context) throws Exception {
+		SoapMessage message = context.getInMessage();
     	String action = null;
     	String to = null;
     	String nsUri = null;
@@ -68,15 +76,13 @@
 	    			} else if (!nsUri.equals(qname.getNamespaceURI())) {
 	    				throw new SoapFault(SoapFault.SENDER, "Inconsistent use of wsa namespaces");
 	    			}
-		    		if (qname.getLocalPart().equals(AddressingInHandler.EL_ACTION)) {
-		    			Element el = (Element) ((DocumentFragment) value).getFirstChild();
-		    			action = DOMUtil.getElementText(el);
+		    		if (EL_ACTION.equals(qname.getLocalPart())) {
+		    			action = getHeaderText(value);
 		        		String[] parts = split(action);
 		        		context.setProperty(Context.INTERFACE, new QName(parts[0], parts[1]));
 		        		context.setProperty(Context.OPERATION, new QName(parts[0], parts[2]));
-		    		} else if (qname.getLocalPart().equals(AddressingInHandler.EL_TO)) {
-		    			Element el = (Element) ((DocumentFragment) value).getFirstChild();
-		    			to = DOMUtil.getElementText(el);
+		    		} else if (EL_TO.equals(qname.getLocalPart())) {
+                        to = getHeaderText(value);
 		        		String[] parts = split(to);
 		        		context.setProperty(Context.SERVICE, new QName(parts[0], parts[1]));
 		        		context.setProperty(Context.ENDPOINT, parts[2]);
@@ -87,6 +93,48 @@
 	    	}
     	}
 	}
+    
+    public void onReply(Context context) throws Exception {
+        SoapMessage in = context.getInMessage();
+        SoapMessage out = context.getOutMessage();
+        Map headers = in.getHeaders();
+        if (headers != null) {
+            for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
+                QName qname = (QName) it.next();
+                Object value = headers.get(qname);
+                if (WSA_NAMESPACE_200303.equals(qname.getNamespaceURI()) ||
+                    WSA_NAMESPACE_200408.equals(qname.getNamespaceURI()) ||
+                    WSA_NAMESPACE_200508.equals(qname.getNamespaceURI())) {
+                    if (EL_MESSAGE_ID.equals(qname.getLocalPart())) {
+                        QName name = new QName(qname.getNamespaceURI(), EL_MESSAGE_ID, qname.getPrefix()
!= null ? qname.getPrefix() : WSA_PREFIX);
+                        DocumentFragment df = createHeader(name, idGenerator.generateSanitizedId());
+                        out.addHeader(name, df);
+                        name = new QName(qname.getNamespaceURI(), EL_RELATES_TO, qname.getPrefix()
!= null ? qname.getPrefix() : WSA_PREFIX);
+                        df = createHeader(name, getHeaderText(value));
+                        out.addHeader(name, df);
+                    }
+                }
+            }
+        }
+    }
+    
+    public void onFault(Context context) throws Exception {
+        
+    }
+    
+    protected String getHeaderText(Object header) {
+        Element el = (Element) ((DocumentFragment) header).getFirstChild();
+        return DOMUtil.getElementText(el);
+    }
+    
+    protected DocumentFragment createHeader(QName name, String value) throws Exception {
+        Document doc = new SourceTransformer().createDocument();
+        DocumentFragment df = doc.createDocumentFragment();
+        Element el = doc.createElementNS(name.getNamespaceURI(), name.getPrefix() + ":" +
name.getLocalPart());
+        el.appendChild(doc.createTextNode(value));
+        df.appendChild(el);
+        return df;
+    }
     
     protected String[] split(String uri) {
 		char sep;



Mime
View raw message