當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。