[jboss-svn-commits] JBL Code SVN: r8821 - in labs/jbossesb/trunk/product/samples/quickstarts: helloworld_file_action and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jan 11 10:18:25 EST 2007


Author: kevin.conner at jboss.com
Date: 2007-01-11 10:18:18 -0500 (Thu, 11 Jan 2007)
New Revision: 8821

Added:
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/src/quickstart/hw_ftp_action/test/
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/src/quickstart/hw_ftp_action/test/CreateTestFile.java
Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/build.xml
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/build.xml
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/jbossesb.xml
   labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/readme.txt
   labs/jbossesb/trunk/product/samples/quickstarts/quickstarts.properties
   labs/jbossesb/trunk/product/samples/quickstarts/static_router/build.xml
   labs/jbossesb/trunk/product/samples/quickstarts/static_router/jbossesb.xml
   labs/jbossesb/trunk/product/samples/quickstarts/static_router/readme.txt
   labs/jbossesb/trunk/product/samples/quickstarts/static_router/src/quickstart/static_router/test/CreateTestFile.java
Log:
Added FTP configuration for ftp and static router.

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/build.xml	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_file_action/build.xml	2007-01-11 15:18:18 UTC (rev 8821)
@@ -92,7 +92,7 @@
     <echo message="Deploying to ${jboss.deploy.dir}"/>
     <copy file="${build.dir}/${ant.project.name}.jar"
           todir="${jboss.deploy.dir}" overwrite="true"/>
-    <copy file="${build.dir}/jbossesb.xml" todir="${jboss.conf.dir}" overwrite="true"/>
+    <copy file="${jbossesb.config}" todir="${jboss.conf.dir}" overwrite="true"/>
     <touch file="${jboss.deploy.dir}/META-INF/jboss-service.xml"/>
   </target>
 

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/build.xml	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/build.xml	2007-01-11 15:18:18 UTC (rev 8821)
@@ -5,8 +5,11 @@
   <property name="build.dir" value="${basedir}/build"/>
   <property name="src.dir" value="${basedir}/src"/>
 		
-  <property name="esb-config" value="${basedir}/jbossesb.xml"/>
+  <property name="jbossesb.name" value="jbossesb.xml"/>
+  <property name="jbossesb.origconfig" location="${jbossesb.name}"/>
 
+  <property name="jbossesb.config" location="${build.dir}/${jbossesb.name}"/>
+
 	<path id="classpath">
     <!-- fileset dir="${basedir}" includes="jbossesb-properties.xml" -->
     <!-- fileset dir="${basedir}" includes="juddi.properties" -->  
@@ -42,6 +45,18 @@
  	</javac>
   </target>
 
+  <target name="config">
+    <copy file="${jbossesb.origconfig}" tofile="${jbossesb.config}"
+        overwrite="true" filtering="true">
+      <filterset>
+        <filter token="FTP_HOSTNAME" value="${jbossesb.ftp.hostname}"/>
+        <filter token="FTP_USERNAME" value="${jbossesb.ftp.username}"/>
+        <filter token="FTP_PASSWORD" value="${jbossesb.ftp.password}"/>
+        <filter token="FTP_DIRECTORY" value="${jbossesb.ftp.directory}"/>
+      </filterset>
+    </copy>
+  </target>
+
   <target name="jars" depends="compile">
 	<delete file="${build.dir}/${ant.project.name}.jar"/>
         <jar destfile="${build.dir}/${ant.project.name}.jar"
@@ -49,24 +64,36 @@
 		includes="**/*.class"/>
   </target>
 
-  <target name="run" depends="jars">
+  <target name="run" depends="jars, config">
 	     <echo>Basic FTP Gateway and JMS Listener with Actions</echo>
 	     <java fork="yes" classname="org.jboss.soa.esb.listeners.StandAloneBootStrapper" failonerror="true">  
-	     	<arg value="${esb-config}"/>
+	     	<arg value="${jbossesb.config}"/>
 			<classpath refid="classpath"/>
 	     </java>     
   </target>	
 
