// Path: src/main/java/uk/ac/ic/wlgitbridge/util/Log.java
// public class Log {
// 
//     private static Logger logger = LoggerFactory.getLogger(GitBridgeApp.class);
// 
//     public static void trace(String msg) {
//         logger.trace(msg);
//     }
// 
//     public static void trace(String msg, Throwable t) {
//         logger.trace(msg, t);
//     }
// 
//     public static void debug(String msg) {
//         logger.debug(msg);
//     }
// 
//     public static void debug(String msg, Throwable t) {
//         logger.debug(msg, t);
//     }
// 
//     public static void info(String msg) {
//         logger.info(msg);
//     }
// 
//     public static void info(String format, Object arg) {
//         logger.info(format, arg);
//     }
// 
//     public static void info(String format, Object arg1, Object arg2) {
//         logger.info(format, arg1, arg2);
//     }
// 
//     public static void info(String format, Object... args) {
//         logger.info(format, args);
//     }
// 
//     public static void info(String msg, Throwable t) {
//         logger.info(msg, t);
//     }
// 
//     public static void warn(String msg) {
//         logger.warn(msg);
//     }
// 
//     public static void warn(String msg, Object arg) {
//         logger.warn(msg, arg);
//     }
// 
//     public static void warn(String msg, Object arg1, Object arg2) {
//         logger.warn(msg, arg1, arg2);
//     }
// 
//     public static void warn(String msg, Object... args) {
//         logger.warn(msg, args);
//     }
// 
//     public static void warn(String msg, Throwable t) {
//         logger.warn(msg, t);
//     }
// 
//     public static void error(String msg) {
//         logger.error(msg);
//     }
// 
//     public static void error(String msg, Object... args) {
//         logger.error(msg, args);
//     }
// 
//     public static void error(String msg, Throwable t) {
//         logger.error(msg, t);
//     }
// 
// }


import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import uk.ac.ic.wlgitbridge.snapshot.servermock.exception.
        InvalidAPICallException;
import uk.ac.ic.wlgitbridge.snapshot.servermock.response.*;
import uk.ac.ic.wlgitbridge.util.Log;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
package uk.ac.ic.wlgitbridge.snapshot.servermock.server;



/**
 * Created by Winston on 09/01/15.
 */
public class MockSnapshotRequestHandler extends AbstractHandler {

    private final SnapshotResponseBuilder responseBuilder;

    public MockSnapshotRequestHandler(
            SnapshotResponseBuilder responseBuilder
    ) {
        this.responseBuilder = responseBuilder;
    }

    @Override
    public void handle(
            String target,
            final Request baseRequest,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws IOException, ServletException {
        boolean handled;
        try {
            final SnapshotResponse snapshotResponse
                    = responseBuilder.buildWithTarget(
                            target, baseRequest.getMethod()
                    );
            response.getWriter().println(snapshotResponse.respond());
            new PostbackThread(
                    baseRequest.getReader(),
                    snapshotResponse.postback()
            ).startIfNotNull();
            handled = true;
        } catch (InvalidAPICallException e) {
            handled = false;
        } catch (RuntimeException e) {
// Path: src/main/java/uk/ac/ic/wlgitbridge/util/Log.java
// public class Log {
// 
//     private static Logger logger = LoggerFactory.getLogger(GitBridgeApp.class);
// 
//     public static void trace(String msg) {
//         logger.trace(msg);
//     }
// 
//     public static void trace(String msg, Throwable t) {
//         logger.trace(msg, t);
//     }
// 
//     public static void debug(String msg) {
//         logger.debug(msg);
//     }
// 
//     public static void debug(String msg, Throwable t) {
//         logger.debug(msg, t);
//     }
// 
//     public static void info(String msg) {
//         logger.info(msg);
//     }
// 
//     public static void info(String format, Object arg) {
//         logger.info(format, arg);
//     }
// 
//     public static void info(String format, Object arg1, Object arg2) {
//         logger.info(format, arg1, arg2);
//     }
// 
//     public static void info(String format, Object... args) {
//         logger.info(format, args);
//     }
// 
//     public static void info(String msg, Throwable t) {
//         logger.info(msg, t);
//     }
// 
//     public static void warn(String msg) {
//         logger.warn(msg);
//     }
// 
//     public static void warn(String msg, Object arg) {
//         logger.warn(msg, arg);
//     }
// 
//     public static void warn(String msg, Object arg1, Object arg2) {
//         logger.warn(msg, arg1, arg2);
//     }
// 
//     public static void warn(String msg, Object... args) {
//         logger.warn(msg, args);
//     }
// 
//     public static void warn(String msg, Throwable t) {
//         logger.warn(msg, t);
//     }
// 
//     public static void error(String msg) {
//         logger.error(msg);
//     }
// 
//     public static void error(String msg, Object... args) {
//         logger.error(msg, args);
//     }
// 
//     public static void error(String msg, Throwable t) {
//         logger.error(msg, t);
//     }
// 
// }


// Path: src/main/java/uk/ac/ic/wlgitbridge/snapshot/servermock/server/MockSnapshotRequestHandler.java
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import uk.ac.ic.wlgitbridge.snapshot.servermock.exception.
        InvalidAPICallException;
import uk.ac.ic.wlgitbridge.snapshot.servermock.response.*;
import uk.ac.ic.wlgitbridge.util.Log;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

package uk.ac.ic.wlgitbridge.snapshot.servermock.server;



/**
 * Created by Winston on 09/01/15.
 */
public class MockSnapshotRequestHandler extends AbstractHandler {

    private final SnapshotResponseBuilder responseBuilder;

    public MockSnapshotRequestHandler(
            SnapshotResponseBuilder responseBuilder
    ) {
        this.responseBuilder = responseBuilder;
    }

    @Override
    public void handle(
            String target,
            final Request baseRequest,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws IOException, ServletException {
        boolean handled;
        try {
            final SnapshotResponse snapshotResponse
                    = responseBuilder.buildWithTarget(
                            target, baseRequest.getMethod()
                    );
            response.getWriter().println(snapshotResponse.respond());
            new PostbackThread(
                    baseRequest.getReader(),
                    snapshotResponse.postback()
            ).startIfNotNull();
            handled = true;
        } catch (InvalidAPICallException e) {
            handled = false;
        } catch (RuntimeException e) {
            Log.warn("Runtime exception when handling request", e);