package org.netmelody.cii.response;

import java.io.IOException;
import java.io.PrintStream;

import org.netmelody.cii.witness.jenkins.JenkinsWitness;
import org.simpleframework.http.Address;
import org.simpleframework.http.Request;
import org.simpleframework.http.Response;
import org.simpleframework.http.resource.Resource;

import com.google.gson.Gson;

public final class JsonResponder implements Resource {

    private final Gson json = new Gson();
    private final Address target;

    public JsonResponder(Address target) {
        this.target = target;
    }

    @Override
    public void handle(Request request, Response response) {
        System.out.println(target.getPath());
        
        PrintStream body;
        try {
            body = response.getPrintStream();
            long time = System.currentTimeMillis();
            response.set("Content-Type", "application/json");
            response.set("Server", "CiEye/1.0 (Simple 4.0)");
            response.setDate("Date", time);
            response.setDate("Last-Modified", time);
            response.setDate("Expires", time + 10000);
            
            JenkinsWitness witness = new JenkinsWitness("http://ccmain:8080");
            
            System.out.println(json.toJson(witness.targetList()));
            body.println(json.toJson(witness.targetList()));
//            body.println("{\"targets\":[{\"name\":\"HIP\"},{\"name\":\"IDS-HIP\"},{\"name\":\"DataType\"}]}");
            
            body.close();        
        } catch (IOException e) {
            response.setCode(500);
        }
    }

}

@@ -1344,121 +1344,8 @@
 ));%0A
-//            body.println(%22%7B%5C%22targets%5C%22:%5B%7B%5C%22name%5C%22:%5C%22HIP%5C%22%7D,%7B%5C%22name%5C%22:%5C%22IDS-HIP%5C%22%7D,%7B%5C%22name%5C%22:%5C%22DataType%5C%22%7D%5D%7D%22);%0A
     

remove dead code