use of jakarta.servlet.ServletContext in project tomcat by apache.
the class FileStore method directory.
// -------------------------------------------------------- Private Methods
/**
* Return a File object representing the pathname to our
* session persistence directory, if any. The directory will be
* created if it does not already exist.
*/
private File directory() throws IOException {
if (this.directory == null) {
return null;
}
if (this.directoryFile != null) {
// NOTE: Race condition is harmless, so do not synchronize
return this.directoryFile;
}
File file = new File(this.directory);
if (!file.isAbsolute()) {
Context context = manager.getContext();
ServletContext servletContext = context.getServletContext();
File work = (File) servletContext.getAttribute(ServletContext.TEMPDIR);
file = new File(work, this.directory);
}
if (!file.exists() || !file.isDirectory()) {
if (!file.delete() && file.exists()) {
throw new IOException(sm.getString("fileStore.deleteFailed", file));
}
if (!file.mkdirs() && !file.isDirectory()) {
throw new IOException(sm.getString("fileStore.createFailed", file));
}
}
this.directoryFile = file;
return file;
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class SSIServletExternalResolver method getServletContextAndPathFromVirtualPath.
protected ServletContextAndPath getServletContextAndPathFromVirtualPath(String virtualPath) throws IOException {
if (!virtualPath.startsWith("/") && !virtualPath.startsWith("\\")) {
return new ServletContextAndPath(context, getAbsolutePath(virtualPath));
}
String normalized = RequestUtil.normalize(virtualPath);
if (isVirtualWebappRelative) {
return new ServletContextAndPath(context, normalized);
}
ServletContext normContext = context.getContext(normalized);
if (normContext == null) {
throw new IOException(sm.getString("ssiServletExternalResolver.noContext", normalized));
}
// '/file1.shtml' vs '/appName1/file1.shtml'
if (!isRootContext(normContext)) {
String noContext = getPathWithoutContext(normContext.getContextPath(), normalized);
return new ServletContextAndPath(normContext, noContext);
}
return new ServletContextAndPath(normContext, normalized);
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class SSIServletExternalResolver method getURLConnection.
protected URLConnection getURLConnection(String originalPath, boolean virtual) throws IOException {
ServletContextAndPath csAndP = getServletContextAndPath(originalPath, virtual);
ServletContext context = csAndP.getServletContext();
String path = csAndP.getPath();
URL url = context.getResource(path);
if (url == null) {
throw new IOException(sm.getString("ssiServletExternalResolver.noResource", path));
}
URLConnection urlConnection = url.openConnection();
return urlConnection;
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class WebappLoader method setPermissions.
/**
* Configure associated class loader permissions.
*/
private void setPermissions() {
if (!Globals.IS_SECURITY_ENABLED) {
return;
}
if (context == null) {
return;
}
// Tell the class loader the root of the context
ServletContext servletContext = context.getServletContext();
// Assigning permissions for the work directory
File workDir = (File) servletContext.getAttribute(ServletContext.TEMPDIR);
if (workDir != null) {
try {
String workDirPath = workDir.getCanonicalPath();
classLoader.addPermission(new FilePermission(workDirPath, "read,write"));
classLoader.addPermission(new FilePermission(workDirPath + File.separator + "-", "read,write,delete"));
} catch (IOException e) {
// Ignore
}
}
for (URL url : context.getResources().getBaseUrls()) {
classLoader.addPermission(url);
}
}
use of jakarta.servlet.ServletContext in project tomcat by apache.
the class WebappLoader method setClassPath.
/**
* Set the appropriate context attribute for our class path. This
* is required only because Jasper depends on it.
*/
private void setClassPath() {
// Validate our current state information
if (context == null) {
return;
}
ServletContext servletContext = context.getServletContext();
if (servletContext == null) {
return;
}
StringBuilder classpath = new StringBuilder();
// Assemble the class path information from our class loader chain
ClassLoader loader = getClassLoader();
if (delegate && loader != null) {
// Skip the webapp loader for now as delegation is enabled
loader = loader.getParent();
}
while (loader != null) {
if (!buildClassPath(classpath, loader)) {
break;
}
loader = loader.getParent();
}
if (delegate) {
// Delegation was enabled, go back and add the webapp paths
loader = getClassLoader();
if (loader != null) {
buildClassPath(classpath, loader);
}
}
this.classpath = classpath.toString();
// Store the assembled class path as a servlet context attribute
servletContext.setAttribute(Globals.CLASS_PATH_ATTR, this.classpath);
}
Aggregations