本文整理匯總了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, "/*");
}
示例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();
}
示例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();
}
}
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}
示例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();
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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");
}
示例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();
}
示例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));
}
}