Package org.apache.shindig.common.uri

Examples of org.apache.shindig.common.uri.Uri$UriException


    Gadget gadget = new Gadget()
        .setContext(context)
        .setSpec(spec)
        .setCurrentView(spec.getView("default"));

    Uri iframeUrl = Uri.parse(urlGenerator.getIframeUrl(gadget));

    assertEquals(IFR_BASE, iframeUrl.getPath());
    assertEquals(CONTAINER, iframeUrl.getQueryParameter("container"));
    assertEquals(UP_VALUE, iframeUrl.getQueryParameter("up_" + UP_NAME));
    assertEquals(Integer.toString(MODULE_ID), iframeUrl.getQueryParameter("mid"));
    assertEquals(VIEW, iframeUrl.getQueryParameter("view"));
  }
View Full Code Here


    Gadget gadget = new Gadget()
        .setContext(context)
        .setSpec(spec)
        .setCurrentView(spec.getView("default"));

    Uri iframeUrl = Uri.parse(urlGenerator.getIframeUrl(gadget));

    assertEquals("locked.example.org", iframeUrl.getAuthority());
    assertEquals(IFR_BASE, iframeUrl.getPath());
    assertEquals(CONTAINER, iframeUrl.getQueryParameter("container"));
    assertEquals(UP_VALUE, iframeUrl.getQueryParameter("up_" + UP_NAME));
    assertEquals(Integer.toString(MODULE_ID), iframeUrl.getQueryParameter("mid"));
    assertEquals(VIEW, iframeUrl.getQueryParameter("view"));
  }
View Full Code Here

  }

  @Test
  public void testParseAuthorizeUrl() throws Exception {
    String xml = "<Authorization url='http://azn.example.com'/>";
    Uri url = service.parseAuthorizationUrl(XmlUtil.parse(xml), SPEC_URL);
    assertEquals("http://azn.example.com", url.toString());
  }
View Full Code Here

  }

  @Test
  public void testParseAuthorizeUrl_extraAttr() throws Exception {
    String xml = "<Authorization url='http://www.example.com' foo='bar'/>";
    Uri url = service.parseAuthorizationUrl(XmlUtil.parse(xml), SPEC_URL);
    assertEquals("http://www.example.com", url.toString());
  }