-  <target name="deployToSAR">
+  <target name="deployToSAR" depends="jars, config">
 	    <echo>Deploys the project to the JBoss Application Server ESB SAR</echo>
 	  	<copy file="${build.dir}/${ant.project.name}.jar" overwrite="true"
 	  		todir="${jbosshome.dir}/server/default/deploy/jbossesb.sar"	
 	  	/>
-	  	<copy file="jbossesb.xml" overwrite="true"
+	  	<copy file="${jbossesb.config}" overwrite="true"
 	  		todir="${jbosshome.dir}/server/default/conf"
 	  	/>
 	  	<touch file="${jbosshome.dir}/server/default/deploy/jbossesb.sar/META-INF/jboss-service.xml"/>
   </target>
 	
+  <target name="runtest">
+     <echo>Runs Test FTP File creator</echo>
+     <java fork="yes" classname="quickstart.hw_ftp_action.test.CreateTestFile" failonerror="true">
+        <arg value="${jbossesb.ftp.hostname}"/>
+        <arg value="${jbossesb.ftp.username}"/>
+        <arg value="${jbossesb.ftp.password}"/>
+        <arg value="${jbossesb.ftp.directory}/HWFtp.dat"/>
+        <arg value="Hello World In A File (for Hello World FTP Action test)"/> <!--  File Contents -->
+                <classpath refid="classpath"/>
+     </java>
+  </target>
 
+
 </project>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/jbossesb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/jbossesb.xml	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/jbossesb.xml	2007-01-11 15:18:18 UTC (rev 8821)
@@ -2,13 +2,13 @@
 <jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.xsd" parameterReloadSecs="5">
 
     <providers>
-          <ftp-provider name="FTPprovider" hostname="localhost" >
+          <ftp-provider name="FTPprovider" hostname="@FTP_HOSTNAME@" >
           	<ftp-bus busid="helloFTPChannel" >
           		<ftp-message-filter
-          			username="ftpuser"
-          			password="ftppassword"
+          			username="@FTP_USERNAME@"
+          			password="@FTP_PASSWORD@"
           			passive="false"
-          			directory="/tmp/esbInput"
+          			directory="@FTP_DIRECTORY@"
           			input-suffix=".dat"
           			work-suffix=".esbWorking"
           			post-delete="false"

Modified: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/readme.txt	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/readme.txt	2007-01-11 15:18:18 UTC (rev 8821)
@@ -6,7 +6,8 @@
   
 Before Running:
 ===============
-	1.	Update the "jbosshome.dir" property in the quickstarts.properties file in "../".
+	1.	Update the "jbosshome.dir" and all the jbossesb.ftp properties
+		in the quickstarts.properties file in "../".
 	2.	Make sure the jbossesb.sar is deployed on your JBoss Application Server.
 	3.	Make sure the JBoss Application server is running
 	4.  Make sure you have read/write access to an FTP server.  Write access is required
@@ -16,33 +17,17 @@
 To Run:
 =======
 	1.  In a command window type "ant" to bring up the listener
-	2.  Using your favorite FTP client place a file in the "/tmp/EsbInput" directory
+	2.  In a second command window type "ant runtest" to execute
 	3.  You should see the file contents displayed in the listener window
 	
 What to consider in this Quickstart:
 ===================================	
-1) There is an FTP server running (port 21) in the host specified in jbossesb.xml:
-	<ftp-provider name="FTPprovider" hostname="localhost" >
-2) That ftp server will take a user 'ftpuser' with password 'ftppasssword' (see jbossesb.xml)
-          		<ftp-message-filter
-          			username="ftpuser"
-          			password="ftppassword"
-          			passive="false"
-          			directory="/tmp/esbInput"
-					...
+1) The FTP configuration has been initialised in ../quickstarts.properties
 
-3) There is a directory tmp/esbInput relative to the home directory of ftpuser
-	(e.g. /home/ftpuser/tmp/esbInput)
-	
-4) This user must also have "write" access to the FTP server as the "in process"
+2) The FTP directory is accessable and can be written to as the "in process"
 and "completed" files are renamed accordingly. 
-
+	
 If you do not have write access you will receive an error that looks something like the 
 following:
      [java] 20:41:36,625 ERROR [Thread-5][AbstractFileGateway] Problems renaming
  file new_file.dat to new_file.dat.esbWorking
