当前位置: 首页>>代码示例>>Java>>正文


Java TServlet类代码示例

本文整理汇总了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());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:20,代码来源:ApiModule.java

示例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.");
}
 
开发者ID:twellhausen,项目名称:spring-thrift-integration,代码行数:18,代码来源:WebApplicationInitializer.java

示例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) {
        }
    });
}
 
开发者ID:coveord,项目名称:Blitz-2015,代码行数:21,代码来源:ReferenceMain.java

示例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();
}
 
开发者ID:coveord,项目名称:Blitz-2015,代码行数:19,代码来源:ThriftHttpTest.java

示例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
    );
}
 
开发者ID:tiaoling,项目名称:high,代码行数:11,代码来源:Application.java

示例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));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:56,代码来源:ThriftServerRunner.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:7,代码来源:ApiModule.java


注:本文中的org.apache.thrift.server.TServlet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。