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


Java ServletRegistration类代码示例

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


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

示例1: WebServer

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的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: start

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
@Override
public void start() {
    System.out.println("Starting GrizzlyTestContainer...");
    try {
        this.server = GrizzlyHttpServerFactory.createHttpServer(uri, rc);

        // Initialize and register Jersey Servlet
        WebappContext context = new WebappContext("WebappContext", "");
        ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
        registration.setInitParameter("javax.ws.rs.Application", rc.getClass().getName());
        // Add an init parameter - this could be loaded from a parameter in the constructor
        registration.setInitParameter("myparam", "myvalue");

        registration.addMapping("/*");
        context.deploy(server);
    } catch (ProcessingException e) {
        throw new TestContainerException(e);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:20,代码来源:MCRJerseyTest.java

示例3: startServer

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
public <T extends DaggerServletContextListener> void startServer(Class<T> listenerClass) {
    LOGGER.info("Starting test server");

    WebappContext context = new WebappContext("Test", getUri().getRawPath());
    context.addListener(listenerClass);

    daggerFilter = new DaggerFilter();
    FilterRegistration filterRegistration = context.addFilter("daggerFilter", daggerFilter);
    filterRegistration.addMappingForUrlPatterns(null, "/*");

    ServletRegistration servletRegistration = context.addServlet("TestServlet", new HttpServlet() {
    });
    servletRegistration.addMapping("/dagger-jersey/*");

    try {
        httpServer = GrizzlyServerFactory.createHttpServer(getUri(), (HttpHandler) null);
        context.deploy(httpServer);
        httpServer.start();
        LOGGER.info("Test server started");
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:johnlcox,项目名称:dagger-servlet,代码行数:24,代码来源:GrizzlyTestServer.java

示例4: start

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的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

示例5: startServer

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
/**
 * Starts Grizzly HTTP server exposing SMAPH JAX-RS resources.
 * 
 * @throws URISyntaxException
 * @throws ProcessingException
 */
public static void startServer(String serverUri, Path storageBase, String watGcubeToken) throws ProcessingException, URISyntaxException {
	LOG.info("Initializing SMAPH services.");
	LOG.info("Storage path: {}", storageBase.toAbsolutePath());

	HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(new URI(serverUri));
	httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler("src/main/webapp/"), "/*");

	WebappContext context = new WebappContext("smaph");
	ResourceConfig rc = new ResourceConfig().packages("it.unipi.di.acube.smaph.servlet");
	ServletRegistration registration = context.addServlet("ServletContainer", new ServletContainer(rc));
	registration.addMapping("/smaph/*");
	context.addListener(SmaphContextListener.class);
	context.setInitParameter(SmaphContextListener.WIKI_PAGES_DB, storageBase.resolve("mapdb/wikipedia_pages.db").toString());
	context.setInitParameter(SmaphContextListener.FREEBASE_DIR, storageBase.resolve("mapdb/freebase.db").toString());
	context.setInitParameter(SmaphContextListener.ENTITY_TO_ANCHORS_DB, storageBase.resolve("mapdb/e2a.db").toString());
	context.setInitParameter(SmaphContextListener.WAT_GCUBE_TOKEN, watGcubeToken);
	context.deploy(httpServer);
	try {
		httpServer.start();
		LOG.info("Smaph started with WADL available at " + "{}application.wadl\nPress CTRL^C (SIGINT) to terminate.",
		        serverUri);
		Thread.currentThread().join();
		LOG.info("Shutting server down..");
	} catch (Exception e) {
		LOG.error("There was an error while starting Grizzly HTTP server.", e);
	}
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:34,代码来源:ServerMain.java

示例6: startServer

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
public HttpServer startServer() throws IOException {
    	HttpServer theServer;
    	
//        String[] packages = { "streams.prometheus.exporter.rest.resources",
//                "streams.prometheus.exporter.rest.errorhandling",
//                "streams.prometheus.exporter.rest.serializers" };

        //final ResourceConfig rc = new ResourceConfig().packages(packages);
        // Enable JSON media conversions
        //rc.register(JacksonFeature.class);
        
        WebappContext context = new WebappContext("WebappContext","");
        ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class);
        registration.setInitParameter("jersey.config.server.provider.packages",
        		"streams.metric.exporter.rest.resources;streams.metric.exporter.rest.errorhandling;streams.metric.exporter.rest.serializers");
        registration.addMapping("/*");
        
       //if (this.serverProtocol.equalsIgnoreCase("https")) {
        if (this.serverProtocol == Protocol.HTTPS) {

        	LOGGER.debug("Using https protocol");
        	theServer = createHttpsServer();
        } else {
        	LOGGER.debug("Using http protcol");
        	theServer = createHttpServer();
        }
        // Prometheus servlet
        // FUTURE: if we go with plugin this needs to be variant if it is created or not
        //ServletRegistration prometheus = context.addServlet("PrometheusContainer",new MetricsServlet());
        //prometheus.addMapping("/prometheus");
        
        context.deploy(theServer);
        
        theServer.start();
 
        return theServer;
    }
 
开发者ID:IBMStreams,项目名称:streamsx.jmxclients,代码行数:38,代码来源:RestServer.java

示例7: _createContext

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
@Nonnull
private static WebappContext _createContext (final URI u,
                                             final Class <? extends Servlet> aServletClass,
                                             final Servlet aServlet,
                                             final Map <String, String> aInitParams,
                                             final Map <String, String> aContextInitParams)
{
  String path = u.getPath ();
  if (path == null)
    throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be non-null");
  if (path.isEmpty ())
    throw new IllegalArgumentException ("The URI path, of the URI " + u + ", must be present");
  if (path.charAt (0) != '/')
    throw new IllegalArgumentException ("The URI path, of the URI " + u + ". must start with a '/'");
  path = String.format ("/%s", UriComponent.decodePath (u.getPath (), true).get (1).toString ());

  final WebappContext aContext = new WebappContext ("GrizzlyContext", path);
  ServletRegistration registration;
  if (aServletClass != null)
    registration = aContext.addServlet (aServletClass.getName (), aServletClass);
  else
    registration = aContext.addServlet (aServlet.getClass ().getName (), aServlet);
  registration.addMapping ("/*");

  if (aContextInitParams != null)
    for (final Map.Entry <String, String> e : aContextInitParams.entrySet ())
      aContext.setInitParameter (e.getKey (), e.getValue ());

  if (aInitParams != null)
    registration.setInitParameters (aInitParams);

  return aContext;
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:34,代码来源:MockServer.java

示例8: LensServer

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
/**
 * Instantiates a new lens server.
 *
 * @param conf the conf
 * @throws IOException Signals that an I/O exception has occurred.
 */
private LensServer(HiveConf conf) throws IOException {
  startServices(conf);
  String baseURI = conf.get(LensConfConstants.SERVER_BASE_URL, LensConfConstants.DEFAULT_SERVER_BASE_URL);
  HttpServer server = GrizzlyHttpServerFactory.createHttpServer(UriBuilder.fromUri(baseURI).build(), getApp(),
    false);

  int corePoolSize = conf.getInt(LensConfConstants.GRIZZLY_CORE_POOL_SIZE,
          LensConfConstants.DEFAULT_GRIZZLY_CORE_POOL_SIZE);
  int maxPoolSize = conf.getInt(LensConfConstants.GRIZZLY_MAX_POOL_SIZE,
          LensConfConstants.DEFAULT_GRIZZLY_MAX_POOL_SIZE);

  ThreadPoolConfig config = ThreadPoolConfig.defaultConfig();
  config.setPoolName("lensserver-pool");
  config.setCorePoolSize(corePoolSize);
  config.setMaxPoolSize(maxPoolSize);
  config.setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d")
    .setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler()).build());

  NetworkListener listener = server.getListeners().iterator().next();
  listener.getTransport().setWorkerThreadPoolConfig(config);
  serverList.add(server);

  WebappContext adminCtx = new WebappContext("admin", "");
  MetricsServiceImpl metricsService = LensServices.get().getService(MetricsService.NAME);
  adminCtx
    .setAttribute("com.codahale.metrics.servlets.MetricsServlet.registry", (metricsService.getMetricRegistry()));
  adminCtx.setAttribute("com.codahale.metrics.servlets.HealthCheckServlet.registry", metricsService.getHealthCheck());
  final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet());
  sgMetrics.addMapping("/admin/*");
  adminCtx.deploy(server);
}
 
开发者ID:apache,项目名称:lens,代码行数:38,代码来源:LensServer.java

示例9: main

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
public static void main(String[] args) {
    try {

        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, false);

        // Creating a webapp context for the resources / DI container
        final WebappContext webappContext = new WebappContext("Widow analyze");

        webappContext.addListener(new WidowAnalyzeServletContextListener());

        ServletRegistration servletRegistration = webappContext.addServlet("ServletContainer", ServletContainer.class);
        servletRegistration.addMapping("/REST/*");
        servletRegistration.setInitParameter("javax.ws.rs.Application",
                "com.widowcrawler.analyze.startup.WidowAnalyzeResourceConfig");

        final FilterRegistration registration = webappContext.addFilter("GuiceFilter", GuiceFilter.class);
        registration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), "/REST/*");

        webappContext.deploy(server);

        // static assets
        CLStaticHttpHandler clStaticHttpHandler = new CLStaticHttpHandler(
                Main.class.getClassLoader(),
                "/", "/lib/", "/js/", "/css/", "/templates/");
        server.getServerConfiguration().addHttpHandler(clStaticHttpHandler);

        server.start();

        System.out.println(String.format("Application started.\nTry out %s%s\nHit enter to stop it...",
                BASE_URI, ROOT_PATH));

        while(System.in.read() != 32);

        server.shutdownNow();
    } catch (Exception ex) {
        logger.error("Error: " + ex.getMessage(), ex);
    }
}
 
