Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 3929 invoked from network); 2 May 2002 18:42:19 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 May 2002 18:42:19 -0000 Received: (qmail 19831 invoked by uid 97); 2 May 2002 18:42:21 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 19725 invoked by alias); 2 May 2002 18:42:21 -0000 Delivered-To: jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 19705 invoked by uid 97); 2 May 2002 18:42:20 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 19690 invoked by alias); 2 May 2002 18:42:20 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 2 May 2002 18:42:08 -0000 Message-ID: <20020502184208.37177.qmail@icarus.apache.org> From: jstrachan@apache.org To: jakarta-commons-sandbox-cvs@apache.org Subject: cvs commit: jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/task ProducerTask.java package.html X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jstrachan 02/05/02 11:42:08 Modified: messenger TODO.txt build.xml Added: messenger/src/java/org/apache/commons/messenger/task ProducerTask.java package.html Log: Added a jmsSend Ant Task for sending files to a JMS provider via Ant using ants filesets. Still needs more work and testing but its almost there Revision Changes Path 1.8 +1 -0 jakarta-commons-sandbox/messenger/TODO.txt Index: TODO.txt =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/messenger/TODO.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- TODO.txt 26 Feb 2002 04:12:52 -0000 1.7 +++ TODO.txt 2 May 2002 18:42:08 -0000 1.8 @@ -1,6 +1,7 @@ Project To Do List ================== +* add an option to the producer task to allow the messenger.xml to be specified * Allow the replyTo destination and Messenger to be overridden in the XML deployment configuration for Messagelets and Servlets. 1.26 +15 -1 jakarta-commons-sandbox/messenger/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/messenger/build.xml,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- build.xml 26 Feb 2002 04:20:57 -0000 1.25 +++ build.xml 2 May 2002 18:42:08 -0000 1.26 @@ -3,7 +3,7 @@ @@ -467,6 +467,20 @@ + + + + + + + + + + + 1.1 jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/task/ProducerTask.java Index: ProducerTask.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE file. * * $Id: ProducerTask.java,v 1.1 2002/05/02 18:42:08 jstrachan Exp $ */ package org.apache.commons.messenger.task; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.util.Iterator; import java.util.Vector; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.TextMessage; import org.apache.commons.messenger.Messenger; import org.apache.commons.messenger.MessengerManager; import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FilterSet; import org.apache.tools.ant.util.FileUtils; /** *

ProducerTask is an Ant task which will * publish all of the given text files as a JMS Text Message * using a given JMS Connection (Messenger) and a Destination * * @author James Strachan * @version $Revision: 1.1 $ */ public class ProducerTask extends Task { private Vector filesets = new Vector(); private Messenger messenger; private String messengerName; private Destination destination; private String subject; // Properties //------------------------------------------------------------------------- /** * Adds a set of files (nested fileset attribute). */ public void addFileset(FileSet set) { filesets.addElement(set); } public Messenger getMessenger() throws JMSException { if ( messenger == null ) { messenger = MessengerManager.get( getMessengerName() ); } return messenger; } /** Sets the Messenger to be used */ public void setMessenger(Messenger messenger) { this.messenger = messenger; } /** Getter for property messengerName. * @return Value of property messengerName. */ public String getMessengerName() { return messengerName; } /** Setter for property messengerName. * @param messengerName New value of property messengerName. */ public void setMessengerName(String messengerName) { this.messengerName = messengerName; } /** Getter for property destination. * @return Value of property destination. */ public Destination getDestination() throws JMSException { if ( destination == null ) { destination = getMessenger().getDestination( getSubject() ); } return destination; } /** Setter for property destination. * @param destination New value of property destination. */ public void setDestination(Destination destination) { this.destination = destination; } /** Getter for property subject. * @return Value of property subject. */ public String getSubject() { return subject; } /** Setter for property subject. * @param subject New value of property subject. */ public void setSubject(String subject) { this.subject = subject; } // Task interface //------------------------------------------------------------------------- /** * Performs the copy operation. */ public void execute() throws BuildException { try { if (filesets.size() == 0) { throw new BuildException("Specify at least one source fileset.", location); } Messenger messenger = getMessenger(); if ( messenger == null ) { throw new BuildException("Must specify a valid Messenger", location ); } Destination destination = getDestination(); if ( destination == null ) { throw new BuildException("Must specify a valid JMS Destination", location ); } // deal with the filesets for (Iterator iter = filesets.iterator(); iter.hasNext(); ) { FileSet fs = (FileSet) iter.next(); DirectoryScanner ds = fs.getDirectoryScanner(project); ds.scan(); String[] files = ds.getIncludedFiles(); for (int i = 0; i < files.length; i++) { sendFile( files[i], messenger, destination ); } } } catch (IOException e) { throw new BuildException(e, location); } catch (JMSException e) { throw new BuildException(e, location); } finally { try { // close the JMS connection to release any background threads messenger.close(); } catch (Exception e) { // ignore close exceptions } } } /** * Sends the contents of the given file to the given Destination * using the given Messenger instance */ protected void sendFile(String file, Messenger messenger, Destination destination) throws IOException, JMSException { log( "Sending message to: " + destination + " from file: " + file ); String text = readText( new BufferedReader( new FileReader( file ) ) ); TextMessage message = messenger.createTextMessage( text ); messenger.send( destination, message ); } /** * Reads the given text stream into a single string */ protected String readText(Reader in) throws IOException { // read all the text into memory StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader( in ); for ( String line; (line = reader.readLine()) != null; ) { buffer.append( line ); buffer.append( '\n' ); } reader.close(); return buffer.toString(); } } 1.1 jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/task/package.html Index: package.html ===================================================================

A collection of Ant tasks for working with JMS.

-- To unsubscribe, e-mail: For additional commands, e-mail: