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


Java ServletContainer类代码示例

本文整理汇总了Java中com.sun.jersey.spi.container.servlet.ServletContainer的典型用法代码示例。如果您正苦于以下问题:Java ServletContainer类的具体用法?Java ServletContainer怎么用?Java ServletContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServletContainer类属于com.sun.jersey.spi.container.servlet包,在下文中一共展示了ServletContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: WebServer

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
public WebServer(URI endpoint) throws IOException {
  this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() {

    @Override
    public void service(Request rqst, Response rspns) throws Exception {
      rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found");
      rspns.getWriter().write("404: not found");
    }
  });

  WebappContext context = new WebappContext("WebappContext", BASE_PATH);
  ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
  registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
      PackagesResourceConfig.class.getName());

  StringJoiner sj = new StringJoiner(",");
  for (String s : PACKAGES) {
    sj.add(s);
  }

  registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString());
  registration.addMapping(BASE_PATH);
  context.deploy(server);
}
 
开发者ID:uber,项目名称:AthenaX,代码行数:25,代码来源:WebServer.java

示例2: createJerseyAdapter

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
private ServletAdapter createJerseyAdapter(Endpoint e) {
    ServletAdapter jersey = new ServletAdapter();

    jersey.setServletInstance(new ServletContainer());
    jersey.addInitParameter("com.sun.jersey.config.property.packages",
            "org.apache.zookeeper.server.jersey.resources");
    jersey.setContextPath(e.getContext());

    Credentials c = Credentials.join(e.getCredentials(), cfg
            .getCredentials());
    if (!c.isEmpty()) {
        jersey.addFilter(new HTTPBasicAuth(c), e.getContext()
                + "-basic-auth", null);
    }

    return jersey;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:18,代码来源:RestMain.java

示例3: configureWebAppServlets

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
protected void configureWebAppServlets() {
  // Add in the web services filters/serves if app has them.
  // Using Jersey/guice integration module. If user has web services
  // they must have also bound a default one in their webapp code.
  if (this.wsName != null) {
    // There seems to be an issue with the guice/jersey integration
    // where we have to list the stuff we don't want it to serve
    // through the guicecontainer. In this case its everything except
    // the the web services api prefix. We can't just change the filter
    // from /* below - that doesn't work.
    String regex = "(?!/" + this.wsName + ")";
    serveRegex(regex).with(DefaultWrapperServlet.class);

    Map<String, String> params = new HashMap<String, String>();
    params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true");
    params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true");
    params.put(FeaturesAndProperties.FEATURE_XMLROOTELEMENT_PROCESSING, "true");
    params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName());
    params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName());
    filter("/*").through(getWebAppFilterClass(), params);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:WebApp.java

示例4: validate

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
private static void validate(VersionModel model) {
  assertNotNull(model);
  assertNotNull(model.getRESTVersion());
  assertEquals(model.getRESTVersion(), RESTServlet.VERSION_STRING);
  String osVersion = model.getOSVersion(); 
  assertNotNull(osVersion);
  assertTrue(osVersion.contains(System.getProperty("os.name")));
  assertTrue(osVersion.contains(System.getProperty("os.version")));
  assertTrue(osVersion.contains(System.getProperty("os.arch")));
  String jvmVersion = model.getJVMVersion();
  assertNotNull(jvmVersion);
  assertTrue(jvmVersion.contains(System.getProperty("java.vm.vendor")));
  assertTrue(jvmVersion.contains(System.getProperty("java.version")));
  assertTrue(jvmVersion.contains(System.getProperty("java.vm.version")));
  assertNotNull(model.getServerVersion());
  String jerseyVersion = model.getJerseyVersion();
  assertNotNull(jerseyVersion);
  assertEquals(jerseyVersion, ServletContainer.class.getPackage()
    .getImplementationVersion());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestVersionResource.java

示例5: testGetStargateVersionText

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
@Test
public void testGetStargateVersionText() throws IOException {
  Response response = client.get("/version", Constants.MIMETYPE_TEXT);
  assertTrue(response.getCode() == 200);
  assertEquals(Constants.MIMETYPE_TEXT, response.getHeader("content-type"));
  String body = Bytes.toString(response.getBody());
  assertTrue(body.length() > 0);
  assertTrue(body.contains(RESTServlet.VERSION_STRING));
  assertTrue(body.contains(System.getProperty("java.vm.vendor")));
  assertTrue(body.contains(System.getProperty("java.version")));
  assertTrue(body.contains(System.getProperty("java.vm.version")));
  assertTrue(body.contains(System.getProperty("os.name")));
  assertTrue(body.contains(System.getProperty("os.version")));
  assertTrue(body.contains(System.getProperty("os.arch")));
  assertTrue(body.contains(ServletContainer.class.getPackage()
    .getImplementationVersion()));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:18,代码来源:TestVersionResource.java

示例6: start

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
/**
 * Starts the server, which will listen to the given path going forward.
 * @throws Exception
 */
public void start() throws Exception {
  logger.info("Starting API server on {}:{}{}", HOST, port, contextPath);
  
  server = new Server();
  server.addListener(String.format("%s:%d", HOST, port));
  
  ServletHttpContext context = (ServletHttpContext) server.getContext(contextPath);
  
  context.addServlet(SERVLET_NAME, SERVLET_PATH, ServletContainer.class.getName());
  context.getServletHandler().getServletHolder(SERVLET_NAME)
      .setInitParameter(INIT_PARAM_PACKAGES, getClass().getPackage().getName());
  
  if (!Strings.isNullOrEmpty(adsPropertiesPath)) {
    context.getServletHandler().getServletHolder(SERVLET_NAME)
        .setInitParameter(INIT_PARAM_ADS_PROPERTIES, adsPropertiesPath);
  }
  if (!Strings.isNullOrEmpty(propertiesPath)) {
    context.getServletHandler().getServletHolder(SERVLET_NAME)
        .setInitParameter(INIT_PARAM_PROPERTIES, propertiesPath);
  }
  
  server.start();
}
 
开发者ID:googleads,项目名称:keyword-optimizer,代码行数:28,代码来源:ApiServer.java

示例7: createComputeRealtimeServer

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
/**
 * Creates a new {@link ComputeRealtimeServer}
 *
 * @param config
 *            The chatalytics config
 * @return A newly created {@link ComputeRealtimeServer}
 */
public ComputeRealtimeServer createComputeRealtimeServer() {
    Server server = new Server(config.computeConfig.rtComputePort);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");

    ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*");
    jerseyServlet.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES,
                                   StatusResource.class.getPackage().toString());
    server.setHandler(context);
    ServerContainer wscontainer;
    try {
        wscontainer = WebSocketServerContainerInitializer.configureContext(context);
        wscontainer.addEndpoint(RealtimeResource.class);
    } catch (ServletException | DeploymentException e) {
        throw new RuntimeException("Can't instantiate websocket. Reason: " + e.getMessage());
    }

    return new ComputeRealtimeServer(server);
}
 
开发者ID:OpenChatAlytics,项目名称:OpenChatAlytics,代码行数:27,代码来源:ComputeRealtimeServerFactory.java

示例8: initRestTestServletAdapter

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
public static ServletAdapter initRestTestServletAdapter(Class<?> applicationConfigClass, int testServerPort,
		String testContextPath, String testServletPath, boolean enableJPA) {
	final ServletAdapter adapter = new ServletAdapter();
	
	adapter.addInitParameter(ServletContainer.APPLICATION_CONFIG_CLASS, applicationConfigClass.getName());
	adapter.addInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", LoggingFilter.class.getName());
	adapter.addInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", LoggingFilter.class.getName());
	
	adapter.addServletListener(ContextLoaderListener.class.getName());
	
	if (enableJPA) {
		adapter.addFilter(new OpenEntityManagerInViewFilter(), "openEntityManagerInViewFilter", null);
	}
	
	adapter.setServletInstance(new SpringServlet());
	adapter.setContextPath(testContextPath);
	adapter.setServletPath(testServletPath);
	
	return adapter;
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:21,代码来源:RestTestUtils.java

示例9: getJerseyContext

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
/**
 * Function to generate the Jersey handler, with configurations for resource scanning and filter inclusion
 *
 * @return
 * @throws IOException
 * @throws MalformedURLException
 */
private static ServletContextHandler getJerseyContext()
		throws IOException {
	// Code to add Jersey Servlet to the Jetty Handlers
	log.info("Initializing Jersey Servlet configuration");
	ServletContextHandler context = new ServletContextHandler(
			ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	server.setHandler(context);
	ServletHolder h = new ServletHolder(new ServletContainer());
	h.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
	h.setInitParameter("com.sun.jersey.config.property.packages",
			"com.topology.resource");
	h.setInitOrder(1);
	context.addServlet(h, "/rest/*");
	return context;
}
 
开发者ID:mohitc,项目名称:NetworkTopologyDatastore,代码行数:24,代码来源:WsLauncher.java

示例10: startServer

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
/**
 * @throws Exception
 * @throws InterruptedException
 */
public static void startServer() throws Exception, InterruptedException {
	Server server = new Server(8089);
	
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	
	ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
	servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
	        "com.sun.jersey.api.core.PackagesResourceConfig");
	servletHolder.setInitParameter("com.sun.jersey.config.property.packages", "rest");
	servletHolder.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
	context.addServlet(servletHolder, "/*");

	server.setHandler(context);

	server.start();
	server.join();
}
 
开发者ID:OwenChang,项目名称:JerseyWithJettyEmbedded,代码行数:23,代码来源:Main.java

示例11: configureServlets

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
@Override
public void configureServlets() {
  setup();

  serve("/", "/__stop").with(Dispatcher.class);

  for (String path : this.getServePathSpecs()) {
    serve(path).with(Dispatcher.class);
  }

  String regex = "(?!/ws)";
  serveRegex(regex).with(SliderDefaultWrapperServlet.class);

  Map<String, String> params = new HashMap<String, String>();
  params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true");
  params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true");
  params.put(ResourceConfig.FEATURE_XMLROOTELEMENT_PROCESSING, "true");
  params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName());
  params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName());
  //params.put("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
  //params.put("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
  //params.put("com.sun.jersey.config.feature.Trace", "true");
  params.put("com.sun.jersey.config.property.WadlGeneratorConfig",
      AMWadlGeneratorConfig.CLASSNAME);
  filter("/*").through(GuiceContainer.class, params);
}
 
开发者ID:apache,项目名称:incubator-slider,代码行数:27,代码来源:SliderAMWebApp.java

示例12: startServer

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
public void startServer(int port, String classBound) throws BindException,
		Exception {
	sh = new ServletHolder(ServletContainer.class);

	sh.setInitParameter(
			"com.sun.jersey.config.property.resourceConfigClass",
			"com.sun.jersey.api.core.PackagesResourceConfig");
	sh.setInitParameter("com.sun.jersey.config.property.packages",
			classBound);

	// custom parameters
	// Map<String, Object> initParameters = getCustomInitParamters(port);
	// sh.setInitParameters(initParameters);

	Server server = new Server(port);

	Context context = new Context(server, "/", Context.SESSIONS);

	context.addServlet(sh, "/*");
	server.start();

}
 
开发者ID:Aeronbroker,项目名称:Aeron,代码行数:23,代码来源:ServerDummy.java

示例13: configure

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
@Override
protected void configure() {
	bind(RefAppResource.class);

	// Install servlet module setting a the Jersey/Guice integration.
	install(new ServletModule() {
		@Override
		protected void configureServlets() {
			filter("/*").through(GuiceContainer.class,
					ImmutableMap.of(JSONConfiguration.FEATURE_POJO_MAPPING, "true",
							ResourceConfig.FEATURE_TRACE, "true",
							ResourceConfig.FEATURE_TRACE_PER_REQUEST, "true",
							ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true"));
		}
	});
}
 
开发者ID:mgm-tp,项目名称:perfload-refapp,代码行数:17,代码来源:RefAppModule.java

示例14: start

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
public static void start() {
    WebappContext webappContext = new WebappContext("TestContext");
    ServletRegistration registration = webappContext.addServlet("ServletContainer", ServletContainer.class);
    registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, "org.moskito.central.connectors.rest;org.codehaus.jackson.jaxrs");
    registration.addMapping("/*");

    SSLContextConfigurator sslConfigurator = new SSLContextConfigurator();
    sslConfigurator.setKeyStoreFile("./target/test-classes/central_server_keystore.jks");
    sslConfigurator.setKeyStorePass("moskito");
    SSLContext sslContext = sslConfigurator.createSSLContext();

    try {
        server = GrizzlyServerFactory.createHttpServer(
                getBaseURI(),
                null,
                true,
                new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)
        );

        webappContext.deploy(server);
        server.start();
    } catch (Exception e) {
        System.out.println("Error while starting the test server: " + e);
    }
}
 
开发者ID:anotheria,项目名称:moskito-central,代码行数:26,代码来源:RESTConnectorHttpsTest.java

示例15: testWebAppBuilder

import com.sun.jersey.spi.container.servlet.ServletContainer; //导入依赖的package包/类
@Test
public void testWebAppBuilder() throws Exception {
    assertThat(webappServerBuilder.servletConfigurations.size(), equalTo(2));

    ServletConfiguration jaxRsConfig = webappServerBuilder.servletConfigurations.get(0);
    assertThat(jaxRsConfig.servletClass.equals(ServletContainer.class), equalTo(true));
    assertThat(jaxRsConfig.initParameters.get("com.sun.jersey.config.property.packages"), equalTo(jerseyScanPackages));
    assertThat(jaxRsConfig.initParameters.get("com.sun.jersey.api.json.POJOMappingFeature"), equalTo("true"));
    assertThat(jaxRsConfig.pathSpecs.get(0), equalTo(restPathSpec));

    ServletConfiguration staticConfig = webappServerBuilder.servletConfigurations.get(1);
    assertThat(staticConfig.servletClass.equals(DefaultServlet.class), equalTo(true));
    assertThat(staticConfig.initParameters.get("resourceBase"), equalTo(resourceBase));
    assertThat(staticConfig.pathSpecs.get(0), equalTo("/"));
    assertThat(server.port, equalTo(serverPort));
    assertThat(server.contextName, equalTo("/"));
    server.toString();
}
 
开发者ID:xoom,项目名称:feathercon,代码行数:19,代码来源:WebappServerBuilderTest.java


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