Search in sources :

Example 1 with ByteArrayEntity

use of io.milton.http.entity.ByteArrayEntity in project lobcder by skoulouzis.

the class LockHandler method respondWithToken.

private void respondWithToken(LockToken tok, Request request, Response response) {
    response.setStatus(Status.SC_OK);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XmlWriter writer = new XmlWriter(out);
    writer.writeXMLHeader();
    String d = WebDavProtocol.DAV_PREFIX;
    writer.open(d + ":prop  xmlns:" + d + "=\"DAV:\"");
    writer.newLine();
    writer.open(d + ":lockdiscovery");
    writer.newLine();
    writer.open(d + ":activelock");
    writer.newLine();
    lockWriterHelper.appendType(writer, tok.info.type);
    lockWriterHelper.appendScope(writer, tok.info.scope);
    lockWriterHelper.appendDepth(writer, tok.info.depth);
    lockWriterHelper.appendOwner(writer, tok.info.lockedByUser);
    lockWriterHelper.appendTimeout(writer, tok.timeout.getSeconds());
    lockWriterHelper.appendTokenId(writer, tok.tokenId);
    String url = request.getAbsoluteUrl().replace("&", "%26");
    lockWriterHelper.appendRoot(writer, url);
    writer.close(d + ":activelock");
    writer.close(d + ":lockdiscovery");
    writer.close(d + ":prop");
    writer.flush();
    response.setEntity(new ByteArrayEntity(out.toByteArray()));
}
Also used : ByteArrayEntity(io.milton.http.entity.ByteArrayEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XmlWriter(io.milton.http.XmlWriter)

Example 2 with ByteArrayEntity

use of io.milton.http.entity.ByteArrayEntity 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)

Aggregations

ByteArrayEntity (io.milton.http.entity.ByteArrayEntity)2 ReadingException (io.milton.common.ReadingException)1 WritingException (io.milton.common.WritingException)1 XmlWriter (io.milton.http.XmlWriter)1 BadRequestException (io.milton.http.exceptions.BadRequestException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 JDOMException (org.jdom.JDOMException)1