@Test
  public void bad_urls_are_skipped(UrlParser f) throws MalformedURLException {
    List<String> mixed_uris =
        asList("http://example.com/good", "example.com/bad", "http://example.com/good2");

    assertThat(
        f.apply(mixed_uris),
        equalTo(asList(new URL("http://example.com/good"), new URL("http://example.com/good2"))));
  }
  @Test
  public void good_urls_pass(UrlParser f) throws MalformedURLException {
    List<String> good_uris =
        asList(
            "http://example.com/example_a",
            "http://example.com/example_b",
            "http://example.com/example_c");

    assertThat(
        f.apply(good_uris),
        equalTo(
            asList(
                new URL("http://example.com/example_a"),
                new URL("http://example.com/example_b"),
                new URL("http://example.com/example_c"))));
  }
 @Override
 public UrlContent execute(UrlContent content) throws CannotParserException {
   if (content.query == null) {
     return null;
   }
   String nav = StringUtil.getParameter(content.query, "nav");
   if (nav == null || !nav.startsWith("/")) {
     return null;
   }
   if (nav.endsWith(".jsp")) {
     nav = nav.substring(0, nav.length() - 4);
   }
   UrlContent result = UrlParser.parse(nav, content.custom);
   if (result == null) {
     return null;
   }
   content.module = result.module;
   content.path = ".index";
   content.query = null;
   return content;
 }
Esempio n. 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;
  }
Esempio n. 5
0
  protected boolean dispatch() throws IOException {
    // LOG.INFO("dispatch start : " + uri.getPath());

    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 == null || model.length() == 0) return false;

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

    // Convert CamelCase to underscore_case
    StringBuffer cName = new StringBuffer();
    byte[] modelname = model.getBytes();
    char ch;
    for (int i = 0; i != model.length(); ++i) {
      if (modelname[i] >= (byte) 'A' && modelname[i] <= (byte) 'Z') {
        ch = (char) (modelname[i] + 0x20);
        if (i != 0) cName.append('_');

      } else ch = (char) modelname[i];
      cName.append(ch);
    }
    String controllerName = cName.toString();

    String strCtrl = "apps/" + application + '/' + model + '/' + controllerName + "_controller";
    if (RhoSupport.findClass(strCtrl) == null) {
      strCtrl = "apps/" + application + '/' + model + '/' + "controller";
      if (RhoSupport.findClass(strCtrl) == null) return false;
    }

    Properties reqHash = new Properties();

    String actionid = up.next();
    String actionnext = up.next();
    if (actionid != null && actionid.length() > 0) {
      if (actionid.length() > 6 && actionid.startsWith("%7B") && actionid.endsWith("%7D"))
        actionid = "{" + actionid.substring(3, actionid.length() - 3) + "}";

      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);

    doDispatch(reqHash, null);

    if (actionid != null
        && actionid.length() > 2
        && actionid.charAt(0) == '{'
        && actionid.charAt(actionid.length() - 1) == '}')
      SyncThread.getInstance().addobjectnotify_bysrcname(model, actionid);

    return true;
  }