use of org.eclipse.jetty.servlet.FilterHolder in project qi4j-sdk by Qi4j.
the class JettyConfigurationHelper method addFilters.
static void addFilters(ServletContextHandler root, Iterable<ServiceReference<Filter>> filters) {
// Iterate the available filters and add them to the server
for (ServiceReference<Filter> filter : filters) {
FilterInfo filterInfo = filter.metaInfo(FilterInfo.class);
String filterPath = filterInfo.getPath();
Filter filterInstance = filter.get();
FilterHolder holder = new FilterHolder(filterInstance);
holder.setInitParameters(filterInfo.initParameters());
root.addFilter(holder, filterPath, filterInfo.dispatchers());
}
}
use of org.eclipse.jetty.servlet.FilterHolder in project platformlayer by platformlayer.
the class StandaloneXaasWebserver method start.
public boolean start() throws Exception {
LogbackHook.attachToRootLogger();
this.server = new Server();
{
SslContextFactory sslContextFactory = new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH);
{
CertificateAndKey certificateAndKey = encryptionStore.getCertificateAndKey("https");
String secret = KeyStoreUtils.DEFAULT_KEYSTORE_SECRET;
KeyStore keystore = KeyStoreUtils.createEmpty(secret);
String alias = "https";
KeyStoreUtils.put(keystore, alias, certificateAndKey, secret);
sslContextFactory.setKeyStore(keystore);
sslContextFactory.setKeyStorePassword(secret);
sslContextFactory.setCertAlias(alias);
}
// TODO: Preconfigure a better SSLContext??
SSLContext sslContext = SSLContext.getDefault();
sslContextFactory.setIncludeCipherSuites(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledCipherSuites());
sslContextFactory.setIncludeProtocols(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledProtocols());
SslSelectChannelConnector connector = new SslSelectChannelConnector(sslContextFactory);
connector.setPort(PORT);
String host = configuration.lookup("http.host", null);
if (host != null) {
connector.setHost(host);
}
server.setConnectors(new Connector[] { connector });
}
ContextHandlerCollection contexts = new ContextHandlerCollection();
{
ServletContextHandler context = new ServletContextHandler(contexts, "/api");
// context.setContextPath("/");
context.addEventListener(guiceServletConfig);
// Must add DefaultServlet for embedded Jetty
// Failing to do this will cause 404 errors.
context.addServlet(DefaultServlet.class, "/");
FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
context.addFilter(filterHolder, "*", EnumSet.of(DispatcherType.REQUEST));
context.setClassLoader(Thread.currentThread().getContextClassLoader());
}
for (Entry<String, File> entry : wars.entrySet()) {
String contextPath = entry.getKey();
File war = entry.getValue();
WebAppContext context = new WebAppContext();
context.setWar(war.getAbsolutePath());
context.setContextPath(contextPath);
context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
context.addFilter(GwtCacheHeaderFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
contexts.addHandler(context);
}
server.setHandler(contexts);
server.addLifeCycleListener(new CloseOnFailLifecycleListener());
server.start();
if (!server.isStarted()) {
return false;
}
if (configuration.lookup("jobrunner.enabled", true)) {
scheduler.start();
jobPoller.start();
}
return true;
}
use of org.eclipse.jetty.servlet.FilterHolder in project pulsar by yahoo.
the class WebService method addServlet.
public void addServlet(String path, ServletHolder servletHolder, boolean requiresAuthentication) {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath(path);
context.addServlet(servletHolder, MATCH_ALL);
context.setAttribute(WebService.ATTRIBUTE_PULSAR_NAME, pulsar);
if (requiresAuthentication && pulsar.getConfiguration().isAuthenticationEnabled()) {
FilterHolder filter = new FilterHolder(new AuthenticationFilter(pulsar));
context.addFilter(filter, MATCH_ALL, EnumSet.allOf(DispatcherType.class));
}
log.info("Servlet path: '{}' -- Enable client version check: {} -- shouldCheckApiVersionOnPath: {}", path, pulsar.getConfiguration().isClientLibraryVersionCheckEnabled(), shouldCheckApiVersionOnPath(path));
if (pulsar.getConfiguration().isClientLibraryVersionCheckEnabled() && shouldCheckApiVersionOnPath(path)) {
// Add the ApiVersionFilter to reject request from deprecated
// clients.
FilterHolder holder = new FilterHolder(new ApiVersionFilter(pulsar, pulsar.getConfiguration().isClientLibraryVersionCheckAllowUnversioned()));
context.addFilter(holder, MATCH_ALL, EnumSet.allOf(DispatcherType.class));
log.info("Enabling ApiVersionFilter");
}
FilterHolder responseFilter = new FilterHolder(new ResponseHandlerFilter(pulsar));
context.addFilter(responseFilter, MATCH_ALL, EnumSet.allOf(DispatcherType.class));
handlers.add(context);
}
use of org.eclipse.jetty.servlet.FilterHolder in project symmetric-ds by JumpMind.
the class SymmetricWebServer method start.
public SymmetricWebServer start(int httpPort, int securePort, int httpJmxPort, Mode mode) throws Exception {
TransportManagerFactory.initHttps(httpSslVerifiedServerNames, allowSelfSignedCerts);
// indicate to the app that we are in stand alone mode
System.setProperty(SystemConstants.SYSPROP_STANDALONE_WEB, "true");
server = new Server();
server.setConnectors(getConnectors(server, httpPort, securePort, mode));
setupBasicAuthIfNeeded(server);
webapp = new WebAppContext();
webapp.setParentLoaderPriority(true);
webapp.setConfigurationDiscovered(true);
webapp.setContextPath(webHome);
webapp.setWar(webAppDir);
webapp.setResourceBase(webAppDir);
webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", allowDirListing);
SessionManager sm = new SessionManager();
webapp.getSessionHandler().setSessionManager(sm);
FilterHolder filterHolder = new FilterHolder(HttpMethodFilter.class);
filterHolder.setInitParameter("server.allow.http.methods", allowedMethods);
filterHolder.setInitParameter("server.disallow.http.methods", disallowedMethods);
webapp.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
webapp.getServletContext().getContextHandler().setMaxFormContentSize(Integer.parseInt(System.getProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "800000")));
webapp.getServletContext().getContextHandler().setMaxFormKeys(Integer.parseInt(System.getProperty("org.eclipse.jetty.server.Request.maxFormKeys", "100000")));
if (propertiesFile != null) {
webapp.getServletContext().getContextHandler().setInitParameter(WebConstants.INIT_SINGLE_SERVER_PROPERTIES_FILE, propertiesFile);
webapp.getServletContext().getContextHandler().setInitParameter(WebConstants.INIT_PARAM_MULTI_SERVER_MODE, Boolean.toString(false));
} else {
webapp.getServletContext().getContextHandler().setInitParameter(WebConstants.INIT_PARAM_MULTI_SERVER_MODE, Boolean.toString(true));
}
server.setHandler(webapp);
server.start();
if (httpJmxPort > 0) {
registerHttpJmxAdaptor(httpJmxPort);
}
if (join) {
log.info("Joining the web server main thread");
server.join();
}
return this;
}
Aggregations