Package org.apache.shindig.gadgets.uri.ProxyUriManager

Examples of org.apache.shindig.gadgets.uri.ProxyUriManager.ProxyUri


  public GadgetsHandlerApi.ProxyResponse getProxy(GadgetsHandlerApi.ProxyRequest request)
      throws ProcessingException {
    verifyBaseParams(request, true);
    Set<String> fields = beanFilter.processBeanFields(request.getFields());

    ProxyUri proxyUri = createProxyUri(request);
    List<Uri> uris = proxyUriManager.make(ImmutableList.of(proxyUri), null);

    HttpResponse httpResponse = null;
    try {
      if (isFieldIncluded(fields, "proxyContent")) {
        httpResponse = proxyHandler.fetch(proxyUri);
      }
    } catch (IOException e) {
      LOG.log(Level.INFO, "Failed to fetch resource " + proxyUri.getResource().toString(), e);
      throw new ProcessingException("Error getting response content", HttpResponse.SC_BAD_GATEWAY);
    } catch (GadgetException e) {
      // TODO: Clean this log if it is too spammy
      LOG.log(Level.INFO, "Failed to fetch resource " + proxyUri.getResource().toString(), e);
      throw new ProcessingException("Error getting response content", HttpResponse.SC_BAD_GATEWAY);
    }

    try {
      return createProxyResponse(uris.get(0), httpResponse, fields,
View Full Code Here


    Object responseObj = operation.execute(emptyFormItems, authContext, converter).get();
    JSONObject response = new JSONObject(converter.convertToString(responseObj));

    JSONObject gadget1 = response.getJSONObject(resUri);
    assertEquals(proxyUri, gadget1.getString("proxyUrl"));
    ProxyUri pUri = captureProxyUri.getValue().get(0);
    ProxyUri expectedUri = new ProxyUri(null, false, false, CONTAINER, null, Uri.parse(resUri));
    assertTrue(expectedUri.equals(pUri));
    assertFalse(gadget1.has("error"));
    verify();
  }
View Full Code Here

    Object responseObj = operation.execute(emptyFormItems, authContext, converter).get();
    JSONObject response = new JSONObject(converter.convertToString(responseObj));

    JSONObject gadget1 = response.getJSONObject(resUri);
    assertEquals(proxyUri, gadget1.getString("proxyUrl"));
    ProxyUri pUri = captureProxyUri.getValue().get(0);
    ProxyUri expectedUri = new ProxyUri(null, false, false, CONTAINER, null, Uri.parse(resUri));
    assertTrue(expectedUri.equals(pUri));
    assertEquals(
            responseData,
            new String(Base64.decodeBase64(((JSONObject) gadget1.get("proxyContent")).getString(
                    "contentBase64").getBytes())));
    assertFalse(gadget1.has("error"));
View Full Code Here

    Object responseObj = operation.execute(emptyFormItems, authContext, converter).get();
    JSONObject response = new JSONObject(converter.convertToString(responseObj));

    JSONObject gadget1 = response.getJSONObject(resUri);
    assertEquals(proxyUri, gadget1.getString("proxyUrl"));
    ProxyUri pUri = captureProxyUri.getValue().get(0);
    ProxyUri expectedUri = new ProxyUri(333, true, true, CONTAINER, GADGET1_URL, Uri.parse(resUri));
    expectedUri.setRewriteMimeType("text/xml").setSanitizeContent(true);
    expectedUri.setFallbackUrl(resUri).setResize(555, 444, 88, true);
    assertTrue(expectedUri.equals(pUri));
    assertFalse(gadget1.has("error"));
    verify();
  }
View Full Code Here

    String host = "host.com";
    String path = "/proxy/path";
    ProxyUriManager.Versioner versioner = makeVersioner(null, version);
    DefaultProxyUriManager manager = makeManager(host, path, versioner);
    List<ProxyUri> proxyUris = Lists.newLinkedList();
    proxyUris.add(new ProxyUri(refresh, debug, noCache, CONTAINER, SPEC_URI.toString(),
        RESOURCE_1));

    List<Uri> uris = manager.make(proxyUris, null);
    assertEquals(1, uris.size());
    verifyQueryUriWithRefresh(RESOURCE_1, uris.get(0), debug, noCache,
View Full Code Here

    String host = "host.com";
    String path = "/proxy/path";
    ProxyUriManager.Versioner versioner = makeVersioner(null, "version1", "version2");
    DefaultProxyUriManager manager = makeManager(host, path, versioner);
    List<ProxyUri> proxyUris = Lists.newLinkedList();
    ProxyUri pUri = new ProxyUri(null, false, true, CONTAINER, SPEC_URI.toString(),
        RESOURCE_1);
    pUri.setResize(100, 10, 90, true);
    proxyUris.add(pUri);

    pUri = new ProxyUri(null, false, true, CONTAINER, SPEC_URI.toString(),
        RESOURCE_2);
    pUri.setResize(null, 10, null, false);
    proxyUris.add(pUri);

    List<Uri> uris = manager.make(proxyUris, null);
    assertEquals(2, uris.size());
    verifyQueryUriWithRefresh(RESOURCE_1, uris.get(0), false, true,
View Full Code Here

    String host = "host.com";
    String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + "/path";
    ProxyUriManager.Versioner versioner = makeVersioner(null, "version");
    DefaultProxyUriManager manager = makeManager(host, path, versioner);
    List<ProxyUri> proxyUris = Lists.newLinkedList();
    ProxyUri pUri = new ProxyUri(null, false, true, CONTAINER, SPEC_URI.toString(),
        RESOURCE_1);
    pUri.setExtensionParams(ImmutableMap.<String, String>of("test", "1"));
    pUri.setResize(100, 10, 90, true);
    proxyUris.add(pUri);

    List<Uri> uris = manager.make(proxyUris, null);
    assertEquals(1, uris.size());
    verifyChainedUri(RESOURCE_1, uris.get(0), false, true,
View Full Code Here

        uris.get(0).getPath());
  }

  @Test
  public void testFallbackUrl() throws Exception {
    ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget",
        Uri.parse("http://example.com/resource"));
    uri.setFallbackUrl("http://example.com/fallback");

    assertEquals("http://example.com/fallback", uri.getFallbackUri().toString());
  }
View Full Code Here

    assertEquals("http://example.com/fallback", uri.getFallbackUri().toString());
  }

  @Test(expected = GadgetException.class)
  public void testBadFallbackUrl() throws Exception {
    ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget",
        Uri.parse("http://example.com/resource"));
    uri.setFallbackUrl("bad url");
    uri.getFallbackUri(); // throws exception!
  }
View Full Code Here

    Uri testUri = new UriBuilder().setAuthority(host).setPath(path)
        .addQueryParameter(Param.CONTAINER.getKey(), CONTAINER)
        .addQueryParameter(Param.URL.getKey(), "http://www.example.org/")
        .addQueryParameter(Param.HTML_TAG_CONTEXT.getKey(), "htmlTag")
        .toUri();
    ProxyUri proxyUri = manager.process(testUri);
    assertEquals("htmlTag", proxyUri.getHtmlTagContext());

    Uri targetUri = Uri.parse("http://www.example2.org/");
    HttpRequest req = proxyUri.makeHttpRequest(targetUri);
    assertEquals("htmlTag", req.getParam(Param.HTML_TAG_CONTEXT.getKey()));

    UriBuilder builder = proxyUri.makeQueryParams(1, "2");
    assertEquals("htmlTag", builder.getQueryParameter(Param.HTML_TAG_CONTEXT.getKey()));
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.uri.ProxyUriManager.ProxyUri

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.