// Path: src/main/java/org/rakam/server/http/util/Lambda.java
// public class Lambda {
//     private final static Method biConsumerAccept;
//     private final static Method consumerAccept;
//     private final static Method functionApply;
//     private final static Method biFunctionApply;
// 
//     static {
//         try {
//             biConsumerAccept = BiConsumer.class.getMethod("accept", Object.class, Object.class);
//             consumerAccept = Consumer.class.getMethod("accept", Object.class);
//             functionApply = Function.class.getMethod("apply", Object.class);
//             biFunctionApply = BiFunction.class.getMethod("apply", Object.class, Object.class);
//         } catch (NoSuchMethodException e) {
//             throw Throwables.propagate(e);
//         }
//     }
// 
//     public static <T> T produceLambdaForConsumer(final Method sourceMethod) {
//         return produceLambda(sourceMethod, consumerAccept);
//     }
// 
//     public static BiFunction produceLambdaForBiFunction(Method method) {
//         return produceLambda(method, biFunctionApply);
//     }
// 
//     public static BiConsumer produceLambdaForBiConsumer(final Method sourceMethod) {
//         return produceLambda(sourceMethod, biConsumerAccept);
//     }
// 
//     public static Function produceLambdaForFunction(final Method sourceMethod) {
//         return produceLambda(sourceMethod, functionApply);
//     }
// 
//     public static <T> T produceLambda(final Method sourceMethod, final Method targetMethod) {
//         MethodHandles.Lookup lookup = lookup();
//         sourceMethod.setAccessible(true);
//         final MethodHandles.Lookup caller = lookup.in(sourceMethod.getDeclaringClass());
//         final MethodHandle implementationMethod;
// 
//         try {
//             implementationMethod = caller.unreflect(sourceMethod);
//         } catch (IllegalAccessException e) {
//            throw Throwables.propagate(e);
//         }
// 
//         final MethodType factoryMethodType = MethodType.methodType(targetMethod.getDeclaringClass());
// 
//         final Class<?> methodReturn = targetMethod.getReturnType();
//         final Class<?>[] methodParams = targetMethod.getParameterTypes();
// 
//         final MethodType functionMethodType = MethodType.methodType(methodReturn, methodParams);
// 
//         final CallSite lambdaFactory;
//         try {
//             lambdaFactory = LambdaMetafactory.metafactory(
//                     lookup,
//                     targetMethod.getName(),
//                     factoryMethodType,
//                     functionMethodType,
//                     implementationMethod,
//                     implementationMethod.type()
//             );
// 
//             final MethodHandle factoryInvoker = lambdaFactory.getTarget();
// 
//             return (T) factoryInvoker.invoke();
//         } catch (Throwable e) {
//             // TODO: fallback to classic reflection method if lambda generation fails.
//             throw new InternalError(String.format("Unable to generate lambda for method %s. %s",
//                     sourceMethod.getDeclaringClass().getName() + "." + sourceMethod.getName(),
//                     e.getMessage()));
//         }
//     }
// }
// 
// Path: src/main/java/org/rakam/server/http/HttpServer.java
// public static void returnError(RakamHttpRequest request, String message, HttpResponseStatus statusCode)
// {
//     byte[] bytes;
//     try {
//         bytes = DEFAULT_MAPPER.writeValueAsBytes(new ErrorMessage(ImmutableList.of(JsonAPIError.title(message)), null));
//     }
//     catch (JsonProcessingException e) {
//         throw new RuntimeException();
//     }
//     request.response(bytes, statusCode).headers().set("Content-Type", "application/json");
//     request.end();
// }


import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import org.rakam.server.http.util.Lambda;
import java.io.IOException;
import java.lang.reflect.Method;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static java.lang.String.format;
import static org.rakam.server.http.HttpServer.returnError;
package org.rakam.server.http;




