Ejemplo n.º 1
0
 public void onRequestHeader(HeaderParser requestHeader) {
   /* portal機能の場合path情報にportal機能用の情報が着いている場合がある。
    * この情報は削除してproxy対象サーバにリクエスト
    */
   MappingResult mapping = proxyHandler.getRequestMapping();
   String path = mapping.getResolvePath();
   Matcher matcher = null;
   synchronized (portalPathInfoPattern) {
     matcher = portalPathInfoPattern.matcher(path);
   }
   StringBuffer sb = null;
   String portalPathInfo = null;
   if (matcher.find()) {
     sb = new StringBuffer();
     matcher.appendReplacement(sb, "");
     portalPathInfo = matcher.group(1);
     matcher.appendTail(sb);
     path = sb.toString();
     mapping.setResolvePath(path);
     requestHeader.setRequestUri(mapping.getResolvePath());
     proxyHandler.setRequestAttribute(PORTAL_PATHINFO_KEY, portalPathInfo);
   }
   /*
    * proxyでAuthrizationヘッダを付加する作戦の場合
   String basicAuthHeader = getBasicAuthHeader(mapping.isResolvedHttps(),mapping.getResolveServer());
   if (basicAuthHeader != null) {
   	requestHeader.addHeader(HeaderParser.WWW_AUTHRIZATION_HEADER, basicAuthHeader);
   	proxyHandler.setRequestAttribute(HeaderParser.WWW_AUTHRIZATION_HEADER, basicAuthHeader);
   }
    */
 }
Ejemplo n.º 2
0
  // 存在確認済みのファイルをレスポンスする。
  private boolean sendFile(
      MappingResult mapping,
      File baseDirectory,
      String path,
      String ifModifiedSince,
      CacheBuffer asyncFile) {
    if (isVelocityUse(mapping, path)) {
      // TODO ちゃんとする
      mapping.setResolvePath(path); // 加工後のpathを設定
      mapping.setDesitinationFile(baseDirectory);
      forwardHandler(Mapping.VELOCITY_PAGE_HANDLER);
      asyncFile.close();
      return false; // 委譲
    }

    // String
    // ifModifiedSince=requestParser.getHeader(HeaderParser.IF_MODIFIED_SINCE_HEADER);
    Date ifModifiedSinceDate = HeaderParser.parseDateHeader(ifModifiedSince);
    long ifModifiedSinceTime = -1;
    if (ifModifiedSinceDate != null) {
      ifModifiedSinceTime = ifModifiedSinceDate.getTime();
    }
    FileInfo fileInfo = asyncFile.getFileInfo();
    long lastModifiedTime = fileInfo.getLastModified();
    String lastModified = HeaderParser.fomatDateHeader(new Date(lastModifiedTime));
    // ファイル日付として表現できる値には、誤差があるため、表現できる時刻を取得
    lastModifiedTime = HeaderParser.parseDateHeader(lastModified).getTime();
    if (ifModifiedSinceTime >= lastModifiedTime) {
      completeResponse("304");
      asyncFile.close();
      return true;
    }
    setHeader(HeaderParser.LAST_MODIFIED_HEADER, lastModified);
    long contentLength = getContentLength(fileInfo.length());
    setContentLength(contentLength);
    String contentDisposition =
        (String) getRequestAttribute(ATTRIBUTE_RESPONSE_CONTENT_DISPOSITION);
    if (contentDisposition != null) {
      setHeader(HeaderParser.CONTENT_DISPOSITION_HEADER, contentDisposition);
    }
    String contentType = getContentType(fileInfo.getCanonicalFile());
    setContentType(contentType);
    setStatusCode("200");
    responseBodyFromFile(asyncFile);
    return false;
  }