-
-
-
-
-				

Added: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/src/quickstart/hw_ftp_action/test/CreateTestFile.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/src/quickstart/hw_ftp_action/test/CreateTestFile.java	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/src/quickstart/hw_ftp_action/test/CreateTestFile.java	2007-01-11 15:18:18 UTC (rev 8821)
@@ -0,0 +1,90 @@
+package quickstart.hw_ftp_action.test;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class CreateTestFile {
+	
+	public static void main(final String[] args) {
+		if (args.length != 5)
+		{
+			System.err.println("Usage: java " + CreateTestFile.class.getName() + " <hostname> <username> <password> <filename> <contents>") ;
+			System.exit(1) ;
+		}
+		else
+		{
+			final String hostname = args[0] ;
+			final String username = args[1] ;
+			final String password = args[2] ;
+			final String filename = args[3] ;
+			final String contents = args[4] ;
+			
+			final URL url ;
+			final String filenameVal ;
+			if (filename.charAt(0) == '/')
+			{
+				filenameVal = (filename.length() > 1 ? "%2F" + filename.substring(1) : "%2F") ;
+			}
+			else
+			{
+				filenameVal = filename ;
+			}
+			try
+			{
+				url = new URL("ftp://" + username + ":" + password + "@" + hostname + "/" + filenameVal) ;
+			}
+			catch (final MalformedURLException murle)
+			{
+				exit("Invalid URL: " + filenameVal, murle, 2) ;
+				return ; // for compiler
+			}
+			final URLConnection connection ;
+			try
+			{
+				connection = url.openConnection() ;
+			}
+			catch (final IOException ioe)
+			{
+				exit("Error accessing location: " + filenameVal, ioe, 3) ;
+				return ; // for compiler
+			}
+			connection.setDoOutput(true) ;
+			final OutputStream os ;
+			try
+			{
+				os = connection.getOutputStream() ;
+			}
+			catch (final IOException ioe)
+			{
+				exit("Error obtaining output stream for location: " + filenameVal, ioe, 4) ;
+				return ; // for compiler
+			}
+			
+			try
+			{
+				final PrintStream ps = new PrintStream(os) ;
+				ps.print(contents) ;
+				ps.close() ;
+			}
+			finally
+			{
+				try
+				{
+					os.close() ;
+				}
+				catch (final IOException ioe) {} //ignore
+			}
+		}
+	}
+	
+	private static void exit(final String message, final Throwable th, final int exitValue)
+	{
+		System.err.println(message) ;
+		th.printStackTrace() ;
+		System.exit(exitValue) ;
+	}
+}


Property changes on: labs/jbossesb/trunk/product/samples/quickstarts/helloworld_ftp_action/src/quickstart/hw_ftp_action/test/CreateTestFile.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/trunk/product/samples/quickstarts/quickstarts.properties
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/quickstarts.properties	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/quickstarts.properties	2007-01-11 15:18:18 UTC (rev 8821)
@@ -13,3 +13,9 @@
 # Location of your JBoss Application Server installation.
 # NB: Avoid using back slashes '\' in the path - '/' works on all platforms.
 jbosshome.dir=
+
+# If you are running the ftp tests then you must complete the following
+jbossesb.ftp.hostname=
+jbossesb.ftp.username=
+jbossesb.ftp.password=
+jbossesb.ftp.directory=

Modified: labs/jbossesb/trunk/product/samples/quickstarts/static_router/build.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/static_router/build.xml	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/static_router/build.xml	2007-01-11 15:18:18 UTC (rev 8821)
@@ -5,8 +5,23 @@
   <property name="build.dir" value="${basedir}/build"/>
   <property name="src.dir" value="${basedir}/src"/>
 		
-  <property name="esb-config" value="${basedir}/jbossesb.xml"/>
+  <property name="jbossesb.name" value="jbossesb.xml"/>
+  <property name="jbossesb.origconfig" location="${jbossesb.name}"/>
 
