servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r797624 - in /servicemix/components/bindings/servicemix-jms/trunk/src: main/java/org/apache/servicemix/jms/endpoints/ test/java/org/apache/servicemix/jms/
Date Fri, 24 Jul 2009 19:24:27 GMT
Author: gertv
Date: Fri Jul 24 19:24:27 2009
New Revision: 797624

URL: http://svn.apache.org/viewvc?rev=797624&view=rev
Log:
SMXCOMP-604: UnsupportedOperation in JMS Consumer endpoint when using robust-in-only MEP

Added:
    servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsConsumerRobustInOnlyTest.java
  (with props)
Modified:
    servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java
    servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java

Modified: servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java?rev=797624&r1=797623&r2=797624&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java
(original)
+++ servicemix/components/bindings/servicemix-jms/trunk/src/main/java/org/apache/servicemix/jms/endpoints/AbstractConsumerEndpoint.java
Fri Jul 24 19:24:27 2009
@@ -434,7 +434,7 @@
                 throw exchange.getError();
             }
             // For InOnly exchanges, ignore DONE exchanges or those where isRollbackOnError
is false
-            return;
+            return; 
         }
 
         // Create session if needed
@@ -485,6 +485,8 @@
         } else if (exchange.getStatus() == ExchangeStatus.DONE) {
             msg = session.createMessage();
             msg.setBooleanProperty(AbstractJmsMarshaler.DONE_JMS_PROPERTY, true);
+            dest = getReplyDestination(exchange, null, session, context);
+            setCorrelationId(context.getMessage(), msg);
             send(msg, session, dest);
         } else {
             throw new IllegalStateException("Unrecognized exchange status");

Added: servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsConsumerRobustInOnlyTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsConsumerRobustInOnlyTest.java?rev=797624&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsConsumerRobustInOnlyTest.java
(added)
+++ servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsConsumerRobustInOnlyTest.java
Fri Jul 24 19:24:27 2009
@@ -0,0 +1,188 @@
+/*
+ * 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.jms;  
+
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.event.ExchangeEvent;
+import org.apache.servicemix.jbi.helper.MessageExchangePattern;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jms.endpoints.AbstractJmsMarshaler;
+import org.apache.servicemix.jms.endpoints.DefaultConsumerMarshaler;
+import org.apache.servicemix.jms.endpoints.JmsConsumerEndpoint;
+import org.apache.servicemix.tck.ExchangeCompletedListener;
+import org.springframework.jms.core.MessageCreator;
+import org.springframework.jms.listener.DefaultMessageListenerContainer;
+
+public class JmsConsumerRobustInOnlyTest extends AbstractJmsTestSupport {
+
+    private static final String FAULT_MESSAGE = "<fault>This is failing now!</fault>";
+ 
+    protected SourceTransformer sourceTransformer = new SourceTransformer();
+    private List<MessageExchange> exchanges = new LinkedList<MessageExchange>();
+
+    private ExchangeCompletedListener listener;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        listener = new ExchangeCompletedListener(1000) {
+            @Override
+            public void exchangeSent(ExchangeEvent event) {
+                super.exchangeSent(event);
+                
+                exchanges.add(event.getExchange());
+            }
+        };
+        container.addListener(listener);
+        
+        createJmsConsumerEndpoint();
+    }
+    
+    @Override
+    protected void createJmsTemplate() throws Exception {
+        super.createJmsTemplate();
+        
+        jmsTemplate.setReceiveTimeout(5000);
+    }
+    
+    public void testRobustInOnlyDone() throws Exception {
+        createReceiver(Result.done);
+        
+        sendJmsMessage();
+                
+        Message done = jmsTemplate.receive("reply");
+        assertTrue(done.getBooleanProperty(AbstractJmsMarshaler.DONE_JMS_PROPERTY));
+        
+        listener.assertExchangeCompleted();
+        
+        MessageExchange exchange = (MessageExchange) exchanges.get(0);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+    }
+    
+    public void testRobustInOnlyFault() throws Exception {
+        // let's make the RobustInOnly end with a Fault
+        createReceiver(Result.fault);
+        
+        sendJmsMessage();
+
+        TextMessage fault = (TextMessage) jmsTemplate.receive("reply");
+        assertEquals(FAULT_MESSAGE, fault.getText());
+        
+        listener.assertExchangeCompleted();
+        
+        MessageExchange exchange = (MessageExchange) exchanges.get(0);
+        assertEquals(ExchangeStatus.DONE, exchange.getStatus());
+    }
+    
+    public void testRobustInOnlyError() throws Exception {
+        //let's make the RobustInOnly end with an error
+        createReceiver(Result.error);
+        
+        sendJmsMessage();
+        
+        Message error = jmsTemplate.receive("reply");
+        assertTrue(error.getBooleanProperty(AbstractJmsMarshaler.ERROR_JMS_PROPERTY));
+        
+        MessageExchange exchange = (MessageExchange) exchanges.get(0);
+        assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+        
+        listener.assertExchangeCompleted();
+    }
+
+    private void sendJmsMessage() {
+        jmsTemplate.send("destination", new MessageCreator() {
+            public Message createMessage(Session session) throws JMSException {
+                return session.createTextMessage("<hello>world</hello>");
+            }
+        });
+    }
+
+    private void createJmsConsumerEndpoint() throws JBIException {
+        JmsComponent component = new JmsComponent();
+        JmsConsumerEndpoint endpoint = new JmsConsumerEndpoint();
+        endpoint.setService(new QName("jms"));
+        endpoint.setEndpoint("endpoint");
+        endpoint.setTransacted("jms");
+        endpoint.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
+        DefaultConsumerMarshaler marshaler = new DefaultConsumerMarshaler();
+        marshaler.setMep(MessageExchangePattern.ROBUST_IN_ONLY);
+        endpoint.setMarshaler(marshaler);
+        endpoint.setTargetService(new QName("receiver"));
+        endpoint.setConnectionFactory(connectionFactory);
+        endpoint.setDestinationName("destination");
+        endpoint.setReplyDestinationName("reply");
+        component.setEndpoints(new JmsConsumerEndpoint[] {endpoint});
+        container.activateComponent(component, "servicemix-jms");
+    }
+    
+    /*
+     * Creates the RobustInOnly receiver endpoint
+     */
+    private void createReceiver(Result result) throws JBIException {
+        RobustInOnlyReceiver receiver = new RobustInOnlyReceiver();
+        receiver.result = result;
+        receiver.setService(new QName("receiver"));
+        receiver.setEndpoint("endpoint");
+        container.activateComponent(receiver, "receiver");
+    }
+
+    /*
+     * Possible results for the RobustInOnlyReceiver
+     */
+    private enum Result { error, fault, done }
+    
+    // TODO: switch to new interface when moving to a new test container 
+    private static final class RobustInOnlyReceiver extends ComponentSupport implements MessageExchangeListener
{
+        
+        private Result result = Result.done;
+                
+        public void onMessageExchange(MessageExchange exchange) throws MessagingException
{
+            if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                switch (result) {
+                case error:
+                    fail(exchange, new RuntimeException("Uhoh... this is going completely
wrong!"));
+                    break;
+                case fault:
+                    Fault fault = exchange.createFault();
+                    fault.setContent(new StringSource(FAULT_MESSAGE));                
+                    fail(exchange, fault);
+                    break;
+                default:
+                    done(exchange);
+                    break;
+                }
+            }
+        }
+    }
+}

Propchange: servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsConsumerRobustInOnlyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java?rev=797624&r1=797623&r2=797624&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java
(original)
+++ servicemix/components/bindings/servicemix-jms/trunk/src/test/java/org/apache/servicemix/jms/JmsXBeanDeployerTest.java
Fri Jul 24 19:24:27 2009
@@ -162,9 +162,15 @@
         component.getServiceUnitManager().start("xbean");
         
         // Test wsdls
-        assertNotNull(container.getRegistry().getEndpointDescriptor(
-                container.getRegistry().getExternalEndpointsForService(
-                        new QName("http://test", "MyConsumerService"))[0]));
+        ServiceEndpoint[] endpoints = 
+            container.getRegistry().getExternalEndpointsForService(new QName("http://test",
"MyConsumerService"));
+        boolean wsdl = false;
+        for (ServiceEndpoint endpoint : endpoints) {
+            if (container.getRegistry().getEndpointDescriptor(endpoint) != null) {
+                wsdl = true;
+            }
+        }
+        assertTrue("Expected at least one endpoint to have a WSDL endpoint descriptor", wsdl);
         
         // Test
         InOut me = client.createInOutExchange();



Mime
View raw message