public class JsonBeanRequestHandler implements HttpRequestHandler {
    private final ObjectMapper mapper;
    private final JavaType jsonClazz;
    private final boolean isAsync;
    private final HttpService service;
    private final List<RequestPreprocessor> requestPreprocessors;
// Path: src/main/java/org/rakam/server/http/util/Lambda.java
// public class Lambda {
//     private final static Method biConsumerAccept;
//     private final static Method consumerAccept;
//     private final static Method functionApply;
//     private final static Method biFunctionApply;
// 
//     static {
//         try {
//             biConsumerAccept = BiConsumer.class.getMethod("accept", Object.class, Object.class);
//             consumerAccept = Consumer.class.getMethod("accept", Object.class);
//             functionApply = Function.class.getMethod("apply", Object.class);
//             biFunctionApply = BiFunction.class.getMethod("apply", Object.class, Object.class);
//         } catch (NoSuchMethodException e) {
//             throw Throwables.propagate(e);
//         }
//     }
// 
//     public static <T> T produceLambdaForConsumer(final Method sourceMethod) {
//         return produceLambda(sourceMethod, consumerAccept);
//     }
// 
//     public static BiFunction produceLambdaForBiFunction(Method method) {
//         return produceLambda(method, biFunctionApply);
//     }
// 
//     public static BiConsumer produceLambdaForBiConsumer(final Method sourceMethod) {
//         return produceLambda(sourceMethod, biConsumerAccept);
//     }
// 
//     public static Function produceLambdaForFunction(final Method sourceMethod) {
//         return produceLambda(sourceMethod, functionApply);
//     }
// 
//     public static <T> T produceLambda(final Method sourceMethod, final Method targetMethod) {
//         MethodHandles.Lookup lookup = lookup();
//         sourceMethod.setAccessible(true);
//         final MethodHandles.Lookup caller = lookup.in(sourceMethod.getDeclaringClass());
//         final MethodHandle implementationMethod;
// 
//         try {
//             implementationMethod = caller.unreflect(sourceMethod);
//         } catch (IllegalAccessException e) {
//            throw Throwables.propagate(e);
//         }
// 
//         final MethodType factoryMethodType = MethodType.methodType(targetMethod.getDeclaringClass());
// 
//         final Class<?> methodReturn = targetMethod.getReturnType();
//         final Class<?>[] methodParams = targetMethod.getParameterTypes();
// 
//         final MethodType functionMethodType = MethodType.methodType(methodReturn, methodParams);
// 
//         final CallSite lambdaFactory;
//         try {
//             lambdaFactory = LambdaMetafactory.metafactory(
//                     lookup,
//                     targetMethod.getName(),
//                     factoryMethodType,
//                     functionMethodType,
//                     implementationMethod,
//                     implementationMethod.type()
//             );
// 
//             final MethodHandle factoryInvoker = lambdaFactory.getTarget();
// 
//             return (T) factoryInvoker.invoke();
//         } catch (Throwable e) {
//             // TODO: fallback to classic reflection method if lambda generation fails.
//             throw new InternalError(String.format("Unable to generate lambda for method %s. %s",
//                     sourceMethod.getDeclaringClass().getName() + "." + sourceMethod.getName(),
//                     e.getMessage()));
//         }
//     }
// }
// 
// Path: src/main/java/org/rakam/server/http/HttpServer.java
// public static void returnError(RakamHttpRequest request, String message, HttpResponseStatus statusCode)
// {
//     byte[] bytes;
//     try {
//         bytes = DEFAULT_MAPPER.writeValueAsBytes(new ErrorMessage(ImmutableList.of(JsonAPIError.title(message)), null));
//     }
//     catch (JsonProcessingException e) {
//         throw new RuntimeException();
//     }
//     request.response(bytes, statusCode).headers().set("Content-Type", "application/json");
//     request.end();
// }


// Path: src/main/java/org/rakam/server/http/JsonBeanRequestHandler.java
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import org.rakam.server.http.util.Lambda;
import java.io.IOException;
import java.lang.reflect.Method;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;
import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST;
import static java.lang.String.format;
import static org.rakam.server.http.HttpServer.returnError;

package org.rakam.server.http;




public class JsonBeanRequestHandler implements HttpRequestHandler {
    private final ObjectMapper mapper;
    private final JavaType jsonClazz;
    private final boolean isAsync;
    private final HttpService service;
    private final List<RequestPreprocessor> requestPreprocessors;
    private final HttpServer httpServer;