+  <property name="jbossesb.config" location="${build.dir}/${jbossesb.name}"/>
+
+  <property name="jbossesb.rootdir" location="${build.dir}/dirs"/>
+  <property name="jbossesb.staticrouter.dir" location="${jbossesb.rootdir}/staticrouter"/>
+  <property name="jbossesb.service1.dir" location="${jbossesb.rootdir}/service01"/>
+  <property name="jbossesb.service1.input" location="${jbossesb.service1.dir}/input"/>
+  <property name="jbossesb.service1.post" location="${jbossesb.service1.dir}/post"/>
+  <property name="jbossesb.service2.dir" location="${jbossesb.rootdir}/service02"/>
+  <property name="jbossesb.service2.input" location="${jbossesb.service2.dir}/input"/>
+  <property name="jbossesb.service2.post" location="${jbossesb.service2.dir}/post"/>
+  <property name="jbossesb.service3.dir" location="${jbossesb.rootdir}/service03"/>
+  <property name="jbossesb.service3.input" location="${jbossesb.service3.dir}/input"/>
+  <property name="jbossesb.service3.post" location="${jbossesb.service3.dir}/post"/>
+
 	<path id="classpath">
     <!-- fileset dir="${basedir}" includes="jbossesb-properties.xml" -->
     <!-- fileset dir="${basedir}" includes="juddi.properties" -->
@@ -40,6 +55,39 @@
  	</javac>
   </target>
 
+  <target name="config">
+    <delete dir="${jbossesb.rootdir}" quiet="true"/>
+    <mkdir dir="${jbossesb.rootdir}"/>
+    <mkdir dir="${jbossesb.staticrouter.dir}"/>
+    <mkdir dir="${jbossesb.service1.dir}"/>
+    <mkdir dir="${jbossesb.service1.input}"/>
+    <mkdir dir="${jbossesb.service1.post}"/>
+    <mkdir dir="${jbossesb.service2.dir}"/>
+    <mkdir dir="${jbossesb.service2.input}"/>
+    <mkdir dir="${jbossesb.service2.post}"/>
+    <mkdir dir="${jbossesb.service3.dir}"/>
+    <mkdir dir="${jbossesb.service3.input}"/>
+    <mkdir dir="${jbossesb.service3.post}"/>
+
+    <copy file="${jbossesb.origconfig}" tofile="${jbossesb.config}"
+        overwrite="true" filtering="true">
+      <filterset>
+        <filter token="FTP_HOSTNAME" value="${jbossesb.ftp.hostname}"/>
+        <filter token="FTP_USERNAME" value="${jbossesb.ftp.username}"/>
+        <filter token="FTP_PASSWORD" value="${jbossesb.ftp.password}"/>
+        <filter token="FTP_DIRECTORY" value="${jbossesb.ftp.directory}"/>
+
+        <filter token="STATICROUTER" value="${jbossesb.staticrouter.dir}"/>
+        <filter token="SERVICE01" value="${jbossesb.service1.input}"/>
+        <filter token="SERVICE01_POST" value="${jbossesb.service1.post}"/>
+        <filter token="SERVICE02" value="${jbossesb.service2.input}"/>
+        <filter token="SERVICE02_POST" value="${jbossesb.service2.post}"/>
+        <filter token="SERVICE03" value="${jbossesb.service3.input}"/>
+        <filter token="SERVICE03_POST" value="${jbossesb.service3.post}"/>
+      </filterset>
+    </copy>
+  </target>
+
   <target name="jars" depends="compile">
 	<delete file="${build.dir}/${ant.project.name}.jar"/>
         <jar destfile="${build.dir}/${ant.project.name}.jar"
@@ -47,22 +95,35 @@
 		includes="**/*.class"/>
   </target>
 
-  <target name="run" depends="jars">
+  <target name="run" depends="jars, config">
 	     <echo>FTP Gateway file Listener and static router to file destination</echo>
 	     <java fork="yes" classname="org.jboss.soa.esb.listeners.StandAloneBootStrapper" failonerror="true">  
-	     	<arg value="${esb-config}"/>
+	     	<arg value="${jbossesb.config}"/>
 			<classpath refid="classpath"/>
 	     </java>     
   </target>	
 
