本文整理汇总了Java中io.undertow.server.handlers.resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于io.undertow.server.handlers.resource包,在下文中一共展示了Resource类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getResource
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
@Override
public URL getResource(final String path) throws MalformedURLException {
if (!path.startsWith("/")) {
throw UndertowServletMessages.MESSAGES.pathMustStartWithSlash(path);
}
Resource resource = null;
try {
resource = deploymentInfo.getResourceManager().getResource(path);
} catch (IOException e) {
return null;
}
if (resource == null) {
return null;
}
return resource.getUrl();
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ServletContextImpl.java
示例2: getRealPath
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
@Override
public String getRealPath(final String path) {
if (path == null) {
return null;
}
String canonicalPath = CanonicalPathUtils.canonicalize(path);
Resource resource = null;
try {
resource = deploymentInfo.getResourceManager().getResource(canonicalPath);
} catch (IOException e) {
return null;
}
if (resource == null) {
return null;
}
File file = resource.getFile();
if (file == null) {
return null;
}
return file.getAbsolutePath();
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:ServletContextImpl.java
示例3: findWelcomeFile
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
private ServletPathMatch findWelcomeFile(final String path, boolean requiresRedirect) {
if(File.separatorChar != '/' && path.contains(File.separator)) {
return null;
}
for (String i : welcomePages) {
try {
final String mergedPath = path + i;
Resource resource = resourceManager.getResource(mergedPath);
if (resource != null) {
final ServletPathMatch handler = data.getServletHandlerByPath(mergedPath);
return new ServletPathMatch(handler.getServletChain(), mergedPath, null, requiresRedirect ? REDIRECT : REWRITE, i);
}
} catch (IOException e) {
}
}
return null;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ServletPathMatches.java
示例4: loadTemplate
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
public static String loadTemplate(String template, ResourceManager resourceManager) throws Exception {
byte[] buf = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream();
Resource resource = resourceManager.getResource(template);
if(resource == null) {
throw UndertowScriptLogger.ROOT_LOGGER.templateNotFound(template);
}
try (InputStream stream = resource.getUrl().openStream()) {
if(stream == null) {
throw UndertowScriptLogger.ROOT_LOGGER.templateNotFound(template);
}
int res;
while ((res = stream.read(buf)) > 0) {
out.write(buf, 0, res);
}
return out.toString("UTF-8");
}
}
开发者ID:undertow-io,项目名称:undertow.js,代码行数:19,代码来源:Templates.java
示例5: getResourcePaths
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
@Override
public Set<String> getResourcePaths(final String path) {
final Resource resource;
try {
resource = deploymentInfo.getResourceManager().getResource(path);
} catch (IOException e) {
return null;
}
if (resource == null || !resource.isDirectory()) {
return null;
}
final Set<String> resources = new HashSet<>();
for (Resource res : resource.list()) {
File file = res.getFile();
if (file != null) {
File base = res.getResourceManagerRoot();
if (base == null) {
resources.add(file.getPath()); //not much else we can do here
} else {
String filePath = file.getAbsolutePath().substring(base.getAbsolutePath().length());
filePath = filePath.replace('\\', '/'); //for windows systems
if (file.isDirectory()) {
filePath = filePath + "/";
}
resources.add(filePath);
}
}
}
return resources;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:ServletContextImpl.java
示例6: getServletHandlerByPath
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
public ServletPathMatch getServletHandlerByPath(final String path) {
ServletPathMatch match = getData().getServletHandlerByPath(path);
if (!match.isRequiredWelcomeFileMatch()) {
return match;
}
try {
String remaining = match.getRemaining() == null ? match.getMatched() : match.getRemaining();
Resource resource = resourceManager.getResource(remaining);
if (resource == null || !resource.isDirectory()) {
return match;
}
boolean pathEndsWithSlash = remaining.endsWith("/");
final String pathWithTrailingSlash = pathEndsWithSlash ? remaining : remaining + "/";
ServletPathMatch welcomePage = findWelcomeFile(pathWithTrailingSlash, !pathEndsWithSlash);
if (welcomePage != null) {
return welcomePage;
} else {
welcomePage = findWelcomeServlet(pathWithTrailingSlash, !pathEndsWithSlash);
if (welcomePage != null) {
return welcomePage;
} else if(pathEndsWithSlash) {
return match;
} else {
return new ServletPathMatch(match.getServletChain(), match.getMatched(), match.getRemaining(), REDIRECT, "/");
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:ServletPathMatches.java
示例7: getResource
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
@Override
public Resource getResource(String path) throws IOException {
URL url = new URL("jar:file:" + this.jarPath + "!" + path);
URLResource resource = new URLResource(url, url.openConnection(), path);
if (resource.getContentLength() < 0) {
return null;
}
return resource;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:UndertowEmbeddedServletContainerFactory.java
示例8: getResource
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
@Override
public Resource getResource(String p) {
for (int i = 0, managersSize = size(); i < managersSize; i++) {
ResourceManager x = get(i);
try {
Resource y = x.getResource(p);
if (y != null)
return y;
} catch (Throwable ignored) {
//ignore
}
}
return null;
}
开发者ID:automenta,项目名称:spimedb,代码行数:15,代码来源:ChainedResourceManager.java
示例9: getResource
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
public Resource getResource(String path) {
if ( path.startsWith( "/WEB-INF" ) ) {
File reqFile = new File( WEBINF, path.replace( "/WEB-INF", "" ) );
return new FileResource( reqFile, this, path );
}
return super.getResource(path);
}
开发者ID:DominicWatson,项目名称:embedded-lucee-undertow-factory,代码行数:8,代码来源:FileResourceManagerWithWebInfMapping.java
示例10: getHandler
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
public HttpHandler getHandler(final HttpHandler next) {
return new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (hotDeployment) {
long lastHotDeploymentCheck = UndertowJS.this.lastHotDeploymentCheck;
if (System.currentTimeMillis() > lastHotDeploymentCheck + HOT_DEPLOYMENT_INTERVAL) {
synchronized (UndertowJS.this) {
if (UndertowJS.this.lastHotDeploymentCheck == lastHotDeploymentCheck) {
for (Map.Entry<Resource, Date> entry : lastModified.entrySet()) {
if (!entry.getValue().equals(entry.getKey().getLastModified())) {
UndertowScriptLogger.ROOT_LOGGER.rebuildingDueToFileChange(entry.getKey().getPath());
buildEngine();
break;
}
}
UndertowJS.this.lastHotDeploymentCheck = System.currentTimeMillis();
}
}
}
}
if(rejectPaths.contains(exchange.getRelativePath())) {
exchange.setResponseCode(StatusCodes.NOT_FOUND);
exchange.endExchange();
return;
}
exchange.putAttachment(NEXT, next);
routingHandler.handleRequest(exchange);
}
};
}
开发者ID:undertow-io,项目名称:undertow.js,代码行数:32,代码来源:UndertowJS.java
示例11: wrapWithStaticHandler
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
protected HttpHandler wrapWithStaticHandler(HttpHandler baseHandler, String path) {
// static path is given relative to application root
if (!new File(path).isAbsolute()) {
path = WunderBoss.options().get("root", "").toString() + File.separator + path;
}
if (!new File(path).exists()) {
log.debug("Not adding static handler for nonexistent directory {}", path);
return baseHandler;
}
log.debug("Adding static handler for {}", path);
final ResourceManager resourceManager =
new CachingResourceManager(1000, 1L, null,
new FileResourceManager(new File(path), 1 * 1024 * 1024), 250);
String[] welcomeFiles = new String[] { "index.html", "index.html", "default.html", "default.htm" };
final List<String> welcomeFileList = new CopyOnWriteArrayList<>(welcomeFiles);
final ResourceHandler resourceHandler = new ResourceHandler()
.setResourceManager(resourceManager)
.setWelcomeFiles(welcomeFiles)
.setDirectoryListingEnabled(false);
return new PredicateHandler(new Predicate() {
@Override
public boolean resolve(HttpServerExchange value) {
try {
Resource resource = resourceManager.getResource(value.getRelativePath());
if (resource == null) {
return false;
}
if (resource.isDirectory()) {
Resource indexResource = getIndexFiles(resourceManager, resource.getPath(), welcomeFileList);
return indexResource != null;
}
return true;
} catch (IOException ex) {
return false;
}
}
}, resourceHandler, baseHandler);
}
开发者ID:projectodd,项目名称:wunderboss,代码行数:40,代码来源:UndertowWeb.java
示例12: getIndexFiles
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
protected Resource getIndexFiles(ResourceManager resourceManager, final String base, List<String> possible) throws IOException {
String realBase;
if (base.endsWith("/")) {
realBase = base;
} else {
realBase = base + "/";
}
for (String possibility : possible) {
Resource index = resourceManager.getResource(realBase + possibility);
if (index != null) {
return index;
}
}
return null;
}
开发者ID:projectodd,项目名称:wunderboss,代码行数:16,代码来源:UndertowWeb.java
示例13: UndertowServer
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
public UndertowServer() {
host = config.getString("server.host");
port = config.getInt("server.port");
staticDir = config.getString("dirs.static");
List<String> staticFileSuffixes = config.getStrings("app.static.suffixes");
ResourceManager resourceManager = new FileResourceManager(new File(staticDir), 10) {
ClassPathResourceManager cprm = new ClassPathResourceManager(this.getClass().getClassLoader(), "");
@Override
public Resource getResource(String path) {
Resource resource = super.getResource(path);
if (isNull(resource)) {
try {
resource = cprm.getResource(path);
} catch (IOException e) {
resource = null;
}
}
return resource;
}
};
RoutesManager routesManager = ApplicationContext.instance().getRoutesManager();
HttpHandler dynamicHandlers =
monitor(errors(session(security(forms(route(routesManager, invocation(redirect(respond()))))))));
server = Undertow.builder()
.addListener(port, host)
.setHandler(
predicate(
suffixs(staticFileSuffixes.toArray(new String[0])), resource(resourceManager),
dynamicHandlers
)
)
.build();
}
开发者ID:gzlabs,项目名称:hightide,代码行数:41,代码来源:UndertowServer.java
示例14: doGet
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
String path = getPath(req);
if (!isAllowed(path, req.getDispatcherType())) {
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
if (File.separatorChar != '/') {
//if the separator char is not / we want to replace it with a / and canonicalise
path = CanonicalPathUtils.canonicalize(path.replace(File.separatorChar, '/'));
}
final Resource resource;
//we want to disallow windows characters in the path
if (File.separatorChar == '/' || !path.contains(File.separator)) {
resource = resourceManager.getResource(path);
} else {
resource = null;
}
if (resource == null) {
if (req.getDispatcherType() == DispatcherType.INCLUDE) {
//servlet 9.3
throw new FileNotFoundException(path);
} else {
resp.sendError(StatusCodes.NOT_FOUND);
}
return;
} else if (resource.isDirectory()) {
if ("css".equals(req.getQueryString())) {
resp.setContentType("text/css");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
return;
} else if ("js".equals(req.getQueryString())) {
resp.setContentType("application/javascript");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_JS);
return;
}
if (directoryListingEnabled) {
StringBuilder output = DirectoryUtils.renderDirectoryListing(req.getRequestURI(), resource);
resp.getWriter().write(output.toString());
} else {
resp.sendError(StatusCodes.FORBIDDEN);
}
} else {
if (path.endsWith("/")) {
//UNDERTOW-432
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
serveFileBlocking(req, resp, resource);
}
}
开发者ID:yangfuhai,项目名称:jboot,代码行数:53,代码来源:JbootResourceServlet.java
示例15: doGet
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
String path = getPath(req);
if (!isAllowed(path, req.getDispatcherType())) {
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
if(File.separatorChar != '/') {
//if the separator char is not / we want to replace it with a / and canonicalise
path = CanonicalPathUtils.canonicalize(path.replace(File.separatorChar, '/'));
}
final Resource resource;
//we want to disallow windows characters in the path
if(File.separatorChar == '/' || !path.contains(File.separator)) {
resource = resourceManager.getResource(path);
} else {
resource = null;
}
if (resource == null) {
if (req.getDispatcherType() == DispatcherType.INCLUDE) {
//servlet 9.3
throw new FileNotFoundException(path);
} else {
resp.sendError(StatusCodes.NOT_FOUND);
}
return;
} else if (resource.isDirectory()) {
if ("css".equals(req.getQueryString())) {
resp.setContentType("text/css");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
return;
} else if ("js".equals(req.getQueryString())) {
resp.setContentType("application/javascript");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_JS);
return;
}
if (directoryListingEnabled) {
StringBuilder output = DirectoryUtils.renderDirectoryListing(req.getRequestURI(), resource);
resp.getWriter().write(output.toString());
} else {
resp.sendError(StatusCodes.FORBIDDEN);
}
} else {
if(path.endsWith("/")) {
//UNDERTOW-432
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
serveFileBlocking(req, resp, resource);
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:53,代码来源:DefaultServlet.java
示例16: ContentEncodedResource
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
public ContentEncodedResource(Resource resource, String contentEncoding) {
this.resource = resource;
this.contentEncoding = contentEncoding;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:ContentEncodedResource.java
示例17: getResource
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
public Resource getResource() {
return resource;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:ContentEncodedResource.java
示例18: getResource
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
/**
* Gets a pre-encoded resource.
* <p/>
* TODO: blocking / non-blocking semantics
*
* @param resource
* @param exchange
* @return
* @throws IOException
*/
public ContentEncodedResource getResource(final Resource resource, final HttpServerExchange exchange) throws IOException {
final String path = resource.getPath();
File file = resource.getFile();
if (file == null) {
return null;
}
if (minResourceSize > 0 && resource.getContentLength() < minResourceSize ||
maxResourceSize > 0 && resource.getContentLength() > maxResourceSize ||
!(encodingAllowed == null || encodingAllowed.resolve(exchange))) {
return null;
}
AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange);
if (encodings == null || encodings.isNoEncodingsAllowed()) {
return null;
}
EncodingMapping encoding = encodings.getEncoding();
if (encoding == null || encoding.getName().equals(ContentEncodingRepository.IDENTITY)) {
return null;
}
String newPath = path + ".undertow.encoding." + encoding.getName();
Resource preCompressed = encoded.getResource(newPath);
if (preCompressed != null) {
return new ContentEncodedResource(preCompressed, encoding.getName());
}
final LockKey key = new LockKey(path, encoding.getName());
if (fileLocks.putIfAbsent(key, this) != null) {
//another thread is already compressing
//we don't do anything fancy here, just return and serve non-compressed content
return null;
}
FileChannel targetFileChannel = null;
FileChannel sourceFileChannel = null;
try {
//double check, the compressing thread could have finished just before we acquired the lock
preCompressed = encoded.getResource(newPath);
if (preCompressed != null) {
return new ContentEncodedResource(preCompressed, encoding.getName());
}
final File finalTarget = new File(encodedResourcesRoot, newPath);
final File tempTarget = new File(encodedResourcesRoot, newPath);
//horrible hack to work around XNIO issue
FileOutputStream tmp = new FileOutputStream(tempTarget);
try {
tmp.close();
} finally {
IoUtils.safeClose(tmp);
}
targetFileChannel = exchange.getConnection().getWorker().getXnio().openFile(tempTarget, FileAccess.READ_WRITE);
sourceFileChannel = exchange.getConnection().getWorker().getXnio().openFile(file, FileAccess.READ_ONLY);
StreamSinkConduit conduit = encoding.getEncoding().getResponseWrapper().wrap(new ImmediateConduitFactory<StreamSinkConduit>(new FileConduitTarget(targetFileChannel, exchange)), exchange);
final ConduitStreamSinkChannel targetChannel = new ConduitStreamSinkChannel(null, conduit);
long transferred = sourceFileChannel.transferTo(0, resource.getContentLength(), targetChannel);
targetChannel.shutdownWrites();
org.xnio.channels.Channels.flushBlocking(targetChannel);
if (transferred != resource.getContentLength()) {
UndertowLogger.REQUEST_LOGGER.error("Failed to write pre-cached file");
}
tempTarget.renameTo(finalTarget);
encoded.invalidate(newPath);
final Resource encodedResource = encoded.getResource(newPath);
return new ContentEncodedResource(encodedResource, encoding.getName());
} finally {
IoUtils.safeClose(targetFileChannel);
IoUtils.safeClose(sourceFileChannel);
fileLocks.remove(key);
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:82,代码来源:ContentEncodedResourceManager.java
示例19: buildEngine
import io.undertow.server.handlers.resource.Resource; //导入依赖的package包/类
private synchronized void buildEngine() throws ScriptException, IOException {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
RoutingHandler routingHandler = new RoutingHandler(true);
routingHandler.setFallbackHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
exchange.getAttachment(NEXT).handleRequest(exchange);
}
});
RoutingHandler wsRoutingHandler = new RoutingHandler(false);
wsRoutingHandler.setFallbackHandler(routingHandler);
for (TemplateProvider templateProvider : templateProviders.values()) {
// TODO properties should be configurable
templateProvider.init(Collections.emptyMap(), resourceManager);
}
UndertowSupport support = new UndertowSupport(routingHandler, classLoader, injectionProviders, javabeanIntrospector, handlerWrappers, resourceManager, wsRoutingHandler, templateProviders);
engine.put("$undertow_support", support);
engine.put(ScriptEngine.FILENAME, "undertow-core-scripts.js");
engine.eval(FileUtils.readFile(UndertowJS.class, "undertow-core-scripts.js"));
Map<Resource, Date> lm = new HashMap<>();
final Set<String> rejectPaths = new HashSet<>();
for (ResourceSet set : resources) {
for (String resource : set.getResources()) {
if(resource.startsWith("/")) {
rejectPaths.add(resource);
} else {
rejectPaths.add("/" + resource);
}
Resource res = set.getResourceManager().getResource(resource);
if (res == null) {
UndertowScriptLogger.ROOT_LOGGER.couldNotReadResource(resource);
} else {
try (InputStream stream = res.getUrl().openStream()) {
engine.put(ScriptEngine.FILENAME, res.getUrl().toString());
engine.eval(new InputStreamReader(new BufferedInputStream(stream)));
}
if (hotDeployment) {
lm.put(res, res.getLastModified());
}
}
}
}
this.engine = engine;
this.routingHandler = wsRoutingHandler;
this.lastModified = lm;
this.rejectPaths = Collections.unmodifiableSet(rejectPaths);
}
开发者ID:undertow-io,项目名称:undertow.js,代码行数:52,代码来源:UndertowJS.java
注:本文中的io.undertow.server.handlers.resource.Resource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论