/**
   * Perform the tag functionality. In this case, set a header in the http response found in the
   * jelly context
   *
   * @param xmlOutput where to send output
   * @throws Exception when an error occurs
   */
  public void doTag(XMLOutput xmlOutput) throws JellyTagException {

    if (null == getName()) {
      throw new JellyTagException("<responseHeader> tag must have a name");
    }

    // get the response from the context
    HttpResponse httpResponse = (HttpResponse) getContext().getVariable("response");
    if (null == httpResponse) {
      throw new JellyTagException("HttpResponse variable not available in Jelly context");
    }

    // if value is valid then set it
    // otherwise remove the field
    if (null != getValue()) {
      httpResponse.setField(getName(), getValue());
    } else {
      httpResponse.removeField(getName());
    }
  }
  protected void handleDelete(
      final HttpRequest request, final HttpResponse response, final NewObjectIdentifier oid)
      throws ArchiveException, IOException {

    long t1 = System.currentTimeMillis();

    Coordinator.getInstance().delete(oid, true, false);

    t1 = System.currentTimeMillis() - t1;
    deleteStats.add(t1);
    if (LOGGER.isLoggable(Level.INFO)) {
      LOGGER.info("MEAS delete __ time " + t1);
    }
    HttpOutputStream out = (HttpOutputStream) response.getOutputStream();
    writeMulticellConfig(out);
  }
Exemple #3
0
 public void setCharacterEncoding(String charset) {
   response.setCharacterEncoding(charset, true);
 }
Exemple #4
0
 public OutputStream getOutputStream() {
   return response.getOutputStream();
 }
Exemple #5
0
 public void addField(String header, String value) {
   response.addField(header, value);
 }
Exemple #6
0
 public void removeField(String name) {
   response.removeField(name);
 }
Exemple #7
0
 public void setReason(String reason) {
   response.setReason(reason);
 }
Exemple #8
0
 public void setContentLength(int length) {
   response.setContentLength(length);
 }
Exemple #9
0
 public void setStatus(int status) {
   response.setStatus(status);
 }
Exemple #10
0
 public void sendError(int code, String message) throws IOException {
   response.sendError(code, message);
 }
Exemple #11
0
 public void addCookie(Cookie cookie) {
   response.addSetCookie(cookie);
 }
Exemple #12
0
 public void sendRedirect(String url) throws IOException {
   response.sendRedirect(url);
 }
Exemple #13
0
 public void setField(String header, String value) {
   response.setField(header, value);
 }
Exemple #14
0
  public void handle(
      String requestPath, String pathParams, HttpRequest request, HttpResponse response)
      throws IOException {
    String threadID = Thread.currentThread().toString();

    HCFile file = null;
    long startTime = System.currentTimeMillis();

    if (logger.isLoggable(Level.INFO)) {
      String sAddr = request.getHttpConnection().getRemoteHost();
      int sPort = getClientPort(request);
      logger.info("StartRequest " + sAddr + ":" + sPort + " " + toString(request) + " " + threadID);
    }

    String sMethod = null;
    int method = 0;
    try {
      sMethod = request.getMethod();
      Integer m = (Integer) methods.get(sMethod);
      method = m.intValue();
    } catch (Exception e) {
      logger.info("Bad method \"" + sMethod + "\": 501 Not implemented");
      response.sendError(HttpResponse.__501_Not_Implemented, sMethod);
      request.setHandled(true);
      return;
    }

    if (!pathSanityCheck(requestPath)) {
      response.sendError(HttpResponse.__404_Not_Found, requestPath + ":  no such file");
      request.setHandled(true);
      return;
    }

    // Remove the root path from the front of the path leaving a
    // relative path

    HCFile root = HCFile.getRoot();
    String rootPath = root.fileName();
    if (rootPath.equals("/")) rootPath = "";
    if (!requestPath.startsWith(rootPath + "/")) {
      response.sendError(HttpResponse.__404_Not_Found, "Unknown prefix in \"" + requestPath + "\"");
      request.setHandled(true);
      return;
    }

    String encodedPath = request.getEncodedPath();
    String prefix = ProtocolConstants.WEBDAV_PATH + rootPath + "/";
    if (!encodedPath.startsWith(prefix)) {
      response.sendError(
          HttpResponse.__500_Internal_Server_Error, "Inconsistent path \"" + encodedPath + "\"");
      request.setHandled(true);
      return;
    }
    String relativePath = encodedPath.substring(prefix.length());

    // Split path into components

    String[] path = FSCache.split(relativePath);
    if (logger.isLoggable(Level.FINE))
      logger.fine(
          "Instr parsed \""
              + FSCache.combine(path)
              + "\" @ "
              + (System.currentTimeMillis() - startTime)
              + " ms)");

    // Load into cache

    try {
      boolean writing = (method == M_PUT || method == M_MOVE || method == M_MKCOL);

      file = CacheLoader.load(path, writing);

      if (logger.isLoggable(Level.FINE)) {
        long d = System.currentTimeMillis() - startTime;
        String f = file.fileName();
        logger.fine("instr " + d + " LOOKUP \"" + f + "\" " + threadID);
        logger.fine(
            "View "
                + file.getViewName()
                + " is "
                + (file.isViewCollapsingNulls() ? "" : "not ")
                + "collapsing trailing nulls");
      }

      String[] extras = null;
      if (file.fileType() == FSCacheObject.ROOTFILETYPE) extras = path;
      else {
        // The distance of the node from the root == the number
        // of components in the full path since "/" has 0 path
        // components.

        int numExtraComps = path.length - file.rootDistance();
        if (numExtraComps > 0) {
          extras = new String[numExtraComps];
          for (int i = file.rootDistance(), j = 0; j < extras.length; i++, j++) extras[j] = path[i];
        }
      }

      if (file.isFile())
        switch (method) {
          case M_GET:
          case M_HEAD:
          case M_OPTIONS:
          case M_PROPFIND:
            response.setField("ETag", file.getOID().toExternalHexString());
        }

      response.setStatus(HttpResponse.__200_OK);

      if (logger.isLoggable(Level.FINE)) {
        String s = "Instr handling " + file + " {";
        if (extras != null) for (int i = 0; i < extras.length; i++) s += " \"" + extras[i] + "\"";
        logger.fine(s + " } @ " + (System.currentTimeMillis() - startTime) + " ms");
      }

      handlers[method].handle(
          file, extras, request, response, request.getInputStream(), response.getOutputStream());
    } catch (FSCacheException e) {
      if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "FSCacheException: " + e, e);
      response.sendError(e.getError(), e.getMessage());
    } catch (HttpException e) {
      if (logger.isLoggable(Level.FINE)) logger.log(Level.FINE, "HTTP exception: " + e, e);
      response.sendError(e.getCode(), e.toString());
    } catch (Exception e) {
      String s = "Couldn't handle " + toString(request);
      logger.log(Level.SEVERE, s + "; " + StringUtil.image(file), e);
      response.sendError(HttpResponse.__500_Internal_Server_Error, s + ": " + StringUtil.image(e));
    }

    long reqTime = System.currentTimeMillis() - startTime;
    if (reqTime > MAX_REQ_TIME) logger.warning("LATE! " + reqTime + "ms " + toString(request));
    if (logger.isLoggable(Level.INFO))
      logger.info(
          "INSTR "
              + reqTime
              + " SUM "
              + response.getStatus()
              + " "
              + toString(request)
              + " "
              + threadID);

    if (logger.isLoggable(Level.FINEST)) logger.finest(HCFile.fileCache.toString());

    request.setHandled(true);
  }