[jboss-svn-commits] JBL Code SVN: r37924 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/soa/esb/common and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Mar 21 10:14:18 EDT 2012
Author: tcunning
Date: 2012-03-21 10:14:16 -0400 (Wed, 21 Mar 2012)
New Revision: 37924
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/GenericPipelineInterceptor.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/InterceptorManager.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/PipelineInterceptor.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/InterceptorProcessingUnitTest.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestEndPipelineInterceptor.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestFailPipelineInterceptor.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestInstantiatePipelineInterceptor.java
labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestStartPipelineInterceptor.java
Modified:
labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
Log:
JBESB-3724
Add global action pipeline interceptors.
Modified: labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
===================================================================
--- labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2012-03-20 18:35:10 UTC (rev 37923)
+++ labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2012-03-21 14:14:16 UTC (rev 37924)
@@ -163,4 +163,17 @@
<!-- drools.resource.scanner.interval (used to be at the agent level as "poll") -->
<property name="org.jboss.soa.esb.services.rules.resource.scanner.interval" value="60"/>
</properties>
+
+ <!-- Interceptor properties define a comma-delimited list of interceptors
+ to be applied at the instantiation of a service, the start of a
+ service, the end of processing of a service, and the failure of a
+ service within the action processing pipeline. The
+ GenericPipelineInterceptor specified here is just an example that
+ does some logging and is not intended for production use. -->
+ <properties name="interceptors">
+ <property name="org.jboss.soa.esb.pipeline.failure.interceptors" value=""org.jboss.soa.esb.listeners.message.GenericPipelineInterceptor"/>
+ <property name="org.jboss.soa.esb.pipeline.instantiate.interceptors" value="org.jboss.soa.esb.listeners.message.GenericPipelineInterceptor"/>
+ <property name="org.jboss.soa.esb.pipeline.start.interceptors" value="org.jboss.soa.esb.listeners.message.GenericPipelineInterceptor"/>
+ <property name="org.jboss.soa.esb.pipeline.end.interceptors" value="org.jboss.soa.esb.listeners.message.GenericPipelineInterceptor"/>
+ </properties>
</esb>
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2012-03-20 18:35:10 UTC (rev 37923)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -91,6 +91,10 @@
new KeyValuePair(Environment.MSG_STORE_DB_POOL_TIMEOUT_MILLIS,getStorePoolTimeoutMillis()),
new KeyValuePair(Environment.MSG_STORE_DB_CONN_MANAGER ,getStoreDBConnectionManager()),
new KeyValuePair(Environment.MSG_STORE_DB_DATASOURCE_NAME ,getStoreDBDatasourceName()),
+ new KeyValuePair(Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS, getPipelineFailureInterceptors()),
+ new KeyValuePair(Environment.PROCESSING_PIPELINE_END_INTERCEPTORS, getPipelineEndInterceptors()),
+ new KeyValuePair(Environment.PROCESSING_PIPELINE_INSTANTIATION_INTERCEPTORS, getPipelineInstantiateInterceptors()),
+ new KeyValuePair(Environment.PROCESSING_PIPELINE_START_INTERCEPTORS, getPipelineStartInterceptors()),
new KeyValuePair(Environment.REGISTRY_INTERCEPTORS ,getRegistryInterceptors()),
new KeyValuePair(Environment.REGISTRY_CACHE_MAX_SIZE ,getRegistryCacheMaxSize()),
new KeyValuePair(Environment.REGISTRY_CACHE_VALIDITY_PERIOD ,getRegistryCacheValidityPeriod()),
@@ -441,6 +445,49 @@
}
/**
+ * Get the pipeline failure event interceptor class names
+ * @return Pipeline failure event interceptor Class names.
+ */
+ public static String getPipelineFailureInterceptors()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.INTERCEPTOR_MODULE).getProperty(Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS,
+ null);
+
+ }
+
+ /**
+ * Get the pipeline end event interceptor class names
+ * @return Pipeline end event interceptor Class names.
+ */
+ public static String getPipelineEndInterceptors()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.INTERCEPTOR_MODULE).getProperty(Environment.PROCESSING_PIPELINE_END_INTERCEPTORS,
+ null);
+
+ }
+
+ /**
+ * Get the pipeline start event interceptor class names
+ * @return Pipeline start event interceptor Class names.
+ */
+ public static String getPipelineStartInterceptors()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.INTERCEPTOR_MODULE).getProperty(Environment.PROCESSING_PIPELINE_START_INTERCEPTORS,
+ null);
+ }
+
+ /**
+ * Get the pipeline instantiate event interceptor class names
+ * @return Pipeline instantiate event interceptor Class names.
+ */
+ public static String getPipelineInstantiateInterceptors()
+ {
+ return ModulePropertyManager.getPropertyManager(ModulePropertyManager.INTERCEPTOR_MODULE).getProperty(Environment.PROCESSING_PIPELINE_INSTANTIATION_INTERCEPTORS,
+ null);
+ }
+
+
+ /**
* Get the registry interceptor class names
* @return Registry interceptor Class names.
*/
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java 2012-03-20 18:35:10 UTC (rev 37923)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -91,6 +91,14 @@
public static final String EXCEPTION_ON_DELIVERY_FAILURE = "org.jboss.soa.esb.exceptionOnDeliverFailure";
/**
+ * Processing pipeline interceptors.
+ */
+ public static final String PROCESSING_PIPELINE_INSTANTIATION_INTERCEPTORS = "org.jboss.soa.esb.pipeline.instantiate.interceptors";
+ public static final String PROCESSING_PIPELINE_START_INTERCEPTORS = "org.jboss.soa.esb.pipeline.start.interceptors";
+ public static final String PROCESSING_PIPELINE_END_INTERCEPTORS = "org.jboss.soa.esb.pipeline.end.interceptors";
+ public static final String PROCESSING_PIPELINE_FAILURE_INTERCEPTORS = "org.jboss.soa.esb.pipeline.failure.interceptors";
+
+ /**
* The Registry Query Manager URI defines the endPoint where registry queries can be made.
*/
public static final String REGISTRY_QUERY_MANAGER_URI = "org.jboss.soa.esb.registry.queryManagerURI";
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2012-03-20 18:35:10 UTC (rev 37923)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/ModulePropertyManager.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -108,6 +108,8 @@
public static final String RULES_MODULE = "rules";
+ public static final String INTERCEPTOR_MODULE = "interceptors";
+
/**
* Get the property manager responsible for the module component in the
* file.
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2012-03-20 18:35:10 UTC (rev 37923)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -149,6 +149,8 @@
private String serviceName;
+ private ConfigTree config;
+
/**
* public constructor
*
@@ -160,7 +162,8 @@
{
throw new IllegalArgumentException( "Configuration needed for action classes");
}
-
+ this.config = config;
+
final String mep = config.getAttribute(ListenerTagNames.MEP_ATTRIBUTE_TAG) ;
final boolean oneWay ;
final boolean defaultProcessing ;
@@ -372,6 +375,9 @@
LOGGER.debug("SecurityContextPropagator in use for service '" + serviceName + "' is '" + securityContextPropagator.getClass().getName() + "'" );
}
}
+
+ // Intercept the instantiation of the service
+ InterceptorManager.getInstance().interceptInstantiate(null, config);
}
/**
@@ -420,9 +426,11 @@
*/
public boolean process(final Message message)
{
+ InterceptorManager.getInstance().interceptStart(message, config);
long start = System.nanoTime();
serviceMessageCounter.incrementTotalCount();
-
+
+
if (active.get())
{
if (LOGGER.isDebugEnabled())
@@ -687,6 +695,8 @@
MessageCounterStatistics.getMessageCounterStatistics().update(new MessageStatusBean(totalProcTime, message,
MessageStatusBean.MESSAGE_FAILED));
+ InterceptorManager.getInstance().interceptFailure(message, config);
+
if (throwRuntime)
{
throw (RuntimeException)ex ;
@@ -697,6 +707,8 @@
serviceMessageCounter.update(new ActionStatusBean(procTime, count, message,
ActionStatusBean.ACTION_SENT, serviceMessageCounter.getObjectName().toString()));
+ InterceptorManager.getInstance().interceptEnding(message, config);
+
if (currentMessage == null)
{
break;
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/GenericPipelineInterceptor.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/GenericPipelineInterceptor.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/GenericPipelineInterceptor.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,36 @@
+/*
+ * 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.listeners.message;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+public class GenericPipelineInterceptor implements PipelineInterceptor {
+ Logger logger = Logger.getLogger(GenericPipelineInterceptor.class);
+
+ @Override
+ public void processMessage(Message msg, ConfigTree config) {
+ logger.info(msg.getBody().toString());
+ }
+
+}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/InterceptorManager.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/InterceptorManager.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/InterceptorManager.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,131 @@
+/*
+ * 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.listeners.message;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.filter.InputOutputFilter;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.util.ClassUtil;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+/**
+ * The InterceptorManager parses the PipelineInterceptors from the configuration
+ * and provides methods which will execute the methods provided by the interceptors.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class InterceptorManager {
+ public final static Logger logger = Logger.getLogger(InterceptorManager.class);
+
+ private static InterceptorManager _instance = null;
+ private ArrayList<PipelineInterceptor> failureInterceptors = new ArrayList<PipelineInterceptor>();
+ private ArrayList<PipelineInterceptor> instantiateInterceptors = new ArrayList<PipelineInterceptor>();
+ private ArrayList<PipelineInterceptor> startInterceptors = new ArrayList<PipelineInterceptor>();
+ private ArrayList<PipelineInterceptor> endInterceptors = new ArrayList<PipelineInterceptor>();
+
+ private InterceptorManager() {
+ PropertyManager pm = ModulePropertyManager.getPropertyManager(ModulePropertyManager.INTERCEPTOR_MODULE);
+
+ loadInterceptors(failureInterceptors, pm.getProperty(Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS));
+ loadInterceptors(endInterceptors, pm.getProperty(Environment.PROCESSING_PIPELINE_END_INTERCEPTORS));
+ loadInterceptors(startInterceptors, pm.getProperty(Environment.PROCESSING_PIPELINE_START_INTERCEPTORS));
+ loadInterceptors(instantiateInterceptors, pm.getProperty(Environment.PROCESSING_PIPELINE_INSTANTIATION_INTERCEPTORS));
+ }
+
+ public static final synchronized InterceptorManager getInstance() {
+ if (_instance == null)
+ _instance = new InterceptorManager();
+
+ return _instance;
+ }
+
+ private void loadInterceptors(ArrayList<PipelineInterceptor> al, String props) {
+ if ((props != null) && (! "".equals(props))) {
+ StringTokenizer tokenizer = new StringTokenizer(props, ",");
+
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ try {
+ Class c = ClassUtil.forName(token, getClass());
+ PipelineInterceptor interceptor = (PipelineInterceptor) c.newInstance();
+ al.add(interceptor);
+ } catch (ClassNotFoundException ex) {
+ logger.warn("FilterManager problem loading class " + token, ex);
+ } catch (Throwable ex) {
+ logger.warn("FilterManager problem during load " + token, ex);
+ }
+ }
+ }
+ }
+
+ public Message interceptFailure(Message msg, ConfigTree config) {
+ if (failureInterceptors == null)
+ return msg;
+
+ for (PipelineInterceptor interceptor : failureInterceptors) {
+ interceptor.processMessage(msg, config);
+ }
+
+ return msg;
+ }
+
+ public Message interceptEnding(Message msg, ConfigTree config) {
+ if (endInterceptors == null)
+ return msg;
+
+ for (PipelineInterceptor interceptor : endInterceptors) {
+ interceptor.processMessage(msg, config);
+ }
+
+ return msg;
+ }
+
+
+ public Message interceptStart(Message msg, ConfigTree config) {
+ if (startInterceptors == null)
+ return msg;
+
+ for (PipelineInterceptor interceptor : startInterceptors) {
+ interceptor.processMessage(msg, config);
+ }
+
+ return msg;
+ }
+
+ public Message interceptInstantiate(Message msg, ConfigTree config) {
+ if (instantiateInterceptors == null)
+ return msg;
+
+ for (PipelineInterceptor interceptor : instantiateInterceptors) {
+ interceptor.processMessage(msg, config);
+ }
+
+ return msg;
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/PipelineInterceptor.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/PipelineInterceptor.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/PipelineInterceptor.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,36 @@
+/*
+ * 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.listeners.message;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Interface implemented by interceptors added to the underlying process pipeline.
+ *
+ * These interceptors will provide additional functionality.
+ *
+ * @author <a href='mailto:tcunning at redhat.com'>Tom Cunningham</a>
+ */
+public interface PipelineInterceptor {
+ public void processMessage(Message msg, ConfigTree config);
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/InterceptorProcessingUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/InterceptorProcessingUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/InterceptorProcessingUnitTest.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,256 @@
+/*
+ * 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.listeners.message;
+
+import java.io.Serializable;
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
+
+import javax.crypto.SealedObject;
+import javax.security.auth.Subject;
+
+import junit.framework.TestCase;
+
+import org.jboss.internal.soa.esb.services.registry.MockRegistry;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.security.PublicCryptoUtil;
+import org.jboss.soa.esb.services.security.SecurityConfig;
+import org.jboss.soa.esb.services.security.SecurityConfigUtil;
+import org.jboss.soa.esb.services.security.SecurityContext;
+import org.jboss.soa.esb.services.security.SecurityService;
+import org.jboss.soa.esb.services.security.TestPrincipal;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequestImpl;
+import org.jboss.soa.esb.services.security.principals.User;
+import org.jboss.soa.esb.util.ClassUtil;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+/**
+ * This test demonstrates the functionality of the pipeline interceptors.
+ * It attempts to test that all of the interception points are hit and
+ * properties are set by all of the test interceptors that are configured.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class InterceptorProcessingUnitTest extends TestCase
+{
+ private static final String DOMAIN = "SuccessfulLogin" ;
+ private static final String DIFF_DOMAIN = "UnsuccessfulLogin" ;
+
+ private String jbossEsbProperties;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ MockActionInfo.reset();
+ System.setProperty("javax.xml.registry.ConnectionFactoryClass","org.apache.ws.scout.registry.ConnectionFactoryImpl");
+
+ MockRegistry.install();
+ LifecycleResourceManager.getSingleton().associateDeployment(getClass().getCanonicalName()) ;
+
+ jbossEsbProperties = System.getProperty(Environment.PROPERTIES_FILE);
+ URL resource = ClassUtil.getResource("security-properties.xml", getClass());
+ System.setProperty(Environment.PROPERTIES_FILE, "abs://" + resource.getFile());
+
+ URL loginConfig = ClassUtil.getResource("test_jaas.config", getClass());
+ System.setProperty("java.security.auth.login.config", loginConfig.getFile());
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ LifecycleResourceManager.getSingleton().disassociateDeployment(getClass().getCanonicalName()) ;
+ if ( jbossEsbProperties != null )
+ System.setProperty(Environment.PROPERTIES_FILE, jbossEsbProperties);
+ super.tearDown();
+ }
+
+ /*
+ * Tests to run
+ * - create a pipeline with a failure, make sure failure is called in correct order and subsequent actions are not called.
+ * Check initialise and destroy called.
+ *
+ * Do the above for each type of action.
+ */
+ public void testInterceptors() throws Exception {
+ PropertyManager pm = ModulePropertyManager.getPropertyManager(ModulePropertyManager.INTERCEPTOR_MODULE);
+ pm.setProperty(Environment.PROCESSING_PIPELINE_END_INTERCEPTORS, "org.jboss.soa.esb.listeners.message.TestEndPipelineInterceptor");
+ pm.setProperty(Environment.PROCESSING_PIPELINE_START_INTERCEPTORS, "org.jboss.soa.esb.listeners.message.TestStartPipelineInterceptor");
+ pm.setProperty(Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS, "org.jboss.soa.esb.listeners.message.TestFailPipelineInterceptor");
+
+ final ConfigTree configTree = new ConfigTree("parent") ;
+ configTree.setAttribute(ListenerTagNames.MEP_ATTRIBUTE_TAG,
+ ListenerTagNames.MEP_ONE_WAY) ;
+ addAction(configTree, MockActionPipelineProcessor.class.getName(),
+ null, null, null) ;
+ addAction(configTree, MockActionPipelineProcessor.class.getName(),
+ null, null, null) ;
+ addAction(configTree, MockActionPipelineProcessor.class.getName(),
+ null, null, null) ;
+
+ final ActionProcessingPipeline pipeline = new ActionProcessingPipeline(configTree) ;
+ pipeline.initialise() ;
+ checkOrder(MockActionInfo.getInitialiseList(), 0, 2, 4) ;
+
+ Message msg = MessageFactory.getInstance().getMessage();
+ final boolean result = pipeline.process(msg);
+ assertTrue("Pipeline process failure", result) ;
+
+ assertTrue("true".equals(msg.getProperties().getProperty(
+ Environment.PROCESSING_PIPELINE_END_INTERCEPTORS)));
+ String failure = (String) msg.getProperties().getProperty(
+ Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS);
+ assertEquals(null,failure);
+ assertTrue("true".equals(msg.getProperties().getProperty(
+ Environment.PROCESSING_PIPELINE_START_INTERCEPTORS)));
+ assertFalse("true".equals(msg.getProperties().getProperty(
+ Environment.PROCESSING_PIPELINE_INSTANTIATION_INTERCEPTORS)));
+
+ pipeline.destroy() ;
+ }
+
+ public void testFailureInterceptor()
+ throws Exception
+ {
+ final ConfigTree configTree = new ConfigTree("parent") ;
+ configTree.setAttribute(ListenerTagNames.MEP_ATTRIBUTE_TAG,
+ ListenerTagNames.MEP_ONE_WAY) ;
+
+ addAction(configTree, MockActionPipelineProcessor.class.getName(),
+ null, null, null) ;
+ addAction(configTree, MockActionPipelineProcessorFailure.class.getName(),
+ null, null, null) ;
+ addAction(configTree, MockActionPipelineProcessor.class.getName(),
+ null, null, null) ;
+
+ final ActionProcessingPipeline pipeline = new ActionProcessingPipeline(configTree) ;
+ pipeline.initialise() ;
+ checkOrder(MockActionInfo.getInitialiseList(), 0, 2, 4) ;
+
+ Message msg = MessageFactory.getInstance().getMessage();
+
+ final boolean result = pipeline.process(msg) ;
+ assertFalse("Pipeline process succeeded", result) ;
+ checkOrder(MockActionInfo.getProcessList(), 0, 2) ;
+ checkOrder(MockActionInfo.getSuccessList()) ;
+ checkOrder(MockActionInfo.getExceptionList(), 2, 0) ;
+
+ final boolean secondResult = pipeline.process(msg) ;
+ assertFalse("Pipeline process succeeded", secondResult) ;
+ checkOrder(MockActionInfo.getProcessList(), 0, 2, 0, 2) ;
+ checkOrder(MockActionInfo.getSuccessList()) ;
+ checkOrder(MockActionInfo.getExceptionList(), 2, 0, 2, 0) ;
+
+ pipeline.destroy() ;
+ checkOrder(MockActionInfo.getDestroyList(), 4, 2, 0) ;
+
+ assertTrue("true".equals(msg.getProperties().getProperty(
+ Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS)));
+
+ pipeline.destroy() ;
+ }
+
+ public static ConfigTree addAction(final ConfigTree configTree, final String actionName) {
+ return addAction(configTree, actionName, null, null, null);
+ }
+
+ public static ConfigTree addAction(final ConfigTree configTree, final String actionName,
+ final String processOverride, final String successOverride,
+ final String exceptionOverride)
+ {
+ final ConfigTree actionChild = new ConfigTree(ListenerTagNames.ACTION_ELEMENT_TAG, configTree) ;
+ actionChild.setAttribute(ListenerTagNames.ACTION_CLASS_TAG, actionName) ;
+ if (processOverride != null)
+ {
+ actionChild.setAttribute(ListenerTagNames.PROCESS_METHOD_TAG, processOverride) ;
+ }
+ if (successOverride != null)
+ {
+ actionChild.setAttribute(ListenerTagNames.NORMAL_COMPLETION_METHOD_TAG, successOverride) ;
+ }
+ if (exceptionOverride != null)
+ {
+ actionChild.setAttribute(ListenerTagNames.EXCEPTION_METHOD_TAG, exceptionOverride) ;
+ }
+
+ return actionChild;
+ }
+
+ private void checkOrder(final Integer[] list, int ... values)
+ {
+ final int numValues = (values == null ? 0 : values.length) ;
+ final int listLength = (list == null ? 0 : list.length) ;
+
+ assertEquals("Unexpected list/values count", numValues, listLength) ;
+
+ for(int count = 0 ; count < numValues ; count++)
+ {
+ assertEquals("Unexpected call order at count " + count, values[count], list[count].intValue()) ;
+ }
+ }
+
+ private ConfigTree addSecurityConfig(
+ final ConfigTree parent,
+ final String runAs,
+ final String callerIdentity,
+ final String moduleName,
+ final String rolesAllowed)
+ {
+ final ConfigTree securityElement = new ConfigTree(ListenerTagNames.SECURITY_TAG, parent);
+ securityElement.setAttribute(ListenerTagNames.RUN_AS_TAG, runAs);
+ securityElement.setAttribute(ListenerTagNames.USE_CALLERS_IDENTIDY_TAG, callerIdentity);
+ securityElement.setAttribute(ListenerTagNames.MODULE_NAME_TAG, moduleName);
+ if ( rolesAllowed != null )
+ {
+ securityElement.setAttribute(ListenerTagNames.ROLES_ALLOWED, rolesAllowed);
+ }
+ return securityElement;
+ }
+
+ private ConfigTree addSecurityConfig(
+ final ConfigTree parent,
+ final String runAs,
+ final String callerIdentity,
+ final String moduleName,
+ final String rolesAllowed,
+ final long timeout)
+ {
+ ConfigTree securityElement = this.addSecurityConfig(parent, runAs, callerIdentity, moduleName, rolesAllowed);
+ if (timeout != 0l)
+ {
+ ConfigTree property = new ConfigTree("property", securityElement);
+ property.setAttribute("name", Environment.SECURITY_SERVICE_CONTEXT_TIMEOUT);
+ property.setAttribute("value", Long.toString(timeout));
+ }
+ return securityElement;
+ }
+
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestEndPipelineInterceptor.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestEndPipelineInterceptor.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestEndPipelineInterceptor.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,42 @@
+/*
+ * 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.listeners.message;
+
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * This test interceptor tests that the end-of-service interception
+ * point is hit and attempts to set a property on the message.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class TestEndPipelineInterceptor implements PipelineInterceptor {
+ @Override
+ public void processMessage(Message msg, ConfigTree config) {
+ if (msg != null) {
+ msg.getProperties().setProperty(Environment.PROCESSING_PIPELINE_END_INTERCEPTORS,
+ "true");
+ }
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestFailPipelineInterceptor.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestFailPipelineInterceptor.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestFailPipelineInterceptor.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,42 @@
+/*
+ * 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.listeners.message;
+
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * This test interceptor tests that the failure-of-service interception
+ * point is hit and attempts to set a property on the message.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class TestFailPipelineInterceptor implements PipelineInterceptor {
+ @Override
+ public void processMessage(Message msg, ConfigTree config) {
+ if (msg != null) {
+ msg.getProperties().setProperty(Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS,
+ "true");
+ }
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestInstantiatePipelineInterceptor.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestInstantiatePipelineInterceptor.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestInstantiatePipelineInterceptor.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,39 @@
+/*
+ * 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.listeners.message;
+
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * This test interceptor tests that the instantiation-of-service interception
+ * point is hit and attempts to set a property on the message.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class TestInstantiatePipelineInterceptor implements PipelineInterceptor {
+ @Override
+ public void processMessage(Message msg, ConfigTree config) {
+ msg.getProperties().setProperty(Environment.PROCESSING_PIPELINE_FAILURE_INTERCEPTORS, "true");
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestStartPipelineInterceptor.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestStartPipelineInterceptor.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/TestStartPipelineInterceptor.java 2012-03-21 14:14:16 UTC (rev 37924)
@@ -0,0 +1,42 @@
+/*
+ * 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.listeners.message;
+
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * This test interceptor tests that the start-of-service interception
+ * point is hit and attempts to set a property on the message.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class TestStartPipelineInterceptor implements PipelineInterceptor {
+ @Override
+ public void processMessage(Message msg, ConfigTree config) {
+ if (msg != null) {
+ msg.getProperties().setProperty(Environment.PROCESSING_PIPELINE_START_INTERCEPTORS,
+ "true");
+ }
+ }
+}
More information about the jboss-svn-commits
mailing list