+  <target name="deployToSAR" depends="jars, config">
+	    <echo>Deploys the project to the JBoss Application Server ESB SAR</echo>
+	  	<copy file="${build.dir}/${ant.project.name}.jar" overwrite="true"
+	  		todir="${jbosshome.dir}/server/default/deploy/jbossesb.sar"	
+	  	/>
+	  	<copy file="${jbossesb.config}" overwrite="true"
+	  		todir="${jbosshome.dir}/server/default/conf"
+	  	/>
+	  	<touch file="${jbosshome.dir}/server/default/deploy/jbossesb.sar/META-INF/jboss-service.xml"/>
+  </target>
+
   <target name="runtest">
-     <echo>Runs Test File creator (local filesystem)</echo>
+     <echo>Runs Test FTP File creator</echo>
      <java fork="yes" classname="quickstart.static_router.test.CreateTestFile" failonerror="true">
-     	<arg value="/tmp/ftpFiles"/> <!--  Directory -->
-     	<arg value="MyInput.dat"/> <!--  File name -->
-     	<arg value="Hello World In A File (for static router test)"/> <!--  File Contnets -->
+        <arg value="${jbossesb.ftp.hostname}"/>
+        <arg value="${jbossesb.ftp.username}"/>
+        <arg value="${jbossesb.ftp.password}"/>
+        <arg value="${jbossesb.ftp.directory}/StaticRouter.dat"/>
+     	<arg value="Hello World In A File (for static router test)"/> <!--  File Contents -->
 		<classpath refid="classpath"/>
      </java>
   </target>  
 
-</project>
\ No newline at end of file
+</project>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/static_router/jbossesb.xml
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/static_router/jbossesb.xml	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/static_router/jbossesb.xml	2007-01-11 15:18:18 UTC (rev 8821)
@@ -2,13 +2,13 @@
 <jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.xsd" >
 
     <providers>
-          <ftp-provider name="FTPprovider" hostname="localhost" >
+          <ftp-provider name="FTPprovider" hostname="@FTP_HOSTNAME@" >
           	<ftp-bus busid="StaticRouterFtpGW" >
           		<ftp-message-filter
-          			username="ftpuser"
-          			password="ftppassword"
+          			username="@FTP_USERNAME@"
+          			password="@FTP_PASSWORD@"
           			passive="false"
-          			directory="/tmp/esbInput"
+          			directory="@FTP_DIRECTORY@"
           			input-suffix=".dat"
           		/>
           	</ftp-bus>
@@ -17,32 +17,32 @@
           <fs-provider name="LocalFsProvider">
           	<fs-bus busid="staticRouter" >
           		<fs-message-filter
-          			directory="home/ftpuser/tmp"
+          			directory="@STATICROUTER@"
           			input-suffix=".esbMessage"
           		/>
           	</fs-bus>
           	<fs-bus busid="fileMessageDestination_01" >
           		<fs-message-filter
-          			directory="home/ftpuser/tmp"
+          			directory="@SERVICE01@"
           			input-suffix=".toRoute01"
           			post-delete="false"
-          			post-directory="/home/ftpuser/tmp"
+          			post-directory="@SERVICE01_POST@"
           		/>
           	</fs-bus>
           	<fs-bus busid="fileMessageDestination_02" >
           		<fs-message-filter
-          			directory="home/ftpuser/tmp"
+          			directory="@SERVICE02@"
           			input-suffix=".toRoute02"
           			post-delete="false"
-          			post-directory="/home/ftpuser/tmp"
+          			post-directory="@SERVICE02_POST@"
           		/>
           	</fs-bus>
           	<fs-bus busid="fileMessageDestination_03" >
           		<fs-message-filter
-          			directory="home/ftpuser/tmp"
+          			directory="@SERVICE03@"
           			input-suffix=".toRoute03"
           			post-delete="false"
-          			post-directory="/home/ftpuser/tmp"
+          			post-directory="@SERVICE03_POST@"
           		/>
           	</fs-bus>
           </fs-provider>

Modified: labs/jbossesb/trunk/product/samples/quickstarts/static_router/readme.txt
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/static_router/readme.txt	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/static_router/readme.txt	2007-01-11 15:18:18 UTC (rev 8821)
@@ -1,17 +1,10 @@
 This test assumes:
 
