Java Code Examples for org.eclipse.jetty.servlet.ServletHolder#setServlet()
The following examples show how to use
org.eclipse.jetty.servlet.ServletHolder#setServlet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletScanner.java From robe with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void scanAndAdd(Environment environment, Injector injector, Reflections reflections) { Set<Class<?>> servletClasses = reflections.getTypesAnnotatedWith(RobeServlet.class); for (Class<?> servlet : servletClasses) { RobeServlet ann = servlet.getAnnotation(RobeServlet.class); ServletHolder holder = new ServletHolder(); try { holder.setServlet(new WrapperServlet((Class<ResourceServlet>) servlet, ann.singleton())); } catch (NoSuchMethodException e) { e.printStackTrace(); } environment.getApplicationContext().addServlet(holder, ann.path()); LOGGER.info("Added servlet: " + servlet); } createServletEventListener(environment, injector); }
Example 2
Source File: UrlRewriteServletContextListenerTest.java From knox with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm(); server = new ServletTester(); server.setContextPath( "/" ); server.getContext().addEventListener( new UrlRewriteServletContextListener() ); server.getContext().setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl ); FilterHolder filter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); filter.setFilter( new UrlRewriteServletFilter() ); interactions = new ArrayDeque<>(); ServletHolder servlet = server.addServlet( MockServlet.class, "/" ); servlet.setServlet( new MockServlet( "mock-servlet", interactions ) ); servlet.setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, getTestResource( "rewrite.xml" ).toExternalForm() ); server.start(); }
Example 3
Source File: JettyTransport.java From data-transfer-project with Apache License 2.0 | 5 votes |
public void registerServlet(String path, Servlet servletContainer) { ServletHolder servletHolder = new ServletHolder(Source.EMBEDDED); servletHolder.setName("Data Transfer Project"); servletHolder.setServlet(servletContainer); servletHolder.setInitOrder(1); ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); handler.setContextPath("/"); handlers.add(handler); handler.getServletHandler().addServletWithMapping(servletHolder, path); }
Example 4
Source File: JettyServer.java From skywalking with Apache License 2.0 | 5 votes |
public void addHandler(JettyHandler handler) { logger.info("Bind handler {} into jetty server {}:{}", handler.getClass().getSimpleName(), host, port); ServletHolder servletHolder = new ServletHolder(); servletHolder.setServlet(handler); servletContextHandler.addServlet(servletHolder, handler.pathSpec()); }
Example 5
Source File: UsernameFunctionProcessorTest.java From knox with Apache License 2.0 | 5 votes |
private void testSetup(String username, Map<String,String> initParams ) throws Exception { String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm(); Log.setLog( new NoOpLogger() ); server = new ServletTester(); server.setContextPath( "/" ); server.getContext().addEventListener( new UrlRewriteServletContextListener() ); server.getContext().setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl ); FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); setupFilter.setFilter( new SetupFilter( username ) ); FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); if( initParams != null ) { for( Map.Entry<String,String> entry : initParams.entrySet() ) { rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() ); } } rewriteFilter.setFilter( new UrlRewriteServletFilter() ); interactions = new ArrayDeque<>(); ServletHolder servlet = server.addServlet( MockServlet.class, "/" ); servlet.setServlet( new MockServlet( "mock-servlet", interactions ) ); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
Example 6
Source File: UrlRewriteServletFilterTest.java From knox with Apache License 2.0 | 5 votes |
private void testSetUp(Map<String,String> initParams ) throws Exception { String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm(); server = new ServletTester(); server.setContextPath( "/" ); server.getContext().addEventListener( new UrlRewriteServletContextListener() ); server.getContext().setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl ); FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); setupFilter.setFilter( new SetupFilter() ); FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); if( initParams != null ) { for( Map.Entry<String,String> entry : initParams.entrySet() ) { rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() ); } } rewriteFilter.setFilter( new UrlRewriteServletFilter() ); interactions = new ArrayDeque<>(); ServletHolder servlet = server.addServlet( MockServlet.class, "/" ); servlet.setServlet( new MockServlet( "mock-servlet", interactions ) ); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
Example 7
Source File: FakeGoServer.java From gocd with Apache License 2.0 | 5 votes |
private void start() throws Exception { server = new Server(); ServerConnector connector = new ServerConnector(server); server.addConnector(connector); SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setCertAlias("cruise"); sslContextFactory.setKeyStoreResource(Resource.newClassPathResource("testdata/fake-server-keystore")); sslContextFactory.setKeyStorePassword("serverKeystorepa55w0rd"); ServerConnector secureConnnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(new HttpConfiguration()) ); server.addConnector(secureConnnector); WebAppContext wac = new WebAppContext(".", "/go"); ServletHolder holder = new ServletHolder(); holder.setServlet(new HttpServlet() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.getOutputStream().println("Hello"); } }); wac.addServlet(holder, "/hello"); addFakeAgentBinaryServlet(wac, "/admin/agent", TEST_AGENT, this); addFakeAgentBinaryServlet(wac, "/admin/agent-launcher.jar", TEST_AGENT_LAUNCHER, this); addFakeAgentBinaryServlet(wac, "/admin/agent-plugins.zip", TEST_AGENT_PLUGINS, this); addFakeAgentBinaryServlet(wac, "/admin/tfs-impl.jar", TEST_TFS_IMPL, this); addlatestAgentStatusCall(wac); addDefaultServlet(wac); server.setHandler(wac); server.setStopAtShutdown(true); server.start(); port = connector.getLocalPort(); securePort = secureConnnector.getLocalPort(); }
Example 8
Source File: FuzzerServer.java From graphicsfuzz with Apache License 2.0 | 4 votes |
public void start() throws Exception { FuzzerServiceImpl fuzzerService = new FuzzerServiceImpl( Paths.get(workingDir, processingDir).toString(), executorService); FuzzerService.Processor processor = new FuzzerService.Processor<FuzzerService.Iface>(fuzzerService); FuzzerServiceManagerImpl fuzzerServiceManager = new FuzzerServiceManagerImpl(fuzzerService, new PublicServerCommandDispatcher()); FuzzerServiceManager.Processor managerProcessor = new FuzzerServiceManager.Processor<FuzzerServiceManager.Iface>(fuzzerServiceManager); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); { ServletHolder sh = new ServletHolder(); sh.setServlet(new TServlet(processor, new TBinaryProtocol.Factory())); context.addServlet(sh, "/request"); } { ServletHolder serveltHolderJson = new ServletHolder(); serveltHolderJson.setServlet(new TServlet(processor, new TJSONProtocol.Factory())); context.addServlet(serveltHolderJson, "/requestJSON"); } { ServletHolder shManager = new ServletHolder(); shManager.setServlet(new TServlet(managerProcessor, new TBinaryProtocol.Factory())); context.addServlet(shManager, "/manageAPI"); } final String staticDir = ToolPaths.getStaticDir(); context.addServlet( new ServletHolder( new FileDownloadServlet( (pathInfo, worker) -> Paths.get(staticDir, pathInfo).toFile(), staticDir)), "/static/*"); HandlerList handlerList = new HandlerList(); handlerList.addHandler(context); GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setHandler(handlerList); Server server = new Server(port); server.setHandler(gzipHandler); server.start(); server.join(); }
Example 9
Source File: FuzzerServer.java From graphicsfuzz with Apache License 2.0 | 4 votes |
public void start() throws Exception { FuzzerServiceImpl fuzzerService = new FuzzerServiceImpl( Paths.get(workingDir, processingDir).toString(), executorService); FuzzerService.Processor processor = new FuzzerService.Processor<FuzzerService.Iface>(fuzzerService); FuzzerServiceManagerImpl fuzzerServiceManager = new FuzzerServiceManagerImpl(fuzzerService, new GraphicsFuzzServerCommandDispatcher()); FuzzerServiceManager.Processor managerProcessor = new FuzzerServiceManager.Processor<FuzzerServiceManager.Iface>(fuzzerServiceManager); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); { ServletHolder sh = new ServletHolder(); sh.setServlet(new TServlet(processor, new TBinaryProtocol.Factory())); context.addServlet(sh, "/request"); } { ServletHolder serveltHolderJson = new ServletHolder(); serveltHolderJson.setServlet(new TServlet(processor, new TJSONProtocol.Factory())); context.addServlet(serveltHolderJson, "/requestJSON"); } { ServletHolder shManager = new ServletHolder(); shManager.setServlet(new TServlet(managerProcessor, new TBinaryProtocol.Factory())); context.addServlet(shManager, "/manageAPI"); } context.addServlet(new ServletHolder(new WebUi(fuzzerServiceManager, fileOps)), "/webui/*"); final String staticDir = ToolPaths.getStaticDir(); context.addServlet( new ServletHolder( new FileDownloadServlet( (pathInfo, workerName) -> Paths.get(staticDir, pathInfo).toFile(), staticDir)), "/static/*"); HandlerList handlerList = new HandlerList(); handlerList.addHandler(context); GzipHandler gzipHandler = new GzipHandler(); gzipHandler.setHandler(handlerList); Server server = new Server(port); server.setHandler(gzipHandler); server.start(); server.join(); }
Example 10
Source File: WorkerStatusPages.java From beam with Apache License 2.0 | 4 votes |
/** Add a status servlet. */ public void addServlet(BaseStatusServlet servlet) { ServletHolder holder = new ServletHolder(); holder.setServlet(servlet); servletHandler.addServletWithMapping(holder, servlet.getPath()); }
Example 11
Source File: WebhookCallbackTest.java From skywalking with Apache License 2.0 | 4 votes |
@Before public void init() throws Exception { server = new Server(new InetSocketAddress("127.0.0.1", 0)); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); servletContextHandler.setContextPath("/webhook"); server.setHandler(servletContextHandler); ServletHolder servletHolder = new ServletHolder(); servletHolder.setServlet(this); servletContextHandler.addServlet(servletHolder, "/receiveAlarm"); server.start(); port = server.getURI().getPort(); assertTrue(port > 0); }
Example 12
Source File: ServiceRegistryFunctionsTest.java From knox with Apache License 2.0 | 4 votes |
private void testSetup(String username, Map<String,String> initParams ) throws Exception { ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock( ServiceRegistry.class ); EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "NAMENODE" ) ).andReturn( "test-nn-scheme://test-nn-host:411" ).anyTimes(); EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "JOBTRACKER" ) ).andReturn( "test-jt-scheme://test-jt-host:511" ).anyTimes(); GatewayServices mockGatewayServices = EasyMock.createNiceMock( GatewayServices.class ); EasyMock.expect( mockGatewayServices.getService(ServiceType.SERVICE_REGISTRY_SERVICE) ).andReturn( mockServiceRegistry ).anyTimes(); EasyMock.replay( mockServiceRegistry, mockGatewayServices ); String descriptorUrl = getTestResource( "rewrite.xml" ).toExternalForm(); Log.setLog( new NoOpLogger() ); server = new ServletTester(); server.setContextPath( "/" ); server.getContext().addEventListener( new UrlRewriteServletContextListener() ); server.getContext().setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl ); server.getContext().setAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster" ); server.getContext().setAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices ); FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); setupFilter.setFilter( new SetupFilter( username ) ); FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); if( initParams != null ) { for( Map.Entry<String,String> entry : initParams.entrySet() ) { rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() ); } } rewriteFilter.setFilter( new UrlRewriteServletFilter() ); interactions = new ArrayDeque<>(); ServletHolder servlet = server.addServlet( MockServlet.class, "/" ); servlet.setServlet( new MockServlet( "mock-servlet", interactions ) ); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
Example 13
Source File: FrontendFunctionProcessorTest.java From knox with Apache License 2.0 | 4 votes |
private void testSetup(String username, Map<String, String> initParams, Attributes attributes) throws Exception { ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock( ServiceRegistry.class ); EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "NAMENODE" ) ).andReturn( "test-nn-scheme://test-nn-host:411" ).anyTimes(); EasyMock.expect( mockServiceRegistry.lookupServiceURL( "test-cluster", "JOBTRACKER" ) ).andReturn( "test-jt-scheme://test-jt-host:511" ).anyTimes(); GatewayServices mockGatewayServices = EasyMock.createNiceMock( GatewayServices.class ); EasyMock.expect( mockGatewayServices.getService(ServiceType.SERVICE_REGISTRY_SERVICE) ).andReturn( mockServiceRegistry ).anyTimes(); EasyMock.replay( mockServiceRegistry, mockGatewayServices ); String descriptorUrl = TestUtils.getResourceUrl( FrontendFunctionProcessorTest.class, "rewrite.xml" ).toExternalForm(); Log.setLog( new NoOpLogger() ); server = new ServletTester(); server.setContextPath( "/" ); server.getContext().addEventListener( new UrlRewriteServletContextListener() ); server.getContext().setInitParameter( UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl ); if( attributes != null ) { server.getContext().setAttributes( attributes ); } server.getContext().setAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster" ); server.getContext().setAttribute( GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices ); FilterHolder setupFilter = server.addFilter( SetupFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); setupFilter.setFilter( new SetupFilter( username ) ); FilterHolder rewriteFilter = server.addFilter( UrlRewriteServletFilter.class, "/*", EnumSet.of( DispatcherType.REQUEST ) ); if( initParams != null ) { for( Map.Entry<String,String> entry : initParams.entrySet() ) { rewriteFilter.setInitParameter( entry.getKey(), entry.getValue() ); } } rewriteFilter.setFilter( new UrlRewriteServletFilter() ); interactions = new ArrayDeque<>(); ServletHolder servlet = server.addServlet( MockServlet.class, "/" ); servlet.setServlet( new MockServlet( "mock-servlet", interactions ) ); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
Example 14
Source File: FakeGoServer.java From gocd with Apache License 2.0 | 4 votes |
private static void addFakeAgentBinaryServlet(WebAppContext wac, final String pathSpec, final TestResource resource, FakeGoServer fakeGoServer) { ServletHolder holder = new ServletHolder(); holder.setServlet(new AgentBinariesServlet(resource, fakeGoServer)); wac.addServlet(holder, pathSpec); }