Archive for October, 2009

SOAP Debugging with tcpdump

October 27th, 2009 No comments

You are on a Linux box (SOAP client) making a SOAP request to a SOAP server somewhere on port 80, to view the request and response with tcpdump here are the commands execute at shell.

Incoming SOAP envelope (server response)

tcpdump  -nnvvlXSs 4096 src port 80

Outgoing SOAP envelope (client request)

tcpdump  -nnvvlXSs 4096 dst port 80

Of course if you have additional traffic going in and out from this box you can use the “and” operator to fine tune what you are after.

Categories: General, Linux, Web/HTML Tags: ,

Java: File Copy and File Move

October 7th, 2009 No comments

It has been a while since I’ve done any major Java development, it seems I have got used to having all the standard file tools which are available in scripted 4th and 5th generation languages like PHP.

Java whilst incredibly powerful is sometimes a bit awkward when dealing with certain problems. Often it’s the level abstraction and/or ability to get under the hood that can cloud a somewhat simple task, in my case file copying and moving.

Here is a small package that simplifies file copies and moves :)

package Utils.SystemTools;


public class FileCopy{
	public static void copy(File source,File dest) throws IOException{
		catch (IOException e){
			throw e;
	public static void copy(String source,String dest) throws IOException{
			File sourceFile = new File(source);
			File destFile = new File(dest);
			InputStream in = new FileInputStream(sourceFile);
			OutputStream out = new FileOutputStream(destFile);
			int bufferSize = 1024;
			byte[] buf = new byte[bufferSize];
			int len;
			while ((len = > 0){
	    catch(IOException e){
	    	throw e;
	public static void move(String source,String dest) throws IOException{
		catch(IOException e){
			throw e;
		File sourceFile = new File(source);
		if (!sourceFile.delete()){
			throw new IOException("File deletion failed for: " + source);

	public static void move(File source,File dest) throws IOException{
		catch(IOException e){
			throw e;
		if (!source.delete()){
			throw new IOException("File deletion failed for: " + source.getPath());
Categories: Code, General, Java Tags: ,

Flex: Multiple File Uploader

October 1st, 2009 13 comments

Flex Multi UploaderUploading is such a common task and can often be a little painful so I decided to write a small library in Flex which simplifies the task. I have released it under GPL license so feel free to use and modify it according to the conditions :)

The Flex client side uploader supports multiple file upload with queuing and multiple threads, meaning more than one upload can be active at a time. It is also written in component style so creating an instance of the uploader is very simple and can be achieved in only a few lines of code (see the example below). It also supports posted additional data with the file upload, handy if you need to pass instructions to the back-end upload script.

The back-end script is not included in the library but could easily be implemented in any language. I have however supplied a PHP example below of how to implement the back-end script to support the Flex uploader (see the example below).

One final note, this code is not polished, it’s definitely Alpha…but still very usable. If you have any issues or questions please let me know, cheers.

Simple example implementation of uploader library

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx=""
			private function init():void{
	<cc:FileUploadComp id="fileUploader"

PHP backend example implementation of uploader code

	$tmpFileName = isset($_FILES['Filedata']['tmp_name']) ? $_FILES['Filedata']['tmp_name'] : '';
	$orgFileName = isset($_FILES['Filedata']['name']) ? $_FILES['Filedata']['name'] : '';
	$mydata = isset($_REQUEST['mydata']) ? $_REQUEST['mydata'] : '';
	error_log('tmpfile: ' . $tmpFileName);
	error_log('filename: ' . $orgFileName);
	error_log('mydata: ' . $mydata);	

	if (true){
		print 'ok'; 
		header('Status: 500 ' . $resultAry[1]);
		header('HTTP/1.1 500 ' . $resultAry[1]);
		$outputStr = '<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">' .
				 '<html><head>' .
				 '<title>500 ' . $resultAry[1] . '</title>' .
				 '</head><body>' .
				 '<h1>500 ' . $resultAry[1] . '</h1>' . 
				 '<hr>' .
		print $outputStr;

Also here’s and example of a Flash crossdomain.xml (this one is reasonably open!) which will be needed in the root of your site…otherwise flex will complain.

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "">
	<allow-access-from domain="*" to-ports="*"/>
	<site-control permitted-cross-domain-policies="all"/>

Demo Flex Uploader

DOWNLOAD (version 1.0a)