package io.sinistral.proteus.controllers.handlers;

import static io.sinistral.proteus.server.Extractors.*;

import com.google.inject.Inject;
import com.google.inject.name.Named;
import io.sinistral.controllers.Benchmarks;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.RoutingHandler;
import io.undertow.server.handlers.PathHandler;

import java.lang.String;
import java.util.Map;
import java.util.function.Supplier;

/**
 * 
 * This would normally be generated by the ProteusApplication.
 * @author noboomu
 *
 */
public class BenchmarksRouteSupplier implements Supplier<HttpHandler> {
  protected final Benchmarks benchmarksController;

  protected final Map<String, HandlerWrapper> registeredHandlerWrappers;

  @Inject
  public BenchmarksRouteSupplier(Benchmarks benchmarksController,
      @Named("registeredHandlerWrappers") Map<String, HandlerWrapper> registeredHandlerWrappers) {
    this.benchmarksController = benchmarksController;
    this.registeredHandlerWrappers = registeredHandlerWrappers;
  }

  public HttpHandler get() {
	  
    final PathHandler router = new PathHandler();

    final io.undertow.server.HttpHandler benchmarksDbPostgresHandler = new io.undertow.server.HttpHandler() {
      @java.lang.Override
      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
          java.lang.Exception {

        benchmarksController.dbPostgres(exchange);
      }
    };

    router.addExactPath("/db",new io.undertow.server.handlers.BlockingHandler(benchmarksDbPostgresHandler));
    


    final io.undertow.server.HttpHandler benchmarksDbMySqlHandler = new io.undertow.server.HttpHandler() {
      @java.lang.Override
      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
          java.lang.Exception {

        benchmarksController.dbMySql(exchange);
      }
    };

    router.addExactPath("/db/mysql",new io.undertow.server.handlers.BlockingHandler(benchmarksDbMySqlHandler));

    final io.undertow.server.HttpHandler benchmarksFortunesMysqlHandler = new io.undertow.server.HttpHandler() {
      @java.lang.Override
      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
          java.lang.Exception {

        benchmarksController.fortunesMysql(exchange);
      }
    };

    router.addExactPath("/fortunes/mysql",new io.undertow.server.handlers.BlockingHandler(benchmarksFortunesMysqlHandler));

    final io.undertow.server.HttpHandler benchmarksFortunesPostgresHandler = new io.undertow.server.HttpHandler() {
      @java.lang.Override
      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
          java.lang.Exception {

        benchmarksController.fortunesPostgres(exchange);
      }
    };

    router.addExactPath("/fortunes",new io.undertow.server.handlers.BlockingHandler(benchmarksFortunesPostgresHandler));

    final io.undertow.server.HttpHandler benchmarksPlaintextHandler = new io.undertow.server.HttpHandler() {
      @java.lang.Override
      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
          java.lang.Exception {

        benchmarksController.plaintext(exchange);
      }
    };

    router.addExactPath("/plaintext",benchmarksPlaintextHandler);

    final io.undertow.server.HttpHandler benchmarksJsonHandler = new io.undertow.server.HttpHandler() {
      @java.lang.Override
      public void handleRequest(final io.undertow.server.HttpServerExchange exchange) throws
          java.lang.Exception {

        benchmarksController.json(exchange);
      }
    };

    router.addExactPath("/json",benchmarksJsonHandler);


    return router;
  }
}

@@ -1423,48 +1423,385 @@
     
-benchmarksController.dbPostgres(exchange
+    exchange.dispatch(() -%3E%0A            %7B%0A              try%0A              %7B%0A                benchmarksController.dbPostgres(exchange);%0A              %7D catch (Exception e)%0A              %7B%0A                exchange.putAttachment(io.sinistral.proteus.server.handlers.ServerDefaultResponseListener.EXCEPTION, e);%0A                exchange.endExchange();%0A              %7D%0A            %7D
 );%0A 
@@ -3107,54 +3107,391 @@
     
-benchmarksController.fortunesPostgres(exchange
+    exchange.dispatch(() -%3E%0A            %7B%0A              try%0A              %7B%0A                benchmarksController.fortunesPostgres(exchange);%0A              %7D catch (Exception e)%0A              %7B%0A                exchange.putAttachment(io.sinistral.proteus.server.handlers.ServerDefaultResponseListener.EXCEPTION, e);%0A                exchange.endExchange();%0A              %7D%0A            %7D
 );%0A 

Update handlers. (#4249)