@Override public void run(Configuration configuration, Environment environment) { LOGGER.info("Registering AssetBundle with name: {} for path {}", assetsName, uriPath + '*'); environment.servlets().addServlet(assetsName, createServlet()).addMapping(uriPath + '*'); }
@Override public void run(T configuration, Environment environment) { ShiroConfiguration shiroConfig = narrow(configuration); if (shiroConfig == null) { shiroConfig = new ShiroConfiguration(); } ResourceConfig resourceConfig = environment.jersey().getResourceConfig(); resourceConfig.register(StormpathShiroFeature.class); // This listener will configure Shiro and Stormpath environment.servlets().addServletListeners(new StormpathShiroEnvironmentLoaderListener()); environment.servlets() .addServlet("default", DefaultServlet.class) .addMapping("/"); // The Stormpath API requires the 'default' servlet environment.servlets() .addFilter("ShiroFilter", ShiroFilter.class) // setup the Shiro Filter .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, shiroConfig.filterUrlPattern()); }
WebSocketResourceProviderFactory provisioningServlet = new WebSocketResourceProviderFactory(provisioningEnvironment); ServletRegistration.Dynamic websocket = environment.servlets().addServlet("WebSocket", webSocketServlet ); ServletRegistration.Dynamic provisioning = environment.servlets().addServlet("Provisioning", provisioningServlet);
@Override public void run(Environment environment) { LOGGER.info("Registering AssetBundle with name: {} for path {}", assetsName, uriPath + '*'); environment.servlets().addServlet(assetsName, createServlet()).addMapping(uriPath + '*'); }
@Override public void scanAndAdd(Environment environment, Injector injector, Reflections reflections) { Set<Class<?>> wsClasses = reflections.getTypesAnnotatedWith(RobeWebSocket.class); for (Class<?> ws : wsClasses) { RobeWebSocket ann = ws.getAnnotation(RobeWebSocket.class); String path = ann.path() + (ann.subPaths() ? "/*" : ""); path = path.charAt(0) != '/' ? path = "/" + path : path; environment.servlets().addServlet(ann.path(), new WebSocketServlet((Class<WebSocket>) ws)).addMapping(path); LOGGER.info("Added websocket: " + ws); } } }
@Override public void run(Configuration configuration, Environment environment) throws Exception { //TODO: NEED TO DISABLE GZIP for text/event-stream environment.servlets().addServlet("mock.stream", new MockStreamServlet()).addMapping("/tenacity/mock.stream"); environment.servlets().addServlet("proxy.stream", new ProxyStreamServlet()).addMapping("/tenacity/proxy.stream"); } }
public void setServlets(ServletEnvironment servlets) { AuthFilter authFilter = (authSpec != null) ? new AuthFilter(authSpec) : null; for ( IndexMapping mapping : mappings ) { String name = Splitter.on('.').split(mapping.getFile()).iterator().next(); servlets.addServlet(name, this).addMapping(mapping.getPath()); servlets.addServlet(name + "-force", this).addMapping(FORCE + mapping.getPath()); if ( !mapping.isAuthServlet() && (authFilter != null) ) { servlets.addFilter("auth-" + name, authFilter).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, mapping.getPath()); servlets.addFilter("auth-" + name + "-force", authFilter).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, FORCE + mapping.getPath()); } } }
private void configure(final ServletEnvironment environment, final HttpServlet servlet, final Class<? extends HttpServlet> type, final String name, final WebServlet annotation) { final ServletRegistration.Dynamic mapping = environment.addServlet(name, servlet); final Set<String> clash = mapping .addMapping(annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value()); if (clash != null && !clash.isEmpty()) { final String msg = String.format( "Servlet registration %s clash with already installed servlets on paths: %s", type.getSimpleName(), Joiner.on(',').join(clash)); if (option(DenyServletRegistrationWithClash)) { throw new IllegalStateException(msg); } else { logger.warn(msg); } } if (annotation.initParams().length > 0) { for (WebInitParam param : annotation.initParams()) { mapping.setInitParameter(param.name(), param.value()); } } mapping.setAsyncSupported(annotation.asyncSupported()); } }
private void registerServlet(Injector injector, Environment environment, Binding<?> binding) { ServletDefinition servletDefinition = (ServletDefinition)binding.getProvider().get(); log.info("Registering servlet: " + servletDefinition); HttpServlet servletInstance = servletDefinition.getServletInstance(); if ( servletInstance == null ) { servletInstance = injector.getInstance(servletDefinition.getServletKey()); } ServletRegistration.Dynamic registration = environment.servlets().addServlet(servletDefinition.getServletKey().toString(), servletInstance); registration.setInitParameters(servletDefinition.getInitParams()); registration.addMapping(servletDefinition.getPatterns()); }
private void configure(final ServletEnvironment environment, final HttpServlet servlet, final Class<? extends HttpServlet> type, final String name, final WebServlet annotation) { final ServletRegistration.Dynamic mapping = environment.addServlet(name, servlet); final Set<String> clash = mapping .addMapping(annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value()); if (clash != null && !clash.isEmpty()) { final String msg = String.format( "Servlet registration %s clash with already installed servlets on paths: %s", type.getSimpleName(), Joiner.on(',').join(clash)); if (option(DenyServletRegistrationWithClash)) { throw new IllegalStateException(msg); } else { logger.warn(msg); } } if (annotation.initParams().length > 0) { for (WebInitParam param : annotation.initParams()) { mapping.setInitParameter(param.name(), param.value()); } } mapping.setAsyncSupported(annotation.asyncSupported()); } }
@Override public void run(T configuration, Environment environment) throws Exception { for (AssetConfiguration assetConf : configuration.getAssets()) { String resourcePath = assetConf.getResourcePath(); // Preconditions.checkArgument(resourcePath.startsWith("/"), "%s is not an absolute path", resourcePath); Preconditions.checkArgument(!"/".equals(resourcePath), "%s is the classpath root", resourcePath); resourcePath = resourcePath.endsWith("/") ? resourcePath : (resourcePath + '/'); String uriPath = assetConf.getUriPath(); uriPath = uriPath.endsWith("/") ? uriPath : (uriPath + '/'); LOGGER.info("Registering AssetBundle with name: {} for path {}", assetConf.getAssetsName(), uriPath + '*'); HttpServlet assetServlet = null; switch (assetConf.getType()) { case "filesystem": assetServlet = getFileAssetServlet(assetConf, resourcePath, uriPath); break; case "classpath": assetServlet = getClasspathAssetServlet(assetConf,resourcePath,uriPath); break; case "http": assetServlet = getHttpAssetServlet(assetConf, resourcePath, uriPath); break; } environment.servlets().addServlet(assetConf.getAssetsName(), assetServlet).addMapping(uriPath + '*'); } }
@Override public void run(T configuration, Environment environment) throws Exception { for (AssetConfiguration assetConf : configuration.getAssets()) { String resourcePath = assetConf.getResourcePath(); // Preconditions.checkArgument(resourcePath.startsWith("/"), "%s is not an absolute path", resourcePath); Preconditions.checkArgument(!"/".equals(resourcePath), "%s is the classpath root", resourcePath); resourcePath = resourcePath.endsWith("/") ? resourcePath : (resourcePath + '/'); String uriPath = assetConf.getUriPath(); uriPath = uriPath.endsWith("/") ? uriPath : (uriPath + '/'); LOGGER.info("Registering AssetBundle with name: {} for path {}", assetConf.getAssetsName(), uriPath + '*'); HttpServlet assetServlet = null; switch (assetConf.getType()) { case "filesystem": assetServlet = getFileAssetServlet(assetConf, resourcePath, uriPath); break; case "classpath": assetServlet = getClasspathAssetServlet(assetConf,resourcePath,uriPath); break; case "http": assetServlet = getHttpAssetServlet(assetConf, resourcePath, uriPath); break; } environment.servlets().addServlet(assetConf.getAssetsName(), assetServlet).addMapping(uriPath + '*'); } }
/** * Method called to create service endpoints, given set of * handlers. */ protected void addServiceEndpoints(Environment environment, CMServletFactory servletFactory) { RequestPathBuilder<?> rootBuilder = rootPath(_serviceStuff.getServiceConfig()); String rootPath = servletPath(rootBuilder); LOG.info("Registering main Dispatcher servlet at: "+rootPath); ServletBase dispatcher = servletFactory.contructDispatcherServlet(); if (dispatcher != null) { environment.servlets() .addServlet("CM-Dispatcher", dispatcher) .addMapping(rootPath); } // // And optional additional servlet for for entry access addStoreEntryServlet(environment); }
/** * Implements com.yammer.dropwizard.Bundle#run() */ @Override public void run(C configuration, Environment environment) { checkArgument(environment != null, "Environment is null"); environment.servlets().addServlet("CXF Servlet " + jaxwsEnvironment.getDefaultPath(), jaxwsEnvironment.buildServlet()).addMapping(servletPath); environment.lifecycle().addServerLifecycleListener( server -> jaxwsEnvironment.logEndpoints()); String publishedEndpointUrlPrefix = getPublishedEndpointUrlPrefix(configuration); if(publishedEndpointUrlPrefix != null) { jaxwsEnvironment.setPublishedEndpointUrlPrefix(publishedEndpointUrlPrefix); } }
private void evaluateWeb() throws Exception { if (!runPerServiceMode(web)) { return; } // Load balancers should hit the ping servlet, exposed on the main port to reflect main connection pool issues _environment.servlets().addServlet("/ping", new PingServlet()); // Serve static assets _environment.jersey().register(FaviconResource.class); // Add a filter to provide finer 5xx metrics than the default DropWizard metrics include. //noinspection unchecked _environment.jersey().getResourceConfig().getContainerResponseFilters() .add(new ServerErrorResponseMetricsFilter(_environment.metrics())); }
@Override public void run(AssetsBundleConfiguration bundleConfig, Environment env) throws Exception { AssetsConfiguration config = bundleConfig.getAssetsConfiguration(); // Let the cache spec from the configuration override the one specified in the code CacheBuilderSpec spec = (config.getCacheSpec() != null) ? CacheBuilderSpec.parse(config.getCacheSpec()) : cacheBuilderSpec; Iterable<Map.Entry<String, String>> overrides = config.getOverrides(); Iterable<Map.Entry<String, String>> mimeTypes = config.getMimeTypes(); AssetServlet servlet = new AssetServlet(resourcePath, spec, uriPath, indexFile, overrides, mimeTypes); env.servlets().addServlet(assetsName, servlet).addMapping(uriPath + "*"); }
@Override public void run(AssetsBundleConfiguration bundleConfig, Environment env) throws Exception { AssetsConfiguration config = bundleConfig.getAssetsConfiguration(); // Let the cache spec from the configuration override the one specified in the code CacheBuilderSpec spec = (config.getCacheSpec() != null) ? CacheBuilderSpec.parse(config.getCacheSpec()) : cacheBuilderSpec; Iterable<Map.Entry<String, String>> overrides = config.getOverrides(); Iterable<Map.Entry<String, String>> mimeTypes = config.getMimeTypes(); AssetServlet servlet = new AssetServlet(resourcePath, spec, uriPath, indexFile, overrides, mimeTypes); env.servlets().addServlet(assetsName, servlet).addMapping(uriPath + "*"); }
@Override public void run(ServerConfiguration serverConfiguration, Environment environment) throws Exception { WebSocketEnvironment webSocketEnvironment = new WebSocketEnvironment(environment, serverConfiguration.getWebSocketConfiguration()); HelloResource helloResource = new HelloResource(serverConfiguration.getHelloResponse()); HelloAccountBasicAuthenticator helloBasicAuthenticator = new HelloAccountBasicAuthenticator(); environment.jersey().register(helloResource); environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<HelloAccount>() .setAuthenticator(helloBasicAuthenticator) .setPrincipal(HelloAccount.class) .buildAuthFilter())); environment.jersey().register(new AuthValueFactoryProvider.Binder()); webSocketEnvironment.jersey().register(helloResource); webSocketEnvironment.setAuthenticator(new HelloAccountWebSocketAuthenticator(helloBasicAuthenticator)); WebSocketResourceProviderFactory servlet = new WebSocketResourceProviderFactory(webSocketEnvironment); ServletRegistration.Dynamic websocket = environment.servlets().addServlet("WebSocket", servlet); websocket.addMapping("/websocket/*"); websocket.setAsyncSupported(true); servlet.start(); }
} else { environment.servlets() .addServlet(tenacityMetricsStream, new HystrixMetricsStreamServlet()) .addMapping(tenacityMetricsStream); environment.jersey().register(propertyKeysResource);
} else { environment.servlets() .addServlet(tenacityMetricsStream, new HystrixMetricsStreamServlet()) .addMapping(tenacityMetricsStream); environment.jersey().register(propertyKeysResource);