package org.positrium.waket;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import dareka.common.CloseUtil;
import dareka.common.Config;
import dareka.processor.HttpHeader;
import dareka.processor.HttpUtil;

/**
 * this is test class.
 * @author token
 * @version $Rev: 122 $
 *
 */
public class TestJsonHandler implements HttpHandler{
	@Override
	public void handle(HttpExchange arg0) throws IOException {
		String test = "{name: 'John Smith', age: 33}";
		arg0.sendResponseHeaders(HttpURLConnection.HTTP_OK, test.length());
		arg0.getResponseHeaders().set(HttpHeader.CONTENT_TYPE, "text/plain");
    		OutputStream out = arg0.getResponseBody();
    		InputStream in = new ByteArrayInputStream(test.getBytes());
        	try {
        		HttpUtil.sendBody(out, in, test.length());
        	} finally {
        		CloseUtil.close(out);
        		CloseUtil.close(in);
        	}
		
	}
}
