当前位置: 首页>>代码示例>>Java>>正文


Java ServletContextHandler.addFilter方法代码示例

本文整理汇总了Java中org.eclipse.jetty.servlet.ServletContextHandler.addFilter方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContextHandler.addFilter方法的具体用法?Java ServletContextHandler.addFilter怎么用?Java ServletContextHandler.addFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.servlet.ServletContextHandler的用法示例。


在下文中一共展示了ServletContextHandler.addFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addApplication

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private void addApplication(final ServletContextHandler context, final MinijaxApplication application)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    // (0) Sort the resource methods by literal length
    application.sortResourceMethods();

    // (1) Add Minijax filter (must come before websocket!)
    context.addFilter(new FilterHolder(new MinijaxFilter(application)), "/*", EnumSet.of(DispatcherType.REQUEST));

    // (2) WebSocket endpoints
    if (OptionalClasses.WEB_SOCKET_UTILS != null) {
        OptionalClasses.WEB_SOCKET_UTILS
                .getMethod("init", ServletContextHandler.class, MinijaxApplication.class)
                .invoke(null, context, application);
    }

    // (3) Dynamic JAX-RS content
    final MinijaxServlet servlet = new MinijaxServlet(application);
    final ServletHolder servletHolder = new ServletHolder(servlet);
    servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
    context.addServlet(servletHolder, "/*");
}
 
开发者ID:minijax,项目名称:minijax,代码行数:23,代码来源:Minijax.java

示例2: start

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void start() throws Exception {
    server = new Server(port);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
    context.addFilter(AuthenticationFilter.class, "/*", null);
    context.setServer(server);

    // Add static files handler
    context.setBaseResource(Resource.newResource(JettyServer.class.getResource("/webapp")));
    context.addServlet(DefaultServlet.class,"/");
    context.setWelcomeFiles(new String[]{"index.html"});

    ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
    wsContainer.addEndpoint(createEndpointConfig(EchoEndpoint.class));

    server.setHandler(context);
    server.start();
}
 
开发者ID:asafalima,项目名称:guice-websocket,代码行数:19,代码来源:JettyServer.java

示例3: addStaticResourceConfig

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private void addStaticResourceConfig(ServletContextHandler context) {
    URL webappLocation = getClass().getResource("/webapp/index.html");
    if (webappLocation == null) {
        System.err.println("Couldn't get webapp location.");
    } else {
        try {
            URI webRootUri = URI.create(webappLocation.toURI().toASCIIString().replaceFirst("/index.html$", "/"));
            context.setBaseResource(Resource.newResource(webRootUri));
            context.setWelcomeFiles(new String[]{"index.html"});

            GzipHandler gzipHandler = new GzipHandler();
            gzipHandler.setIncludedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name());
            context.setGzipHandler(gzipHandler);
            context.addFilter(TryFilesFilter.class, "*", EnumSet.of(DispatcherType.REQUEST));
        } catch (URISyntaxException | MalformedURLException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:sparkled,项目名称:sparkled,代码行数:20,代码来源:RestApiServerImpl.java

示例4: ParticipantHoster

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public ParticipantHoster(final List<ContextParticipantProxy> unregisteredParticipants, final short port) throws Exception {
	participants = unregisteredParticipants;

	participantsUrl = FluentIterable.from(participants).transform(new Function<ContextParticipantProxy, String>() {

		@Override
		public String apply(final ContextParticipantProxy input) {
			// return "/" + input.getApplicationName() +
			// "/ContextParticipant/*";
			return input.getApplicationName();
		}
	}).append("/*");

	server = new Server(port);
	final ServletContextHandler sch = new ServletContextHandler(server, "/");
	sch.addEventListener(new InnerListener());
	sch.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
	sch.addServlet(DefaultServlet.class, "/");
	server.start();
}
 
开发者ID:jkiddo,项目名称:ccow,代码行数:21,代码来源:ParticipantHoster.java

示例5: initTracing

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
protected void initTracing(ServletContextHandler context) {
    client.register(new Builder(mockTracer).build());

    ServerTracingDynamicFeature serverTracingFeature =
        new ServerTracingDynamicFeature.Builder(mockTracer)
            .withOperationNameProvider(HTTPMethodOperationName.newBuilder())
            .withDecorators(Collections.singletonList(ServerSpanDecorator.STANDARD_TAGS))
            .withSkipPattern("/health")
        .build();
    // TODO clarify dispatcher types
    context.addFilter(new FilterHolder(new SpanFinishingFilter(mockTracer)), "/*",
        EnumSet.of(
            DispatcherType.REQUEST,
            DispatcherType.FORWARD,
            // TODO CXF does not call AsyncListener#onComplete() without this (it calls only onStartAsync)
            DispatcherType.ASYNC,
            DispatcherType.ERROR,
            DispatcherType.INCLUDE));

    context.setAttribute(CLIENT_ATTRIBUTE, client);
    context.setAttribute(TRACER_ATTRIBUTE, mockTracer);
    context.setAttribute(SERVER_TRACING_FEATURE, serverTracingFeature);
}
 
开发者ID:opentracing-contrib,项目名称:java-jaxrs,代码行数:24,代码来源:AbstractJettyTest.java

示例6: createServletHandlerWithServlet

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private ServletContextHandler createServletHandlerWithServlet() {
    ServletContextHandler context = new ServletContextHandler(
            ServletContextHandler.SESSIONS);

    FilterHolder pushCacheFilter = context.addFilter(PushCacheFilter.class, "/*",
            null);
    Map<String, String> config = new HashMap<>();
    config.put("maxAssociations", "32");
    config.put("ports", Objects.toString(SSL_PORT));
    pushCacheFilter.setInitParameters(config);

    context.addServlet(NoopServlet.class, "/*");
    context.setContextPath("/");

    return context;
}
 
开发者ID:AndreasKl,项目名称:embedded-jetty-http2,代码行数:17,代码来源:Application.java

示例7: addServlet

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
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));
    }

    FilterHolder responseFilter = new FilterHolder(new ResponseHandlerFilter(pulsar));
    context.addFilter(responseFilter, MATCH_ALL, EnumSet.allOf(DispatcherType.class));

    handlers.add(context);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:17,代码来源:WebService.java

