org.apache.thrift.server.TServlet Java Examples
The following examples show how to use
org.apache.thrift.server.TServlet.
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: HttpEchoTestServer.java From pinpoint with Apache License 2.0 | 5 votes |
private EchoHttpServerHandler(String path, TProcessor processor, TProtocolFactory protocolFactory) { this.path = path; this.servlet = new TServlet(processor, protocolFactory) { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.service(req, resp); } }; }
Example #2
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 #3
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 #4
Source File: ThriftAutoConfiguration.java From spring-thrift-starter with MIT License | 4 votes |
protected void register(ServletContext servletContext, String[] urls, Class<? extends TProtocolFactory> factory, Object handler) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException { Class<?>[] handlerInterfaces = ClassUtils.getAllInterfaces(handler); Class ifaceClass = null; Class<TProcessor> processorClass = null; Class serviceClass = null; for (Class<?> handlerInterfaceClass : handlerInterfaces) { if (!handlerInterfaceClass.getName().endsWith("$Iface")) { continue; } serviceClass = handlerInterfaceClass.getDeclaringClass(); if (serviceClass == null) { continue; } for (Class<?> innerClass : serviceClass.getDeclaredClasses()) { if (!innerClass.getName().endsWith("$Processor")) { continue; } if (!TProcessor.class.isAssignableFrom(innerClass)) { continue; } if (ifaceClass != null) { throw new IllegalStateException("Multiple Thrift Ifaces defined on handler"); } ifaceClass = handlerInterfaceClass; processorClass = (Class<TProcessor>) innerClass; break; } } if (ifaceClass == null) { throw new IllegalStateException("No Thrift Ifaces found on handler"); } handler = wrapHandler(ifaceClass, handler); Constructor<TProcessor> processorConstructor = processorClass.getConstructor(ifaceClass); TProcessor processor = BeanUtils.instantiateClass(processorConstructor, handler); TServlet servlet; if (TProtocolFactory.class.equals(factory)) { servlet = getServlet(processor, protocolFactory); } else { servlet = getServlet(processor, factory.newInstance()); } String servletBeanName = handler.getClass().getSimpleName() + "Servlet"; ServletRegistration.Dynamic registration = servletContext.addServlet(servletBeanName, servlet); if (urls != null && urls.length > 0) { registration.addMapping(urls); } else { registration.addMapping("/" + serviceClass.getSimpleName()); } }
Example #5
Source File: ThriftAutoConfiguration.java From spring-thrift-starter with MIT License | 4 votes |
protected TServlet getServlet(TProcessor processor, TProtocolFactory protocolFactory) { return new TServlet(processor, protocolFactory); }
Example #6
Source File: ThriftServer.java From hbase with Apache License 2.0 | 2 votes |
/** * Create a Servlet for the http server * @param protocolFactory protocolFactory * @return the servlet */ protected TServlet createTServlet(TProtocolFactory protocolFactory) { return new ThriftHttpServlet(processor, protocolFactory, serviceUGI, httpUGI, hbaseServiceHandler, securityEnabled, doAsEnabled); }