[jboss-svn-commits] JBL Code SVN: r25296 - in labs/jbossesb/branches/JBESB_4_4_GA_FP/product: rosetta/src/org/jboss/soa/esb/client and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 16 23:49:31 EST 2009
Author: beve
Date: 2009-02-16 23:49:31 -0500 (Mon, 16 Feb 2009)
New Revision: 25296
Added:
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/IncompatibleTransactionScopeException.java
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ResponseTimeoutException.java
Modified:
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/docs/ProgrammersGuide.odt
labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2407 "Check for invalid synchronous invocations within a transactional context"
Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/docs/ProgrammersGuide.odt
===================================================================
(Binary files differ)
Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java 2009-02-17 04:18:52 UTC (rev 25295)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java 2009-02-17 04:49:31 UTC (rev 25296)
@@ -25,6 +25,7 @@
import javax.crypto.SealedObject;
+
import org.apache.log4j.Logger;
import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
import org.jboss.internal.soa.esb.assertion.AssertArgument;
@@ -38,11 +39,14 @@
import org.jboss.soa.esb.common.Configuration;
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.common.TransactionStrategyException;
import org.jboss.soa.esb.couriers.Courier;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.couriers.CourierMarshalUnmarshalException;
import org.jboss.soa.esb.couriers.CourierServiceBindException;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
import org.jboss.soa.esb.couriers.CourierTransportException;
import org.jboss.soa.esb.couriers.CourierUtil;
import org.jboss.soa.esb.couriers.FaultMessageException;
@@ -51,7 +55,9 @@
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.message.IncompatibleTransactionScopeException;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.listeners.message.ResponseTimeoutException;
import org.jboss.soa.esb.listeners.message.errors.Factory;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.util.Type;
@@ -295,7 +301,7 @@
private Message post(Message message, EPRInvoker eprInvoker) throws MessageDeliverException, FaultMessageException {
boolean staleEPRCache = true;
boolean initialPass = true;
-
+
/*
* Re-attach encrypted SecurityContext to outgoing message.
*/
@@ -582,9 +588,26 @@
try {
call.setTo(targetEPR);
- final EPR replyToEPR ;
+ EPR replyToEPR ;
if (synchronous) {
replyToEPR = (currentReplyToEpr == null ? getReplyToAddress(targetEPR) : currentReplyToEpr) ;
+ /*
+ * Currently all couriers that have transactional semantics work in a manner similar
+ * to JMS, i.e., messages are not delivered on to a queue (or to an endpoint) until
+ * the enclosing transaction has committed. In a synchronous invocation this will
+ * result in timeouts if the sending thread is also the terminating thread. We check
+ * for this here and throw an exception before we try to do a send so the application can
+ * figure it out.
+ *
+ * Note: if the transactional semantics change (e.g., to support true distributed transactions)
+ * then this will need to be modified too.
+ */
+
+ if (isTransactional())
+ throw new IncompatibleTransactionScopeException("Request-response attempt within running transaction controlling request delivery! Using epr [" + targetEPR + "] for Service [" + service + "] and Message ["+message.getHeader()+"]");
+
+ if (replyToEPR == null)
+ replyToEPR = getReplyToAddress(targetEPR);
if (replyToEPR == null) {
logger.debug("Not using epr [" + targetEPR + "] for Service [" + service + "] and Message ["+message.getHeader()+"]. No reply-to address available for synchronous response.");
@@ -632,6 +655,14 @@
logger.error("Unexpected error. Badly formed EPR [" + targetEPR + "] for Service [" + service + "]. But the EPR has already been validated!!");
throw e;
+ } catch (final CourierTimeoutException ex) {
+ logger.error("Response timeout using Courier for EPR [" + targetEPR + "] for Service [" + service + "] and Message ["+message.getHeader()+"].");
+
+ // timeout from synchronous invocation
+
+ // would like to make this an independent exception (not inherit from MDE). But signatures and applications would break.
+
+ throw new ResponseTimeoutException("Caught response timeout!", ex);
} catch (Throwable t) {
logger.error("Unexpected throwable during attempted message delivery using Courier for EPR [" + targetEPR + "] for Service [" + service + "] and Message ["+message.getHeader()+"].", t);
@@ -652,6 +683,37 @@
}
}
+ private boolean isTransactional() throws MessageDeliverException
+ {
+ boolean transactional;
+
+ try
+ {
+ TransactionStrategy txStrategy = TransactionStrategy.getTransactionStrategy(true);
+ Object txHandle = ((txStrategy == null) ? null : txStrategy.getTransaction());
+ boolean isActive = ((txStrategy == null) ? false : txStrategy.isActive());
+
+ transactional = (txHandle != null);
+
+ /*
+ * Make sure the current transaction is still active! If we
+ * have previously slept, then the timeout may be longer than that
+ * associated with the transaction.
+ */
+
+ if (transactional && !isActive)
+ {
+ throw new MessageDeliverException("Associated transaction is no longer active!");
+ }
+ }
+ catch (final TransactionStrategyException ex)
+ {
+ throw new MessageDeliverException("Could not determine transactionality.", ex);
+ }
+
+ return transactional;
+ }
+
static
{
String pruneDead = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE).getProperty(Environment.REMOVE_DEAD_EPR, "false");
Added: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/IncompatibleTransactionScopeException.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/IncompatibleTransactionScopeException.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/IncompatibleTransactionScopeException.java 2009-02-17 04:49:31 UTC (rev 25296)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.message;
+
+import org.jboss.soa.esb.BaseException;
+
+/**
+ * If a user attempts to use a request-response MEP while within the
+ * scope of a transaction then the request won't be sent until the transaction
+ * commits, which can't happen if the sender thread is blocked. Rather than wait for
+ * a timeout to occur we spot this incompatibility at send time and throw this
+ * exception. The application can then take appropriate action.
+ */
+
+public class IncompatibleTransactionScopeException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+
+ public IncompatibleTransactionScopeException(String message) {
+ super(message);
+ }
+
+ public IncompatibleTransactionScopeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
Added: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ResponseTimeoutException.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ResponseTimeoutException.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ResponseTimeoutException.java 2009-02-17 04:49:31 UTC (rev 25296)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.message;
+
+/**
+ * Timeout on response.
+ */
+
+public class ResponseTimeoutException extends MessageDeliverException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ResponseTimeoutException(String message) {
+ super(message);
+ }
+
+ public ResponseTimeoutException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
More information about the jboss-svn-commits
mailing list