[jboss-svn-commits] JBL Code SVN: r38074 - in labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta: src/org/jboss/soa/esb/common and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue May 8 12:24:40 EDT 2012
Author: tcunning
Date: 2012-05-08 12:24:40 -0400 (Tue, 08 May 2012)
New Revision: 38074
Added:
labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerErrorUnitTest.java
Modified:
labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
Log:
JBESB-3794
If MessageDeliveryException occurs in deliverSync or deliverAsync, throw
a RuntimeException if isTransactional() and org.jboss.soa.esb.serviceInvokerRollbackOnException is set in jbossesb-propertis.xml.
is set in jbossesb-properties.xml.
Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java 2012-05-08 12:31:59 UTC (rev 38073)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java 2012-05-08 16:24:40 UTC (rev 38074)
@@ -57,6 +57,7 @@
import org.jboss.soa.esb.listeners.ha.LoadBalancePolicy;
import org.jboss.soa.esb.listeners.ha.ServiceClusterInfo;
import org.jboss.soa.esb.listeners.ha.ServiceClusterInfoImpl;
+import org.jboss.soa.esb.listeners.jca.JcaGatewayException;
import org.jboss.soa.esb.listeners.message.IncompatibleTransactionScopeException;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.listeners.message.MissingServiceException;
@@ -218,7 +219,16 @@
try {
message = post(message, new EPRInvoker(timeoutMillis));
} catch (MessageDeliverException mde) {
- if (asyncRedelivery(message) && !service.equals(dlqService)) {
+
+ String rollback = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).
+ getProperty(Environment.SI_ROLLBACK_ON_EXCEPTION, "false");
+
+ // We want to trigger JCA rollback in case of messagedeliver exception
+ if ("true".equals(rollback) && (isTransactional())) {
+ throw new JcaGatewayException(mde);
+ }
+
+ if (asyncRedelivery(message) && !service.equals(dlqService)) {
//Send a copy to the DLQ, no retries for syncDeliveries
message.getProperties().setProperty(DELIVER_TO, service);
@@ -252,8 +262,16 @@
// Not interested in a reply
try {
post(message, new EPRInvoker());
- } catch (MessageDeliverException mde) {
- if (message.getProperties().getProperty(RedeliverStore.IS_REDELIVERY)==null
+ } catch (MessageDeliverException mde) {
+ String rollback = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).
+ getProperty(Environment.SI_ROLLBACK_ON_EXCEPTION, "false");
+
+ // We want to trigger JCA rollback in case of messagedeliver exception
+ if ("true".equals(rollback) && (isTransactional())) {
+ throw new JcaGatewayException(mde);
+ }
+
+ if (message.getProperties().getProperty(RedeliverStore.IS_REDELIVERY)==null
&& asyncRedelivery(message)
&& !service.equals(dlqService)) {
message.getProperties().setProperty(MessageStore.CLASSIFICATION, MessageStore.CLASSIFICATION_RDLVR);
Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java 2012-05-08 12:31:59 UTC (rev 38073)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java 2012-05-08 16:24:40 UTC (rev 38074)
@@ -89,7 +89,10 @@
public static final String REGISTRY_CACHE_LIFE_MILLIS = "org.jboss.soa.esb.registry.cache.life";
public static final String REMOVE_DEAD_EPR = "org.jboss.soa.esb.failure.detect.removeDeadEPR";
public static final String EXCEPTION_ON_DELIVERY_FAILURE = "org.jboss.soa.esb.exceptionOnDeliverFailure";
+ public static final String SI_ROLLBACK_ON_EXCEPTION = "org.jboss.soa.esb.serviceInvokerRollbackOnException";
+
+
/**
* Processing pipeline interceptors.
*/
Added: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerErrorUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerErrorUnitTest.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerErrorUnitTest.java 2012-05-08 16:24:40 UTC (rev 38074)
@@ -0,0 +1,165 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.rosetta.pooling.MockTransactionStrategy;
+
+import org.jboss.internal.soa.esb.couriers.MockCourier;
+import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.client.ServiceInvoker;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.common.TransactionStrategy;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.message.MissingServiceException;
+import org.jboss.soa.esb.listeners.message.ResponseTimeoutException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+public class ServiceInvokerErrorUnitTest extends TestCase
+{
+ private String redeliverDlsServiceOn ;
+ private EPR timeoutEPR ;
+
+ protected final void setUp() throws Exception
+ {
+ MockCourierFactory.install() ;
+ MockRegistry.install() ;
+ timeoutEPR = new EPR(new URI("timeout")) ;
+ MockRegistry.register("timeout", "service", timeoutEPR, new MockCourier(true)) ;
+ final PropertyManager propertyManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
+ if (propertyManager != null)
+ {
+ redeliverDlsServiceOn = propertyManager.getProperty(Environment.REDELIVER_DLS_SERVICE_ON) ;
+ propertyManager.setProperty(Environment.REDELIVER_DLS_SERVICE_ON, "false") ;
+ propertyManager.setProperty(Environment.SI_ROLLBACK_ON_EXCEPTION, "true");
+ }
+
+ MockTransactionStrategy.isActive = true;
+ MockTransactionStrategy.transactionObject = new String("foo");
+ try {
+ TransactionStrategy.setTransactionStrategy(new MockTransactionStrategy());
+ } catch (Exception e) {
+ }
+ }
+
+ protected final void tearDown()
+ {
+
+ TransactionStrategy txStrategy = TransactionStrategy.getTransactionStrategy(true);
+ try {
+ txStrategy.rollbackOnly();
+ txStrategy.terminate();
+ } catch (Exception e) {
+ }
+
+ final PropertyManager propertyManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
+ if (propertyManager != null)
+ {
+ if (redeliverDlsServiceOn == null)
+ {
+ propertyManager.removeProperty(Environment.REDELIVER_DLS_SERVICE_ON) ;
+ }
+ else
+ {
+ propertyManager.setProperty(Environment.REDELIVER_DLS_SERVICE_ON, redeliverDlsServiceOn) ;
+ }
+ }
+ MockRegistry.uninstall();
+ MockCourierFactory.uninstall() ;
+ }
+
+ public void testRollbackOnExceptionOn() throws Exception
+ {
+ final PropertyManager propertyManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
+ propertyManager.setProperty(Environment.SI_ROLLBACK_ON_EXCEPTION, "true");
+
+ Message message = MessageFactory.getInstance().getMessage();
+ final String category = "test" ;
+ final String name = "qwerty" ;
+
+ int foo = 0;
+ try
+ {
+ ServiceInvoker invoker = new ServiceInvoker("foo", "bar");
+ invoker.deliverAsync(message);
+ fail();
+ }
+ catch (MessageDeliverException ex)
+ {
+ fail();
+ }
+ catch (RuntimeException re) {
+ foo = 1;
+ }
+
+ assertEquals(foo, 1);
+ }
+
+ public void testRollbackOnExceptionOff() throws Exception
+ {
+ final PropertyManager propertyManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
+ propertyManager.setProperty(Environment.SI_ROLLBACK_ON_EXCEPTION, "false");
+
+ Message message = MessageFactory.getInstance().getMessage();
+ final String category = "test" ;
+ final String name = "qwerty" ;
+
+ try
+ {
+ ServiceInvoker invoker = new ServiceInvoker("foo", "bar");
+ invoker.deliverAsync(message);
+ fail();
+ }
+ catch (MessageDeliverException ex)
+ {
+ }
+
+ final EPR epr = new EPR(new URI(category + name));
+
+ MockRegistry.register(category, name, epr, new MockCourier(true)) ;
+
+ {
+ ServiceInvoker invoker = new ServiceInvoker(category, name);
+ invoker.deliverAsync(message);
+ }
+
+ RegistryUtil.unregister(category, name, epr);
+
+ try
+ {
+ ServiceInvoker invoker = new org.jboss.soa.esb.client.ServiceInvoker(category, name);
+ invoker.deliverAsync(message);
+ }
+ catch (final MissingServiceException mse) {} // expected
+ }
+}
More information about the jboss-svn-commits
mailing list