@Override
  public String processForm(Map<String, String> parameters, Map<String, FileItem> files)
      throws BadRequestException, NotAuthorizedException, ConflictException {
    log.trace("process");
    try {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      Request request = HttpManager.request();
      IOUtils.copy(request.getInputStream(), bout);
      String iCalText = bout.toString("UTF-8");
      if (log.isTraceEnabled()) {
        log.trace("Freebusy query: " + iCalText);
      }
      List<SchedulingResponseItem> respItems = queryFreeBusy(iCalText);

      String xml = schedulingHelper.generateXml(respItems);
      xmlResponse = xml.getBytes(StringUtils.UTF8);
      if (log.isTraceEnabled()) {
        log.trace("FreeBusy response= " + xml);
      }

    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
    return null;
  }
Example #2
0
 @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();
     // Prevent possibily of malicious clients using remote the parser to load remote resources
     builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
     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.info("process report: " + reportName + " with : " + r.getClass());
       String xml = r.process(request.getHostHeader(), request.getAbsolutePath(), resource, doc);
       if (log.isTraceEnabled()) {
         log.trace("Report XML:\n" + xml);
       }
       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);
   }
 }