當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。