Example #1
0
  protected boolean httpServeFile(String strContType) throws IOException {
    String strPath = uri.getPath();
    // if ( !strPath.startsWith("/apps") )
    //	strPath = "/apps" + strPath;

    LOG.TRACE("httpServeFile: " + strPath);

    if (!isDbFilesPath(strPath)) {
      if (strContType.equals("application/javascript")) {
        responseData = RhoRuby.loadFile(strPath);
        if (responseData == null) {
          String str = "";
          responseData = new ByteArrayInputStream(str.getBytes());
        }
      } else responseData = RhoRuby.loadFile(strPath);
    } else {
      if (strPath.startsWith("/apps/app/db/db-files"))
        strPath = strPath.substring(9); // remove /apps/app
      else strPath = strPath.substring(5); // remove /apps
    }

    if (responseData == null) {

      SimpleFile file = null;
      try {
        file = RhoClassFactory.createFile();
        String strFileName = strPath;
        //				if ( strFileName.startsWith("/apps") )
        //					strFileName = strPath.substring(5);

        file.open(strFileName, true, true);
        responseData = file.getInputStream();
        if (responseData != null) {
          contentLength = (int) file.length();
        }
        m_file = file;
      } catch (Exception exc) {
        if (file != null) file.close();
      }
    } else {
      if (responseData != null) {
        contentLength = responseData.available();
      }
    }

    if (responseData == null) return false;

    if (strContType.length() > 0) resHeaders.addProperty("Content-Type", strContType);

    resHeaders.addProperty("Content-Length", Integer.toString(contentLength));

    // resHeaders.addProperty("Date",getLocalHttpTimeString());
    // resHeaders.addProperty("Cache-control", "public, max-age=3600" );
    // resHeaders.addProperty("Expires", "Thu, 01 Dec 2010 16:00:00 GMT" );

    return true;
  }
Example #2
0
  protected boolean httpServeFile(String strContType) throws IOException {

    String strPath = uri.getPath();
    // if ( !strPath.startsWith("/apps") )
    //	strPath = "/apps" + strPath;

    if (strContType.equals("application/javascript")) {
      responseData = RhoRuby.loadFile(strPath);
      if (responseData == null) {
        String str = "";
        responseData = new ByteArrayInputStream(str.getBytes());
      }
    } else responseData = RhoRuby.loadFile(strPath);

    if (responseData == null) {
      Jsr75File file = new Jsr75File();
      String strFileName = strPath;
      if (strFileName.startsWith("/apps")) strFileName = strPath.substring(5);

      try {
        file.open(strFileName, true, true);
        responseData = file.getInputStream();
        if (responseData != null) {
          contentLength = (int) file.length();
        }
        m_file = file;
      } catch (StorageError exc) {
        file.close();
      } catch (IOException exc) {
        file.close();
      }
    } else {
      if (responseData != null) {
        contentLength = responseData.available();
      }
    }

    if (responseData == null) return false;

    if (strContType.length() > 0) resHeaders.addProperty("Content-Type", strContType);

    resHeaders.addProperty("Content-Length", Integer.toString(contentLength));

    return true;
  }
Example #3
0
  void doDispatch(Properties reqHash, String strIndex) throws IOException {
    reqHash.setProperty("request-method", this.method);
    reqHash.setProperty("request-uri", uri.getPath());
    reqHash.setProperty("request-query", uri.getQueryString());

    if (postData != null && postData.size() > 0) {
      if (!RHOCONF().getBool("log_skip_post")) LOG.TRACE(postData.toString());
      reqHash.setProperty("request-body", postData.toString());
    }

    RubyValue res = RhoRuby.processRequest(reqHash, reqHeaders, resHeaders, strIndex);
    processResponse(res);

    RhodesApp.getInstance().keepLastVisitedUrl(url_external);
    LOG.INFO("dispatch end");
  }
Example #4
0
  protected boolean dispatch() throws IOException {
    UrlParser up = new UrlParser(uri.getPath());
    String apps = up.next();
    String application;
    if (apps.equalsIgnoreCase("apps")) application = up.next();
    else application = apps;

    String model = up.next();

    if (model.length() == 0) return false;

    if (checkRhoExtensions(application, model)) return true;

    Properties reqHash = new Properties();

    String actionid = up.next();
    String actionnext = up.next();
    if (actionid.length() > 0) {
      if (actionid.length() > 2
          && actionid.charAt(0) == '{'
          && actionid.charAt(actionid.length() - 1) == '}') {
        reqHash.setProperty("id", actionid);
        reqHash.setProperty("action", actionnext);
      } else {
        reqHash.setProperty("id", actionnext);
        reqHash.setProperty("action", actionid);
      }
    }
    reqHash.setProperty("application", application);
    reqHash.setProperty("model", model);

    reqHash.setProperty("request-method", this.method);
    reqHash.setProperty("request-uri", uri.getPath());
    reqHash.setProperty("request-query", uri.getQueryString());

    if (postData != null && postData.size() > 0) {
      log(postData.toString());
      reqHash.setProperty("request-body", postData.toString());
    }

    RubyValue res = RhoRuby.processRequest(reqHash, reqHeaders, resHeaders);
    processResponse(res);

    return true;
  }
Example #5
0
  protected boolean httpGetIndexFile() {
    String strIndex = null;
    String slash = "";
    if (uri.getPath() != null && uri.getPath().length() > 0)
      slash = uri.getPath().charAt(uri.getPath().length() - 1) == '/' ? "" : "/";

    for (int i = 0; i < m_arIndexes.length; i++) {
      String name = uri.getPath() + slash + m_arIndexes[i];
      String nameClass = name;
      if (nameClass.endsWith(".iseq")) nameClass = nameClass.substring(0, nameClass.length() - 5);

      if (RhoSupport.findClass(nameClass) != null || RhoRuby.resourceFileExists(name)) {
        strIndex = name;
        break;
      }
    }

    if (strIndex == null) return false;

    respondMoved(strIndex);
    return true;
  }
Example #6
0
  protected boolean httpGetFile() throws IOException {

    String strContType = getContentType();
    if (strContType.length() == 0) {
      String strTemp = uri.getPath();
      if (strTemp.length() == 0 || strTemp.charAt(strTemp.length() - 1) != '/') strTemp += '/';

      if (RhoSupport.findClass(strTemp + "controller") != null) return false;

      int nPos = findIndex(uri.getPath());
      if (nPos >= 0) {
        String url = uri.getPath(); // + (nPos == 0 ? ".iseq" : "");
        RubyValue res = RhoRuby.processIndexRequest(url); // erb-compiled should load from class
        processResponse(res);
        return true;
      }

      if (httpGetIndexFile()) return true;
    }

    return httpServeFile(strContType);
  }