package com.creative.server;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;

import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.core.Container;
import org.simpleframework.http.core.ContainerSocketProcessor;
import org.simpleframework.transport.SocketProcessor;
import org.simpleframework.transport.connect.Connection;
import org.simpleframework.transport.connect.SocketConnection;

import com.creative.json.JsonData;
import com.creative.service.HTTPService;
import com.creative.service.StateService;
import com.creative.service.GeneralService;


public class ExchangeServer implements Container {

	private static HTTPService httpService;
	public static void main(String[] args) throws Exception{
		Container container = new ExchangeServer();
		SocketProcessor server = new ContainerSocketProcessor(container);
		Connection connection = new SocketConnection(server);
		SocketAddress address = new InetSocketAddress(10001);
		connection.connect(address);
		servicesPool.add(new StateService());
		ExchangeServer.httpService = new HTTPService();
	}
	private static ArrayList<GeneralService> servicesPool = new ArrayList<GeneralService>();
	public void handle(Request request, Response response) {
		System.out.println(request.getPath().getPath());
		boolean handled = false;		
		JsonData data;
		try{
			data = new JsonData(request.getPath().getPath().substring(1));
		}catch(Exception e){
			try {
				ExchangeServer.httpService.onMessage(response.getPrintStream(),request.getPath().getPath());
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			return;
		}

		for(GeneralService service : servicesPool){
			try { 
				if(service.processMessage(response.getPrintStream(), data)) 
					handled = true;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if(!handled) {
			try {
				response.getPrintStream().println("Error 404: Unknow request!");
				response.getPrintStream().close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}

@@ -132,22 +132,113 @@
 ava.
-util.ArrayList
+text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.ArrayList;%0Aimport java.util.Calendar
 ;%0A%0Ai
@@ -862,16 +862,101 @@
 ervice;%0A
+%09private static DateFormat dateFormat = new SimpleDateFormat(%22yyyy/MM/dd HH:mm:ss%22);%0A
 %09public 
@@ -1005,16 +1005,19 @@
 eption%7B%0A
+%09%09%0A
 %09%09Contai
@@ -1512,27 +1512,105 @@
 %7B%0A%09%09
-System.out.println(
+Calendar now = Calendar.getInstance();%0A%09%09System.out.println(dateFormat.format(now.getTime())+%22;%22+
 requ

add time stamp to log