package com.boundary.camel.component.util;

//This example is from the book _Java in a Nutshell_ by David Flanagan.
//Written by David Flanagan.  Copyright (c) 1996 O'Reilly & Associates.
//You may study, use, modify, and distribute this example for any purpose.
//This example is provided WITHOUT WARRANTY either expressed or implied.

import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.List;

public class SimpleServer extends Thread {
	public final static int DEFAULT_PORT = 6789;
	protected int port;
	protected ServerSocket listen_socket;
	List<Connection> connectionList;

	// Exit with an error message, when an exception occurs.
	public static void fail(Exception e, String msg) {
		System.err.println(msg + ": " + e);
		System.exit(1);
	}

	// Create a ServerSocket to listen for connections on; start the thread.
	public SimpleServer(int port) {
		connectionList = new ArrayList<Connection>();
		if (port == 0)
			port = DEFAULT_PORT;
		this.port = port;
		try {
			listen_socket = new ServerSocket(port);
		} catch (IOException e) {
			fail(e, "Exception creating server socket");
		}
		System.out.println("Server: listening on port " + port);
		this.start();
	}

	// The body of the server thread. Loop forever, listening for and
	// accepting connections from clients. For each connection,
	// create a Connection object to handle communication through the
	// new Socket.
	public void run() {
		try {
			Socket clientSocket = listen_socket.accept();
		} catch (IOException e) {
			fail(e, "Exception while listening for connections");
		}
	}

	// Start the server up, listening on an optionally specified port
	public static void main(String[] args) {
		int port = 5555;
		if (args.length == 1) {
			try {
				port = Integer.parseInt(args[0]);
			} catch (NumberFormatException e) {
				port = 0;
			}
		}
		new SimpleServer(port);
	}

	public void stopServer(){
		try {
		listen_socket.close();
		} catch(Exception e) {
			System.out.println("Stopping Server");
		}
	}
}

@@ -41,301 +41,8 @@
 l;%0A%0A
-//This example is from the book _Java in a Nutshell_ by David Flanagan.%0A//Written by David Flanagan.  Copyright (c) 1996 O'Reilly & Associates.%0A//You may study, use, modify, and distribute this example for any purpose.%0A//This example is provided WITHOUT WARRANTY either expressed or implied.%0A%0A
 impo
@@ -126,16 +126,102 @@
 .List;%0A%0A
+/**%0A * Implements a simple TCP listener for port testing%0A * %0A * @author davidg%0A *%0A */%0A
 public c
@@ -402,55 +402,84 @@
 %0A%0A%09/
-/ Exit with an error message, when an e
+**%0A%09 * Helper function to output an error%0A%09 * %0A%09 * @param e %7B@link E
 xception
  occ
@@ -478,16 +478,91 @@
 tion
+%7D that
  oc
-c
 ur
-s.
+red%0A%09 * @param msg %7B@link String%7D containing an informative message%0A%09 */
 %0A%09pu
@@ -676,79 +676,120 @@
 %0A%0A%09/
-/ Create a ServerSocket to listen for connections on; start the thread.
+**%0A%09 * Starts a simple TCP server on the provided report.%0A%09 * %0A%09 * @param port Number of the listening port%0A%09 */
 %0A%09pu
@@ -1143,216 +1143,69 @@
 %0A%0A%09/
-/ The body of the server thread. Loop forever, listening for and%0A%09// accepting connections from clients. For each connection,%0A%09// create a Connection object to handle communication through the%0A%09// new Socket.
+**%0A%09 * Runs waiting for a connection on the socket.%0A%09 * %0A%09 */
 %0A%09pu
@@ -1378,72 +1378,131 @@
 %0A%0A%09/
-/ Start the server up, listening on an optionally specified port
+**%0A%09 * Application that runs a socket on port passed to the program%0A%09 * %0A%09 * @param args Port to use, defaults to 5555%0A%09 */
 %0A%09pu
@@ -1724,16 +1724,95 @@
 t);%0A%09%7D%0A%0A
+%09/**%0A%09 * Stop listening on the socket by closing %7B@link Socket%7D instance.%0A%09 */%0A
 %09public 

Add javadocs to TCP listener used for testing