Ejemplo n.º 1
0
  void showGeoLocation() {
    String location;
    if (!GeoLocation.isStarted()) location = "Unavailable;Unavailable;Unavailable";
    else if (!GeoLocation.isKnownPosition())
      location = "reading...;reading...;reading..."; // <br/>" + GeoLocation.getLog();
    else {
      double latitude = GeoLocation.GetLatitude();
      double longitude = GeoLocation.GetLongitude();

      location =
          String.valueOf(Math.abs(latitude))
              + "f° "
              + (latitude < 0 ? "South" : "North")
              + ", "
              + String.valueOf(Math.abs(longitude))
              + "f° "
              + (longitude < 0 ? "West" : "East")
              + ";"
              + String.valueOf(latitude)
              + ";"
              + String.valueOf(longitude)
              + ";";
    }

    respondOK();

    contentLength = location.length();
    responseData = new ByteArrayInputStream(location.getBytes());
    resHeaders.addProperty("Content-Type", "text/html");
    resHeaders.addProperty("Content-Length", Integer.toString(contentLength));
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  void respondNotFound(String strError) {
    responseCode = HTTP_NOT_FOUND;
    responseMsg = "Not found";
    if (strError != null && strError.length() != 0) responseMsg += ".Error: " + strError;

    String strBody = "Page not found: " + uri.getPath();

    contentLength = strBody.length();
    responseData = new ByteArrayInputStream(strBody.getBytes());

    resHeaders.addProperty("Content-Type", "text/html");
    resHeaders.addProperty("Content-Length", Integer.toString(contentLength));
  }
Ejemplo n.º 4
0
  void showGeoLocation() {
    String location = "";
    try {
      IRhoRubyHelper helper = RhoClassFactory.createRhoRubyHelper();
      location = helper.getGeoLocationText();
    } catch (Exception exc) {
      LOG.ERROR("getGeoLocationText failed", exc);
    }
    respondOK();

    contentLength = location.length();
    responseData = new ByteArrayInputStream(location.getBytes());
    resHeaders.addProperty("Content-Type", "text/html");
    resHeaders.addProperty("Content-Length", Integer.toString(contentLength));
  }
Ejemplo n.º 5
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"));
    }
  }
Ejemplo n.º 6
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();

      log(strBody);

      responseData = new ByteArrayInputStream(strBody.getBytes());
      if (responseData != null)
        contentLength = Integer.parseInt(resHeaders.getPropertyIgnoreCase("Content-Length"));
    }
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
  void respondMoved(String location) {
    responseCode = HTTP_MOVED_PERM;
    responseMsg = "Moved Permanently";

    String strLoc = location;
    if (strLoc.startsWith("/apps")) strLoc = strLoc.substring(5);

    String strQuery = uri.getQueryString();
    if (strQuery != null && strQuery.length() > 0) strLoc += "?" + strQuery;

    resHeaders.addProperty("Location", strLoc);
    contentLength = 0;
  }