[jboss-svn-commits] JBL Code SVN: r13241 - in labs/jbossesb/workspace/dbevenius/wslistener/product: lib/ext and 12 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jul 8 09:57:32 EDT 2007
Author: beve
Date: 2007-07-08 09:57:32 -0400 (Sun, 08 Jul 2007)
New Revision: 13241
Added:
labs/jbossesb/workspace/dbevenius/wslistener/product/lib/ext/quartz-1.6.0.jar
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractScheduler.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JobListenerAdapter.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SchedularSingleton.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractSchedulerUnitTest.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JobAdapterUnitTest.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/SchedulerSingletonUnitTest.java
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java
Removed:
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGateway.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGatewayUnitTest.java
Modified:
labs/jbossesb/workspace/dbevenius/wslistener/product/.classpath
labs/jbossesb/workspace/dbevenius/wslistener/product/build-distr.xml
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/base-project-build.xml
labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/resources/log4j.xml
Log:
Added scheduling plus ws listener.
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/.classpath
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/.classpath 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/.classpath 2007-07-08 13:57:32 UTC (rev 13241)
@@ -34,7 +34,6 @@
<classpathentry kind="lib" path="lib/ext/xml-apis-1.3.02.jar"/>
<classpathentry kind="lib" path="lib/ext/xmlpublic.jar"/>
<classpathentry kind="lib" path="lib/ext/xstream-1.1.3.jar"/>
- <classpathentry kind="lib" path="build/jbossesb/lib/jbossesb-config-model-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/ext/jboss.jar"/>
<classpathentry kind="lib" path="lib/ext/commons-io-1.3.jar"/>
<classpathentry kind="lib" path="lib/ext/edtftpj-1.5.4.jar"/>
@@ -67,5 +66,7 @@
<classpathentry kind="lib" path="lib/ext/jbossweb.jar"/>
<classpathentry kind="lib" path="lib/ext/stringtemplate-3.0.jar"/>
<classpathentry kind="lib" path="lib/ext/trove.jar"/>
+ <classpathentry kind="lib" path="build/jbossesb/lib/jbossesb-config-model-1.0.1.jar"/>
+ <classpathentry kind="lib" path="lib/ext/quartz-1.6.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/build-distr.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/build-distr.xml 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/build-distr.xml 2007-07-08 13:57:32 UTC (rev 13241)
@@ -141,6 +141,8 @@
<fileset dir="${lib.ext.dir}" includes="xstream-*.jar,wstx-lgpl-*.jar"/>
<!-- JBossCache jars - including jgroups -->
<fileset dir="${lib.ext.dir}" includes="cache.jar,jgroups-all.jar"/>
+ <!-- Quarts -->
+ <fileset dir="${lib.ext.dir}" includes="quartz-1.6.0.jar"/>
</copy>
</target>
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/lib/ext/quartz-1.6.0.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/workspace/dbevenius/wslistener/product/lib/ext/quartz-1.6.0.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/config/GatewayGenerator.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -23,6 +23,7 @@
import java.util.List;
+import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.dom.YADOMUtil;
import org.jboss.soa.esb.listeners.config.FsListenerDocument.FsListener;
@@ -42,6 +43,7 @@
import org.jboss.soa.esb.listeners.config.mappers.JmsListenerMapper;
import org.jboss.soa.esb.listeners.config.mappers.SqlListenerMapper;
import org.jboss.soa.esb.listeners.config.mappers.UntypedListenerMapper;
+import org.jgroups.util.GetNetworkInterfaces;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -53,6 +55,7 @@
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
*/
public class GatewayGenerator {
+ private Logger log = Logger.getLogger( GatewayGenerator.class );
/**
* XMLBeans based configuration model instance.
@@ -97,6 +100,7 @@
* @throws ConfigurationException Invalid listener configuration.
*/
private void addGatewayConfig(Element root, Listener gateway) throws ConfigurationException {
+ log.debug( " addGatewayConfig : " + gateway.getClass().getName() );
// Of course we could do the following reflectively if we really want to - TODO perhaps!!
if(gateway instanceof JmsListener) {
JmsListenerMapper.map(root, (JmsListener)gateway, model);
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractFileGateway.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -52,7 +52,6 @@
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.util.ClassUtil;
-import org.jboss.soa.esb.util.Util;
/**
* Base class for all file gateways: local filesystem, ftp, sftp and ftps.
@@ -64,7 +63,7 @@
* @since Version 4.0
*
*/
-public abstract class AbstractFileGateway extends AbstractPollingGateway
+public abstract class AbstractFileGateway extends AbstractScheduler
{
abstract File[] getFileList() throws GatewayException;
@@ -93,9 +92,9 @@
*
* @throws ManagedLifecycleException for errors while initialisation.
*/
- protected void doInitialise()
- throws ManagedLifecycleException
+ protected void doInitialise() throws ManagedLifecycleException
{
+ super.doInitialise();
try
{
_targetEprs = RegistryUtil.getEprs(_targetServiceCategory,_targetServiceName);
@@ -359,9 +358,9 @@
*
* @throws ManagedLifecycleException for errors while destroying.
*/
- protected void doDestroy()
- throws ManagedLifecycleException
+ protected void doDestroy() throws ManagedLifecycleException
{
+ super.doDestroy();
}
/*
Deleted: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGateway.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGateway.java 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGateway.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -1,107 +0,0 @@
-/*
- * 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.gateway;
-
-import static org.jboss.soa.esb.listeners.ListenerTagNames.POLL_LATENCY_SECS_TAG;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
-import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
-import org.jboss.soa.esb.util.Util;
-
-/**
- * AbstractPollingGateway
- * </p>
- * Implements the behaviour for triggering ...
- *
- * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
- *
- */
-public abstract class AbstractPollingGateway extends AbstractThreadedManagedLifecycle
-{
- private Logger log = Logger.getLogger( AbstractPollingGateway.class );
-
- /* polling interval in milliseconds */
- private long pollingInterval = 10000l;
-
- protected AbstractPollingGateway( final ConfigTree configTree ) throws ConfigurationException
- {
- super( configTree );
- checkMyParms( configTree );
- }
-
- @Override
- protected void doRun()
- {
- do
- {
- performGatewayOperation();
- }
- while (!waitForRunningStateChange(ManagedLifecycleThreadState.STOPPING, pollingInterval )) ;
-
- log.debug("doRun() method of " + this.getClass().getSimpleName() + " finished on thread " + Thread.currentThread().getName());
- }
-
- /**
- * This method performs whatever needs to be preformed when
- * the polling intervall is reached.
- * </p>
- *
- */
- protected abstract void performGatewayOperation();
-
- public long getPollIntervalMS()
- {
- return pollingInterval;
- }
-
- public long getPollIntervalSec()
- {
- return pollingInterval / 1000;
- }
-
- private void checkMyParms( final ConfigTree configTree ) throws ConfigurationException
- {
- assert( configTree != null ) : "configTree was null in checkMyParams!";
-
- final String pollIntervalSecondStr = configTree.getAttribute( POLL_LATENCY_SECS_TAG );
- if ( Util.isNullString( pollIntervalSecondStr ) )
- {
- log.warn("No value specified for: " + POLL_LATENCY_SECS_TAG + " - Using default of " + getPollIntervalSec() );
- return;
- }
-
- try
- {
- pollingInterval = 1000 * Long.parseLong( pollIntervalSecondStr );
- if ( pollingInterval <= 0 )
- throw new ConfigurationException( "[pollingInterval] must be greater then 0, was : " + pollingInterval );
- }
- catch ( final NumberFormatException e)
- {
- log.warn("Invalid poll latency: "+ pollIntervalSecondStr + " - keeping default of " + getPollIntervalSec() );
- }
- }
-
-}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractScheduler.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractScheduler.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/AbstractScheduler.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,302 @@
+/*
+ * 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.gateway;
+
+import static org.jboss.soa.esb.listeners.ListenerTagNames.POLL_LATENCY_SECS_TAG;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.util.Util;
+import org.quartz.CronExpression;
+import org.quartz.CronTrigger;
+import org.quartz.JobDetail;
+import org.quartz.JobListener;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+import org.quartz.TriggerUtils;
+import org.quartz.jobs.NoOpJob;
+
+/**
+ * AbstractScheduler
+ * </p>
+ * Implements the behaviour for triggering ...
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public abstract class AbstractScheduler extends AbstractThreadedManagedLifecycle
+{
+ private Logger log = Logger.getLogger( AbstractScheduler.class );
+
+ /* Quartz scheduler instance */
+ private Scheduler scheduler;
+ /* polling interval in milliseconds */
+ private int pollingInterval;
+ /* nr of times to execute */
+ private int repeatCount;
+ /* cron expression for job */
+ private String cronExpression;
+ /* start date for job */
+ private Date startDate;
+ /* end date for job */
+ private Date endDate;
+
+ /* config file attribute names */
+ public static final String ATTR_CRON_EXPRESSION = "cronExpression";
+ public static final String ATTR_START_DATE = "startDate";
+ public static final String ATTR_END_DATE = "endDate";
+ public static final String ATTR_REPEAT_COUNT = "repeatCount";
+
+ /* Date format used for dates if none is supplied TODO: add to conifg */
+ private static final String DEFAULT_DATE_FORMAT = "yy-MM-dd HH:mm:ss";
+
+ protected AbstractScheduler( final ConfigTree configTree ) throws ConfigurationException
+ {
+ super( configTree );
+ checkMyParms( configTree );
+ try
+ {
+ scheduler = SchedularSingleton.getInstance().getScheduler();
+ }
+ catch (SchedulerException e)
+ {
+ log.error ( e );
+ throw new ConfigurationException ( e );
+ }
+ }
+
+ /**
+ * This method performs whatever needs to be preformed when
+ * the polling intervall is reached.
+ * </p>
+ *
+ */
+ protected abstract void performGatewayOperation();
+
+ @Override
+ protected void doInitialise() throws ManagedLifecycleException
+ {
+ log.info ( toString() );
+ try
+ {
+ final String jobName = hashCode() + "-job";
+ final String jobGroupName = jobName + "-polling-group";
+ Trigger trigger = cronExpression != null ?
+ new CronTrigger( jobName, jobGroupName, cronExpression ):
+ TriggerUtils.makeSecondlyTrigger( pollingInterval, repeatCount );
+
+ trigger.setName( hashCode() + "-trigger" );
+
+ if ( startDate != null )
+ trigger.setStartTime( startDate );
+ if ( endDate != null )
+ trigger.setEndTime( endDate );
+
+ final JobDetail jbd = new JobDetail( jobName, jobGroupName, NoOpJob.class );
+ final JobListener listener = new JobListenerAdapter( this );
+ scheduler.addJobListener( listener );
+ jbd.addJobListener( listener.getName() );
+ scheduler.scheduleJob( jbd, trigger);
+ }
+ catch (SchedulerException e)
+ {
+ log.error ( e );
+ throw new ManagedLifecycleException ( e );
+ }
+ catch (ParseException e)
+ {
+ log.error ( e );
+ throw new ManagedLifecycleException ( e );
+ }
+ }
+
+ @Override
+ protected void doStart() throws ManagedLifecycleException
+ {
+ super.doStart();
+ try
+ {
+ scheduler.start();
+ }
+ catch (SchedulerException e)
+ {
+ log.error ( e );
+ throw new ManagedLifecycleException ( e );
+ }
+ }
+
+ @Override
+ protected void doStop()throws ManagedLifecycleException
+ {
+ log.debug( "doStop called ");
+ try
+ {
+ scheduler.shutdown();
+ }
+ catch (SchedulerException e)
+ {
+ log.error ( e );
+ throw new ManagedLifecycleException ( e );
+ }
+ }
+
+ @Override
+ protected void doRun() { }
+
+ public int getPollIntervalSec()
+ {
+ return pollingInterval;
+ }
+
+ private void checkMyParms( final ConfigTree configTree ) throws ConfigurationException
+ {
+ setCronExpression( configTree );
+ setStartDate( configTree );
+ setEndDate( configTree );
+
+ if ( cronExpression == null )
+ {
+ setPollInterval( configTree );
+ setRepeatCount( configTree );
+ }
+ }
+
+ private void setCronExpression( final ConfigTree configTree ) throws ConfigurationException
+ {
+ cronExpression = configTree.getAttribute( ATTR_CRON_EXPRESSION );
+
+ if ( cronExpression != null && ! CronExpression.isValidExpression( cronExpression ) )
+ throw new ConfigurationException ("cronExpression '" + cronExpression + "' is not a valid cron expression.");
+ }
+
+ private void setStartDate( final ConfigTree configTree ) throws ConfigurationException
+ {
+ endDate = parseDate( configTree.getAttribute( ATTR_END_DATE ) );
+ }
+
+ private void setEndDate( final ConfigTree configTree ) throws ConfigurationException
+ {
+ startDate = parseDate( configTree.getAttribute( ATTR_START_DATE ) );
+ }
+
+ private Date parseDate( final String dateString ) throws ConfigurationException
+ {
+ if ( dateString == null )
+ return null;
+
+ final SimpleDateFormat sd = new SimpleDateFormat( DEFAULT_DATE_FORMAT, Locale.getDefault() );
+ try
+ {
+ return sd.parse( dateString );
+ }
+ catch (ParseException e)
+ {
+ log.error( e );
+ throw new ConfigurationException( "Could not parse string '" + dateString + "' into a valid date", e);
+ }
+ }
+
+ private void setRepeatCount( final ConfigTree configTree) throws ConfigurationException
+ {
+ final String repeatCountStr = configTree.getAttribute( ATTR_REPEAT_COUNT );
+ if ( repeatCountStr == null )
+ repeatCount = SimpleTrigger.REPEAT_INDEFINITELY;
+ else
+ {
+ try
+ {
+ repeatCount = Integer.parseInt( repeatCountStr );
+ }
+ catch( NumberFormatException e )
+ {
+ log.error( e );
+ log.warn("Invalid repeatCount: "+ repeatCountStr + " - will repeat indefinitely" );
+ }
+ }
+
+ }
+
+ private void setPollInterval( final ConfigTree configTree ) throws ConfigurationException
+ {
+ final String pollIntervalSecondStr = configTree.getAttribute( POLL_LATENCY_SECS_TAG );
+ if ( !Util.isNullString( pollIntervalSecondStr ) )
+ {
+ try
+ {
+ pollingInterval = Integer.parseInt( pollIntervalSecondStr );
+ if ( pollingInterval < 0 )
+ throw new ConfigurationException( POLL_LATENCY_SECS_TAG + " must be a positiv integer");
+ }
+ catch ( final NumberFormatException e)
+ {
+ log.warn("Invalid poll latency: "+ pollIntervalSecondStr + " - keeping default of " + getPollIntervalSec() );
+ }
+ }
+ else
+ {
+ pollingInterval = 10;
+ }
+ }
+
+ public String getCronExpression()
+ {
+ return cronExpression;
+ }
+
+ public Date getStartDate()
+ {
+ return startDate;
+ }
+
+ public Date getEndDate()
+ {
+ return endDate;
+ }
+
+ public int getRepeatCount()
+ {
+ return repeatCount;
+ }
+
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append( "[cronExpression:" ).append( cronExpression );
+ sb.append( ", pollInterval: ").append( pollingInterval );
+ sb.append( ", startDate:").append( startDate );
+ sb.append( ", endDate:").append( endDate );
+ sb.append( ", repeatCount:").append( repeatCount );
+ sb.append( "]" );
+ return sb.toString();
+ }
+
+}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JobListenerAdapter.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JobListenerAdapter.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JobListenerAdapter.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,66 @@
+/*
+ * 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.gateway;
+
+import org.apache.log4j.Logger;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.JobListener;
+
+/**
+ * Adapter that 'adapts' a Quartz JobListener to meet
+ * the AbstractScheduler class.
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class JobListenerAdapter implements JobListener
+{
+ private Logger log = Logger.getLogger( JobListenerAdapter.class );
+
+ private AbstractScheduler gateway;
+
+ public JobListenerAdapter( final AbstractScheduler gateway )
+ {
+ if ( gateway == null)
+ throw new IllegalArgumentException( "gateway must not be null" );
+ this.gateway = gateway;
+ }
+
+ public void jobWasExecuted( final JobExecutionContext jobContext, final JobExecutionException exception )
+ {
+ log.info( "jobWasExceuted.." );
+ if ( gateway != null )
+ gateway.performGatewayOperation();
+ else
+ log.warn( "gateway was null, when job fired!!");
+ }
+
+ public String getName()
+ {
+ return "listener-job";
+ }
+
+ public void jobExecutionVetoed( JobExecutionContext jobContext ) { }
+ public void jobToBeExecuted( JobExecutionContext jobContext ) { }
+
+}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SchedularSingleton.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SchedularSingleton.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SchedularSingleton.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,61 @@
+/*
+ * 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.gateway;
+
+import org.apache.log4j.Logger;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SchedulerFactory;
+import org.quartz.impl.StdSchedulerFactory;
+
+/**
+ * Scheduler singleton based on Quartz
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class SchedularSingleton
+{
+ @SuppressWarnings( "unused" )
+ private Logger log = Logger.getLogger( SchedularSingleton.class );
+
+ private static SchedularSingleton instance = new SchedularSingleton();
+ private SchedulerFactory sf;
+
+ private SchedularSingleton()
+ {
+ sf = new StdSchedulerFactory();
+ }
+
+ public static SchedularSingleton getInstance()
+ {
+ return instance;
+ }
+
+ public Scheduler getScheduler() throws SchedulerException
+ {
+ return sf.getScheduler();
+ }
+
+
+
+}
Deleted: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGatewayUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGatewayUnitTest.java 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractPollingGatewayUnitTest.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -1,115 +0,0 @@
-/*
- * 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.gateway;
-
-import static org.junit.Assert.*;
-
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
-import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
-import org.junit.Test;
-
-/**
- * Test the AbstractPollingGateway.
- * </p>
- *
- * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
- *
- */
-public class AbstractPollingGatewayUnitTest
-{
- @SuppressWarnings ( "unused")
- private Logger log = Logger .getLogger( AbstractPollingGatewayUnitTest.class );
-
- @Test ( expected = ConfigurationException.class )
- public void constructor_pollingIntervalNegative() throws ConfigurationException
- {
- long pollInterval = -1000;
- new MockAbstractPollingGateway( createConfigTree( pollInterval ) );
- }
-
- @Test ( expected = ConfigurationException.class )
- public void constructor_pollingIntervalNegative_zero() throws ConfigurationException
- {
- long pollInterval = 0;
- new MockAbstractPollingGateway( createConfigTree( pollInterval ) );
- }
-
- @Test
- public void constructor_pollingInterval() throws ConfigurationException
- {
- long pollIntervalSec = 10;
- MockAbstractPollingGateway gateway = new MockAbstractPollingGateway( createConfigTree( pollIntervalSec ) );
- equals ( gateway.getPollIntervalMS() == 1000 );
- }
-
- @Test
- public void start() throws ConfigurationException, ManagedLifecycleException, InterruptedException
- {
- long pollIntervalSec = 10;
- MockAbstractPollingGateway gateway = new MockAbstractPollingGateway( createConfigTree( pollIntervalSec ) );
- gateway.initialise();
- gateway.start();
- Thread.sleep( 1000 );
- gateway.stop();
- assertTrue ( gateway.hasRun );
- }
-
- private ConfigTree createConfigTree( long pollInterval )
- {
- ConfigTree tree = new ConfigTree("AbstractPollingGatewayUnitTest");
- tree.setAttribute(ListenerTagNames.POLL_LATENCY_SECS_TAG, String.valueOf( pollInterval ) );
- return tree;
- }
-
- private static class MockAbstractPollingGateway extends AbstractPollingGateway
- {
- private static final long serialVersionUID = 1L;
-
- private Logger log = Logger .getLogger( MockAbstractPollingGateway.class );
-
- private boolean hasRun;
-
- protected MockAbstractPollingGateway(ConfigTree config) throws ConfigurationException
- {
- super( config );
- }
-
- protected void doInitialise() throws ManagedLifecycleException { }
-
- @Override
- protected void performGatewayOperation()
- {
- log.debug( "Performing mock gateway operation" );
- hasRun = true;
- }
-
- public boolean hasRun()
- {
- return hasRun;
- }
-
- }
-
-}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractSchedulerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractSchedulerUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/AbstractSchedulerUnitTest.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,187 @@
+/*
+ * 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.gateway;
+
+import static org.jboss.soa.esb.listeners.ListenerTagNames.POLL_LATENCY_SECS_TAG;
+import static org.jboss.soa.esb.listeners.gateway.AbstractScheduler.ATTR_CRON_EXPRESSION;
+import static org.jboss.soa.esb.listeners.gateway.AbstractScheduler.ATTR_END_DATE;
+import static org.jboss.soa.esb.listeners.gateway.AbstractScheduler.ATTR_REPEAT_COUNT;
+import static org.jboss.soa.esb.listeners.gateway.AbstractScheduler.ATTR_START_DATE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.junit.Test;
+
+/**
+ * Test the AbstractScheduler
+ * </p>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class AbstractSchedulerUnitTest
+{
+ @SuppressWarnings ( "unused")
+ private Logger log = Logger .getLogger( AbstractSchedulerUnitTest.class );
+
+ @Test ( expected = ConfigurationException.class )
+ public void constructor_pollingIntervalNegative() throws ConfigurationException
+ {
+ int pollInterval = -1000;
+ new MockAbstractScheduler( createConfigTree( pollInterval ) );
+ }
+
+ @Test
+ public void constructor_pollingInterval() throws ConfigurationException
+ {
+ int pollIntervalSec = 10;
+ MockAbstractScheduler gateway = new MockAbstractScheduler( createConfigTree( pollIntervalSec ) );
+ equals ( gateway.getPollIntervalSec() == 10 );
+ }
+
+ @Test
+ public void constructor_cronExpression() throws ConfigurationException
+ {
+ String cronExpression = "0/10 * * * * ?";
+ MockAbstractScheduler gateway = new MockAbstractScheduler( createConfigTree( cronExpression ) );
+ assertEquals( cronExpression, gateway.getCronExpression() );
+ }
+
+ @Test
+ public void constructor_startDate() throws ConfigurationException
+ {
+ String cronExpression = "0/10 * * * * ?";
+ String startDate = "07-07-08 13:00:00";
+ MockAbstractScheduler gateway = new MockAbstractScheduler( createConfigTree( cronExpression, startDate, null ) );
+ log.debug( "StartDate : " + gateway.getStartDate());
+ assertNotNull( gateway.getStartDate() );
+ }
+
+ @Test
+ public void constructor_endDate() throws ConfigurationException
+ {
+ String cronExpression = "0/10 * * * * ?";
+ String endDate = "07-07-08 13:00:00";
+ MockAbstractScheduler gateway = new MockAbstractScheduler( createConfigTree( cronExpression, endDate, null ) );
+ log.debug( "EndDate : " + gateway.getEndDate());
+ assertNotNull( gateway.getEndDate() );
+ }
+
+ @Test
+ public void constructor_repeatCount() throws ConfigurationException
+ {
+ MockAbstractScheduler gateway = new MockAbstractScheduler( createConfigTree( 10, 2 ) );
+ log.debug( "RepeatCount : " + gateway.getEndDate());
+ assertEquals( 2, gateway.getRepeatCount() );
+ }
+
+ @Test
+ public void start_pollInterval() throws ConfigurationException, ManagedLifecycleException, InterruptedException
+ {
+ int pollIntervalSec = 3;
+ MockAbstractScheduler gateway = new MockAbstractScheduler( createConfigTree( pollIntervalSec ) );
+ gateway.initialise();
+ gateway.start();
+ Thread.sleep( 10000 );
+ gateway.stop();
+ assertTrue ( gateway.hasRun );
+ }
+
+ @Test
+ public void start_cronExpression() throws ConfigurationException, ManagedLifecycleException, InterruptedException
+ {
+ String cronExpression = "0/10 * * * * ?";
+ MockAbstractScheduler gateway = new MockAbstractScheduler( createConfigTree( cronExpression ) );
+ gateway.initialise();
+ gateway.start();
+ Thread.sleep( 10000 );
+ gateway.stop();
+ assertTrue ( gateway.hasRun );
+ }
+
+ private ConfigTree createConfigTree()
+ {
+ return new ConfigTree("AbstractPollingGatewayUnitTest");
+ }
+
+ private ConfigTree createConfigTree( final int pollInterval )
+ {
+ final ConfigTree tree = createConfigTree();
+ tree.setAttribute( POLL_LATENCY_SECS_TAG, String.valueOf( pollInterval ) );
+ return tree;
+ }
+
+ private ConfigTree createConfigTree( final int pollInterval, final int repeatCount )
+ {
+ final ConfigTree tree = createConfigTree( pollInterval );
+ tree.setAttribute( ATTR_REPEAT_COUNT, String.valueOf( repeatCount ) );
+ return tree;
+ }
+
+ private ConfigTree createConfigTree( final String cronExpression )
+ {
+ final ConfigTree tree = createConfigTree();
+ tree.setAttribute( ATTR_CRON_EXPRESSION, cronExpression );
+ return tree;
+ }
+
+ private ConfigTree createConfigTree( final String cronExpression, final String startDate, final String endDate )
+ {
+ final ConfigTree tree = createConfigTree( cronExpression );
+ tree.setAttribute( ATTR_START_DATE, startDate );
+ tree.setAttribute( ATTR_END_DATE, startDate );
+ return tree;
+ }
+
+ private static class MockAbstractScheduler extends AbstractScheduler
+ {
+ private static final long serialVersionUID = 1L;
+
+ private Logger log = Logger .getLogger( MockAbstractScheduler.class );
+
+ private boolean hasRun;
+
+ protected MockAbstractScheduler( final ConfigTree config) throws ConfigurationException
+ {
+ super( config );
+ }
+
+ @Override
+ protected void performGatewayOperation()
+ {
+ log.debug( "Performing mock gateway operation" );
+ hasRun = true;
+ }
+
+ public boolean hasRun()
+ {
+ return hasRun;
+ }
+
+ }
+
+}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JobAdapterUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JobAdapterUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/JobAdapterUnitTest.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,40 @@
+/*
+ * 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.gateway;
+
+import org.junit.Test;
+
+/**
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class JobAdapterUnitTest
+{
+
+ @Test ( expected = IllegalArgumentException.class )
+ public void constructor()
+ {
+ new JobListenerAdapter( null );
+ }
+
+}
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/RemoteGatewayListenerUnitTest.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -28,20 +28,21 @@
import java.io.File;
import java.net.MalformedURLException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import junit.framework.JUnit4TestAdapter;
import org.apache.log4j.Logger;
+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.internal.soa.esb.util.embedded.EmbeddableException;
import org.jboss.internal.soa.esb.util.embedded.ftp.FtpTestUtil;
import org.jboss.internal.soa.esb.util.embedded.ftp.NoConfigFileFtpServer;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.MalformedEPRException;
-import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.couriers.Courier;
import org.jboss.soa.esb.couriers.CourierException;
import org.jboss.soa.esb.helpers.ConfigTree;
@@ -81,7 +82,7 @@
/* name of the remote ftp input directory */
protected static String remoteInputDirName;
-
+
/* name of the remote ftp upload directory */
protected static String remoteUploadDirName;
@@ -106,6 +107,10 @@
@BeforeClass
public static void classSetup() throws EmbeddableException, ConfigurationException, GatewayException, RegistryException, MalformedURLException
{
+ MockCourierFactory.install();
+ MockRegistry.install();
+ MockCourier courier = new MockCourier(true);
+ MockRegistry.register(SERVICE_CATEGORY, SERVICE_NAME, courier);
ftpServer = createFtpServer();
ftpServer.start();
@@ -141,6 +146,8 @@
@AfterClass
public static void classTearDown()
{
+ MockRegistry.uninstall();
+ MockCourierFactory.uninstall();
try
{
ftpServer.stop();
@@ -181,22 +188,25 @@
setAbsolutePostDirToUploadDir();
boolean getCourierReturnValue = true;
- RemoteGatewayListenerMock mock = createAndStartListener ( configTree, getCourierReturnValue );
+ File processedFile = null;
+ RemoteGatewayListenerMock mock = null;
+ try
+ {
+ mock = createAndStartListener ( configTree, getCourierReturnValue );
- File done = ftpServer.getLocalUploadDir();
- String doneFileName = testFile.getName() + POST_SUFFIX;
+ File done = ftpServer.getLocalUploadDir();
+ String doneFileName = testFile.getName() + POST_SUFFIX;
+
+ waitForFile( done, doneFileName );
+ stopdoRun( mock );
- waitForFile( done, doneFileName );
- stopdoRun( mock );
-
- File processedFile = new File ( done, doneFileName );
- try
- {
+ processedFile = new File ( done, doneFileName );
assertTrue ( processedFile.exists() );
}
finally
{
FtpTestUtil.deleteFile( processedFile );
+ stopdoRun( mock );
}
}
@@ -331,7 +341,7 @@
* inputSuffix=".txt"
* maxThreads="1"
* passive="false"
- * pollLatencySeconds="5"
+ * pollLatencySeconds="1"
* postDelete="false"
* postDir="/upload"
* postSuffix=".done"
@@ -347,6 +357,7 @@
configTree.setAttribute( ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, SERVICE_CATEGORY );
configTree.setAttribute( ListenerTagNames.TARGET_SERVICE_NAME_TAG, SERVICE_NAME );
+ configTree.setAttribute( ListenerTagNames.POLL_LATENCY_SECS_TAG, "5");
try
{
@@ -402,12 +413,18 @@
private RemoteGatewayListenerMock createAndStartListener ( ConfigTree configTree, boolean returnValueForCourier ) throws ConfigurationException, GatewayException, RegistryException
{
final RemoteGatewayListenerMock mock = new RemoteGatewayListenerMock( configTree , returnValueForCourier );
- mock.doInitialise();
Thread thread = new Thread ( new Runnable () {
public void run()
{
- mock.doRun();
+ try
+ {
+ mock.initialise();
+ mock.start();
+ } catch (ManagedLifecycleException e)
+ {
+ e.printStackTrace();
+ }
}
});
thread.start();
@@ -524,12 +541,21 @@
};
}
+ /*
@Override
protected void doInitialise()
{
- _targetEprs = new ArrayList<EPR>();
- _targetEprs.add( new JMSEpr( new EPR() ) );
+ try
+ {
+ _targetEprs = new ArrayList<EPR>();
+ _targetEprs.add( new JMSEpr( new EPR() ) );
+ super.doInitialise();
+ } catch (ManagedLifecycleException e)
+ {
+ e.printStackTrace();
+ }
};
+ */
@Override
protected boolean waitForRunningStateChange(final ManagedLifecycleThreadState state, final long terminationPeriod)
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/SchedulerSingletonUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/SchedulerSingletonUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/SchedulerSingletonUnitTest.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,80 @@
+/*
+ * 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.gateway;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+import org.quartz.Job;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleTrigger;
+import org.quartz.TriggerUtils;
+
+/**
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class SchedulerSingletonUnitTest
+{
+ private static Logger log = Logger.getLogger( SchedulerSingletonUnitTest.class );
+
+ @Test
+ public void getInstance()
+ {
+ final SchedularSingleton instance = SchedularSingleton.getInstance();
+ final SchedularSingleton instance2 = SchedularSingleton.getInstance();
+ assertEquals( instance, instance2 );
+ assertTrue( instance == instance2 );
+ }
+
+ @Test
+ public void getScheduler() throws SchedulerException
+ {
+ final SchedularSingleton instance = SchedularSingleton.getInstance();
+ final Scheduler scheduler = instance.getScheduler();
+ JobDetail jbd = new JobDetail( "junit", "junitgroup", MockJob.class );
+ Date runTime = TriggerUtils.getEvenMinuteDate(new Date());
+ SimpleTrigger trigger = new SimpleTrigger("trigger1", "junitgroup", runTime);
+ scheduler.scheduleJob( jbd, trigger);
+ scheduler.start();
+ scheduler.shutdown();
+ }
+
+ public static class MockJob implements Job
+ {
+
+ public void execute( JobExecutionContext arg0 ) throws JobExecutionException
+ {
+ log.debug( "Running job...");
+ }
+
+ }
+
+}
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/samples/quickstarts/helloworld_file_action/jboss-esb-unfiltered.xml 2007-07-08 13:57:32 UTC (rev 13241)
@@ -44,9 +44,11 @@
<fs-listener name="FileGateway"
busidref="helloFileChannel"
maxThreads="1"
- is-gateway="true"
- poll-frequency-seconds="10"
- />
+ is-gateway="true">
+ <property name="cronExpression" value="0/30 * * * * ?" />
+ <property name="startDate" value="07-07-08 14:25:00" />
+ <property name="endDate" value="07-07-08 14:27:00" />
+ </fs-listener>
<jms-listener name="helloWorldFileAction"
busidref="quickstartEsbChannel"
maxThreads="1"
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/base-project-build.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/base-project-build.xml 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/base-project-build.xml 2007-07-08 13:57:32 UTC (rev 13241)
@@ -17,7 +17,7 @@
<delete dir="build" />
</target>
- <target name="prepare" depends="clean">
+ <target name="prepare">
<mkdir dir="build/${ant.project.name}.esb/META-INF" />
<mkdir dir="build/classes" />
</target>
@@ -31,6 +31,7 @@
<fileset dir="${esb.product.lib.dir}" includes="*.jar" /> <!-- Product Jars. -->
<pathelement location="src/test/resources"/>
<fileset dir="../../lib/ext" includes="jboss-system.jar" />
+ <fileset dir="../../lib/ext" includes="quartz-1.6.0.jar" />
</path>
<target name="echoCP">
@@ -97,4 +98,4 @@
</target>
-</project>
\ No newline at end of file
+</project>
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGateway.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,361 @@
+/*
+ * 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.gateway;
+
+import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG;
+import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_NAME_TAG;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionLifecycleException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.soap.SOAPClient;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.couriers.Courier;
+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.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerUtil;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.services.registry.RegistryException;
+
+/**
+ * Abstract Web Service Gateway
+ * </p>
+ * This class is inteded to be sublclasses to implement..
+ * <p/>
+ * <p/>
+ * Sample Gateway Configuration:
+ * <pre>
+ * <provider name="WS-Provider">
+ * <bus busid="WSPoller">
+ * </bus>
+ * </provider>
+ *
+ * <listener name="WS-Gateway" busidref="WSPoller" is-gateway="true" maxThreads="1">
+ * <property name="gatewayClass" value="org.jboss.soa.esb.listeners.gateway.WSGateway"/>
+ * <property name="pollLatencySeconds" value="10"/>
+ * <property name="pollLatencySeconds" value="10"/>
+ * <property name="wsdl" value="http://127.0.0.1:8080/Quickstart_webservice_gateway/ABI_Shipping?wsdl"/>
+ * <property name="operation" value="shippingRequest"/>
+ * <property name="soapHeaders">
+ * <header name="param1" value="value1" />
+ * <header name="param2" value="value2" />
+ * ...
+ * </property>
+ * <property name="soapParameters">
+ * <param name="param1" value="value1" />
+ * <param name="param2" value="value2" />
+ * ...
+ * </property>
+ * </listener>
+ * </pre>
+ * <p/>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public abstract class AbstractWSGateway extends AbstractScheduler
+{
+ private Logger log = Logger.getLogger( AbstractWSGateway.class );
+
+ /* ESB Category */
+ private String targetServiceCategory;
+ /* ESB Service Name */
+ private String targetServiceName;
+
+ /* Map with SOAP parameters */
+ private Map<String,String> soapParameters;
+
+ /* Map with SOAP Headers*/
+ private Map<String, String> soapHeaders;
+
+ /* SOAPClient used to perform web service call */
+ private SOAPClient soapUIClient;
+
+ /* EPRs for calling ESB services */
+ protected Collection<EPR> targetEprs;
+
+ /* Location in the Message object body */
+ protected static final String ATTR_SOAP_PARAMETERS = "soapParameters";
+ protected static final String ATTR_SOAP_PARAMETER = "parameter";
+ protected static final String ATTR_SOAP_HEADERS = "soapHeaders";
+ protected static final String ATTR_SOAP_HEADER = "header";
+ protected static final String ATTR_WSDL = "wsdl";
+ protected static final String ATTR_OPERATION = "operation";
+
+ public AbstractWSGateway( final ConfigTree configTree) throws ConfigurationException
+ {
+ super( configTree );
+ checkMyParms( configTree );
+ soapUIClient = new SOAPClient( configTree );
+ }
+
+ /**
+ * Perform action prior to invoking the Web Service
+ * This method gives subclasses a chance to add variable arguments to the
+ * WebService.
+ *
+ * @return Map<String,String> <soapParameter,value>
+ */
+ protected abstract Map<String,String> getWebServiceArguments();
+
+ /**
+ * Perform action prior to invoking the target service.
+ *
+ * @param soapResponseMessage The message that will be sent to the target service
+ */
+ protected abstract void preESBServiceProcessing( final Message soapResponseMessage );
+
+ /**
+ * Perform action after invoking the target service.
+ *
+ * @param soapResponseMessage The message that was sent to the target service
+ */
+ protected abstract void postESBServiceProcessing( final Message soapResponseMessage );
+
+ /**
+ * Templete method that will :
+ * <lu>
+ * <li> invoke the target Web Service,
+ * <li> execute preESBServiceProcess,
+ * <li> send the message response from Web Service to ESB pipeline
+ * <li> execute postESBServiceProcess,
+ * </lu>
+ */
+ @Override
+ protected void performGatewayOperation()
+ {
+ log.debug( " ---------- performingGatewayOperation ----------------");
+
+ Message responseMessage = null;
+ try
+ {
+ final Message message = createMessage();
+
+ final Map<String, String> webServiceArguments = getWebServiceArguments();
+ if ( webServiceArguments != null )
+ soapParameters.putAll( getWebServiceArguments() );
+ if ( soapHeaders != null )
+ soapParameters.putAll( soapHeaders );
+
+ log.debug( "Parameters : " + soapParameters);
+
+ message.getBody().add( soapParameters );
+
+ responseMessage = invokeWebService( message );
+ preESBServiceProcessing( responseMessage );
+ sendToService( responseMessage );
+ }
+ catch ( final CourierException e)
+ {
+ log.error( e );
+ }
+ catch ( final MalformedEPRException e)
+ {
+ log.error( e );
+ }
+ catch ( final ActionProcessingException e)
+ {
+ log.error( e );
+ }
+ finally
+ {
+ postESBServiceProcessing( responseMessage );
+ }
+ log.debug( " ---------- performingGatewayOperation done ----------");
+ }
+
+ /**
+ * Will send the passed in Message object to the target ESB Service.
+ *
+ * @param message the message to pass to the ESB service
+ *
+ * @throws CourierException
+ * @throws MalformedEPRException
+ */
+ protected void sendToService ( final Message message ) throws CourierException, MalformedEPRException
+ {
+ Courier courier = null;
+ for (EPR current : targetEprs)
+ {
+ courier = getCourier(current);
+ try
+ {
+ message.getHeader().getCall().setTo(current);
+ if ( courier.deliver( message ))
+ break;
+ }
+ finally
+ {
+ CourierUtil.cleanCourier( courier ) ;
+ }
+ }
+ }
+
+ /**
+ * Will try to invoke the target web service by calling
+ * SOAPUI.process(message)
+ *
+ * @param message the message object which holds the information about
+ * the web service call and payload
+ * @return Message A response message containg the SOAP response as its payload
+ *
+ * @throws ActionProcessingException
+ */
+ protected Message invokeWebService( final Message message ) throws ActionProcessingException
+ {
+ if (message == null)
+ throw new IllegalArgumentException( "message must not be null" );
+
+ return soapUIClient.process( message );
+ }
+
+ /*
+ * Simple creation of Message objects.
+ */
+ private Message createMessage()
+ {
+ return MessageFactory.getInstance().getMessage();
+ }
+
+ /**
+ * Lifecycle initialization
+ */
+ @Override
+ protected void doInitialise() throws ManagedLifecycleException
+ {
+ try
+ {
+ soapUIClient.initialise();
+ }
+ catch ( final ActionLifecycleException e)
+ {
+ log.debug ( e );
+ throw new ManagedLifecycleException ( e );
+ }
+
+ try
+ {
+ targetEprs = RegistryUtil.getEprs( targetServiceCategory, targetServiceName);
+ if ( targetEprs == null || targetEprs.size() < 1)
+ throw new ManagedLifecycleException("EPR <" + targetServiceName + "> not found in registry") ;
+ }
+ catch (final RegistryException re)
+ {
+ throw new ManagedLifecycleException("Unexpected registry exception", re) ;
+ }
+ }
+
+ /**
+ * Lifecycle destruction
+ */
+ @Override
+ protected void doDestroy() throws ManagedLifecycleException
+ {
+ super.doDestroy();
+ if( soapUIClient != null )
+ {
+ try
+ {
+ soapUIClient.destroy();
+ }
+ catch ( final ActionLifecycleException e)
+ {
+ log.error ( "Excpetion while calling soapUIClient.destroy()." + e );
+ }
+ }
+ }
+
+ protected Courier getCourier( final EPR current ) throws CourierException, MalformedEPRException
+ {
+ return CourierFactory.getCourier(current);
+ }
+
+ /**
+ * Extracts and verify that conifiguration properties exist.
+ *
+ * @param configTree
+ * @throws ConfigurationException
+ */
+ private void checkMyParms( final ConfigTree configTree ) throws ConfigurationException
+ {
+ log.debug( "WSGateway configtree : " + configTree );
+ targetServiceCategory = ListenerUtil.obtainAtt( configTree, TARGET_SERVICE_CATEGORY_TAG, null);
+ targetServiceName = ListenerUtil.obtainAtt( configTree, TARGET_SERVICE_NAME_TAG, null);
+ soapHeaders = getHeaders( configTree );
+ soapParameters = getParameters( configTree );
+
+ log.debug( "SoapHeaders :" + soapHeaders );
+ log.debug( "SoapParameters :" + soapParameters );
+ }
+
+ /**
+ * Will extract the SOAP parameters from the ConfigTree and put
+ * them into a Map which is returned.
+ *
+ * @param configTree config which may contains SOAP parameters
+ * @return
+ */
+ protected Map<String,String> getParameters( final ConfigTree configTree )
+ {
+ return getParameters( configTree, ATTR_SOAP_PARAMETER );
+ }
+
+ /**
+ * Will extract the SOAP Headers from the ConfigTree and put
+ * them into a Map which is returned.
+ *
+ * @param configTree config which may contains SOAP parameters
+ * @return
+ */
+ protected Map<String,String> getHeaders( final ConfigTree configTree )
+ {
+ return getParameters( configTree, ATTR_SOAP_HEADER );
+ }
+
+ protected Map<String,String> getParameters( final ConfigTree configTree, String childName )
+ {
+ final Map<String,String> parameters = new HashMap<String,String>();
+
+ final ConfigTree[] children = configTree.getChildren( childName );
+
+ if ( children != null )
+ for ( ConfigTree child : children )
+ {
+ parameters.put( child.getAttribute( "name" ), child.getAttribute( "value" ) );
+ log.debug ( "put child into map; " + child );
+ }
+
+ return parameters;
+ }
+
+}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/main/java/org/jboss/soa/esb/listeners/gateway/WSGateway.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,80 @@
+/*
+ * 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.gateway;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Web Service Gateway
+ * </p>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class WSGateway extends AbstractWSGateway
+{
+ private static final long serialVersionUID = 1L;
+
+ private Logger log = Logger.getLogger( WSGateway.class );
+
+ public WSGateway( final ConfigTree configTree) throws ConfigurationException
+ {
+ super( configTree );
+ }
+
+ /**
+ * Gets the SOAP parameters. If using document style this might simply be
+ * one parameter that is an xml string.
+ *
+ * @return <code>Map</code> map of parameters used to invoke the web service
+ */
+ protected Map<String, String> getWebServiceArguments()
+ {
+ return null;
+ }
+
+ /**
+ * Perform action prior to invoking the target service.
+ *
+ * @param soapResponseMessage The message that will be sent to the target service
+ */
+ protected void preESBServiceProcessing( final Message soapResponseMessage )
+ {
+ log.debug( "preESBServiceProcessing..." );
+ }
+
+ /**
+ * Perform action after invoking the target service.
+ *
+ * @param soapResponseMessage The message that was sent to the target service
+ */
+ protected void postESBServiceProcessing( final Message soapResponseMessage )
+ {
+ log.debug( "postESBServiceProcessing..." );
+ }
+
+}
Added: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/java/org/jboss/soa/esb/listeners/gateway/AbstractWSGatewayUnitTest.java 2007-07-08 13:57:32 UTC (rev 13241)
@@ -0,0 +1,214 @@
+/*
+ * 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.gateway;
+
+import static org.jboss.soa.esb.listeners.ListenerTagNames.POLL_LATENCY_SECS_TAG;
+import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG;
+import static org.jboss.soa.esb.listeners.ListenerTagNames.TARGET_SERVICE_NAME_TAG;
+import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_OPERATION;
+import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_SOAP_HEADER;
+import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_SOAP_PARAMETER;
+import static org.jboss.soa.esb.listeners.gateway.AbstractWSGateway.ATTR_WSDL;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.junit.Test;
+
+/**
+ * Test the AbstractWSGateway.
+ * </p>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ *
+ */
+public class AbstractWSGatewayUnitTest
+{
+ @SuppressWarnings ( "unused")
+ private Logger log = Logger .getLogger( AbstractWSGatewayUnitTest.class );
+
+ @Test ( expected = ConfigurationException.class )
+ public void constructor_negative_no_serviceName() throws ConfigurationException
+ {
+ final ConfigTree tree = new ConfigTree("AbstractPollingGatewayUnitTest");
+ tree.setAttribute( POLL_LATENCY_SECS_TAG, String.valueOf( 10 ) );
+ tree.setAttribute( TARGET_SERVICE_CATEGORY_TAG , "wsCatetory");
+ new MockWSGateway( tree );
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void constructor_negative_no_category() throws ConfigurationException
+ {
+ final ConfigTree tree = new ConfigTree("AbstractPollingGatewayUnitTest");
+ tree.setAttribute( POLL_LATENCY_SECS_TAG, String.valueOf( 10 ) );
+ tree.setAttribute( TARGET_SERVICE_NAME_TAG, "wsService");
+ new MockWSGateway( tree );
+ }
+
+ @Test ( expected = IllegalArgumentException.class )
+ public void callWS_negative() throws ConfigurationException, ActionProcessingException
+ {
+ MockWSGateway gateway = new MockWSGateway( createConfigTree( 10 ) );
+ gateway.invokeWebService( null );
+ }
+
+ @Test
+ public void getSOAPParameters() throws ConfigurationException
+ {
+ ConfigTree tree = createSoapParametersConfigTree();
+ log.debug ( tree );
+
+ MockWSGateway gateway = new MockWSGateway( tree );
+ Map<String, String> parameters = gateway.getParameters( tree );
+ assertNotNull ( parameters );
+ assertEquals( 2, parameters.size() );
+ }
+
+ @Test
+ public void getSOAPHeaders() throws ConfigurationException
+ {
+ ConfigTree tree = createSoapHeaderConfigTree();
+ log.debug ( tree );
+
+ MockWSGateway gateway = new MockWSGateway( tree );
+ Map<String, String> headers = gateway.getHeaders( tree );
+ assertNotNull ( headers );
+ assertEquals( 2, headers.size() );
+ }
+
+ /**
+ * Produces the following ConfigTree:
+ *
+ * <AbstractPollingGatewayUnitTest operation="ZZZ" pollLatencySeconds="10"
+ * target-service-category="wsCatetory"
+ * target-service-name="wsService"
+ * wsdl="http://localhost:8180/active-bpel/services/RetailerCallback?wsd">
+ * </AbstractPollingGatewayUnitTest>
+ *
+ */
+ private ConfigTree createConfigTree( final long pollInterval )
+ {
+ final ConfigTree tree = new ConfigTree("AbstractPollingGatewayUnitTest");
+ tree.setAttribute( POLL_LATENCY_SECS_TAG, String.valueOf( pollInterval ) );
+ tree.setAttribute( TARGET_SERVICE_CATEGORY_TAG, "wsCatetory");
+ tree.setAttribute( TARGET_SERVICE_NAME_TAG, "wsService");
+
+ tree.setAttribute( ATTR_WSDL, "http://localhost:8180/active-bpel/services/RetailerCallback?wsd");
+ tree.setAttribute( ATTR_OPERATION,"ZZZ");
+
+ return tree;
+ }
+
+ /**
+ * Produces the following ConfigTree:
+ *
+ * <AbstractPollingGatewayUnitTest operation="ZZZ" pollLatencySeconds="10"
+ * target-service-category="wsCatetory"
+ * target-service-name="wsService"
+ * wsdl="http://localhost:8180/active-bpel/services/RetailerCallback?wsd">
+ * <property name="soapHeaders">
+ * <header name="user" value="beve"/>
+ * <header name="password" value="letmein"/>
+ * </property>
+ * </AbstractPollingGatewayUnitTest>
+ *
+ */
+ private ConfigTree createSoapHeaderConfigTree()
+ {
+ ConfigTree tree = createConfigTree( 10 );
+
+ ConfigTree property1 = new ConfigTree( ATTR_SOAP_HEADER , tree );
+ property1.setAttribute( "name", "user");
+ property1.setAttribute( "value", "beve" );
+
+ ConfigTree property2 = new ConfigTree( ATTR_SOAP_HEADER , tree );
+ property2.setAttribute( "name", "password");
+ property2.setAttribute( "value", "letmein" );
+
+ return tree;
+ }
+
+
+
+ /**
+ * Produces the following ConfigTree:
+ *
+ * <AbstractPollingGatewayUnitTest operation="ZZZ" pollLatencySeconds="10"
+ * target-service-category="wsCatetory"
+ * target-service-name="wsService"
+ * wsdl="http://localhost:8180/active-bpel/services/RetailerCallback?wsd">
+ * <property name="soapParameters">
+ * <parameter name="Param-param1" value="value1"/>
+ * <parameter name="Param-param2" value="value2"/>
+ * </property>
+ * </AbstractPollingGatewayUnitTest>
+ *
+ * @return
+ */
+ private ConfigTree createSoapParametersConfigTree()
+ {
+ ConfigTree tree = createConfigTree( 10 );
+
+ ConfigTree property1 = new ConfigTree( ATTR_SOAP_PARAMETER, tree );
+ property1.setAttribute( "name", "param1");
+ property1.setAttribute( "value", "value1" );
+
+ ConfigTree property2 = new ConfigTree( ATTR_SOAP_PARAMETER, tree );
+ property2.setAttribute( "name", "param2");
+ property2.setAttribute( "value", "value2" );
+
+ return tree;
+ }
+
+ private static class MockWSGateway extends AbstractWSGateway
+ {
+ private Logger log = Logger.getLogger( MockWSGateway.class );
+ private static final long serialVersionUID = 1L;
+
+ protected MockWSGateway( final ConfigTree configTree) throws ConfigurationException
+ {
+ super( configTree );
+ }
+
+ @Override
+ protected void preESBServiceProcessing( final Message message )
+ {
+ log.debug( "do something before calling target service" );
+ }
+
+ @Override
+ protected void postESBServiceProcessing( final Message soapResponseMessage ) { }
+
+ @Override
+ protected Map<String, String> getWebServiceArguments()
+ {
+ return null;
+ }
+
+ }
+}
Modified: labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/resources/log4j.xml
===================================================================
--- labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/resources/log4j.xml 2007-07-08 13:32:59 UTC (rev 13240)
+++ labs/jbossesb/workspace/dbevenius/wslistener/product/services/soap/src/test/resources/log4j.xml 2007-07-08 13:57:32 UTC (rev 13241)
@@ -44,7 +44,7 @@
<priority value="WARN"/>
</category>
<category name="org.jboss.soa.esb">
- <priority value="ERROR"/>
+ <priority value="DEBUG"/>
</category>
<category name="org.jboss.internal.soa.esb">
<priority value="ERROR"/>
@@ -52,7 +52,7 @@
<category name="org.apache">
<priority value="ERROR"/>
</category>
- <category name="org.jboss.soa.esb.services.jbpm">
+ <category name="org.jboss.soa.esb.services.soapui">
<priority value="DEBUG"/>
</category>
<!-- ======================= -->
More information about the jboss-svn-commits
mailing list