<p>With interceptor, you can handle various events in message processing. In this example, a simple interceptor, SimpleInterceptor, is implemented and configured.
When the example is running, the interceptor will print out each events that are passed in the interceptor. And it will add a string property to the message being
delivered. You can see that after the message is received, there will be a new string property appears in the received message.</p>
<p>With our interceptor we always return <code>true</code> from the <code>intercept</code> method. If we were
to return <code>false</code> that signifies that no more interceptors are to run or the target
is not to be called. Return <code>false</code> to abort processing of the packet.</p>
<h2>Example step-by-step</h2>
<p><i>To run the example, simply type <code>mvn verify</code> from this directory</i></p>
<ol>
<li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
<li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
<preclass="prettyprint">
<code>
finally
{
if (initialContext != null)
{
initialContext.close();
}
if (connection != null)
{
connection.close();
}
}
</code>
</pre>
</ol>
<ol>
<li>The SimpleInterceptor:</li>
<preclass="prettyprint">
<code>
public class SimpleInterceptor implements Interceptor