Beispiel #1
0
  @Override
  public String toString() {
    if (logStr == null) {
      content = StringUtils.replace(content, objs);
      if (throwable != null) {
        StringWriter str = new StringWriter();
        PrintWriter out = new PrintWriter(str);
        try {
          out.println();
          out.println("$err_start");
          throwable.printStackTrace(out);
          out.println("$err_end");
        } finally {
          out.close();
        }
        content += str.toString();
      }

      if (stackTraceElement != null) {
        logStr = level + " " + date + " " + stackTraceElement + "\t" + content;
      } else {
        logStr = level + " " + date + "\t" + content;
      }
    }
    return logStr;
  }
 @Override
 public Cookie[] getCookies() {
   if (cookies == null) {
     List<Cookie> list = new ArrayList<Cookie>();
     String cookieStr = getHeader("Cookie");
     if (VerifyUtils.isEmpty(cookieStr)) {
       cookies = EMPTY_COOKIE_ARR;
     } else {
       String[] c = StringUtils.split(cookieStr, ';');
       for (String t : c) {
         int j = 0;
         for (int i = 0; i < t.length(); i++) {
           if (t.charAt(i) == '=') {
             j = i;
             break;
           }
         }
         if (j > 1) {
           String name = t.substring(0, j).trim();
           String value = t.substring(j + 1).trim();
           Cookie cookie = new Cookie(name, value);
           list.add(cookie);
         } else continue;
       }
       cookies = list.toArray(EMPTY_COOKIE_ARR);
     }
   }
   return cookies;
 }
Beispiel #3
0
 public static String systemPageTemplate(int status, String content) {
   StringBuilder ret = new StringBuilder();
   try {
     ret.append("<!DOCTYPE html><html><head><title>firefly</title></head><body><h2>HTTP ERROR ")
         .append(status)
         .append("</h2><div>")
         .append(StringUtils.escapeXML(URLDecoder.decode(content, "UTF-8")))
         .append("</div><hr/><i><small>firefly framework</small></i></body></html>");
   } catch (UnsupportedEncodingException e) {
     log.error("url decode error", e);
   }
   return ret.toString();
 }
  @Override
  public Enumeration<String> getHeaders(String name) {
    String value = getHeader(name);
    final String[] values = StringUtils.split(value, ',');
    return new Enumeration<String>() {
      private int i = 0;

      @Override
      public boolean hasMoreElements() {
        return i < values.length;
      }

      @Override
      public String nextElement() {
        return values[i++];
      }
    };
  }
  private void loadParam(String str) throws UnsupportedEncodingException {
    if (VerifyUtils.isNotEmpty(str)) {
      String[] p = StringUtils.split(str, '&');
      for (String kv : p) {
        int i = kv.indexOf('=');
        if (i > 0) {
          String name = kv.substring(0, i);
          String value = kv.substring(i + 1);

          List<String> list = parameterMap.get(name);
          if (list == null) {
            list = new ArrayList<String>();
            parameterMap.put(name, list);
          }
          list.add(URLDecoder.decode(value, characterEncoding));
        }
      }
    }
  }