Ejemplo n.º 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"));
    }
  }
Ejemplo n.º 2
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.º 3
0
  public void processConnection(HttpConnection connection, Object e) {
    BrowserContent browserContent = null;

    try {
      if (connection.getResponseCode() != HttpConnection.HTTP_NOT_MODIFIED)
        browserContent = _renderingSession.getBrowserContent(connection, this, (Event) e);

      if (browserContent != null) {
        browserContent.finishLoading();

        Field field = browserContent.getDisplayableContent();
        if (field != null) {

          synchronized (Application.getEventLock()) {
            m_oMainScreen.deleteAll();
            m_oMainScreen.add(field);

            /*if ( m_oMainScreen.getFieldCount() > 0 )
            {
            	Field old = m_oMainScreen.getField(0);
            	m_oMainScreen.add(field);
            	m_oMainScreen.delete(old);
            }else
            	m_oMainScreen.add(field);*/
            /*
            _mainScreen.doPaint();
            if ( e == null )
            {//This should awake screen in case of long network response
             KeyCodeEvent inject1 = 	new KeyCodeEvent( KeyCodeEvent.KEY_DOWN, (char)Keypad.KEY_ESCAPE, 0);
             KeyCodeEvent inject2 =  new KeyCodeEvent( KeyCodeEvent.KEY_UP, (char)Keypad.KEY_ESCAPE, 0);
             inject1.post();
             inject2.post();
             m_bSkipKeyPress = true;
            }*/
          }
        }
      }
    } catch (Exception re) {
      LOG.ERROR("processConnection failed.", re);
    } finally {
      SecondaryResourceFetchThread.doneAddingImages();
    }
  }
Ejemplo n.º 4
0
  public void resetUrl(String url) {
    url_external = url;
    uri = new URI(url_external);

    if (!uri.getPath().startsWith("/apps")) uri.setPath("/apps" + uri.getPath());
    else uri.setPath(uri.getPath());

    method = "";
    responseCode = 200;
    responseMsg = "OK";
    contentLength = -1;
    reqHeaders.clear();
    resHeaders.clear();
    requestProcessed = false;

    try {
      clean();
    } catch (IOException exc) {
      LOG.ERROR("clean failed.", exc);
    }
  }
Ejemplo n.º 5
0
  public HttpConnection getResource(RequestedResource resource, BrowserContent referrer) {

    if (resource == null) return null;

    String url = resource.getUrl();
    if (url == null || url.endsWith("/favicon.ico")) return null;

    try {
      if (referrer == null || URI.isLocalData(url) || !m_bLoadImageAsync) {
        boolean bLocalHost = RhodesApp.getInstance().isRhodesAppUrl(url);
        if (bLocalHost && m_connResource != null) {
          com.rho.net.RhoConnection rhoConn =
              (com.rho.net.RhoConnection)
                  ((com.rho.net.bb.NativeBBHttpConnection) m_connResource).getNativeConnection();
          rhoConn.resetUrl(url);

          Utilities.makeConnection(url, resource.getRequestHeaders(), null, m_connResource);
          return m_connResource;
        } else {
          HttpConnection connection =
              Utilities.makeConnection(url, resource.getRequestHeaders(), null, null);
          // if (bLocalHost)
          //	m_connResource = connection;
          return connection;
        }
      } else {
        SecondaryResourceFetchThread.enqueue(resource, referrer);
      }
    } catch (Exception exc) {
      LOG.ERROR("getResource failed.", exc);
    }

    return null;

    /*
     // check if this is cache-only request
     if (resource.isCacheOnly()) {
         // no cache support
         return null;
     }

     String url = resource.getUrl();

     if (url == null) {
         return null;
     }

     try{
      // if referrer is null we must return the connection
      if (referrer == null) {
          HttpConnection connection = Utilities.makeConnection(url, resource.getRequestHeaders(), null);
          return connection;

      } else
      {
    if ( URI.isLocalHost(url) || URI.isLocalData(url))
    {
              HttpConnection connection = Utilities.makeConnection(url, resource.getRequestHeaders(), null);
              return connection;
    }else
    {
           // if referrer is provided we can set up the connection on a separate thread
           SecondaryResourceFetchThread.enqueue(resource, referrer);
    }
      }
     }catch(Exception exc)
     {
     	LOG.ERROR("getResource failed.", exc);
     }

     return null;*/
  }