/** * Return a new resource handler * * @param resourceManager The resource manager to use * @return A new resource handler */ public static ResourceHandler resource(final ResourceManager resourceManager) { return new ResourceHandler(resourceManager).setDirectoryListingEnabled(false); }
@Override public HttpHandler wrap(HttpHandler handler) { ResourceManager rm = new PathResourceManager(Paths.get(location), 1024); ResourceHandler resourceHandler = new ResourceHandler(rm); resourceHandler.setDirectoryListingEnabled(allowDirectoryListing); return resourceHandler; } }
@Override public HttpHandler createHandler(final OperationContext context, ModelNode model) throws OperationFailedException { final String path = PATH.resolveModelAttribute(context, model).asString(); final boolean directoryListing = DIRECTORY_LISTING.resolveModelAttribute(context, model).asBoolean(); final boolean followSymlink = FOLLOW_SYMLINK.resolveModelAttribute(context, model).asBoolean(); final boolean caseSensitive = CASE_SENSITIVE.resolveModelAttribute(context, model).asBoolean(); final int cacheBufferSize = CACHE_BUFFER_SIZE.resolveModelAttribute(context, model).asInt(); final int cacheBuffers = CACHE_BUFFERS.resolveModelAttribute(context, model).asInt(); final List<String> safePaths = SAFE_SYMLINK_PATHS.unwrap(context, model); final String[] paths = safePaths.toArray(new String[safePaths.size()]); UndertowLogger.ROOT_LOGGER.creatingFileHandler(path, directoryListing, followSymlink, caseSensitive, safePaths); Path base; try { base = Paths.get(path).normalize().toRealPath(); //workaround for JBEAP-10231 } catch (IOException e) { throw new OperationFailedException(UndertowLogger.ROOT_LOGGER.unableAddHandlerForPath(path)); } PathResourceManager resourceManager = new PathResourceManager(base, cacheBufferSize * cacheBuffers, caseSensitive, followSymlink, paths); ResourceHandler handler = new ResourceHandler(resourceManager); handler.setDirectoryListingEnabled(directoryListing); return handler; } }
public PathResourceHandler() { PathResourceConfig config = (PathResourceConfig)Config.getInstance().getJsonObjectConfig(PathResourceConfig.CONFIG_NAME, PathResourceConfig.class); if(config.isPrefix()) { pathHandler = new PathHandler() .addPrefixPath(config.getPath(), new ResourceHandler(new PathResourceManager(Paths.get(config.getBase()), config.getTransferMinSize())) .setDirectoryListingEnabled(config.isDirectoryListingEnabled())); } else { pathHandler = new PathHandler() .addExactPath(config.getPath(), new ResourceHandler(new PathResourceManager(Paths.get(config.getBase()), config.getTransferMinSize())) .setDirectoryListingEnabled(config.isDirectoryListingEnabled())); } }
public VirtualHostHandler() { VirtualHostConfig config = (VirtualHostConfig)Config.getInstance().getJsonObjectConfig(VirtualHostConfig.CONFIG_NAME, VirtualHostConfig.class); virtualHostHandler = new NameVirtualHostHandler(); for(VirtualHost host: config.hosts) { virtualHostHandler.addHost(host.domain, new PathHandler().addPrefixPath(host.getPath(), new ResourceHandler((new PathResourceManager(Paths.get(host.getBase()), host.getTransferMinSize()))).setDirectoryListingEnabled(host.isDirectoryListingEnabled()))); } }
/** * Return a new resource handler * * @param resourceManager The resource manager to use * @return A new resource handler */ public static ResourceHandler resource(final ResourceManager resourceManager) { return new ResourceHandler(resourceManager).setDirectoryListingEnabled(false); }
/** * Return a new resource handler * * @param resourceManager The resource manager to use * @return A new resource handler */ public static ResourceHandler resource(final ResourceManager resourceManager) { return new ResourceHandler(resourceManager).setDirectoryListingEnabled(false); }
@Override public HttpHandler wrap(HttpHandler handler) { ResourceManager rm = new PathResourceManager(Paths.get(location), 1024); ResourceHandler resourceHandler = new ResourceHandler(rm); resourceHandler.setDirectoryListingEnabled(allowDirectoryListing); return resourceHandler; } }
@Override public HttpHandler wrap(HttpHandler handler) { ResourceManager rm = new PathResourceManager(Paths.get(location), 1024); ResourceHandler resourceHandler = new ResourceHandler(rm); resourceHandler.setDirectoryListingEnabled(allowDirectoryListing); return resourceHandler; } }
.setResourceManager(resourceManager) .setWelcomeFiles(welcomeFiles) .setDirectoryListingEnabled(false);
ResourceHandler handler = resource(new FileResourceManager(file, 3)) .addWelcomeFiles(welcomeFile) .setDirectoryListingEnabled(false);
@Override public HttpHandler createHandler(final OperationContext context, ModelNode model) throws OperationFailedException { final String path = PATH.resolveModelAttribute(context, model).asString(); final boolean directoryListing = DIRECTORY_LISTING.resolveModelAttribute(context, model).asBoolean(); final boolean followSymlink = FOLLOW_SYMLINK.resolveModelAttribute(context, model).asBoolean(); final boolean caseSensitive = CASE_SENSITIVE.resolveModelAttribute(context, model).asBoolean(); final int cacheBufferSize = CACHE_BUFFER_SIZE.resolveModelAttribute(context, model).asInt(); final int cacheBuffers = CACHE_BUFFERS.resolveModelAttribute(context, model).asInt(); final List<String> safePaths = SAFE_SYMLINK_PATHS.unwrap(context, model); final String[] paths = safePaths.toArray(new String[safePaths.size()]); UndertowLogger.ROOT_LOGGER.creatingFileHandler(path, directoryListing, followSymlink, caseSensitive, safePaths); Path base; try { base = Paths.get(path).normalize().toRealPath(); //workaround for JBEAP-10231 } catch (IOException e) { throw new OperationFailedException(UndertowLogger.ROOT_LOGGER.unableAddHandlerForPath(path)); } PathResourceManager resourceManager = new PathResourceManager(base, cacheBufferSize * cacheBuffers, caseSensitive, followSymlink, paths); ResourceHandler handler = new ResourceHandler(resourceManager); handler.setDirectoryListingEnabled(directoryListing); return handler; } }
@Override public HttpHandler createHandler(final OperationContext context, ModelNode model) throws OperationFailedException { final String path = PATH.resolveModelAttribute(context, model).asString(); final boolean directoryListing = DIRECTORY_LISTING.resolveModelAttribute(context, model).asBoolean(); final boolean followSymlink = FOLLOW_SYMLINK.resolveModelAttribute(context, model).asBoolean(); final boolean caseSensitive = CASE_SENSITIVE.resolveModelAttribute(context, model).asBoolean(); final int cacheBufferSize = CACHE_BUFFER_SIZE.resolveModelAttribute(context, model).asInt(); final int cacheBuffers = CACHE_BUFFERS.resolveModelAttribute(context, model).asInt(); final List<String> safePaths = SAFE_SYMLINK_PATHS.unwrap(context, model); final String[] paths = safePaths.toArray(new String[safePaths.size()]); UndertowLogger.ROOT_LOGGER.creatingFileHandler(path, directoryListing, followSymlink, caseSensitive, safePaths); Path base; try { base = Paths.get(path).normalize().toRealPath(); //workaround for JBEAP-10231 } catch (IOException e) { throw new OperationFailedException(UndertowLogger.ROOT_LOGGER.unableAddHandlerForPath(path)); } PathResourceManager resourceManager = new PathResourceManager(base, cacheBufferSize * cacheBuffers, caseSensitive, followSymlink, paths); ResourceHandler handler = new ResourceHandler(resourceManager); handler.setDirectoryListingEnabled(directoryListing); return handler; } }
public static HttpHandler createErrorContext(final String slot) throws ModuleLoadException { final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), ""); final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource) .setAllowed(not(path("META-INF"))) .setDirectoryListingEnabled(false) .setCachable(Predicates.<HttpServerExchange>falsePredicate()); //we also need to setup the default resource redirect return new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(ERROR_CONTEXT + DEFAULT_RESOURCE)), handler); }
static ResourceHandlerDefinition createConsoleHandler(String slot, String resource) throws ModuleLoadException { final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), ""); final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource) .setAllowed(not(path("META-INF"))) .setResourceManager(cpresource) .setDirectoryListingEnabled(false) .setCachable(Predicates.<HttpServerExchange>falsePredicate()); //we also need to setup the default resource redirect PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(CONTEXT + resource)), handler); return new ResourceHandlerDefinition(CONTEXT, resource, predicateHandler); }
static ResourceHandlerDefinition createStaticContentHandler(ResourceManager resource, String context) { final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(resource) .setCacheTime(60 * 60 * 24 * 31) .setAllowed(not(path("META-INF"))) .setResourceManager(resource) .setDirectoryListingEnabled(false) .setCachable(not(suffixes(NOCACHE_JS, APP_HTML, INDEX_HTML))); // avoid clickjacking attacks: console must not be included in (i)frames SetHeaderHandler frameHandler = new SetHeaderHandler(handler, "X-Frame-Options", "SAMEORIGIN"); // we also need to setup the default resource redirect PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(context + DEFAULT_RESOURCE)), frameHandler); return new ResourceHandlerDefinition(context, DEFAULT_RESOURCE, predicateHandler); }