コード例 #1
0
  private void processResponse(RubyValue res) {
    if (res != null && res != RubyConstant.QNIL && res instanceof RubyHash) {
      RubyHash resHash = (RubyHash) res;
      RubyValue resBody = null;

      RubyArray arKeys = resHash.keys();
      RubyArray arValues = resHash.values();
      for (int i = 0; i < arKeys.size(); i++) {
        String strKey = arKeys.get(i).toString();
        if (strKey.equals("request-body")) resBody = arValues.get(i);
        else if (strKey.equals("status")) responseCode = arValues.get(i).toInt();
        else if (strKey.equals("message")) responseMsg = arValues.get(i).toString();
        else resHeaders.addProperty(strKey, arValues.get(i).toString());
      }
      String strBody = "";

      if (resBody != null && resBody != RubyConstant.QNIL)
        strBody = resBody.toRubyString().toString();

      if (!RHOCONF().getBool("log_skip_post")) LOG.TRACE(strBody);

      try {
        responseData = new ByteArrayInputStream(strBody.getBytes("UTF-8"));
      } catch (java.io.UnsupportedEncodingException exc) {
        LOG.ERROR("Error getting utf-8 body :", exc);
      }

      if (responseData != null)
        contentLength = Integer.parseInt(resHeaders.getPropertyIgnoreCase("Content-Length"));
    }
  }
コード例 #2
0
ファイル: RhoConnection.java プロジェクト: spike/rhodes
  private void processResponse(RubyValue res) {
    if (res != null && res != RubyConstant.QNIL && res instanceof RubyHash) {
      RubyHash resHash = (RubyHash) res;
      RubyValue resBody = null;

      RubyArray arKeys = resHash.keys();
      RubyArray arValues = resHash.values();
      for (int i = 0; i < arKeys.size(); i++) {
        String strKey = arKeys.get(i).toString();
        if (strKey.equals("request-body")) resBody = arValues.get(i);
        else if (strKey.equals("status")) responseCode = arValues.get(i).toInt();
        else if (strKey.equals("message")) responseMsg = arValues.get(i).toString();
        else resHeaders.addProperty(strKey, arValues.get(i).toString());
      }
      String strBody = "";

      if (resBody != null && resBody != RubyConstant.QNIL)
        strBody = resBody.toRubyString().toString();

      log(strBody);

      responseData = new ByteArrayInputStream(strBody.getBytes());
      if (responseData != null)
        contentLength = Integer.parseInt(resHeaders.getPropertyIgnoreCase("Content-Length"));
    }
  }
コード例 #3
0
  public void processRequest() throws IOException {
    if (!requestProcessed) {
      String strErr = "";

      LOG.TRACE("processRequest: " + getURL());
      String strReferer = reqHeaders != null ? reqHeaders.getPropertyIgnoreCase("Referer") : "";
      if (getRef() != null
          && getRef().length() > 0
          && strReferer != null
          && strReferer.equalsIgnoreCase(uri_orig.getPathNoFragment())) {
        respondNotModified();
      } else {
        String strContType = getContentType();

        if (uri.getPath().startsWith("/apps/public")) {
          httpServeFile(strContType);
        } else {
          if (this.method.equals("POST")
              || strContType.length() == 0
              || strContType.indexOf("application/x-www-form-urlencoded") >= 0) {
            if (dispatch()) {
              requestProcessed = true;
              return;
            }
          }

          if (
          /*this.method == "GET" &&*/ httpGetFile(strContType)) {

            // }else if ( dispatch() ){
          } else {
            respondNotFound(strErr);
          }
        }
      }
      requestProcessed = true;
    }
  }
コード例 #4
0
 public String getRequestProperty(String key) {
   LOG.TRACE("getRequestProperty: " + key);
   return reqHeaders.getPropertyIgnoreCase(key);
 }
コード例 #5
0
 public String getHeaderField(String name) throws IOException {
   LOG.TRACE("getHeaderField: " + name);
   processRequest();
   return resHeaders.getPropertyIgnoreCase(name);
 }