Package org.apache.shindig.common.uri

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


  }

  private void injectBaseTag(Gadget gadget, Node headTag) {
    GadgetContext context = gadget.getContext();
    if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) {
      Uri base = gadget.getSpec().getUrl();
      View view = gadget.getCurrentView();
      if (view != null && view.getHref() != null) {
        base = view.getHref();
      }
      Element baseTag = headTag.getOwnerDocument().createElement("base");
      baseTag.setAttribute("href", base.toString());
      headTag.insertBefore(baseTag, headTag.getFirstChild());
    }
  }
View Full Code Here


    if (httpApiRequest.href == null) {
      throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "href parameter is missing");
    }

    // Canonicalize the path
    Uri href = normalizeUrl(httpApiRequest.href);
    try {
      HttpRequest req = new HttpRequest(href);
      req.setMethod(method);
      if (httpApiRequest.body != null) {
        req.setPostBody(httpApiRequest.body.getBytes());
      }

      // Copy over allowed headers
      for (Map.Entry<String, List<String>> header : httpApiRequest.headers.entrySet()) {
        if (!BAD_HEADERS.contains(header.getKey().trim().toUpperCase())) {
          for (String value : header.getValue()) {
            req.addHeader(header.getKey(), value);
          }
        }
      }

      // Extract the gadget URI from the request or the security token
      Uri gadgetUri = getGadgetUri(requestItem.getToken(), httpApiRequest);
      if (gadgetUri == null) {
        throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
            "Gadget URI not specified in request");
      }
      req.setGadget(gadgetUri);
View Full Code Here

    }

    public Result filterAttribute(Attr attr, Uri context) {
      if (uriAttributes.contains(attr.getName().toLowerCase())) {
        try {
          Uri uri = Uri.parse(attr.getValue());
          String scheme = uri.getScheme();
          if (scheme != null && !scheme.equals("http") && !scheme.equals("https")) {
            return Result.REMOVE;
          }
        } catch (IllegalArgumentException iae) {
          return Result.REMOVE;
View Full Code Here

    this.pipelineExecutor = pipelineExecutor;
  }

  public String render(Gadget gadget) throws RenderingException, GadgetException {
    View view = gadget.getCurrentView();
    Uri href = view.getHref();
    Preconditions.checkArgument(href != null, "Gadget does not have href for the current view");

    GadgetContext context = gadget.getContext();
    String path = context.getParameter(PATH_PARAM);
    if (path != null) {
      try {
        Uri relative = Uri.parse(path);
        if (!relative.isAbsolute()) {
          href = href.resolve(relative);
        }
      } catch (IllegalArgumentException e) {
        // TODO: Spec does not say what to do for an invalid relative path.
        // Just ignoring for now.
View Full Code Here

  private static Cache<String, Object> makeCache(CacheProvider cacheProvider) {
    return cacheProvider.createCache(CACHE_NAME);
  }

  public GadgetSpec getGadgetSpec(GadgetContext context) throws GadgetException {
    Uri gadgetUri = getGadgetUri(context);
    if (RAW_GADGET_URI.equals(gadgetUri)) {
      try {
        String rawxml = context.getParameter(RAW_GADGETSPEC_XML_PARAM_NAME);
        return new GadgetSpec(gadgetUri, XmlUtil.parse(rawxml), rawxml);
      } catch (XmlException e) {
View Full Code Here

  @Test
  public void getLinks() throws Exception {
    String link1Rel = "foo";
    String link2Rel = "bar";
    Uri link1Href = Uri.parse("http://example.org/foo");
    Uri link2Href = Uri.parse("/bar");
    String xml = "<ModulePrefs title='links'>" +
                 "  <Link rel='" + link1Rel + "' href='" + link1Href + "'/>" +
                 "  <Link rel='" + link2Rel + "' href='" + link2Href + "'/>" +
                 "</ModulePrefs>";
View Full Code Here

    assertEquals(response, cache.getResponse(request));
  }

  @Test
  public void renderProxiedRelative() throws Exception {
    Uri base = EXPECTED_PROXIED_HTML_HREF;
    final Uri relative = Uri.parse("/some/path?foo=bar");
    Uri resolved = new UriBuilder(base.resolve(relative))
      .addQueryParameter("lang", GadgetSpec.DEFAULT_LOCALE.getLanguage())
      .addQueryParameter("country", GadgetSpec.DEFAULT_LOCALE.getCountry())
      .toUri();

    HttpRequest request = new HttpRequest(resolved);
View Full Code Here

  private OAuthCallbackGenerator createRealCallbackGenerator() {
    return new OAuthCallbackGenerator() {
      public String generateCallback(OAuthFetcherConfig fetcherConfig, String baseCallback,
          HttpRequest request, OAuthResponseParams responseParams) {
        SecurityToken st = request.getSecurityToken();
        Uri activeUrl = Uri.parse(st.getActiveUrl());
        assertEquals(GADGET_MAKE_REQUEST_URL, activeUrl.toString());
        assertEquals(GadgetTokenStoreTest.DEFAULT_CALLBACK, baseCallback);
        return new UriBuilder()
            .setScheme("http")
            .setAuthority(activeUrl.getAuthority())
            .setPath("/realcallback")
            .toString();
      }     
    };
  }
View Full Code Here

   
    control.replay();
   
    String callback = getGenerator().generateCallback(fetcherConfig, "http://base/basecallback",
        request, responseParams);
    Uri callbackUri = Uri.parse(callback);
    assertEquals("http", callbackUri.getScheme());
    assertEquals("base", callbackUri.getAuthority());
    assertEquals("/basecallback", callbackUri.getPath());
    OAuthCallbackState state = new OAuthCallbackState(stateCrypter,
        callbackUri.getQueryParameter("cs"));
    assertEquals("http://renderinghost/final/callback", state.getRealCallbackUrl());
   
    control.verify();
  }
View Full Code Here

   
    control.replay();
   
    String callback = getGenerator().generateCallback(fetcherConfig, "http://base/basecallback",
        request, responseParams);
    Uri callbackUri = Uri.parse(callback);
    assertEquals("http", callbackUri.getScheme());
    assertEquals("base", callbackUri.getAuthority());
    assertEquals("/basecallback", callbackUri.getPath());
    OAuthCallbackState state = new OAuthCallbackState(stateCrypter,
        callbackUri.getQueryParameter("cs"));
    assertEquals("https://renderinghost/final/callback", state.getRealCallbackUrl());
   
    control.verify();
  }
View Full Code Here

TOP

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

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.