use of org.apache.catalina.WebResource in project tomcat by apache.
the class DefaultServlet method doPut.
/**
* Process a PUT request for the specified resource.
*
* @param req The servlet request we are processing
* @param resp The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet-specified error occurs
*/
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (readOnly) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
String path = getRelativePath(req);
WebResource resource = resources.getResource(path);
Range range = parseContentRange(req, resp);
InputStream resourceInputStream = null;
try {
// Assume just one range is specified for now
if (range != null) {
File contentFile = executePartialPut(req, range, path);
resourceInputStream = new FileInputStream(contentFile);
} else {
resourceInputStream = req.getInputStream();
}
if (resources.write(path, resourceInputStream, true)) {
if (resource.exists()) {
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
} else {
resp.setStatus(HttpServletResponse.SC_CREATED);
}
} else {
resp.sendError(HttpServletResponse.SC_CONFLICT);
}
} finally {
if (resourceInputStream != null) {
try {
resourceInputStream.close();
} catch (IOException ioe) {
// Ignore
}
}
}
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class WebdavStatus method parseProperties.
/**
* Propfind helper method.
*
* @param req The servlet request
* @param resources Resources object associated with this context
* @param generatedXML XML response to the Propfind request
* @param path Path of the current resource
* @param type Propfind type
* @param propertiesVector If the propfind type is find properties by
* name, then this Vector contains those properties
*/
private void parseProperties(HttpServletRequest req, XMLWriter generatedXML, String path, int type, Vector<String> propertiesVector) {
// Exclude any resource in the /WEB-INF and /META-INF subdirectories
if (isSpecialPath(path))
return;
WebResource resource = resources.getResource(path);
if (!resource.exists()) {
// Broken symlink or odd permission settings?
return;
}
String href = req.getContextPath() + req.getServletPath();
if ((href.endsWith("/")) && (path.startsWith("/")))
href += path.substring(1);
else
href += path;
if (resource.isDirectory() && (!href.endsWith("/")))
href += "/";
String rewrittenUrl = rewriteUrl(href);
generatePropFindResponse(generatedXML, rewrittenUrl, path, type, propertiesVector, resource.isFile(), false, resource.getCreation(), resource.getLastModified(), resource.getContentLength(), getServletContext().getMimeType(resource.getName()), resource.getETag());
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testGetResourceCaseSensitive.
@Test
public final void testGetResourceCaseSensitive() {
WebResource webResource = resourceRoot.getResource(getMount() + "/d1/d1-F1.txt");
Assert.assertFalse(webResource.exists());
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testWriteDirA.
@Test
public final void testWriteDirA() {
WebResource d1 = resourceRoot.getResource(getMount() + "/d1");
InputStream is = new ByteArrayInputStream("test".getBytes());
if (d1.exists()) {
Assert.assertFalse(resourceRoot.write(getMount() + "/d1", is, false));
} else if (d1.isVirtual()) {
Assert.assertTrue(resourceRoot.write(getMount() + "/d1", is, false));
File file = new File(getBaseDir(), "d1");
Assert.assertTrue(file.exists());
Assert.assertTrue(file.delete());
} else {
Assert.fail("Unhandled condition in unit test");
}
}
use of org.apache.catalina.WebResource in project tomcat by apache.
the class AbstractTestResourceSet method testGetResourceDirA.
@Test
public final void testGetResourceDirA() {
WebResource webResource = resourceRoot.getResource(getMount() + "/d1");
Assert.assertTrue(webResource.isDirectory());
Assert.assertEquals("d1", webResource.getName());
Assert.assertEquals(getMount() + "/d1/", webResource.getWebappPath());
Assert.assertEquals(-1, webResource.getContentLength());
Assert.assertNull(webResource.getContent());
Assert.assertNull(webResource.getInputStream());
}
Aggregations