org.glassfish.grizzly.servlet.WebappContext.deploy()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(171)

本文整理了Java中org.glassfish.grizzly.servlet.WebappContext.deploy()方法的一些代码示例,展示了WebappContext.deploy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebappContext.deploy()方法的具体详情如下:
包路径:org.glassfish.grizzly.servlet.WebappContext
类名称:WebappContext
方法名:deploy

WebappContext.deploy介绍

暂无

代码示例

代码示例来源:origin: jersey/jersey

context.deploy(server);
return server;

代码示例来源:origin: aol/micro-server

private void startServer(WebappContext webappContext, HttpServer httpServer, CompletableFuture start, CompletableFuture end) {
  webappContext.deploy(httpServer);
  try {
    logger.info("Starting application {} on port {}", serverData.getModule().getContext(), serverData.getPort());
    logger.info("Browse to http://localhost:{}/{}/application.wadl", serverData.getPort(), serverData.getModule().getContext());
    logger.info("Configured resource classes :-");
    serverData.extractResources()
        .forEach(t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getModule().getContext() + t._2()));
    ;
    httpServer.start();
    start.complete(true);
    end.get();
  } catch (IOException e) {
    throw ExceptionSoftener.throwSoftenedException(e);
  } catch (ExecutionException e) {
    throw ExceptionSoftener.throwSoftenedException(e);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw ExceptionSoftener.throwSoftenedException(e);
  } finally {
    httpServer.stop();
  }
}

代码示例来源:origin: jersey/jersey

context.deploy(server);
} catch (final ProcessingException ex) {
  throw new TestContainerException(ex);

代码示例来源:origin: uber/AthenaX

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);
}

代码示例来源:origin: com.helger/peppol-smp-server-webapp

/**
  * Starts Grizzly HTTP server exposing JAX-RS resources defined in this
  * application.
  *
  * @return Grizzly HTTP server.
  */
 @Nonnull
 public static HttpServer startRegularServer ()
 {
  final WebappContext aContext = _createContext (BASE_URI_HTTP);

  // create and start a new instance of grizzly http server
  // exposing the Jersey application at BASE_URI
  final HttpServer ret = GrizzlyHttpServerFactory.createHttpServer (URI.create (BASE_URI_HTTP));
  aContext.deploy (ret);
  return ret;
 }
}

代码示例来源:origin: phax/peppol-smp-server

/**
  * Starts Grizzly HTTP server exposing JAX-RS resources defined in this
  * application.
  *
  * @return Grizzly HTTP server.
  */
 @Nonnull
 public static HttpServer startRegularServer ()
 {
  final WebappContext aContext = _createContext (BASE_URI_HTTP);

  // create and start a new instance of grizzly http server
  // exposing the Jersey application at BASE_URI
  final HttpServer ret = GrizzlyHttpServerFactory.createHttpServer (URI.create (BASE_URI_HTTP));
  aContext.deploy (ret);
  return ret;
 }
}

代码示例来源:origin: stackoverflow.com

HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI());
WebappContext context = new WebappContext("WebappContext", "/api");
ServletRegistration registration = context.addServlet("ServletContainer",
 new ServletContainer(config));
registration.addMapping("/*");
context.deploy(httpServer);

代码示例来源:origin: stackoverflow.com

private static HttpServer create(URI u, Servlet servlet) throws IOException {

  String path = u.getPath();
  path = String.format("/%s", UriComponent.decodePath(u.getPath(), true)
         .get(1).toString());

  WebappContext context = new WebappContext("GrizzlyContext", path);
  context.addListener(MyListener.class);
  ServletRegistration registration;
  registration = context.addServlet(servlet.getClass().getName(), servlet);
  registration.addMapping("/*");

  HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u);
  context.deploy(server);
  return server;
}

代码示例来源:origin: stackoverflow.com

@Before
public void setUp() throws Exception {
  if (server == null) {
    System.out.println("Initializing an instance of Grizzly Container");
    final ResourceConfig rc = new ResourceConfig(A.class, B.class);

    WebappContext ctx = new WebappContext() {};
    ctx.addContextInitParameter("contextConfigLocation", "classpath:applicationContext.xml");

    ctx.addListener("com.package.something.AServletContextListener");

    server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
      ctx.deploy(server);
    }
  }

代码示例来源:origin: stackoverflow.com

@Before
 public void setup() throws Exception {
   if (server == null) {
     System.out.println("Initializing an instance of Grizzly Container ...");
     final ResourceConfig rc = new ResourceConfig(ResourceEndpointIntegrationTest.class, ..., ..., ...); //update
     WebappContext ctx = new WebappContext("IntegrationTestContext");
           //register your listeners from web.xml in here
     ctx.addListener("com.xxx.yyy.XEndpointServletContextListener");
           //register your applicationContext.xml here
     ctx.addContextInitParameter("contextConfigLocation", "classpath:applicationContext.xml");
           //ServletRegistration is needed to load the ResourceConfig rc inside ServletContainer or you will have no 
           //Servlet-based features available 
     ServletRegistration registration = ctx.addServlet("ServletContainer",
         new ServletContainer(rc));
           //Initialize the Grizzly server passing it base URL
     server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI));
           //Deploy the server using our custom context
     ctx.deploy(server);
   }
 }

代码示例来源:origin: stackoverflow.com

