[jboss-svn-commits] JBL Code SVN: r27386 - in labs/jbossesb/trunk/product/rosetta: src/org/jboss/soa/esb/listeners/message and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jul 1 10:04:55 EDT 2009
Author: kevin.conner at jboss.com
Date: 2009-07-01 10:04:55 -0400 (Wed, 01 Jul 2009)
New Revision: 27386
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MissingServiceException.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerUnitTest.java
Log:
Clarify delivery exceptions: JBESB-2097
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java 2009-07-01 13:09:27 UTC (rev 27385)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java 2009-07-01 14:04:55 UTC (rev 27386)
@@ -57,6 +57,7 @@
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.MissingServiceException;
import org.jboss.soa.esb.listeners.message.ResponseTimeoutException;
import org.jboss.soa.esb.listeners.message.errors.Factory;
import org.jboss.soa.esb.message.Message;
@@ -303,7 +304,7 @@
*/
private Message post(Message message, EPRInvoker eprInvoker) throws MessageDeliverException, FaultMessageException {
boolean staleEPRCache = true;
- boolean initialPass = true;
+ boolean timeout = false ;
/*
* Re-attach encrypted SecurityContext to outgoing message.
@@ -334,29 +335,27 @@
if ((serviceClusterInfo.getEPRs().size() == 0) || (new Date().after(expirationDate))) {
loadServiceClusterInfo();
- if (initialPass && (serviceClusterInfo.getEPRs().size() == 0)) // zero from a previous send
+ if (serviceClusterInfo.getEPRs().size() == 0)
{
- /*
- * We need to check to see if this instance used up all of it's attempts to deliver
- * in a previous deliver or we'll only refresh the cache once per subsequent send
- * because we will have exhausted the EPRs in the cache, i.e., size==0.
- *
- * When the instance is originally created we do an initial cache fetch. Until this
- * check, that cache fetch was not being done again after a complete failure. Unlikely
- * to cause problems anyway, but possible.
- */
- initialPass = false;
+ /*
+ * We have just reloaded the cache so a size of 0 means that the service was not located.
+ * We differentiate here by throwing a different exception.
+ */
+ throw new MissingServiceException("Registry details for service [" + service + "] could not be determined from the registry.") ;
}
- else
- staleEPRCache = false;
+ staleEPRCache = false;
}
- Message replyMessage;
EPR epr;
// Iterate over all the EPRs in the list until delivered
while ((epr = loadBalancer.chooseEPR(serviceClusterInfo)) != null) {
try
{
- replyMessage = eprInvoker.attemptDelivery(message, epr);
+ Message replyMessage = null;
+ try {
+ replyMessage = eprInvoker.attemptDelivery(message, epr);
+ } catch (final ResponseTimeoutException rte) {
+ timeout = true ;
+ }
if (replyMessage != null) {
if(eprInvoker.synchronous) {
// remove the security context so that it is not exposed to the action pipeline.
@@ -392,8 +391,13 @@
* then don't do retries even if there are other EPRs in the list.
*/
- if (("true".equals(message.getProperties().getProperty(Environment.EXCEPTION_ON_DELIVERY_FAILURE, "false")) || exceptionOnDeliveryFailure))
- throw new MessageDeliverException("Failed to deliver message ["+message.getHeader()+"] to Service [" + service + "]. Told not to retry.");
+ if (("true".equals(message.getProperties().getProperty(Environment.EXCEPTION_ON_DELIVERY_FAILURE, "false")) || exceptionOnDeliveryFailure)) {
+ if (timeout) {
+ throw new ResponseTimeoutException("No response received for service [" + service + "], Told not to retry.") ;
+ } else {
+ throw new MessageDeliverException("Failed to deliver message ["+message.getHeader()+"] to Service [" + service + "]. Told not to retry.");
+ }
+ }
}
}
catch (MalformedEPRException ex) // so we can differentiate failure modes, since returning null is limiting
@@ -415,7 +419,11 @@
}
// Throw exception if delivery failed...
- throw new MessageDeliverException("Failed to deliver message ["+message.getHeader()+"] to Service [" + service + "]. Check for errors.");
+ if (timeout) {
+ throw new ResponseTimeoutException("No response received for service [" + service + "].") ;
+ } else {
+ throw new MessageDeliverException("Failed to deliver message ["+message.getHeader()+"] to Service [" + service + "]. Check for errors.");
+ }
}
/**
@@ -630,7 +638,11 @@
// do we need to do this for synchronous calls? Vagueries of Couriers?
courier.setReplyToEpr(replyToEPR);
- return courier.pickup(timeout);
+ final Message response = courier.pickup(timeout);
+ if (response == null) {
+ throw new ResponseTimeoutException("No response received within timeout period") ;
+ }
+ return response ;
} else {
return message;
}
@@ -672,6 +684,8 @@
// 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 (final MessageDeliverException mde) {
+ throw mde ;
} catch (Throwable t) {
logger.error("Unexpected throwable during attempted message delivery using Courier for EPR [" + targetEPR + "] for Service [" + service + "] and Message ["+message.getHeader()+"].", t);
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MissingServiceException.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MissingServiceException.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MissingServiceException.java 2009-07-01 14:04:55 UTC (rev 27386)
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+/**
+ * Service has not been located in the registry.
+ */
+
+public class MissingServiceException extends MessageDeliverException
+{
+ /**
+ * The serial version UID for this class.
+ */
+ private static final long serialVersionUID = -7560505311665332064L;
+
+ /**
+ * Construct the exception with the specific message.
+ * @param message The message associated with this exception.
+ */
+ public MissingServiceException(String message)
+ {
+ super(message) ;
+ }
+
+ /**
+ * Construct the exception with the specific message and cause.
+ * @param message The message associated with this exception.
+ * @param cause The cause associated with this exception.
+ */
+ public MissingServiceException(final String message, final Throwable cause)
+ {
+ super(message, cause) ;
+ }
+}
Property changes on: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MissingServiceException.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerUnitTest.java 2009-07-01 13:09:27 UTC (rev 27385)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/ServiceInvokerUnitTest.java 2009-07-01 14:04:55 UTC (rev 27386)
@@ -22,131 +22,119 @@
package org.jboss.soa.esb.listeners;
-import java.io.File;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.Statement;
-import java.util.Properties;
+import java.net.URI;
import junit.framework.TestCase;
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.addressing.eprs.FileEpr;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
+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.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 org.jboss.soa.esb.testutils.FileUtil;
-import org.jboss.soa.esb.testutils.HsqldbUtil;
-import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
public class ServiceInvokerUnitTest extends TestCase
{
- private Logger log = Logger.getLogger( ServiceInvokerUnitTest.class );
+ private String redeliverDlsServiceOn ;
+ private EPR timeoutEPR ;
- protected final void setup()
+ protected final void setUp() throws Exception
{
- try
+ 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)
{
- TestEnvironmentUtil.setESBPropertiesFileToUse("product",
- "../product");
- // Set the juddi properties file in System so juddi will pick it up
- // later and use the test values.
- String juddiPropertiesFile = "/org/jboss/soa/esb/listeners/juddi-unittest.properties";
- System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
- // Read this properties file to get the db connection string
- Properties props = new Properties();
- InputStream inStream = Class.class
- .getResourceAsStream(juddiPropertiesFile);
+ redeliverDlsServiceOn = propertyManager.getProperty(Environment.REDELIVER_DLS_SERVICE_ON) ;
+ propertyManager.setProperty(Environment.REDELIVER_DLS_SERVICE_ON, "false") ;
+ }
+ }
- props.load(inStream);
- mDbDriver = props.getProperty("juddi.jdbcDriver");
- mDbUrl = props.getProperty("juddi.jdbcUrl");
- mDbUsername = props.getProperty("juddi.jdbcUsername");
- mDbPassword = props.getProperty("juddi.jdbcPassword");
-
- String database = "not tested yet";
- if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
+ protected final void tearDown()
+ {
+ final PropertyManager propertyManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
+ if (propertyManager != null)
+ {
+ if (redeliverDlsServiceOn == null)
{
- database = "hsqldb";
- // Bring up hsql on default port 9001
- HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir(
- "product", "../product")
- + "/build/hsqltestdb", "juddi");
+ propertyManager.removeProperty(Environment.REDELIVER_DLS_SERVICE_ON) ;
}
- else if ("com.mysql.jdbc.Driver".equals(mDbDriver))
+ else
{
- database = "mysql";
- } // add and test your own database..
-
- // Get the registry-schema create scripts
- String sqlDir = TestEnvironmentUtil.getUserDir("product",
- "../product")
- + "/install/jUDDI-registry/sql/" + database + "/";
- // Drop what is there now, if exists. We want to start fresh.
- String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir
- + "drop_database.sql")).replaceAll("\\$\\{prefix}", "");
- String resource = "juddi-sql/" + database + "/create_database.sql";
- InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
- String sqlCreateCmd = FileUtil.readStream(is).trim().replaceAll("\\$\\{prefix}", "");
- String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir
- + "import.sql")).trim().replaceAll("\\$\\{prefix}", "");
-
- try
- {
- Class.forName(mDbDriver);
+ propertyManager.setProperty(Environment.REDELIVER_DLS_SERVICE_ON, redeliverDlsServiceOn) ;
}
- catch (Exception e)
- {
- log.error("ERROR: failed to load " + database
- + " JDBC driver.", e);
- return;
- }
- con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
- Statement stmnt = con.createStatement();
- stmnt.execute(sqlDropCmd);
- stmnt.execute(sqlCreateCmd);
- stmnt.execute(sqlInsertPubCmd);
- stmnt.close();
}
- catch (Throwable e)
+ MockRegistry.uninstall();
+ MockCourierFactory.uninstall() ;
+ }
+
+ public void testMissingService() throws Exception
+ {
+ final Message message = MessageFactory.getInstance().getMessage() ;
+ final ServiceInvoker invoker = new ServiceInvoker("missing", "service") ;
+ try
{
- log.error("We should stop testing, since we don't have a db.", e);
- assertTrue(false);
+ invoker.deliverSync(message, 5000) ;
+ fail("Expected MissingServiceException") ;
}
+ catch (final MissingServiceException mse) {} // expected
}
- protected final void tearDown()
+ public void testTimeoutService() throws Exception
{
+ final Message message = MessageFactory.getInstance().getMessage() ;
+ message.getHeader().getCall().setReplyTo(timeoutEPR) ;
+ final ServiceInvoker invoker = new ServiceInvoker("timeout", "service") ;
try
{
- Thread.sleep(1000);
- Statement stmnt = con.createStatement();
+ invoker.deliverSync(message, 5000) ;
+ fail("Expected ResponseTimeoutException") ;
+ }
+ catch (final ResponseTimeoutException rte)
+ {
+ // expected
+ assertFalse("Checking for exception", rte.getMessage().contains("Told not to retry")) ;
+ }
+ }
- stmnt.execute("SHUTDOWN");
- stmnt.close();
-
- con.close();
+ public void testTimeoutServiceNoRetry() throws Exception
+ {
+ final Message message = MessageFactory.getInstance().getMessage() ;
+ message.getHeader().getCall().setReplyTo(timeoutEPR) ;
+ message.getProperties().setProperty(Environment.EXCEPTION_ON_DELIVERY_FAILURE, "true") ;
+ final ServiceInvoker invoker = new ServiceInvoker("timeout", "service") ;
+ try
+ {
+ invoker.deliverSync(message, 5000) ;
+ fail("Expected ResponseTimeoutException") ;
}
- catch (Exception ex)
+ catch (final ResponseTimeoutException rte)
{
- log.error(ex);
+ // expected
+ assertTrue("Checking for exception", rte.getMessage().contains("Told not to retry")) ;
}
}
public void testInvalidParameters() throws Exception
{
- setup();
-
Message message = MessageFactory.getInstance().getMessage();
+ final String category = "test" ;
+ final String name = "qwerty" ;
try
{
- org.jboss.soa.esb.client.ServiceInvoker invoker = new org.jboss.soa.esb.client.ServiceInvoker("foo", "bar");
+ ServiceInvoker invoker = new ServiceInvoker("foo", "bar");
invoker.deliverAsync(message);
fail();
}
@@ -154,68 +142,22 @@
{
}
- final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
- final String tmpDirForm = tmpDir.toURL().toExternalForm();
- FileEpr epr = new FileEpr(tmpDirForm);
+ final EPR epr = new EPR(new URI(category + name));
- epr.setInputSuffix(".testFile");
- epr.setPostDelete(true);
- epr.setPostSuffix(".unitProcessedOK");
+ MockRegistry.register(category, name, epr, new MockCourier(true)) ;
- ConfigTree tree = new ConfigTree("test");
-
- tree.setAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG,
- "eprmanager");
- tree.setAttribute(ListenerTagNames.SERVICE_NAME_TAG, "qwerty");
-
- RegistryUtil.register(tree, epr);
-
- try
{
- ServiceInvoker invoker = new org.jboss.soa.esb.client.ServiceInvoker("eprmanager", "qwerty");
- invoker.deliverAsync(message);
+ ServiceInvoker invoker = new ServiceInvoker(category, name);
+ invoker.deliverAsync(message);
}
- catch (Exception ex)
- {
- fail();
- }
- RegistryUtil.unregister("eprmanager", "qwerty", epr);
+ RegistryUtil.unregister(category, name, epr);
try
{
- ServiceInvoker invoker = new org.jboss.soa.esb.client.ServiceInvoker("eprmanager", "qwerty");
- invoker.deliverAsync(message);
+ ServiceInvoker invoker = new org.jboss.soa.esb.client.ServiceInvoker(category, name);
+ invoker.deliverAsync(message);
}
- catch (Exception ex)
- {
- }
-
- File[] files = tmpDir.listFiles();
-
- for (int i = 0; i < files.length; i++)
- {
- if ((files[i].getName().endsWith(".unitProcessedOK")) ||
- (files[i].getName().equals("qwerty")))
- {
- try
- {
- files[i].delete();
- }
- catch (Exception ex)
- {
- }
- }
- }
+ catch (final MissingServiceException mse) {} // expected
}
-
- private static String mDbDriver;
-
- private static String mDbUrl;
-
- private static String mDbUsername;
-
- private static String mDbPassword;
-
- private static Connection con;
}
More information about the jboss-svn-commits
mailing list