[jboss-svn-commits] JBL Code SVN: r13980 - in labs/jbossesb/trunk/product/rosetta: src/org/jboss/soa/esb/couriers and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 3 05:08:50 EDT 2007
Author: mark.little at jboss.com
Date: 2007-08-03 05:08:50 -0400 (Fri, 03 Aug 2007)
New Revision: 13980
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/FaultMessageException.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/TwoWayCourier.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ServiceInvoker.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FileCourierUnitTest.java
Log:
http://jira.jboss.com/jira/browse/JBESB-639
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2007-08-03 08:31:34 UTC (rev 13979)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/FileCourier.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -43,8 +43,11 @@
import org.jboss.soa.esb.common.Environment;
import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.couriers.FaultMessageException;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.util.Type;
import org.jboss.soa.esb.util.FileUtil;
import org.jboss.soa.esb.util.Util;
@@ -255,7 +258,7 @@
} // ________________________________
- public Message pickup(long millis) throws CourierException
+ public Message pickup(long millis) throws CourierException, CourierTimeoutException
{
Message result = null;
long limit = System.currentTimeMillis()
@@ -291,6 +294,14 @@
else
handler.renameFile(work, done);
+ /*
+ * If this is fault message, then throw an exception with the contents. With the
+ * exception of user-defined exceptions, faults will have nothing in the body, properties etc.
+ */
+
+ if (Type.isFaultMessage(result))
+ throw new FaultMessageException(result.getFault().getReason(), result.getFault().getCode());
+
return result;
}
try
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2007-08-03 08:31:34 UTC (rev 13979)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/JmsCourier.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -49,9 +49,12 @@
import org.jboss.soa.esb.addressing.MalformedEPRException;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
+import org.jboss.soa.esb.couriers.FaultMessageException;
import org.jboss.soa.esb.helpers.KeyValuePair;
import org.jboss.soa.esb.helpers.NamingContext;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.util.Type;
import org.jboss.soa.esb.util.Util;
import org.xml.sax.SAXException;
@@ -302,7 +305,7 @@
}
} // ________________________________
- public Message pickup (long millis) throws CourierException
+ public Message pickup (long millis) throws CourierException, CourierTimeoutException
{
if (!_isReceiver)
throw new CourierException("This is an outgoing-only Courier");
@@ -356,6 +359,14 @@
Message msg = Util.deserialize(obj);
+ /*
+ * If this is fault message, then throw an exception with the contents. With the
+ * exception of user-defined exceptions, faults will have nothing in the body, properties etc.
+ */
+
+ if (Type.isFaultMessage(msg))
+ throw new FaultMessageException(msg.getFault().getReason(), msg.getFault().getCode());
+
return msg;
}
catch (JMSException e1)
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java 2007-08-03 08:31:34 UTC (rev 13979)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -35,9 +35,12 @@
import org.jboss.soa.esb.addressing.MalformedEPRException;
import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.couriers.CourierTimeoutException;
+import org.jboss.soa.esb.couriers.FaultMessageException;
import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
import org.jboss.soa.esb.helpers.persist.SimpleDataSource;
import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.util.Type;
import org.jboss.soa.esb.util.Util;
import org.xml.sax.SAXParseException;
@@ -187,7 +190,7 @@
return false;
} // ________________________________
- public Message pickup(long millis) throws CourierException
+ public Message pickup(long millis) throws CourierException, CourierTimeoutException
{
Message result = null;
long limit = System.currentTimeMillis()
@@ -203,6 +206,14 @@
if (null == (result = tryToPickup(messageId)))
continue;
+ /*
+ * If this is fault message, then throw an exception with the contents. With the
+ * exception of user-defined exceptions, faults will have nothing in the body, properties etc.
+ */
+
+ if (Type.isFaultMessage(result))
+ throw new FaultMessageException(result.getFault().getReason(), result.getFault().getCode());
+
return result;
}
}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/FaultMessageException.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/FaultMessageException.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/FaultMessageException.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -0,0 +1,60 @@
+/*
+ * 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.couriers;
+
+import java.net.URI;
+
+/**
+ * The service encountered an error and returned a Fault message. This
+ * is received and then thrown as an exception.
+ *
+ * @since Version 4.2
+ */
+
+public class FaultMessageException extends CourierException
+{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct an exception instance.
+ *
+ * @param message
+ * Exception message.
+ */
+
+ public FaultMessageException (String message, URI code)
+ {
+ super(message);
+
+ _code = code;
+ }
+
+ public final URI getCode ()
+ {
+ return _code;
+ }
+
+ private URI _code;
+
+}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/TwoWayCourier.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/TwoWayCourier.java 2007-08-03 08:31:34 UTC (rev 13979)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/couriers/TwoWayCourier.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -34,7 +34,7 @@
*
* @param waitTime - Pickup timeout for before giving up on this pickup. Time in millis.
* @return - the message that was picked up.
- * @throws CourierException the courier fails (i.e. gets a flat tire).
+ * @throws CourierException the courier fails (e.g., gets a flat tire).
* @throws CourierTimeoutException if the pickup timed out (nobody home).
*/
public Message pickup(long waitTime) throws CourierException, CourierTimeoutException;
@@ -44,7 +44,7 @@
* @param waitTime - Pickup timeout for before giving up on this pickup. Time in millis.
* @param epr - Pickup address
* @return - the message that was picked up.
- * @throws CourierException the courier fails (i.e. gets a flat tire).
+ * @throws CourierException the courier fails (e.g., gets a flat tire).
* @throws CourierTimeoutException if the pickup timed out (nobody home).
*/
public Message pickup(long waitTime, EPR epr) throws CourierException, CourierTimeoutException, MalformedEPRException;
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ServiceInvoker.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ServiceInvoker.java 2007-08-03 08:31:34 UTC (rev 13979)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/ServiceInvoker.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -37,6 +37,7 @@
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.couriers.FaultMessageException;
import org.jboss.soa.esb.couriers.TwoWayCourier;
import org.jboss.soa.esb.listeners.RegistryUtil;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
@@ -129,7 +130,7 @@
* @throws MessageDeliverException
* @throws RegistryException
*/
- public Message deliverOne (Message message) throws MessageDeliverException, RegistryException
+ public Message deliverOne (Message message) throws MessageDeliverException, RegistryException, FaultMessageException
{
try {
deliverAsync(message);
@@ -161,7 +162,7 @@
* without error, otherwise an exception is thrown.
* @throws MessageDeliverException Failed to deliver message, after trying all available EPRs.
*/
- public Message deliverSync(Message message, long timeoutMillis) throws MessageDeliverException, RegistryException {
+ public Message deliverSync(Message message, long timeoutMillis) throws MessageDeliverException, RegistryException, FaultMessageException {
if (message == null)
throw new IllegalArgumentException();
@@ -180,7 +181,15 @@
throw new IllegalArgumentException();
// Not interested in a reply
- post(message, false);
+
+ try
+ {
+ post(message, false);
+ }
+ catch (FaultMessageException ex)
+ {
+ throw new MessageDeliverException("Unexpected FaultMessageException");
+ }
}
/**
@@ -192,7 +201,7 @@
* without error, otherwise an exception is thrown.
* @throws MessageDeliverException Failed to deliver message, after trying all available EPRs.
*/
- private Message post(Message message, boolean synchronous) throws MessageDeliverException
+ private Message post(Message message, boolean synchronous) throws MessageDeliverException, FaultMessageException
{
int numberOfAttemps=0;
while (numberOfAttemps++ < 2) {
@@ -245,7 +254,7 @@
* @return Returns the message (or a reply message if synchronous) if the message was delivered
* without error, otherwise null.
*/
- private Message attemptDelivery(Message message, EPR epr, boolean synchronous) {
+ private Message attemptDelivery(Message message, EPR epr, boolean synchronous) throws FaultMessageException {
TwoWayCourier courier = null;
// Get a courier for the EPR...
@@ -284,6 +293,8 @@
return message;
}
}
+ } catch (FaultMessageException e) {
+ throw e;
} catch (CourierException e) {
logger.debug("Badly formed EPR [" + epr + "] for Service [" + serviceCategory + ":" + serviceName + "]. " + e.getMessage());
} catch (MalformedEPRException e) {
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java 2007-08-03 08:31:34 UTC (rev 13979)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/UncomposedMessageDeliveryAdapter.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -21,9 +21,9 @@
import org.jboss.internal.soa.esb.assertion.AssertArgument;
import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.couriers.FaultMessageException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.*;
-import org.jboss.soa.esb.listeners.ServiceInvoker;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.registry.RegistryException;
@@ -81,7 +81,7 @@
* ({@link MessageComposer#decompose(org.jboss.soa.esb.message.Message) decomposed}).
* @throws MessageDeliverException Failed to deliverAsync message, after trying all available EPRs.
*/
- public Object deliverSync(Object messagePayload, long timeoutMillis) throws MessageDeliverException, RegistryException {
+ public Object deliverSync(Object messagePayload, long timeoutMillis) throws MessageDeliverException, RegistryException, FaultMessageException {
// Deliver the message...
Message message = deliverSyncWithoutDecomposing(messagePayload, timeoutMillis);
@@ -99,7 +99,7 @@
* @return The reply {@link Message}. The caller must decompose the message.
* @throws MessageDeliverException Failed to deliverAsync message, after trying all available EPRs.
*/
- public Message deliverSyncWithoutDecomposing(Object messagePayload, long timeoutMillis) throws MessageDeliverException, RegistryException {
+ public Message deliverSyncWithoutDecomposing(Object messagePayload, long timeoutMillis) throws MessageDeliverException, RegistryException, FaultMessageException {
AssertArgument.isNotNull(messagePayload, "messagePayload");
Message message = composer.compose(messagePayload);
Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FileCourierUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FileCourierUnitTest.java 2007-08-03 08:31:34 UTC (rev 13979)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/FileCourierUnitTest.java 2007-08-03 09:08:50 UTC (rev 13980)
@@ -36,8 +36,10 @@
import org.jboss.soa.esb.addressing.eprs.FileEpr;
import org.jboss.soa.esb.common.Environment;
import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.couriers.CourierUtil;
+import org.jboss.soa.esb.couriers.FaultMessageException;
import org.jboss.soa.esb.couriers.TwoWayCourier;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
@@ -155,6 +157,56 @@
}
@Test
+ public void testFaultMessage () throws Exception
+ {
+ // toEpr for files must be a directory
+ FileEpr toEpr = new FileEpr(_tmpDir.toURL());
+ toEpr.setInputSuffix(TEST_SUFFIX);
+
+ Message msg = MessageFactory.getInstance().getMessage();
+ String errorMessage = "Some failure occurred!";
+ URI code = new URI("urn:errorcode");
+
+ msg.getFault().setReason(errorMessage);
+ msg.getFault().setCode(code);
+
+ Call call = new Call(toEpr);
+ String uid = UUID.randomUUID().toString();
+ call.setMessageID(new URI(uid));
+ msg.getHeader().setCall(call);
+
+ CourierUtil.deliverMessage(msg);
+
+ File theFile = new File(_tmpDir,uid+TEST_SUFFIX);
+ Assert.assertTrue(theFile.exists());
+ _logger.info("Message file "+theFile.toString()+" successfully created");
+
+ FileEpr fromEpr = new FileEpr(toEpr.getURL());
+ fromEpr.setInputSuffix(TEST_SUFFIX);
+ fromEpr.setPostSuffix(DONE_SUFFIX);
+
+ TwoWayCourier pickUp = CourierFactory.getPickupCourier(fromEpr);
+
+ try
+ {
+ Message retrieved = pickUp.pickup(1000);
+
+ Assert.fail();
+ }
+ catch (FaultMessageException ex)
+ {
+ Assert.assertEquals(ex.getMessage(), errorMessage);
+ Assert.assertEquals(ex.getCode(), code);
+ }
+ catch (CourierException ex)
+ {
+ Assert.fail();
+ }
+
+ purgeStaleFiles();
+ }
+
+ @Test
public void testStoreRetrieve() throws Exception
{
String contents = "This is the text that travels in the Message body";
More information about the jboss-svn-commits
mailing list