WebappContext context = new WebappContext("context");
 ServletRegistration registration = 
     context.addServlet("ServletContainer", ServletContainer.class);
 registration.setInitParameter("com.sun.jersey.config.property.packages",
     "com.sun.jersey.samples.https_grizzly.resource;com.sun.jersey.samples.https_grizzly.auth");
 // add security filter (which handles http basic authentication)
 registration.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
     "com.sun.jersey.samples.https_grizzly.auth.SecurityFilter;com.sun.jersey.api.container.filter.LoggingFilter");
 registration.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS,
     LoggingFilter.class.getName());
 try {
   webServer = GrizzlyServerFactory.createHttpServer(
       getBaseURI()
   );
   // start Grizzly embedded server //
   System.out.println("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
   context.deploy(webServer);
   webServer.start();
 } catch (Exception ex) {
   System.out.println(ex.getMessage());
 }

代码示例来源:origin: stackoverflow.com

ctx.addListener("org.springframework.web.context.ContextLoaderListener");
ctx.addListener("org.springframework.web.context.request.RequestContextListener");
ctx.deploy(server);

代码示例来源:origin: net.krotscheck/kangaroo-common

registration.addMapping(String.format("%s/*", path));
context.deploy(server);

代码示例来源:origin: stackoverflow.com

WebappContext webappContext = new WebappContext("grizzly web context", "");
 FilterRegistration testFilterReg = webappContext.addFilter("TestFilter", TestFilter.class);
 testFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), "/*");
 ServletRegistration servletRegistration = webappContext.addServlet("Jersey", org.glassfish.jersey.servlet.ServletContainer.class);
 servletRegistration.addMapping("/myapp/*");
 servletRegistration.setInitParameter("jersey.config.server.provider.packages", "com.example");
 HttpServer server = HttpServer.createSimpleServer();
 webappContext.deploy(server);
 server.start();

代码示例来源:origin: stackoverflow.com

private static String API_PACKAGE = "package where TestRESTService class";

public static final URI BASE_URI = UriBuilder
    .fromUri("http://localhost/")
    .port(8000)
    .build();

private static HttpServer initServer() throws IOException {
  System.out.println("Starting grizzly... " + BASE_URI);

  HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, new HttpHandler() {
    @Override
    public void service(Request rqst, Response rspns) throws Exception {
      rspns.sendError(404);
    }
  });

  // Initialize and register Jersey Servlet
  WebappContext context = new WebappContext("GrizzlyContext", "/");
  ServletRegistration registration = context.addServlet(
      ServletContainer.class.getName(), ServletContainer.class);
  registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
      PackagesResourceConfig.class.getName());
  registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, API_PACKAGE);
  registration.addMapping("/*");
  context.deploy(httpServer);

  return httpServer;
}

代码示例来源:origin: com.bitplan.rest/com.bitplan.simplerest

@Override
public synchronized void startWebServer() throws Exception {
 createServer();
 // start server
 httpServer.start();
 if (context != null) {
  context.deploy(httpServer);
 }
 // FIXME?
 /*
  * if (guiceModule != null) { WebappContext context =
  * createWebappContext(""); context.deploy(srv); }
  */
 LOGGER.log(Level.INFO, "starting server for URL: " + getUrl());
 running = true;
 informStarter();
 int sleep = 0;
 // timeOut is in Secs - we go by 1/20th of sec = 50 millisecs
 while (running && (sleep < settings.getTimeOut() * 20)) {
  // System.out.println(sleep+":"+running);
  // sleep 50 millisecs
  Thread.sleep(50);
  sleep++;
 }
 stop();
}

代码示例来源:origin: com.jpmorgan.quorum/jersey-server

registration.addMapping("/*");
ctx.deploy(this.server);

代码示例来源:origin: com.oath.microservices/micro-grizzly

private void startServer(WebappContext webappContext, HttpServer httpServer, CompletableFuture start, CompletableFuture end) {
  webappContext.deploy(httpServer);
  try {
    logger.info("Starting application {} on port {}", serverData.getModule().getContext(), serverData.getPort());
    logger.info("Browse to http://localhost:{}/{}/application.wadl", serverData.getPort(), serverData.getModule().getContext());
    logger.info("Configured resource classes :-");
    serverData.extractResources()
        .forEach(t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getModule().getContext() + t._2()));
    ;
    httpServer.start();
    start.complete(true);
    end.get();
  } catch (IOException e) {
    throw ExceptionSoftener.throwSoftenedException(e);
  } catch (ExecutionException e) {
    throw ExceptionSoftener.throwSoftenedException(e);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw ExceptionSoftener.throwSoftenedException(e);
  } finally {
    httpServer.stop();
  }
}

代码示例来源:origin: com.aol.microservices/micro-grizzly

private void startServer(WebappContext webappContext, HttpServer httpServer, CompletableFuture start, CompletableFuture end) {
  webappContext.deploy(httpServer);
  try {
    logger.info("Starting application {} on port {}", serverData.getModule().getContext(), serverData.getPort());
    logger.info("Browse to http://localhost:{}/{}/application.wadl", serverData.getPort(), serverData.getModule().getContext());
    logger.info("Configured resource classes :-");
    serverData.extractResources()
        .forEach(t -> logger.info(t.v1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getModule().getContext() + t.v2()));
    ;
    httpServer.start();
    start.complete(true);
    end.get();
  } catch (IOException e) {
    throw ExceptionSoftener.throwSoftenedException(e);
  } catch (ExecutionException e) {
    throw ExceptionSoftener.throwSoftenedException(e);
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw ExceptionSoftener.throwSoftenedException(e);
  } finally {
    httpServer.stop();
  }
}

代码示例来源:origin: apache/lens

final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet());
sgMetrics.addMapping("/admin/*");
adminCtx.deploy(server);

相关文章

WebappContext类方法