@Override protected void configureServlets() { if (ENABLE_CORS_FOR.get() != null) { filter(API_PATH).through(new CorsFilter(ENABLE_CORS_FOR.get())); } serve(API_PATH).with(TServlet.class); filter(ApiBeta.PATH, ApiBeta.PATH + "/*").through(LeaderRedirectFilter.class); filter(ApiBeta.PATH, ApiBeta.PATH + "/*") .through(GuiceContainer.class, JettyServerModule.GUICE_CONTAINER_PARAMS); bind(ApiBeta.class); serve("/apiclient", "/apiclient/*") .with(new DefaultServlet(), ImmutableMap.<String, String>builder() .put("resourceBase", API_CLIENT_ROOT) .put("pathInfoOnly", "true") .put("dirAllowed", "false") .build()); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Setup Spring AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SpringConfiguration.class); rootContext.refresh(); servletContext.addListener(new ContextLoaderListener(rootContext)); LoggerFactory.getLogger(WebApplicationInitializer.class).info("Spring setup done."); // Register Thrift servlet as endpoint TServlet thriftServlet = rootContext.getBean("thriftServlet", TServlet.class); ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("apiServlet", thriftServlet); servletRegistration.setLoadOnStartup(2); servletRegistration.addMapping("/api"); LoggerFactory.getLogger(WebApplicationInitializer.class).info("Registered Thrift servlet."); }
public void startServer1() throws Exception { Server server = new Server(9091); ServletHandler handler = new ServletHandler(); AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(referenceServer); ServletHolder holder = new ServletHolder(new TServlet(processor, new TJSONProtocol.Factory())); handler.addFilterWithMapping(CORSFilter.class, "/*", 0); handler.addServletWithMapping(holder, "/*"); server.setHandler(handler); server.start(); logger.info("Started JSON interface."); joinMethods.add(() -> { try { server.join(); } catch (InterruptedException ignored) { } }); }
@Before public void spawnServer() throws Exception { server = new Server(SERVER_PORT); ServletHandler handler = new ServletHandler(); mockedServer = Mockito.mock(AwesomeService.Iface.class); when(mockedServer.getData(any(Request.class))).thenReturn(new Response(Arrays.asList(new DataPoint(), new DataPoint()))); AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(mockedServer); ServletHolder holder = new ServletHolder(new TServlet(processor, new TJSONProtocol.Factory())); handler.addServletWithMapping(holder, "/*"); server.setHandler(handler); server.start(); }
@Bean Servlet thrift(ThriftCodecManager thriftCodecManager, TProtocolFactory protocolFactory, TCalculatorService calculatorService) { ThriftServiceProcessor processor = new ThriftServiceProcessor(thriftCodecManager, Arrays.<ThriftEventHandler>asList(), calculatorService); return new TServlet( NiftyProcessorAdapters.processorToTProcessor(processor), protocolFactory, protocolFactory ); }
private void setupHTTPServer() throws IOException { TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); TProcessor processor = new Hbase.Processor<Hbase.Iface>(handler); TServlet thriftHttpServlet = new ThriftHttpServlet(processor, protocolFactory, realUser, conf, hbaseHandler, securityEnabled, doAsEnabled); httpServer = new Server(); // Context handler Context context = new Context(httpServer, "/", Context.SESSIONS); context.setContextPath("/"); String httpPath = "/*"; httpServer.setHandler(context); context.addServlet(new ServletHolder(thriftHttpServlet), httpPath); // set up Jetty and run the embedded server Connector connector = new SelectChannelConnector(); if(conf.getBoolean(THRIFT_SSL_ENABLED, false)) { SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(); String keystore = conf.get(THRIFT_SSL_KEYSTORE_STORE); String password = HBaseConfiguration.getPassword(conf, THRIFT_SSL_KEYSTORE_PASSWORD, null); String keyPassword = HBaseConfiguration.getPassword(conf, THRIFT_SSL_KEYSTORE_KEYPASSWORD, password); sslConnector.setKeystore(keystore); sslConnector.setPassword(password); sslConnector.setKeyPassword(keyPassword); connector = sslConnector; } String host = getBindAddress(conf).getHostAddress(); connector.setPort(listenPort); connector.setHost(host); connector.setHeaderBufferSize(1024 * 64); httpServer.addConnector(connector); if (doAsEnabled) { ProxyUsers.refreshSuperUserGroupsConfiguration(conf); } // Set the default max thread number to 100 to limit // the number of concurrent requests so that Thrfit HTTP server doesn't OOM easily. // Jetty set the default max thread number to 250, if we don't set it. // // Our default min thread number 2 is the same as that used by Jetty. int minThreads = conf.getInt(HTTP_MIN_THREADS, 2); int maxThreads = conf.getInt(HTTP_MAX_THREADS, 100); QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads); threadPool.setMinThreads(minThreads); httpServer.setThreadPool(threadPool); httpServer.setSendServerVersion(false); httpServer.setSendDateHeader(false); httpServer.setStopAtShutdown(true); LOG.info("Starting Thrift HTTP Server on " + Integer.toString(listenPort)); }
@Provides @Singleton TServlet provideApiThriftServlet(AnnotatedAuroraAdmin schedulerThriftInterface) { return new TServlet( new AuroraAdmin.Processor<>(schedulerThriftInterface), new TJSONProtocol.Factory()); }