本文整理汇总了Java中org.apache.thrift.server.TServlet类的典型用法代码示例。如果您正苦于以下问题:Java TServlet类的具体用法?Java TServlet怎么用?Java TServlet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TServlet类属于org.apache.thrift.server包,在下文中一共展示了TServlet类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureServlets
import org.apache.thrift.server.TServlet; //导入依赖的package包/类
@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());
}
示例2: onStartup
import org.apache.thrift.server.TServlet; //导入依赖的package包/类
@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.");
}
示例3: startServer1
import org.apache.thrift.server.TServlet; //导入依赖的package包/类
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) {
}
});
}
示例4: spawnServer
import org.apache.thrift.server.TServlet; //导入依赖的package包/类
@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();
}
示例5: thrift
import org.apache.thrift.server.TServlet; //导入依赖的package包/类
@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
);
}
示例6: setupHTTPServer
import org.apache.thrift.server.TServlet; //导入依赖的package包/类
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));
}
示例7: provideApiThriftServlet
import org.apache.thrift.server.TServlet; //导入依赖的package包/类
@Provides
@Singleton
TServlet provideApiThriftServlet(AnnotatedAuroraAdmin schedulerThriftInterface) {
return new TServlet(
new AuroraAdmin.Processor<>(schedulerThriftInterface), new TJSONProtocol.Factory());
}