示例8: compose

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public static void compose(Server server) {
    //Servlets + Guice
    ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
    servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
    servletContextHandler.addServlet(DefaultServlet.class, "/");

    //JMX stuff...
    MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addEventListener(mbContainer);
    server.addBean(mbContainer);
    server.addBean(Log.getLog());
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:13,代码来源:JettyComposer.java

示例9: beforeTest

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
@Before
public void beforeTest() throws Exception {
    mockTracer = Mockito.spy(new MockTracer(new ThreadLocalScopeManager(), MockTracer.Propagator.TEXT_MAP));

    ServletContextHandler servletContext = new ServletContextHandler();
    servletContext.setContextPath(contextPath);
    servletContext.addServlet(TestServlet.class, "/hello");
    
    ServletHolder asyncServletHolder = new ServletHolder(new AsyncServlet(mockTracer));
    servletContext.addServlet(asyncServletHolder, "/async");
    asyncServletHolder.setAsyncSupported(true);
    servletContext.addServlet(AsyncImmediateExitServlet.class, "/asyncImmediateExit")
            .setAsyncSupported(true);

    servletContext.addServlet(new ServletHolder(new LocalSpanServlet(mockTracer)), "/localSpan");
    servletContext.addServlet(new ServletHolder(new CurrentSpanServlet(mockTracer)), "/currentSpan");
    servletContext.addServlet(ExceptionServlet.class, "/servletException");

    servletContext.addFilter(new FilterHolder(tracingFilter()), "/*", EnumSet.of(DispatcherType.REQUEST,
            DispatcherType.FORWARD, DispatcherType.ASYNC, DispatcherType.ERROR, DispatcherType.INCLUDE));
    servletContext.addFilter(ErrorFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

    jettyServer = new Server(0);
    jettyServer.setHandler(servletContext);
    jettyServer.start();
    serverPort = ((ServerConnector)jettyServer.getConnectors()[0]).getLocalPort();
}
 
开发者ID:opentracing-contrib,项目名称:java-web-servlet-filter,代码行数:28,代码来源:AbstractJettyTest.java

示例10: run

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public void run() {
	ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
	servletContextHandler.setContextPath("/");
	servletContextHandler.setResourceBase("./res");
	servletContextHandler.addFilter(CommonFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));//增加过滤器
	servletContextHandler.addServlet(LoginServlet.class, "/login.cgi");
	servletContextHandler.addServlet(UserinfoServlet.class, "/userinfo.cgi");
	servletContextHandler.addServlet(FileBrowseServlet.class, "/file_browse.cgi");
	servletContextHandler.addServlet(DefaultServlet.class, "/");
	servletContextHandler.addServlet(ChangePassword.class, "/changepassword.cgi");
	servletContextHandler.addServlet(AddDeviceToGroupServlet.class, "/device/add_device_to_group.cgi");
	servletContextHandler.addServlet(AddGroupServlet.class, "/group/add_group.cgi");
	servletContextHandler.addServlet(GetGroupsServlet.class	, "/group/get_groups.cgi");
	servletContextHandler.addServlet(EditGroupServlet.class, "/group/edit_group.cgi");
	servletContextHandler.addServlet(GetAllGroupsServlet.class, "/group/get_all_groups.cgi");
	servletContextHandler.addServlet(DeteleGroupServlet.class, "/group/delete_group.cgi");
	servletContextHandler.addServlet(AddDeviceToGroupServlet.class, "/group/add_device_to_group.cgi");
	servletContextHandler.addServlet(DeleteDeviceFromGroupServlet.class,"/group/delete_device_from_group.cgi");
	
	ServletHolder fileUploadServletHolder = new ServletHolder(new UploadServlet());
	fileUploadServletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(System.getProperty("user.dir") +JettyConfig.UPLOAD_TMP_PATH));
	servletContextHandler.addServlet(fileUploadServletHolder, "/upload.cgi");
	
	servletContextHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
       
       server.setHandler(servletContextHandler);
       try {
		server.start();
		server.join();
		
	} catch (Exception e) {
		logger.error("",e);
	}
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:35,代码来源:JettyServer.java

示例11: get

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public Handler get() {
  ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
  handler.setContextPath("/");
  handler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
  handler.addServlet(servletHolder, "/*");

  return handler;
}
 
开发者ID:sorskod,项目名称:webserver,代码行数:9,代码来源:ServletContextHandlerProvider.java

示例12: start

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public synchronized void start(int port, boolean join) throws Exception {
	
	if(server != null) {
		throw new IllegalStateException("Server is already running");
	}
	
	Guice.createInjector(sm);

	//Swagger
	String resourceBasePath = Main.class.getResource("/swagger-ui").toExternalForm();
	this.server = new Server(port);
	
	ServletContextHandler context = new ServletContextHandler();
	context.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
	context.setResourceBase(resourceBasePath);
	context.setWelcomeFiles(new String[] { "index.html" });
	
	server.setHandler(context);


	DefaultServlet staticServlet = new DefaultServlet();
	context.addServlet(new ServletHolder(staticServlet), "/*");
	
	server.start();
	System.out.println("Started server on http://localhost:" + port + "/");
	try {
		boolean create = Boolean.getBoolean("loadSample");
		if(create) {
			System.out.println("Creating kitchensink workflow");
			createKitchenSink(port);
		}
	}catch(Exception e) {
		logger.error(e.getMessage(), e);
	}
	
	if(join) {
		server.join();
	}

}
 
开发者ID:Netflix,项目名称:conductor,代码行数:41,代码来源:ConductorServer.java

示例13: initCorsFilter

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
private void initCorsFilter(ServletContextHandler context) {
    FilterHolder corsFilter = context.addFilter(CrossOriginFilter.class, REST_PATH, EnumSet.of(DispatcherType.REQUEST));
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
    corsFilter.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "DELETE,GET,POST,PUT");
    corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin");
}
 
