com.thoughtworks.webstub.server.ServletContextFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of web-stub Show documentation
Show all versions of web-stub Show documentation
Library for stubbing external HTTP dependencies
The newest version!
package com.thoughtworks.webstub.server;
import static org.apache.commons.lang.StringUtils.isBlank;
public class ServletContextFactory {
public static final String STATUS_PATH = "/__status__";
public static ServletContextHandler create(String contextRoot) {
ServletContextHandler context = contextFor(contextRoot);
context.addServlet(STATUS_PATH, new StatusServlet(200));
return context;
}
private static ServletContextHandler contextFor(String contextRoot) {
if (isBlank(contextRoot))
throw new IllegalArgumentException("Invalid context root");
String prefixedRoot = contextRoot.startsWith("/") ? contextRoot : ("/" + contextRoot);
return new ServletContextHandler(prefixedRoot);
}
}