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

    expect(request.getIgnoreCache()).andStubReturn(true);
    expect(request.getImageParams()).andStubReturn(image);
    expect(request.getRewriteMimeType()).andStubReturn("image/png");
    expect(request.getSanitize()).andStubReturn(true);
    replay();
    ProxyUri pUri = gadgetHandler.createProxyUri(request);

    ProxyUri expectedUri = new ProxyUri(333, true, true, CONTAINER,
            FakeProcessor.SPEC_URL.toString(), RESOURCE);
    expectedUri.setRewriteMimeType("image/png").setSanitizeContent(true);
    expectedUri.setResize(210, 120, 77, true).setFallbackUrl(FALLBACK);
    assertEquals(pUri, expectedUri);
    verify();
  }
View Full Code Here

    expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn(
            ImmutableList.of(resUri));
    replay();
    GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request);
    assertEquals(1, uriCapture.getValue().size());
    ProxyUri pUri = uriCapture.getValue().get(0);
    assertEquals(CONTAINER, pUri.getContainer());
    assertEquals(resUri, response.getProxyUrl());
    assertNull(response.getProxyContent());
    assertEquals(timeSource.currentTimeMillis() + HttpUtil.getDefaultTtl() * 1000, response
            .getExpireTimeMs().longValue());
    verify();
View Full Code Here

    HttpResponse httpResponse = builder.create();
    expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andReturn(httpResponse);
    replay();
    GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request);
    assertEquals(1, uriCapture.getValue().size());
    ProxyUri pUri = uriCapture.getValue().get(0);
    assertEquals(CONTAINER, pUri.getContainer());
    assertNull(response.getProxyUrl());
    assertEquals("response",
            new String(Base64.decodeBase64(response.getProxyContent().getContentBase64())));
    assertEquals(20000L, response.getExpireTimeMs().longValue());
    verify();
View Full Code Here

    HttpResponse httpResponse = new HttpResponseBuilder().setHttpStatusCode(504).create();
    expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andReturn(httpResponse);
    replay();
    GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request);
    assertEquals(1, uriCapture.getValue().size());
    ProxyUri pUri = uriCapture.getValue().get(0);
    assertEquals(CONTAINER, pUri.getContainer());
    assertNull(response.getProxyUrl());
    assertEquals("", response.getProxyContent().getContentBase64());
    assertEquals(504, response.getProxyContent().getCode());
    verify();
  }
View Full Code Here

  @Test
  public void testDoGetWithOAuth2() throws Exception {
    Map<String, String> options = new HashMap<String, String>();
    options.put("OAUTH_SERVICE_NAME", "example");
    ProxyUriManager.ProxyUri proxyUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL);
    proxyUri.setAuthType(AuthType.OAUTH2);

    Uri uri = Uri.parse(BASIC_SYNTAX_URL + "&authz=oauth2&OAUTH_SERVICE_NAME=example&container=default&gadget=http://example.org/gadget.xml");
    expect(proxyUriManager.process(uri)).andReturn(proxyUri);
    expect(request.getScheme()).andReturn(uri.getScheme());
    expect(request.getServerName()).andReturn(uri.getAuthority());
    expect(request.getServerPort()).andReturn(80);
    expect(request.getRequestURI()).andReturn(uri.getPath());
    expect(request.getQueryString()).andReturn(uri.getQuery());
    expect(request.getHeader("Host")).andReturn(uri.getAuthority());
    expect(request.getParameter("OAUTH_SERVICE_NAME")).andReturn("example");
    expect(request.getParameterNames()).andReturn(Collections.enumeration(options.keySet()));
    expect(lockedDomainService.isSafeForOpenProxy(uri.getAuthority())).andReturn(true);

    ProxyUriManager.ProxyUri pUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL);
    pUri.setAuthType(AuthType.OAUTH2);
    pUri.setOAuth2Arguments(new OAuth2Arguments(AuthType.OAUTH2, options));

    expect(proxyHandler.fetch(pUri)).andReturn(new HttpResponse(RESPONSE_BODY));
    replay();
    servlet.doGet(request, recorder);
    verify();
View Full Code Here

  @Test
  public void testDoGetWithOAuth() throws Exception {
    Map<String, String> options = new HashMap<String, String>();
    options.put("OAUTH_SERVICE_NAME", "example");
    ProxyUriManager.ProxyUri proxyUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL);
    proxyUri.setAuthType(AuthType.OAUTH);

    Uri uri = Uri.parse(BASIC_SYNTAX_URL + "&authz=oauth&OAUTH_SERVICE_NAME=example&container=default&gadget=http://example.org/gadget.xml");
    expect(proxyUriManager.process(uri)).andReturn(proxyUri);
    expect(request.getScheme()).andReturn(uri.getScheme());
    expect(request.getServerName()).andReturn(uri.getAuthority());
    expect(request.getServerPort()).andReturn(80);
    expect(request.getRequestURI()).andReturn(uri.getPath());
    expect(request.getQueryString()).andReturn(uri.getQuery());
    expect(request.getHeader("Host")).andReturn(uri.getAuthority());
    expect(request.getParameter("OAUTH_SERVICE_NAME")).andReturn("example");
    expect(request.getParameterNames()).andReturn(Collections.enumeration(options.keySet()));
    expect(lockedDomainService.isSafeForOpenProxy(uri.getAuthority())).andReturn(true);

    ProxyUriManager.ProxyUri pUri = new ProxyUri(-1, false, true, "default", "http://example.org/gadget.xml", REQUEST_URL);
    pUri.setAuthType(AuthType.OAUTH);
    pUri.setOAuthArguments(new OAuthArguments(AuthType.OAUTH, options));

    expect(proxyHandler.fetch(pUri)).andReturn(new HttpResponse(RESPONSE_BODY));
    replay();
    servlet.doGet(request, recorder);
    verify();
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.