开发者ID:sparkled,项目名称:sparkled,代码行数:8,代码来源:RestApiServerImpl.java

示例14: main

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {

		// This test server exposes the CCOW ContextManager according to the
		// HTTP Web bindings and exposes the ContextParticipant notification
		// part through Websockets.

		// Connect to the server at
		// ws://host:serverPort/ws/ContextManager/{unique-client-id}

		// All invocations on ContextParticipants that the ContextManager does
		// according to the HTTP Web bindings spec will also be done to the
		// Websocket client (see ccow.cma.IContextParticipant for procedures
		// that are invoked). As
		// ContextParticipant.ContextChangedPending return values the
		// connected Websocket client will have a max of 5 seconds to respond
		// accordingly.

		server = new Server(2116);
		final CCOWContextListener servletContextListener = new CCOWContextListener();

		final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
		server.addBean(mbContainer);

		final ServletContextHandler webSocketServletContextHandler = new ServletContextHandler(server, "/ws",
				ServletContextHandler.SESSIONS);
		webSocketServletContextHandler.addEventListener(servletContextListener);
		WebSocketServerContainerInitializer.configureContext(webSocketServletContextHandler);

		final ServletContextHandler restServletContextHandler = new ServletContextHandler(server, "/");
		restServletContextHandler.addEventListener(servletContextListener);
		restServletContextHandler.addFilter(AppGuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

		final ContextHandlerCollection contexts = new ContextHandlerCollection();
		contexts.setHandlers(new Handler[] { webSocketServletContextHandler, restServletContextHandler });
		
		server.setHandler(contexts);
		server.start();
		server.join();
	}
 
开发者ID:jkiddo,项目名称:ccow,代码行数:40,代码来源:EmbeddedJettyInstance.java

示例15: applyCrossOriginFiltering

import org.eclipse.jetty.servlet.ServletContextHandler; //导入方法依赖的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));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:CometdComponent.java


注:本文中的org.eclipse.jetty.servlet.ServletContextHandler.addFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。