Search in sources :

Example 1 with StubRequestHandler

use of com.github.tomakehurst.wiremock.http.StubRequestHandler in project wiremock by wiremock.

the class JettyHttpServer method addMockServiceContext.

@SuppressWarnings({ "rawtypes", "unchecked" })
private ServletContextHandler addMockServiceContext(StubRequestHandler stubRequestHandler, FileSource fileSource, AsynchronousResponseSettings asynchronousResponseSettings, Options.ChunkedEncodingPolicy chunkedEncodingPolicy, boolean stubCorsEnabled, boolean browserProxyingEnabled, Notifier notifier) {
    ServletContextHandler mockServiceContext = new ServletContextHandler(jettyServer, "/");
    mockServiceContext.setInitParameter("org.eclipse.jetty.servlet.Default.maxCacheSize", "0");
    mockServiceContext.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", fileSource.getPath());
    mockServiceContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    mockServiceContext.addServlet(DefaultServlet.class, FILES_URL_MATCH);
    mockServiceContext.setAttribute(JettyFaultInjectorFactory.class.getName(), new JettyFaultInjectorFactory());
    mockServiceContext.setAttribute(StubRequestHandler.class.getName(), stubRequestHandler);
    mockServiceContext.setAttribute(Notifier.KEY, notifier);
    mockServiceContext.setAttribute(Options.ChunkedEncodingPolicy.class.getName(), chunkedEncodingPolicy);
    mockServiceContext.setAttribute("browserProxyingEnabled", browserProxyingEnabled);
    ServletHolder servletHolder = mockServiceContext.addServlet(WireMockHandlerDispatchingServlet.class, "/");
    servletHolder.setInitOrder(1);
    servletHolder.setInitParameter(RequestHandler.HANDLER_CLASS_KEY, StubRequestHandler.class.getName());
    servletHolder.setInitParameter(FaultInjectorFactory.INJECTOR_CLASS_KEY, JettyFaultInjectorFactory.class.getName());
    servletHolder.setInitParameter(WireMockHandlerDispatchingServlet.SHOULD_FORWARD_TO_FILES_CONTEXT, "true");
    if (asynchronousResponseSettings.isEnabled()) {
        scheduledExecutorService = newScheduledThreadPool(asynchronousResponseSettings.getThreads());
        mockServiceContext.setAttribute(WireMockHandlerDispatchingServlet.ASYNCHRONOUS_RESPONSE_EXECUTOR, scheduledExecutorService);
    }
    mockServiceContext.setAttribute(MultipartRequestConfigurer.KEY, buildMultipartRequestConfigurer());
    MimeTypes mimeTypes = new MimeTypes();
    mimeTypes.addMimeMapping("json", "application/json");
    mimeTypes.addMimeMapping("html", "text/html");
    mimeTypes.addMimeMapping("xml", "application/xml");
    mimeTypes.addMimeMapping("txt", "text/plain");
    mockServiceContext.setMimeTypes(mimeTypes);
    mockServiceContext.setWelcomeFiles(new String[] { "index.json", "index.html", "index.xml", "index.txt" });
    NotFoundHandler errorHandler = new NotFoundHandler(mockServiceContext);
    mockServiceContext.setErrorHandler(errorHandler);
    mockServiceContext.addFilter(ContentTypeSettingFilter.class, FILES_URL_MATCH, EnumSet.of(DispatcherType.FORWARD));
    mockServiceContext.addFilter(TrailingSlashFilter.class, FILES_URL_MATCH, EnumSet.allOf(DispatcherType.class));
    if (stubCorsEnabled) {
        addCorsFilter(mockServiceContext);
    }
    return mockServiceContext;
}
Also used : StubRequestHandler(com.github.tomakehurst.wiremock.http.StubRequestHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) MimeTypes(org.eclipse.jetty.http.MimeTypes) DispatcherType(javax.servlet.DispatcherType)

Example 2 with StubRequestHandler

use of com.github.tomakehurst.wiremock.http.StubRequestHandler in project wiremock by wiremock.

the class JettyHttpServerTest method init.

@BeforeEach
public void init() {
    Admin admin = Mockito.mock(Admin.class);
    adminRequestHandler = new AdminRequestHandler(AdminRoutes.defaults(), admin, new BasicResponseRenderer(), new NoAuthenticator(), false, Collections.<RequestFilter>emptyList());
    stubRequestHandler = new StubRequestHandler(Mockito.mock(StubServer.class), Mockito.mock(ResponseRenderer.class), admin, Collections.<String, PostServeAction>emptyMap(), Mockito.mock(RequestJournal.class), Collections.<RequestFilter>emptyList(), false);
}
Also used : NoAuthenticator(com.github.tomakehurst.wiremock.security.NoAuthenticator) StubRequestHandler(com.github.tomakehurst.wiremock.http.StubRequestHandler) PostServeAction(com.github.tomakehurst.wiremock.extension.PostServeAction) AdminRequestHandler(com.github.tomakehurst.wiremock.http.AdminRequestHandler) BasicResponseRenderer(com.github.tomakehurst.wiremock.http.BasicResponseRenderer) Admin(com.github.tomakehurst.wiremock.core.Admin) RequestFilter(com.github.tomakehurst.wiremock.extension.requestfilter.RequestFilter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StubRequestHandler (com.github.tomakehurst.wiremock.http.StubRequestHandler)2 Admin (com.github.tomakehurst.wiremock.core.Admin)1 PostServeAction (com.github.tomakehurst.wiremock.extension.PostServeAction)1 RequestFilter (com.github.tomakehurst.wiremock.extension.requestfilter.RequestFilter)1 AdminRequestHandler (com.github.tomakehurst.wiremock.http.AdminRequestHandler)1 BasicResponseRenderer (com.github.tomakehurst.wiremock.http.BasicResponseRenderer)1 NoAuthenticator (com.github.tomakehurst.wiremock.security.NoAuthenticator)1 DispatcherType (javax.servlet.DispatcherType)1 MimeTypes (org.eclipse.jetty.http.MimeTypes)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1