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()));
}
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);
}
}
Aggregations