Search in sources :

Example 1 with WritingException

use of io.milton.common.WritingException 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);
    }
}
Also used : ReadingException(io.milton.common.ReadingException) ArrayList(java.util.ArrayList) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException) IOException(java.io.IOException) WritingException(io.milton.common.WritingException) PropPatchEvent(io.milton.event.PropPatchEvent)

Example 2 with WritingException

use of io.milton.common.WritingException 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);
    }
}
Also used : IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) ReadingException(io.milton.common.ReadingException) ByteArrayEntity(io.milton.http.entity.ByteArrayEntity) BadRequestException(io.milton.http.exceptions.BadRequestException) WritingException(io.milton.common.WritingException)

Example 3 with WritingException

use of io.milton.common.WritingException 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);
    }
}
Also used : ReadingException(io.milton.common.ReadingException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) IOException(java.io.IOException) WritingException(io.milton.common.WritingException) SAXException(org.xml.sax.SAXException)

Example 4 with WritingException

use of io.milton.common.WritingException 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);
    }
}
Also used : ReadingException(io.milton.common.ReadingException) NotFoundException(io.milton.http.exceptions.NotFoundException) WritingException(io.milton.common.WritingException)

Example 5 with WritingException

use of io.milton.common.WritingException 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);
    }
}
Also used : ReadingException(io.milton.common.ReadingException) InputStream(java.io.InputStream) BufferingOutputStream(io.milton.common.BufferingOutputStream) IOException(java.io.IOException) WritingException(io.milton.common.WritingException)

Aggregations

ReadingException (io.milton.common.ReadingException)5 WritingException (io.milton.common.WritingException)5 IOException (java.io.IOException)4 BufferingOutputStream (io.milton.common.BufferingOutputStream)1 PropPatchEvent (io.milton.event.PropPatchEvent)1 ByteArrayEntity (io.milton.http.entity.ByteArrayEntity)1 BadRequestException (io.milton.http.exceptions.BadRequestException)1 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)1 NotFoundException (io.milton.http.exceptions.NotFoundException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 JDOMException (org.jdom.JDOMException)1 SAXException (org.xml.sax.SAXException)1