use of io.milton.common.ReadingException in project lobcder by skoulouzis.
the class PropPatchHandler method processExistingResource.
@Override
public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
// todo: check if token header
try {
PropFindResponse resp = doPropPatch(request, resource);
manager.getEventManager().fireEvent(new PropPatchEvent(resource, resp));
List<PropFindResponse> responses = new ArrayList<PropFindResponse>();
responses.add(resp);
responseHandler.respondPropFind(responses, response, request, resource);
} catch (NotAuthorizedException e) {
responseHandler.respondUnauthorised(resource, response, request);
} catch (WritingException ex) {
throw new RuntimeException(ex);
} catch (ReadingException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of io.milton.common.ReadingException in project lobcder by skoulouzis.
the class ReportHandler method processExistingResource.
@Override
public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
try {
org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder();
org.jdom.Document doc = builder.build(request.getInputStream());
String reportName = doc.getRootElement().getName();
Report r = reports.get(reportName);
if (r == null) {
log.error("report not known: " + reportName);
throw new BadRequestException(resource);
} else {
log.trace("process report: " + reportName + " with : " + r.getClass());
String xml = r.process(request.getHostHeader(), request.getAbsolutePath(), resource, doc);
response.setStatus(Response.Status.SC_MULTI_STATUS);
response.setContentTypeHeader("text/xml");
response.setEntity(new ByteArrayEntity(xml.getBytes("UTF-8")));
}
} catch (JDOMException ex) {
java.util.logging.Logger.getLogger(ReportHandler.class.getName()).log(Level.SEVERE, null, ex);
} catch (ReadingException ex) {
throw new RuntimeException(ex);
} catch (WritingException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of io.milton.common.ReadingException in project lobcder by skoulouzis.
the class DefaultPropPatchParser method getRequestedFields.
@Override
public ParseResult getRequestedFields(InputStream in) {
log.debug("getRequestedFields");
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
StreamUtils.readTo(in, bout, false, true);
byte[] arr = bout.toByteArray();
return parseContent(arr);
} catch (SAXException ex) {
throw new RuntimeException(ex);
} catch (ReadingException ex) {
throw new RuntimeException(ex);
} catch (WritingException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of io.milton.common.ReadingException in project lobcder by skoulouzis.
the class FsFileResource method sendContent.
@Override
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotFoundException {
InputStream in = null;
try {
in = contentService.getFileContent(file);
if (range != null) {
log.debug("sendContent: ranged content: " + file.getAbsolutePath());
RangeUtils.writeRange(in, range, out);
} else {
log.debug("sendContent: send whole file " + file.getAbsolutePath());
IOUtils.copy(in, out);
}
out.flush();
} catch (FileNotFoundException e) {
throw new NotFoundException("Couldnt locate content");
} catch (ReadingException e) {
throw new IOException(e);
} catch (WritingException e) {
throw new IOException(e);
} finally {
IOUtils.closeQuietly(in);
}
}
use of io.milton.common.ReadingException in project lobcder by skoulouzis.
the class BufferingGetableResourceEntity method write.
@Override
public void write(Response response, OutputStream outputStream) throws Exception {
log.trace("buffering content...");
BufferingOutputStream tempOut = new BufferingOutputStream(maxMemorySize);
try {
getResource().sendContent(tempOut, getRange(), getParams(), getContentType());
tempOut.close();
} catch (IOException ex) {
tempOut.deleteTempFileIfExists();
throw new RuntimeException("Exception generating buffered content", ex);
}
Long bufContentLength = tempOut.getSize();
if (contentLength != null) {
if (!contentLength.equals(bufContentLength)) {
throw new RuntimeException("Content Length specified by resource: " + contentLength + " is not equal to the size of content when generated: " + bufContentLength + " This error can be suppressed by setting the buffering property to whenNeeded or never");
}
}
response.setContentLengthHeader(bufContentLength);
if (log.isTraceEnabled()) {
log.trace("sending buffered content... " + tempOut.getSize() + " bytes contentLength=" + contentLength);
}
InputStream in = tempOut.getInputStream();
try {
// StreamUtils.readTo(in, outputStream);
IOUtils.copy(in, outputStream);
} catch (ReadingException ex) {
throw new RuntimeException(ex);
} catch (WritingException ex) {
log.warn("exception writing, client probably closed connection", ex);
} finally {
// make sure we close to delete temporary file
IOUtils.closeQuietly(in);
}
}
Aggregations