package com.ociweb.oe.foglight.api;


import com.ociweb.iot.maker.FogApp;
import com.ociweb.iot.maker.FogRuntime;
import com.ociweb.iot.maker.Hardware;
import com.ociweb.pronghorn.network.config.HTTPHeaderDefaults;

public class HTTPServer implements FogApp
{
	byte[] cookieHeader = HTTPHeaderDefaults.COOKIE.rootBytes();
	
	int emptyResponseRouteId;
	int smallResponseRouteId;
	int largeResponseRouteId;
	int fileServerId;
	int port;
	
	
	byte[] myArgName = "myarg".getBytes();
	
	public HTTPServer(int port) {
		this.port = port;
	}
	
    @Override
    public void declareConnections(Hardware c) {
        
        c.useHTTP1xServer(port).setHost("0.0.0.0").useInsecureServer();
		emptyResponseRouteId = c.registerRoute("/testpageA?arg=#{myarg}", cookieHeader);
		smallResponseRouteId = c.registerRoute("/testpageB");
		largeResponseRouteId = c.registerRoute("/testpageC", cookieHeader);
		fileServerId         = c.registerRoute("/file${path}");
		c.enableTelemetry();
		
    }


    @Override
    public void declareBehavior(FogRuntime runtime) {
        runtime.addRestListener(new RestBehaviorEmptyResponse(runtime, myArgName))
                 .includeRoutes(emptyResponseRouteId);
        
        runtime.addRestListener(new RestBehaviorSmallResponse(runtime))
        		.includeRoutes(smallResponseRouteId);
        
        runtime.addRestListener(new RestBehaviorLargeResponse(runtime))
        		 .includeRoutes(largeResponseRouteId);
        
        //NOTE .includeAllRoutes() can be used to write a behavior taking all routes
        
        //NOTE when using the above no routes need to be registered and if they are
        //     all other routes will return a 404

    }
   
}

@@ -697,37 +697,54 @@
 RouteId = c.
-registerRoute
+defineRoute(cookieHeader).path
 (%22/testpageA
@@ -757,30 +757,26 @@
 %7Bmyarg%7D%22
-, cookieHeader
+).routeId(
 );%0A%09%09sma
@@ -793,37 +793,42 @@
 RouteId = c.
-registerRoute
+defineRoute().path
 (%22/testpageB
@@ -829,16 +829,26 @@
 tpageB%22)
+.routeId()
 ;%0A%09%09larg
@@ -872,48 +872,61 @@
 = c.
-registerRoute(%22/testpageC%22, cookieHeader
+defineRoute(cookieHeader).path(%22/testpageC%22).routeId(
 );%0A%09
@@ -955,21 +955,26 @@
 = c.
-registerRoute
+defineRoute().path
 (%22/f
@@ -985,16 +985,26 @@
 %7Bpath%7D%22)
+.routeId()
 ;%0A%09%09c.en

update to new API