开发者ID:ScottMansfield,项目名称:widow,代码行数:39,代码来源:Main.java

示例10: setupHttpServer

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
private static HttpServer setupHttpServer(URI baseUri, final Injector injector) {
    final HttpServer serverLocal = GrizzlyHttpServerFactory
            .createHttpServer(baseUri, false);

    final WebappContext context = new WebappContext("Guice Webapp sample",
            "");

    context.addListener(new GuiceServletContextListener(){
        @Override
        protected Injector getInjector() {
            return injector;
        }
    });

    // Initialize and register Jersey ServletContainer
    final ServletRegistration servletRegistration = context.addServlet(
            "ServletContainer", ServletContainer.class);
    servletRegistration.addMapping("/*");
    servletRegistration.setInitParameter("javax.ws.rs.Application",
            WebApp.class.getName());

    // Initialize and register GuiceFilter
    final FilterRegistration registration = context.addFilter(
            "GuiceFilter", GuiceFilter.class);
    registration.addMappingForUrlPatterns(
            EnumSet.allOf(DispatcherType.class), "/*");

    context.deploy(serverLocal);

    return serverLocal;
}
 
开发者ID:udoprog,项目名称:exposr,代码行数:32,代码来源:Main.java

示例11: createRESTContext

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
/***************************************************************************
 *                                                                         *
 * Private Methods                                                         *
 *                                                                         *
 **************************************************************************/

