本文整理汇总了Java中org.eclipse.jetty.servlet.FilterHolder.setFilter方法的典型用法代码示例。如果您正苦于以下问题:Java FilterHolder.setFilter方法的具体用法?Java FilterHolder.setFilter怎么用?Java FilterHolder.setFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.servlet.FilterHolder
的用法示例。
在下文中一共展示了FilterHolder.setFilter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFilters
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
private void setFilters(JettyHttpEndpoint endpoint, Server server, String connectorKey) {
ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
List<Filter> filters = endpoint.getFilters();
for (Filter filter : filters) {
FilterHolder filterHolder = new FilterHolder();
filterHolder.setFilter(new CamelFilterWrapper(filter));
String pathSpec = endpoint.getPath();
if (pathSpec == null || "".equals(pathSpec)) {
pathSpec = "/";
}
if (endpoint.isMatchOnUriPrefix()) {
pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
}
addFilter(context, filterHolder, pathSpec);
}
}
示例2: setFilters
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
private void setFilters(JettyHttpEndpoint endpoint, Server server, String connectorKey) {
ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
List<Filter> filters = endpoint.getFilters();
for (Filter filter : filters) {
FilterHolder filterHolder = new FilterHolder();
if (endpoint.getFilterInitParameters() != null) {
filterHolder.setInitParameters(endpoint.getFilterInitParameters());
}
filterHolder.setFilter(new CamelFilterWrapper(filter));
String pathSpec = endpoint.getPath();
if (pathSpec == null || "".equals(pathSpec)) {
pathSpec = "/";
}
if (endpoint.isMatchOnUriPrefix()) {
pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
}
addFilter(context, filterHolder, pathSpec);
}
}
示例3: enableMultipartFilter
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
private void enableMultipartFilter(HttpEndpoint endpoint, Server server, String connectorKey) throws Exception {
ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
CamelContext camelContext = this.getCamelContext();
FilterHolder filterHolder = new FilterHolder();
filterHolder.setInitParameter("deleteFiles", "true");
if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) {
File file = new File(camelContext.getProperty(TMP_DIR));
if (!file.isDirectory()) {
throw new RuntimeCamelException(
"The temp file directory of camel-jetty is not exists, please recheck it with directory name :"
+ camelContext.getProperties().get(TMP_DIR));
}
context.setAttribute("javax.servlet.context.tempdir", file);
}
// if a filter ref was provided, use it.
Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
if (filter == null) {
// if no filter ref was provided, use the default filter
filter = new MultiPartFilter();
}
filterHolder.setFilter(new CamelFilterWrapper(filter));
String pathSpec = endpoint.getPath();
if (pathSpec == null || "".equals(pathSpec)) {
pathSpec = "/";
}
if (endpoint.isMatchOnUriPrefix()) {
pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
}
addFilter(context, filterHolder, pathSpec);
if (LOG.isDebugEnabled()) LOG.debug("using multipart filter implementation " + filter.getClass().getName() + " for path " + pathSpec);
}
示例4: enableMultipartFilter
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
private void enableMultipartFilter(HttpCommonEndpoint endpoint, Server server, String connectorKey) throws Exception {
ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
CamelContext camelContext = this.getCamelContext();
FilterHolder filterHolder = new FilterHolder();
filterHolder.setInitParameter("deleteFiles", "true");
if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) {
File file = new File(camelContext.getProperty(TMP_DIR));
if (!file.isDirectory()) {
throw new RuntimeCamelException(
"The temp file directory of camel-jetty is not exists, please recheck it with directory name :"
+ camelContext.getProperties().get(TMP_DIR));
}
context.setAttribute("javax.servlet.context.tempdir", file);
}
// if a filter ref was provided, use it.
Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
if (filter == null) {
// if no filter ref was provided, use the default filter
filter = new MultiPartFilter();
}
filterHolder.setFilter(new CamelFilterWrapper(filter));
String pathSpec = endpoint.getPath();
if (pathSpec == null || "".equals(pathSpec)) {
pathSpec = "/";
}
if (endpoint.isMatchOnUriPrefix()) {
pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
}
addFilter(context, filterHolder, pathSpec);
LOG.debug("using multipart filter implementation " + filter.getClass().getName() + " for path " + pathSpec);
}
示例5: applyCrossOriginFiltering
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
private void applyCrossOriginFiltering(WebsocketEndpoint endpoint, ServletContextHandler context) {
if (endpoint.isCrossOriginFilterOn()) {
FilterHolder filterHolder = new FilterHolder();
CrossOriginFilter filter = new CrossOriginFilter();
filterHolder.setFilter(filter);
filterHolder.setInitParameter("allowedOrigins", endpoint.getAllowedOrigins());
context.addFilter(filterHolder, endpoint.getFilterPath(), EnumSet.allOf(DispatcherType.class));
}
}
示例6: applyCrossOriginFiltering
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
private void applyCrossOriginFiltering(CometdEndpoint endpoint, ServletContextHandler context) {
if (endpoint.isCrossOriginFilterOn()) {
FilterHolder filterHolder = new FilterHolder();
CrossOriginFilter filter = new CrossOriginFilter();
filterHolder.setFilter(filter);
filterHolder.setInitParameter("allowedOrigins", endpoint.getAllowedOrigins());
context.addFilter(filterHolder, endpoint.getFilterPath(), EnumSet.allOf(DispatcherType.class));
}
}
示例7: startServer
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
public static void startServer() throws Exception {
Thread t = new Thread() {
@Override
public void run() {
try {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
Server server = new Server(8080);
server.setHandler(context);
ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", RESTHandler.class.getCanonicalName());
FilterHolder filter = new FilterHolder();
filter.setInitParameter("allowedOrigins", "*");
filter.setInitParameter("allowedMethods", "POST,GET,OPTIONS,PUT,DELETE,HEAD");
filter.setInitParameter("allowedHeaders", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept");
filter.setInitParameter("preflightMaxAge", "728000");
filter.setInitParameter("allowCredentials", "true");
CrossOriginFilter corsFilter = new CrossOriginFilter();
filter.setFilter(corsFilter);
context.addFilter(filter, "/*", EnumSet.of(DispatcherType.REQUEST));
server.start();
server.join();
} catch (Exception e) {
Debug.log("Error starting uiserver: " + e);
}
}
};
t.start();
}
示例8: createBoshHandler
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
/**
* Creates a Jetty context handler that can be used to expose BOSH (HTTP-Bind) functionality.
*
* Note that an invocation of this method will not register the handler (and thus make the related functionality
* available to the end user). Instead, the created handler is returned by this method, and will need to be
* registered with the embedded Jetty webserver by the caller.
*
* @return A Jetty context handler (never null).
*/
protected Handler createBoshHandler()
{
final ServletContextHandler context = new ServletContextHandler( null, "/http-bind", ServletContextHandler.SESSIONS );
// Ensure the JSP engine is initialized correctly (in order to be able to cope with Tomcat/Jasper precompiled JSPs).
final List<ContainerInitializer> initializers = new ArrayList<>();
initializers.add( new ContainerInitializer( new JasperInitializer(), null ) );
context.setAttribute( "org.eclipse.jetty.containerInitializers", initializers );
context.setAttribute( InstanceManager.class.getName(), new SimpleInstanceManager() );
// Generic configuration of the context.
context.setAllowNullPathInfo( true );
// Add the functionality-providers.
context.addServlet( new ServletHolder( new HttpBindServlet() ), "/*" );
// Add compression filter when needed.
if ( isHttpCompressionEnabled() )
{
final Filter gzipFilter = new AsyncGzipFilter()
{
@Override
public void init( FilterConfig config ) throws ServletException
{
super.init( config );
_methods.add( HttpMethod.POST.asString() );
Log.info( "Installed response compression filter" );
}
};
final FilterHolder filterHolder = new FilterHolder();
filterHolder.setFilter( gzipFilter );
context.addFilter( filterHolder, "/*", EnumSet.of( DispatcherType.REQUEST ) );
}
return context;
}
示例9: start
import org.eclipse.jetty.servlet.FilterHolder; //导入方法依赖的package包/类
public void start() throws Exception {
((ServerConnector) server.getConnectors()[0]).setReuseAddress(true);
// Root context
context.setContextPath("/abnormal");
// Setup static content
context.setResourceBase("src/main/webapp/");
context.addServlet(DefaultServlet.class, "/");
// Enable Jersey debug output
context.setInitParameter("com.sun.jersey.config.statistic.Trace", "true");
// Enable CORS - cross origin resource sharing
FilterHolder cors = new FilterHolder();
cors.setInitParameter("allowedOrigins", "https?://localhost:*, https?://*.e-navigation.net:*");
cors.setInitParameter("allowedHeaders", "*");
cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD");
cors.setFilter(new CrossOriginFilter());
context.addFilter(cors, "*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC, DispatcherType.INCLUDE));
// Little hack to satisfy OpenLayers URLs in DMA context
RewritePatternRule openlayersRewriteRule = new RewritePatternRule();
openlayersRewriteRule.setPattern("/abnormal/theme/*");
openlayersRewriteRule.setReplacement("/abnormal/js/theme/");
RewriteHandler rewrite = new RewriteHandler();
rewrite.setRewriteRequestURI(true);
rewrite.setRewritePathInfo(false);
rewrite.setOriginalPathAttribute("requestedPath");
rewrite.addRule(openlayersRewriteRule);
rewrite.setHandler(context);
server.setHandler(rewrite);
// Setup Guice-Jersey integration
context.addEventListener(new GuiceServletContextListener() {
@Override
protected Injector getInjector() {
return Guice.createInjector(new RestModule(
repositoryName,
pathToEventDatabase,
eventRepositoryType,
eventDataDbHost,
eventDataDbPort,
eventDataDbName,
eventDataDbUsername,
eventDataDbPassword
));
}
});
context.addFilter(com.google.inject.servlet.GuiceFilter.class, "/rest/*", EnumSet.allOf(DispatcherType.class));
// Start the server
server.start();
}