context.deploy(server); return 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(); } }
context.deploy(server); } catch (final ProcessingException ex) { throw new TestContainerException(ex);
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); }
/** * 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; } }
/** * 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; } }
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI()); WebappContext context = new WebappContext("WebappContext", "/api"); ServletRegistration registration = context.addServlet("ServletContainer", new ServletContainer(config)); registration.addMapping("/*"); context.deploy(httpServer);
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; }
@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); } }
@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); } }
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()); }
ctx.addListener("org.springframework.web.context.ContextLoaderListener"); ctx.addListener("org.springframework.web.context.request.RequestContextListener"); ctx.deploy(server);
registration.addMapping(String.format("%s/*", path)); context.deploy(server);
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();
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; }
@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(); }
registration.addMapping("/*"); ctx.deploy(this.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(); } }
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(); } }
final ServletRegistration sgMetrics = adminCtx.addServlet("admin", new AdminServlet()); sgMetrics.addMapping("/admin/*"); adminCtx.deploy(server);