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;
}
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);
}
Aggregations