View Full Code Here

    final org.apache.http.HttpResponse response;
    final long started = System.currentTimeMillis();

    // Break the request Uri to its components:
    Uri uri = request.getUri();
    if (Strings.isNullOrEmpty(uri.getAuthority())) {
      throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
          "Missing domain name for request: " + uri,
          HttpServletResponse.SC_BAD_REQUEST);
    }
    if (Strings.isNullOrEmpty(uri.getScheme())) {
      throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
          "Missing schema for request: " + uri,
          HttpServletResponse.SC_BAD_REQUEST);
    }
    String[] hostparts = StringUtils.splitPreserveAllTokens(uri.getAuthority(),':');
    int port = -1; // default port
    if (hostparts.length > 2) {
      throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
          "Bad host name in request: " + uri.getAuthority(),
          HttpServletResponse.SC_BAD_REQUEST);
    }
    if (hostparts.length == 2) {
      try {
        port = Integer.parseInt(hostparts[1]);
      } catch (NumberFormatException e) {
        throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
            "Bad port number in request: " + uri.getAuthority(),
            HttpServletResponse.SC_BAD_REQUEST);
      }
    }

    String requestUri = uri.getPath();
    // Treat path as / if set as null.
    if (uri.getPath() == null) {
      requestUri = "/";
    }
    if (uri.getQuery() != null) {
      requestUri += '?' + uri.getQuery();
    }

    // Get the http host to connect to.
    HttpHost host = new HttpHost(hostparts[0], port, uri.getScheme());

    try {
      if ("POST".equals(methodType) || "PUT".equals(methodType)) {
        HttpEntityEnclosingRequestBase enclosingMethod = ("POST".equals(methodType))
            ? new HttpPost(requestUri)
View Full Code Here

      issueUriFormatError("Unexpected: Js Uri has no host");
      return INVALID_URI;
    }
   
    // We somewhat cheat in that jsHost may contain protocol/scheme as well.
    Uri hostUri = Uri.parse(jsHost);
   
    if (!host.equals(hostUri.getAuthority())) {
      issueUriFormatError("Js Uri host mismatch, is: " + host + ", expected: " + jsHost);
      return INVALID_URI;
    }
   
    // Pull out the collection of features referenced by the Uri.
    String path = uri.getPath();
    if (path == null) {
      issueUriFormatError("Unexpected: Js Uri has no path");
      return INVALID_URI;
    }
    if (!path.startsWith(jsPrefix)) {
      issueUriFormatError("Js Uri path invalid, expected prefix: " + jsPrefix + ", is: " + path);
      return INVALID_URI;
    }
    if (!path.endsWith(JS_SUFFIX)) {
      issueUriFormatError("Js Uri path invalid, expected suffix: " + JS_SUFFIX + ", is: " + path);
      return INVALID_URI;
    }
   
    // Pull off prefix and suffix strings
    path = path.substring(jsPrefix.length());
    path = path.substring(0, path.length() - JS_SUFFIX.length());
    while (path.startsWith("/")) {
      path = path.substring(1);
    }
   
    Collection<String> libs = getJsLibs(path);
    UriStatus status = UriStatus.VALID_UNVERSIONED;
    String version = uri.getQueryParameter(Param.VERSION.getKey());
    if (version != null && versioner != null) {
      Uri gadgetUri = null;
      String gadgetParam = uri.getQueryParameter(Param.URL.getKey());
      if (gadgetParam != null) {
        gadgetUri = Uri.parse(gadgetParam);
      }
      status = versioner.validate(gadgetUri, container, libs, version);
View Full Code Here

    final org.apache.http.HttpResponse response;
    final long started = System.currentTimeMillis();

    // Break the request Uri to its components:
    Uri uri = request.getUri();
    if (StringUtils.isEmpty(uri.getAuthority())) {
      throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
          "Missing domain name for request: " + uri,
          HttpServletResponse.SC_BAD_REQUEST);
    }
    if (StringUtils.isEmpty(uri.getScheme())) {
      throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
          "Missing schema for request: " + uri,
          HttpServletResponse.SC_BAD_REQUEST);
    }
    String[] hostparts = uri.getAuthority().split(":");
    int port = -1; // default port
    if (hostparts.length > 2) {
      throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
          "Bad host name in request: " + uri.getAuthority(),
          HttpServletResponse.SC_BAD_REQUEST);
    }
    if (hostparts.length == 2) {
      try {
        port = Integer.parseInt(hostparts[1]);
      } catch (NumberFormatException e) {
        throw new GadgetException(GadgetException.Code.INVALID_USER_DATA,
            "Bad port number in request: " + uri.getAuthority(),
            HttpServletResponse.SC_BAD_REQUEST);
      }
    }
    HttpHost host = new HttpHost(hostparts[0], port, uri.getScheme());  
    String requestUri = uri.getPath();
    if (uri.getQuery() != null) {
      requestUri += "?" + uri.getQuery();
    }

    try {
      if ("POST".equals(methodType) || "PUT".equals(methodType)) {
        HttpEntityEnclosingRequestBase enclosingMethod = ("POST".equals(methodType))
View Full Code Here

    this.jsManager = jsManager;
    this.oauthManager = oauthManager;
  }

  public String getIframeUrl(Gadget gadget) {
    Uri iframeUri = iframeManager.makeRenderingUri(gadget);
    return iframeUri.toString();
  }
View Full Code Here

    Uri iframeUri = iframeManager.makeRenderingUri(gadget);
    return iframeUri.toString();
  }

  public UrlValidationStatus validateIframeUrl(String url) {
    Uri iframeUri = Uri.parse(url);
    UriStatus uriStatus = iframeManager.validateRenderingUri(iframeUri);
    return translateStatus(uriStatus);
  }
View Full Code Here

    return translateStatus(uriStatus);
  }

  public String getBundledJsUrl(Collection<String> features, GadgetContext context) {
    Gadget gadget = new Gadget().setContext(context);
    Uri jsUri = jsManager.makeExternJsUri(gadget, features);
    return jsUri.toString();
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.common.uri.Uri$UriException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.