package org.usergrid.vx.client;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.vertx.java.core.Handler;
import org.vertx.java.core.SimpleHandler;
import org.vertx.java.core.Vertx;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.http.HttpClient;
import org.vertx.java.core.http.HttpClientRequest;
import org.vertx.java.core.http.HttpClientResponse;

public class HelloClient implements Handler<HttpClientResponse> {
        private static Logger logger = LoggerFactory.getLogger(HelloClient.class);
        private static Vertx vertx;
        private HttpClient httpClient;

        public static void main(String[] args) throws Exception {
                HelloClient hc = new HelloClient();
                hc.post();
        }
     
        public HelloClient(){
        	vertx = Vertx.newVertx();
            this.httpClient = vertx.createHttpClient().setHost("localhost").setPort(8080).setMaxPoolSize(1).setKeepAlive(true);
        }
        
        public void post(){
        	HttpClientRequest req = httpClient.request("POST", "/:appid/hello", this);
        	String value ="";
        	req.putHeader("content-length", value.length());
        	req.write(value);
        	req.exceptionHandler(new Handler<Exception>(){
                public void handle(Exception arg0) {
                        System.out.println("Something went wrong in client "+arg0);
                }
        	});
        	req.end();
        	try {
        		Thread.sleep(3000);
        	} catch (InterruptedException e) {
        		e.printStackTrace();
        	}
        }

        @Override
        public void handle(HttpClientResponse response) {
                response.endHandler(new SimpleHandler() {
                        public void handle() {
                                System.out.println("This is the end. My only friend, the end.");
                        }
                });
                response.dataHandler( new Handler<Buffer>(){
                        public void handle(Buffer buf) {
                                String s = new String( buf.getBytes() );
                                System.out.println("Data recieved: "+s);
                        }
                });
        }

}
@@ -687,22 +687,16 @@
         
-      
 HelloCli
@@ -719,30 +719,24 @@
 loClient();%0A
-      
           hc
@@ -821,26 +821,24 @@
 newVertx();%0A
-  
           th
@@ -1658,38 +1658,32 @@
 se) %7B%0A          
-      
 response.endHand
@@ -1716,36 +1716,24 @@
             
-          
-  
 public void 
@@ -1743,34 +1743,16 @@
 dle() %7B%0A
-                  
         
@@ -1822,28 +1822,16 @@
 end.%22);%0A
-            
         
@@ -1846,32 +1846,20 @@
         
-      %7D);%0A      
+%7D);%0A
         
@@ -1913,36 +1913,24 @@
             
-   
-         
 public void 
@@ -1964,34 +1964,16 @@
         
-       
-           
 String s
@@ -2019,34 +2019,16 @@
         
-     
-             
 System.o
@@ -2072,36 +2072,18 @@
         
-            %7D%0A      
+%7D%0A
         

fix ed's crazy indenting