[jboss-svn-commits] JBL Code SVN: r15701 - in labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults: src/org/jboss/soa/esb/samples/quickstart/exceptions and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 9 22:25:47 EDT 2007
Author: burrsutter
Date: 2007-10-09 22:25:47 -0400 (Tue, 09 Oct 2007)
New Revision: 15701
Modified:
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/build.xml
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/jboss-esb.xml
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/readme.txt
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/JustAnotherAction.java
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyBasicAction.java
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyExceptionHandlingAction.java
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessage.java
labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessageSync.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1149
http://jira.jboss.com/jira/browse/JBESB-825
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/build.xml 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/build.xml 2007-10-10 02:25:47 UTC (rev 15701)
@@ -35,7 +35,7 @@
<java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.exceptions.test.SendEsbMessageSync" failonerror="true">
<arg value="ExceptionalServices"/>
<arg value="LostMessageService"/>
- <arg value="NO Gateway: Sync No Catch"/>
+ <arg value="NO Gateway: Sync w catch in client-side"/>
<classpath refid="exec-classpath"/>
</java>
</target>
@@ -56,7 +56,7 @@
<java fork="yes" classname="org.jboss.soa.esb.samples.quickstart.exceptions.test.SendEsbMessageSync" failonerror="true">
<arg value="ExceptionalServices"/>
<arg value="ExceptionCaughtService"/>
- <arg value="NO Gateway: Sync w/Catch"/>
+ <arg value="NO Gateway: Sync w/catch in server-side"/>
<classpath refid="exec-classpath"/>
</java>
</target>
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/jboss-esb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/jboss-esb.xml 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/jboss-esb.xml 2007-10-10 02:25:47 UTC (rev 15701)
@@ -61,12 +61,13 @@
process="displayMessage" >
</action>
<action name="Bad Action" class="org.jboss.soa.esb.samples.quickstart.exceptions.MyBasicAction"
- process="causesException" >
+ process="causesMyException" >
</action>
- <action name="Final Good Action" class="org.jboss.soa.esb.samples.quickstart.exceptions.MyBasicAction"
+ <action name="Final Good Action" class="org.jboss.soa.esb.samples.quickstart.exceptions.JustAnotherAction"
process="displayMessage" >
</action>
- </actions>
+ </actions>
+
</service>
<service category="ExceptionalServices"
name="ExceptionCaughtService"
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/readme.txt 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/readme.txt 2007-10-10 02:25:47 UTC (rev 15701)
@@ -1,8 +1,9 @@
Overview:
=========
- The purpose of the custom_action quickstart example is to show different ways of
- using Action classes.
+ The purpose of the exceptions_faults quickstart example is to demonstrate
+ how to handle exceptions in your action chains and service invocations.
+
Running this quickstart:
========================
Please refer to 'ant help-quickstarts' for prerequisites about the quickstarts
@@ -26,7 +27,64 @@
'ant runtest'.
3. Switch back to Application Server console to see the output from the ESB
4. In this folder ("Window1"), type 'ant undeploy'.
-
+
Things to Consider:
===================
+ This quickstart illustrates the use of JMS message selectors:
+ <jms-bus busid="ExceptionCaughtServiceGW">
+ <jms-message-filter
+ dest-type="QUEUE"
+ dest-name="queue/quickstart_exceptions_faults_GW"
+ selector="serviceName='ExceptionCaughtService'"
+ />
+
+ </jms-bus>
+ <jms-bus busid="ExceptionCaughtServiceESB">
+ <jms-message-filter
+ dest-type="QUEUE"
+ dest-name="queue/quickstart_exceptions_faults_ESB"
+ selector="serviceName='ExceptionCaughtService'"
+ />
+ </jms-bus>
+
+ Note: the matching selector for the gateway + native listener pairing.
+
+ You should carefully review the jboss-esb.xml. It has two services:
+ LostMessageService and ExceptionCaughtService.
+ The LostMessageService is aptly named because the user did not attempt to
+ "catch" exceptions in the action chain therefore they are unaware that an
+ error occurred.
+ Also review the build.xml, it has runtest, runtest2, callAsync, callAsync2,
+ callSync and callSync2 targets. The 2's are for the ExceptionCaughtService.
+ The goal is to illustrate the differences in behavior depending on if you
+ are making an asynchronous (gateways are always async) or
+ synchronous invocation (ServiceInvoker allows both options).
+
+ 1. ant runtest/callAsync: sends in a JMS message via the JMS gateway which in turn hands
+ it off to a JMS listener (esb aware/native listener). The execution of the action chain
+ causes an exception:
+ <action name="Bad Action" class="org.jboss.soa.esb.samples.quickstart.exceptions.MyBasicAction"
+ process="causesException" >
+ </action>
+
+ public Message causesException(Message message) throws ActionProcessingException {
+ System.out.println("About to cause an exception");
+ throw new ActionProcessingException("BAD STUFF HAPPENED");
+ }
+ You should note that JustAnotherAction is never reached:
+ <action name="Final Good Action"
+ class="org.jboss.soa.esb.samples.quickstart.exceptions.JustAnotherAction"
+ process="displayMessage" >
+ </action>
+ 2. Your custom buiness logic exceptions will be wrapped by an ActionProcessingException but still
+ be available on the client-side when using the
+ ServiceInvoker.deliverSync(String myMessage,int timeout) option.
+ SendEsbMessageSync.java demostrates ths when you run "ant callSync".
+
+ 3. The ExceptionCaughtService service demonstrates how the action chain is "unwound" when an
+ exception is thrown downstream. In this case, JustAnotherAction & MyExceptionHandlingAction will
+ both have their exceptionMethod's triggered by the "Bad Action".
+
+ 4. ant callSync2: demonstrates that an exception within the action chain, that is handled
+ by the service is still propagated back to the client invoker.
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/JustAnotherAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/JustAnotherAction.java 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/JustAnotherAction.java 2007-10-10 02:25:47 UTC (rev 15701)
@@ -29,9 +29,9 @@
{
public Message displayMessage(Message message) throws ActionProcessingException {
- String content = new String(message.getBody().getByteArray());
- message.getBody().setByteArray(new String(content + " |JUST_ANOTHER_ACTION| ").getBytes());;
- String newContent = new String(message.getBody().getByteArray());
+ String content = (String) message.getBody().get();
+ message.getBody().add(content + " |JUST_ANOTHER_ACTION| ");;
+ String newContent = (String) message.getBody().get();
logHeader();
System.out.println("JustAnotherAction Body: " + newContent);
logFooter();
@@ -40,7 +40,7 @@
}
public void exceptionHandler(Message message, Throwable exception) {
- String content = new String(message.getBody().getByteArray());
+ String content = (String) message.getBody().get();
logHeader();
System.out.println("JustAnotherAction exceptionHandler:\n " + content);
logFooter();
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyBasicAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyBasicAction.java 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyBasicAction.java 2007-10-10 02:25:47 UTC (rev 15701)
@@ -24,6 +24,7 @@
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.samples.quickstart.exceptions.MyBusinessException;
public class MyBasicAction extends AbstractActionLifecycle
{
@@ -38,9 +39,9 @@
}
public Message displayMessage(Message message) throws ActionProcessingException {
- String content = new String(message.getBody().getByteArray());
- message.getBody().setByteArray(new String(content + " |BASIC_ACTION| ").getBytes());
- String newContent = new String(message.getBody().getByteArray());
+ String content = (String) message.getBody().get();
+ message.getBody().add(content + " |BASIC_ACTION| ");
+ String newContent = (String) message.getBody().get();
logHeader();
System.out.println("MyBasicAction Body: " + newContent);
logFooter();
@@ -48,9 +49,22 @@
}
public Message causesException(Message message) throws ActionProcessingException {
+ System.out.println("About to cause an exception");
throw new ActionProcessingException("BAD STUFF HAPPENED");
}
+ public Message causesMyException(Message message) throws ActionProcessingException {
+ System.out.println("About to cause an exception");
+ try {
+ // some logic that bubbles up MyBusinessException
+ throw new MyBusinessException("Business Logic Violation");
+ } catch (MyBusinessException mbe) {
+ System.out.println(mbe.getMessage());
+ throw new ActionProcessingException(mbe);
+ }
+ // return message; // unreachable due to the way this demo code is setup
+ }
+
// This makes it easier to read on the console
private void logHeader() {
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyExceptionHandlingAction.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyExceptionHandlingAction.java 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/MyExceptionHandlingAction.java 2007-10-10 02:25:47 UTC (rev 15701)
@@ -29,9 +29,9 @@
{
public Message displayMessage(Message message) throws ActionProcessingException {
- String content = new String(message.getBody().getByteArray());
- message.getBody().setByteArray(new String(content + " |EXCEPTION_HANDLING| ").getBytes());;
- String newContent = new String(message.getBody().getByteArray());
+ String content = (String) message.getBody().get();
+ message.getBody().add(content + " |EXCEPTION_HANDLING| ");
+ String newContent = (String) message.getBody().get();
logHeader();
System.out.println("MyExceptionHandlingAction Body: " + newContent);
logFooter();
@@ -39,7 +39,7 @@
}
public void catchesException(Message message, Throwable exception) {
- String content = new String(message.getBody().getByteArray());
+ String content = (String) message.getBody().get();
logHeader();
System.out.println("MyExceptionHandlingAction catchesException:\n " + content);
logFooter();
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessage.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessage.java 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessage.java 2007-10-10 02:25:47 UTC (rev 15701)
@@ -60,7 +60,7 @@
ServiceInvoker invoker = new ServiceInvoker(category,serviceName);
Message requestMessage;
requestMessage = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
- requestMessage.getBody().setByteArray(msgText.getBytes());
+ requestMessage.getBody().add(msgText);
try {
invoker.deliverAsync(requestMessage); // no waiting for a response
} catch (Exception e) {
Modified: labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessageSync.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessageSync.java 2007-10-10 00:19:17 UTC (rev 15700)
+++ labs/jbossesb/trunk/product/samples/quickstarts/exceptions_faults/src/org/jboss/soa/esb/samples/quickstart/exceptions/test/SendEsbMessageSync.java 2007-10-10 02:25:47 UTC (rev 15701)
@@ -60,14 +60,15 @@
Message requestMessage;
Message replyMessage = null;
requestMessage = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
- requestMessage.getBody().setByteArray(msgText.getBytes());
+ requestMessage.getBody().add(msgText);
try {
replyMessage = invoker.deliverSync(requestMessage, 20000);
- System.out.println("Reply Message: " + new String(replyMessage.getBody().getByteArray()));
+ System.out.println("Reply Message: " + replyMessage.getBody().get());
} catch (Exception e) {
System.out.println("Exception caught by client: " + e);
+ System.out.println(e.getCause().getMessage());
}
}
More information about the jboss-svn-commits
mailing list