// Path: jadler-core/src/main/java/net/jadler/RequestManager.java
// public interface RequestManager {
// 
//     /**
//      * Returns a stub response for the given request. The request is recorded for further mocking (verifying).
//      *
//      * @param req http request to return a stub response for
//      * @return definition of a stub response to be returned by the stub http server (never returns {@code null})
//      */
//     StubResponse provideStubResponseFor(Request req);
// 
// 
//     /**
//      * Verifies whether the number of received http requests fitting the given predicates is as expected. Basically
//      * at first this operation computes the exact number of http requests received so far fitting the given predicates
//      * and then verifies whether the number is as expected. If not a {@link net.jadler.mocking.VerificationException}
//      * is thrown and the exact reason is logged on the {@code INFO} level.
//      *
//      * @param requestPredicates   predicates about the http requests received so far (cannot be {@code null}, can be
//      *                            empty however)
//      * @param nrRequestsPredicate a predicate about the number of http requests received so far which fit the given
//      *                            request predicates (cannot be {@code null})
//      * @throws net.jadler.mocking.VerificationException if the verification fails
//      */
//     void evaluateVerification(Collection<Matcher<? super Request>> requestPredicates,
//                               Matcher<Integer> nrRequestsPredicate);
// 
// 
//     /**
//      * @param predicates predicates to be applied on all incoming http requests
//      * @return number of requests recorded by {@link #provideStubResponseFor(net.jadler.Request)} matching the
//      * given matchers
//      * @deprecated this (rather internal) method has been deprecated. Please use
//      * {@link #evaluateVerification(java.util.Collection, org.hamcrest.Matcher)} instead
//      */
//     @Deprecated
//     int numberOfRequestsMatching(Collection<Matcher<? super Request>> predicates);
// }
// 
// Path: jadler-core/src/main/java/net/jadler/stubbing/server/StubHttpServer.java
// public interface StubHttpServer {
// 
//     /**
//      * Registers a response provider. This component provides a response prescription (in form
//      * of a {@link net.jadler.stubbing.StubResponse} instance) for a given http request.
//      *
//      * @param requestManager response provider to use to retrieve response prescriptions.
//      */
//     void registerRequestManager(RequestManager requestManager);
// 
// 
//     /**
//      * Starts the underlying http server. From now, the server must be able to respond
//      * according to prescriptions returned from the registered {@link StubHttpServerManager} instance.
//      *
//      * @throws Exception when ugh... something went wrong
//      */
//     void start() throws Exception;
// 
// 
//     /**
//      * Stops the underlying http server.
//      *
//      * @throws Exception when an error occurred while stopping the server
//      */
//     void stop() throws Exception;
// 
// 
//     /**
//      * @return HTTP server port
//      */
//     int getPort();
// }


import net.jadler.RequestManager;
import net.jadler.stubbing.server.StubHttpServer;
import org.apache.commons.lang.Validate;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
 * Copyright (c) 2012 - 2016 Jadler contributors
 * This program is made available under the terms of the MIT License.
 */
package net.jadler.stubbing.server.jetty;



/**
 * Default stub http server implementation using Jetty as an http server.
 */
public class JettyStubHttpServer implements StubHttpServer {

    private static final Logger logger = LoggerFactory.getLogger(JettyStubHttpServer.class);
    private final Server server;
    private final Connector httpConnector;

    public JettyStubHttpServer() {
        this(0);
    }


    public JettyStubHttpServer(final int port) {
        this.server = new Server();
        this.server.setSendServerVersion(false);
        this.server.setSendDateHeader(true);

        this.httpConnector = new SelectChannelConnector();
        this.httpConnector.setPort(port);
        server.addConnector(this.httpConnector);
    }


    /**
     * {@inheritDoc}
     */
    @Override
// Path: jadler-core/src/main/java/net/jadler/RequestManager.java
// public interface RequestManager {
// 
//     /**
//      * Returns a stub response for the given request. The request is recorded for further mocking (verifying).
//      *
//      * @param req http request to return a stub response for
//      * @return definition of a stub response to be returned by the stub http server (never returns {@code null})
//      */
//     StubResponse provideStubResponseFor(Request req);
// 
// 
//     /**
//      * Verifies whether the number of received http requests fitting the given predicates is as expected. Basically
//      * at first this operation computes the exact number of http requests received so far fitting the given predicates
//      * and then verifies whether the number is as expected. If not a {@link net.jadler.mocking.VerificationException}
//      * is thrown and the exact reason is logged on the {@code INFO} level.
//      *
//      * @param requestPredicates   predicates about the http requests received so far (cannot be {@code null}, can be
//      *                            empty however)
//      * @param nrRequestsPredicate a predicate about the number of http requests received so far which fit the given
//      *                            request predicates (cannot be {@code null})
//      * @throws net.jadler.mocking.VerificationException if the verification fails
//      */
//     void evaluateVerification(Collection<Matcher<? super Request>> requestPredicates,
//                               Matcher<Integer> nrRequestsPredicate);
// 
// 
//     /**
//      * @param predicates predicates to be applied on all incoming http requests
//      * @return number of requests recorded by {@link #provideStubResponseFor(net.jadler.Request)} matching the
//      * given matchers
//      * @deprecated this (rather internal) method has been deprecated. Please use
//      * {@link #evaluateVerification(java.util.Collection, org.hamcrest.Matcher)} instead
//      */
//     @Deprecated
//     int numberOfRequestsMatching(Collection<Matcher<? super Request>> predicates);
// }
// 
// Path: jadler-core/src/main/java/net/jadler/stubbing/server/StubHttpServer.java
// public interface StubHttpServer {
// 
//     /**
//      * Registers a response provider. This component provides a response prescription (in form
//      * of a {@link net.jadler.stubbing.StubResponse} instance) for a given http request.
//      *
//      * @param requestManager response provider to use to retrieve response prescriptions.
//      */
//     void registerRequestManager(RequestManager requestManager);
// 
// 
//     /**
//      * Starts the underlying http server. From now, the server must be able to respond
//      * according to prescriptions returned from the registered {@link StubHttpServerManager} instance.
//      *
//      * @throws Exception when ugh... something went wrong
//      */
//     void start() throws Exception;
// 
// 
//     /**
//      * Stops the underlying http server.
//      *
//      * @throws Exception when an error occurred while stopping the server
//      */
//     void stop() throws Exception;
// 
// 
//     /**
//      * @return HTTP server port
//      */
//     int getPort();
// }


// Path: jadler-jetty/src/main/java/net/jadler/stubbing/server/jetty/JettyStubHttpServer.java
import net.jadler.RequestManager;
import net.jadler.stubbing.server.StubHttpServer;
import org.apache.commons.lang.Validate;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * Copyright (c) 2012 - 2016 Jadler contributors
 * This program is made available under the terms of the MIT License.
 */
package net.jadler.stubbing.server.jetty;



/**
 * Default stub http server implementation using Jetty as an http server.
 */
public class JettyStubHttpServer implements StubHttpServer {

    private static final Logger logger = LoggerFactory.getLogger(JettyStubHttpServer.class);
    private final Server server;
    private final Connector httpConnector;

    public JettyStubHttpServer() {
        this(0);
    }


    public JettyStubHttpServer(final int port) {
        this.server = new Server();
        this.server.setSendServerVersion(false);
        this.server.setSendDateHeader(true);

        this.httpConnector = new SelectChannelConnector();
        this.httpConnector.setPort(port);
        server.addConnector(this.httpConnector);
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public void registerRequestManager(final RequestManager ruleProvider) {