Refine search
final WebappContext context = new WebappContext("TestContext", contextPathLocal); final ServletRegistration registration; if (servletInstance != null) { registration = context.addServlet(servletInstance.getClass().getName(), servletInstance); } else { registration = context.addServlet(servletClass.getName(), servletClass); context.addListener(eventListener); context.addContextInitParameter(contextParamName, contextParams.get(contextParamName)); context.addFilter(filterDescriptor.getFilterName(), filterDescriptor.getFilterClass()); context.deploy(server); } catch (final ProcessingException ex) { throw new TestContainerException(ex);
WebappContext context = new WebappContext("GrizzlyContext", path); ServletRegistration registration; if (c != null) { registration = context.addServlet(c.getName(), c); } else { registration = context.addServlet(servlet.getClass().getName(), servlet); context.setInitParameter(e.getKey(), e.getValue()); context.deploy(server); return server;
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); }
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { WebappContext webappContext = new WebappContext("WebappContext", ""); new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData); jaxRsConfigurer.addServlet(this.serverData,webappContext); new ServletConfigurer(serverData, servletData).addServlets(webappContext); new FilterConfigurer(serverData, this.filterData).addFilters(webappContext); addListeners(webappContext); HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort()); serverData.getModule().getServerConfigManager().accept(new WebServerProvider(httpServer)); addAccessLog(httpServer); addSSL(httpServer); startServer(webappContext, httpServer, start, end); }
final DefaultServlet s = new DefaultServlet((StaticHttpHandlerBase) h); final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration); try { s.init(sConfig); updateMappings(servletHandler, "/")); if (servletHandlers == null) {
@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 aRegistration; if (aServletClass != null) aRegistration = aContext.addServlet (aServletClass.getName (), aServletClass); else aRegistration = aContext.addServlet (aServlet.getClass ().getName (), aServlet); aRegistration.addMapping ("/*"); if (aContextInitParams != null) for (final Map.Entry <String, String> e : aContextInitParams.entrySet ()) aContext.setInitParameter (e.getKey (), e.getValue ()); if (aInitParams != null) aRegistration.setInitParameters (aInitParams); return aContext; }
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();
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);
addListener(createEventListenerInstance(listenerClass)); } catch (Exception e) { throw new IllegalStateException(e);
private void requestInitialized(ServletRequestEvent event) { final EventListener[] listeners = ctx.getEventListeners(); for (int i = 0, len = listeners.length; i < len; i++) { if (listeners[i] instanceof ServletRequestListener) { try { ((ServletRequestListener) listeners[i]).requestInitialized(event); } catch (Throwable t) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("requestDestroyed", "ServletRequestListener", listeners[i].getClass().getName()), t); } } } } }
/** * */ public synchronized void undeploy() { try { if (deployed) { deployed = false; final HttpServer server = DEPLOYED_APPS.remove(this); destoryServlets(server); // destroy filter instances destroyFilters(); // invoke servlet context listeners contextDestroyed(); } } catch (Exception e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "[" + displayName + "] Exception undeploying application. See stack trace for details.", e); } } }
WebappContext webappContext = new WebappContext("myWebappContext"); webappContext.addListener(new ServletContextListener() { @Override public void contextInitialized(ServletContextEvent sce) { sce.getServletContext().setAttribute(ServletProperties.SERVICE_LOCATOR, MY_SERVICE_LOCATOR); } @Override public void contextDestroyed(ServletContextEvent sce) { } }); ServletRegistration servlet = webappContext.addServlet("myAppplication", new ServletContainer(resourceConfig)); servlet.addMapping("/application/*"); ServletRegistration hello = webappContext.addServlet("myServlet", MyServlet.class); hello.addMapping("/servlet/*"); HttpServer createHttpServer = GrizzlyHttpServerFactory.createHttpServer(MY_URI, false); webappContext.deploy(createHttpServer); createHttpServer.start();
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 requestDestroyed(ServletRequestEvent event) { // TODO don't create the event unless necessary final EventListener[] listeners = ctx.getEventListeners(); for (int i = 0, len = listeners.length; i < len; i++) { if (listeners[i] instanceof ServletRequestListener) { try { ((ServletRequestListener) listeners[i]).requestDestroyed(event); } catch (Throwable t) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_DESTROYED_ERROR("requestDestroyed", "ServletRequestListener", listeners[i].getClass().getName()), t); } } } } }
/** * {@inheritDoc} */ @Override public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... servletNames) { if (ctx.deployed) { throw new IllegalStateException("WebappContext has already been deployed"); } if ((servletNames==null) || (servletNames.length==0)) { throw new IllegalArgumentException("'servletNames' is null or zero-length"); } for (String servletName : servletNames) { FilterMap fmap = new FilterMap(); fmap.setFilterName(getName()); fmap.setServletName(servletName); fmap.setDispatcherTypes(dispatcherTypes); ctx.addFilterMap(fmap, isMatchAfter); } }
checkUnusualURLPattern(urlPattern); return true; } else checkUnusualURLPattern(urlPattern); return true; } else
@Override protected EventListener[] getEventListeners() { return super.getEventListeners(); }
HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI()); WebappContext context = new WebappContext("WebappContext", "/api"); ServletRegistration registration = context.addServlet("ServletContainer", new ServletContainer(config)); registration.addMapping("/*"); context.deploy(httpServer);
public void initialize(final Request request, final HttpServletResponseImpl servletResponse, final WebSocketMappingData mappingData) throws IOException { if (mappingData != null) { updatePaths(mappingData); } else { contextPath = request.getContextPath(); } if (mappingData != null && mappingData.isGlassfish) { glassfishSupport = new GlassfishSupport(mappingData.context, mappingData.wrapper, this); } else { glassfishSupport = new GlassfishSupport(); } super.initialize(request, servletResponse, new WebappContext("web-socket-ctx", contextPath)); }
final DefaultServlet s = new DefaultServlet((StaticHttpHandlerBase) h); final ServletRegistration registration = addServlet("DefaultServlet", s); registration.addMapping("/"); final ServletConfigImpl sConfig = createServletConfig(registration); try { s.init(sConfig); updateMappings(servletHandler, "/")); if (servletHandlers == null) {