Search in sources :

Example 1 with AdminRequestHandler

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

the class JettyHttpServer method addAdminContext.

private ServletContextHandler addAdminContext(AdminRequestHandler adminRequestHandler, Notifier notifier) {
    ServletContextHandler adminContext = new ServletContextHandler(jettyServer, ADMIN_CONTEXT_ROOT);
    adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.maxCacheSize", "0");
    String javaVendor = System.getProperty("java.vendor");
    if (javaVendor != null && javaVendor.toLowerCase().contains("android")) {
        // Special case for Android, fixes IllegalArgumentException("resource assets not found."):
        // The Android ClassLoader apparently does not resolve directories.
        // Furthermore, lib assets will be merged into a single asset directory when a jar file is
        // assimilated into an apk.
        // As resources can be addressed like "assets/swagger-ui/index.html", a static path element
        // will suffice.
        adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", "assets");
    } else {
        adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", Resources.getResource("assets").toString());
    }
    Resources.getResource("assets/swagger-ui/index.html");
    adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    ServletHolder swaggerUiServletHolder = adminContext.addServlet(DefaultServlet.class, "/swagger-ui/*");
    swaggerUiServletHolder.setAsyncSupported(false);
    adminContext.addServlet(DefaultServlet.class, "/recorder/*");
    ServletHolder servletHolder = adminContext.addServlet(WireMockHandlerDispatchingServlet.class, "/");
    servletHolder.setInitParameter(RequestHandler.HANDLER_CLASS_KEY, AdminRequestHandler.class.getName());
    adminContext.setAttribute(AdminRequestHandler.class.getName(), adminRequestHandler);
    adminContext.setAttribute(Notifier.KEY, notifier);
    adminContext.setAttribute(MultipartRequestConfigurer.KEY, buildMultipartRequestConfigurer());
    addCorsFilter(adminContext);
    return adminContext;
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) AdminRequestHandler(com.github.tomakehurst.wiremock.http.AdminRequestHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 2 with AdminRequestHandler

use of com.github.tomakehurst.wiremock.http.AdminRequestHandler 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)

Example 3 with AdminRequestHandler

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

the class AdminRequestHandlerTest method init.

@BeforeEach
public void init() {
    httpResponder = new MockHttpResponder();
    handler = new AdminRequestHandler(AdminRoutes.defaults(), admin, new BasicResponseRenderer(), new NoAuthenticator(), false, Collections.<RequestFilter>emptyList());
}
Also used : NoAuthenticator(com.github.tomakehurst.wiremock.security.NoAuthenticator) AdminRequestHandler(com.github.tomakehurst.wiremock.http.AdminRequestHandler) BasicResponseRenderer(com.github.tomakehurst.wiremock.http.BasicResponseRenderer) MockHttpResponder(com.github.tomakehurst.wiremock.testsupport.MockHttpResponder) RequestFilter(com.github.tomakehurst.wiremock.extension.requestfilter.RequestFilter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

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