-1) There is an FTP server running (port 21) in the host specified in jbossesb.xml:
-	<ftp-provider name="FTPprovider" hostname="localhost" >
-2) That ftp server will take a user 'ftpuser' with password 'ftppasssword' (see jbossesb.xml)
-          		<ftp-message-filter
-          			username="ftpuser"
-          			password="ftppassword"
-          			passive="false"
-          			directory="/tmp/esbInput"
-					...
+1) That the quickstarts.properties file has been configured with the details
+   of the ftp server.
 
-3) there is a directory tmp/esbInput relative to the home directory of ftpuser
-	(e.g. /home/ftpuser/tmp/esbInput)
+2) That the configured ftp directory is writable.
 
-4) /home/ftpuser/tmp and child directories are readable-writeable- for everybody
-				
+This quick start will create a file on the FTP server and show the progress
+of the message through a static route.  Intermediate files will be created
+in the directories under build/dirs/

Modified: labs/jbossesb/trunk/product/samples/quickstarts/static_router/src/quickstart/static_router/test/CreateTestFile.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/static_router/src/quickstart/static_router/test/CreateTestFile.java	2007-01-11 14:57:39 UTC (rev 8820)
+++ labs/jbossesb/trunk/product/samples/quickstarts/static_router/src/quickstart/static_router/test/CreateTestFile.java	2007-01-11 15:18:18 UTC (rev 8821)
@@ -1,26 +1,90 @@
 package quickstart.static_router.test;
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
 
 public class CreateTestFile {
-           
-    
-    public static void main(String args[]) throws Exception
-    {        	    	
-    	String inputDirectory = args[0];
-    	String fileName = args[1];
-    	String fileContents = args[2];
-    	File x = new File(inputDirectory + "/" + fileName);
-    	try {
-    		BufferedWriter out = new BufferedWriter(new FileWriter(x));
-    		out.write(fileContents.toCharArray());
-    		out.close();
-    	} catch (Exception e) {
-    		System.out.println("Error while writing the file: " + inputDirectory + "/" + fileName);
-    		System.out.println(e.getMessage());
-    	}
-    }
-    
+	
+	public static void main(final String[] args) {
+		if (args.length != 5)
+		{
+			System.err.println("Usage: java " + CreateTestFile.class.getName() + " <hostname> <username> <password> <filename> <contents>") ;
+			System.exit(1) ;
+		}
+		else
+		{
+			final String hostname = args[0] ;
+			final String username = args[1] ;
+			final String password = args[2] ;
+			final String filename = args[3] ;
+			final String contents = args[4] ;
+			
+			final URL url ;
+			final String filenameVal ;
+			if (filename.charAt(0) == '/')
+			{
+				filenameVal = (filename.length() > 1 ? "%2F" + filename.substring(1) : "%2F") ;
+			}
+			else
+			{
+				filenameVal = filename ;
+			}
+			try
+			{
+				url = new URL("ftp://" + username + ":" + password + "@" + hostname + "/" + filenameVal) ;
+			}
+			catch (final MalformedURLException murle)
+			{
+				exit("Invalid URL: " + filenameVal, murle, 2) ;
+				return ; // for compiler
+			}
+			final URLConnection connection ;
+			try
+			{
+				connection = url.openConnection() ;
+			}
+			catch (final IOException ioe)
+			{
+				exit("Error accessing location: " + filenameVal, ioe, 3) ;
+				return ; // for compiler
+			}
+			connection.setDoOutput(true) ;
+			final OutputStream os ;
+			try
+			{
+				os = connection.getOutputStream() ;
+			}
+			catch (final IOException ioe)
+			{
+				exit("Error obtaining output stream for location: " + filenameVal, ioe, 4) ;
+				return ; // for compiler
+			}
+			
+			try
+			{
+				final PrintStream ps = new PrintStream(os) ;
+				ps.print(contents) ;
+				ps.close() ;
+			}
+			finally
+			{
+				try
+				{
+					os.close() ;
+				}
+				catch (final IOException ioe) {} //ignore
+			}
+		}
+	}
+	
+	private static void exit(final String message, final Throwable th, final int exitValue)
+	{
+		System.err.println(message) ;
+		th.printStackTrace() ;
+		System.exit(exitValue) ;
+	}
 }




More information about the jboss-svn-commits mailing list