private WebappContext createRESTContext(){
    WebappContext webappContext = new WebappContext("Grizzly Web Context", "");

    ServletRegistration servletRegistration = webappContext.addServlet(SERVLET_JERSEY, org.glassfish.jersey.servlet.ServletContainer.class);
    servletRegistration.addMapping("/api/*"); // map the REST API to the /api
    servletRegistration.setInitParameter(
            ServerProperties.PROVIDER_PACKAGES,
                    "vidada.server.rest.resource;" +   // scan this package for resource classes
                    "vidada.server.rest.provider"); // Specail Providers for server such as Authentication

    return webappContext;
}
 
开发者ID:Vidada-Project,项目名称:vidada-desktop,代码行数:19,代码来源:VidadaRestServer.java

示例12: addRestApplicationServlet

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
protected void addRestApplicationServlet(WebappContext context, ResourceConfig resourceConfig) {
	Servlet restFilter = new ServletContainer(resourceConfig);
	ServletRegistration restFilterRegistration = context.addServlet("restFilter", restFilter);
	restFilterRegistration.addMapping(getServletPath() + "/*");
}
 
开发者ID:openwide-java,项目名称:owsi-core-parent,代码行数:6,代码来源:RestServerTestResource.java

示例13: startEmbeddedServer

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
static void startEmbeddedServer() throws IOException {

		// Create test web application context.
		WebappContext webappContext = new WebappContext("Test Context");
		webappContext
		.addContextInitParameter("contextClass",
				"org.springframework.web.context.support.XmlWebApplicationContext");
		webappContext.addContextInitParameter("contextConfigLocation",
				"classpath*:spring-context.xml");
		webappContext
		.addListener("org.springframework.web.context.ContextLoaderListener");

		// Create a servlet registration for the web application in order to wire up Spring managed collaborators to Jersey resources.
		ServletRegistration servletRegistration = webappContext.addServlet(
				"jersey-servlet", ServletContainer.class);

		// The logging filters for server logging.
		servletRegistration
		.setInitParameter(
				"com.sun.jersey.spi.container.ContainerResponseFilters",
				"com.sun.jersey.api.container.filter.LoggingFilter");
		servletRegistration.setInitParameter(
				"com.sun.jersey.spi.container.ContainerRequestFilters",
				"com.sun.jersey.api.container.filter.LoggingFilter");

		servletRegistration.setInitParameter("javax.ws.rs.Application",
				"com.test.MyDemoApplication");

		servletRegistration.setInitParameter(
				"com.sun.jersey.config.property.packages", "com.test");
		servletRegistration.setInitParameter(
				"com.sun.jersey.api.json.POJOMappingFeature", "true");
		servletRegistration.addMapping("/*");

		HttpServer server = new HttpServer();
		NetworkListener listener = new NetworkListener("grizzly2", "localhost",
				3388);
		server.addListener(listener);

		webappContext.deploy(server);

		try {
			server.start();
			System.out.println("Press enter to stop the server...");
			System.in.read();
		} finally {
			server.shutdownNow();
		}
	}
 
开发者ID:janusdn,项目名称:jersey2-spring4-grizzly2,代码行数:50,代码来源:Start.java

示例14: registerServlet

import org.glassfish.grizzly.servlet.ServletRegistration; //导入依赖的package包/类
private void registerServlet(final WebappContext webapp) {
    ServletRegistration registration = webapp.addServlet(servlet.getSimpleName(), servlet);
    registration.addMapping(mapping);
    registration.setInitParameters(initParameters);
    registration.setLoadOnStartup(1);
}
 
开发者ID:trautonen,项目名称:jersey-mustache,代码行数:7,代码来源:GrizzlyServerBuilder.java


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