Package org.apache.shindig.gadgets.http

Examples of org.apache.shindig.gadgets.http.HttpResponseBuilder.create()


  @Test
  public void testHandleResponse_3() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponseBuilder builder = new HttpResponseBuilder().setStrictNoCache();
    builder.setHttpStatusCode(HttpResponse.SC_FORBIDDEN);
    final HttpResponse response = builder.create();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNotNull(result);
View Full Code Here


    final HttpResponseBuilder builder = new HttpResponseBuilder().setStrictNoCache();
    builder.setHttpStatusCode(HttpResponse.SC_OK);
    builder.setHeader("Content-Type", "text/plain");
    builder
        .setContent("access_token=xxx&token_type=Bearer&expires=1&refresh_token=yyy&example_parameter=example_value");
    final HttpResponse response = builder.create();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNull(result);
View Full Code Here

    final HttpResponseBuilder builder = new HttpResponseBuilder().setStrictNoCache();
    builder.setHttpStatusCode(HttpResponse.SC_OK);
    builder.setHeader("Content-Type", "application/json");
    builder
        .setContent("{\"access_token\"=\"xxx\",\"token_type\"=\"Bearer\",\"expires_in\"=\"1\",\"refresh_token\"=\"yyy\",\"example_parameter\"=\"example_value\"}");
    final HttpResponse response = builder.create();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNull(result);
View Full Code Here

  public void testHandleResponse_6() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponseBuilder builder = new HttpResponseBuilder().setStrictNoCache();
    builder.setHttpStatusCode(HttpResponse.SC_OK);
    builder.setHeader("Content-Type", "BAD");
    final HttpResponse response = builder.create();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNotNull(result);
View Full Code Here

      builder.setStrictNoCache();
      builder.setHttpStatusCode(HttpResponse.SC_OK);
      builder.setHeader("Content-Type", "application/json");
      builder
          .setContent("{\"access_token\"=\"xxx\",\"token_type\"=\"Bearer\",\"expires_in\"=\"1\",\"refresh_token\"=\"yyy\",\"example_parameter\"=\"example_value\"}");
      return builder.create();
    }
  }

  static class DummyMessageProvider implements Provider<OAuth2Message> {
    public OAuth2Message get() {
View Full Code Here

    setupGadgetAdminMock(true);

    HttpRequest req = new HttpRequestCache(Uri.parse(url)).setCacheTtl(120).setIgnoreCache(false);
    HttpResponseBuilder resp = new HttpResponseBuilder().setCacheTtl(1234);
    resp.setContent("Hello");
    expect(pipeline.execute(req)).andReturn(resp.create());

    replay();
    HttpResponse proxyResp = proxyHandler.fetch(request);
    assertEquals(120, proxyResp.getCacheTtl() / 1000);
    verify();
View Full Code Here

    setupGadgetAdminMock(true);

    HttpRequest req = new HttpRequestCache(Uri.parse(url)).setCacheTtl(-1).setIgnoreCache(false);
    HttpResponseBuilder resp = new HttpResponseBuilder().setCacheTtl(1234);
    resp.setContent("Hello");
    expect(pipeline.execute(req)).andReturn(resp.create());

    replay();
    HttpResponse proxyResp = proxyHandler.fetch(request);
    assertEquals(1234, proxyResp.getCacheTtl() / 1000);
    verify();
View Full Code Here

      resp.setHeader(BODY_ECHO_HEADER, info.body);
    }
    if (info.rawBody != null) {
      resp.setHeader(RAW_BODY_ECHO_HEADER, new String(Base64.encodeBase64(info.rawBody)));
    }
    return resp.create();
  }

  private void validateMessage(OAuthAccessor accessor, MessageInfo info, boolean tokenEndpoint)
      throws OAuthException, IOException, URISyntaxException {
    OAuthValidator validator = new FakeTimeOAuthValidator();
View Full Code Here

      responseParams.setSendTraceToClient(true);
      response = new HttpResponseBuilder()
          .setHttpStatusCode(HttpResponse.SC_FORBIDDEN)
          .setStrictNoCache();
      responseParams.addToResponse(response, e);
      return response.create();
    }

    // OK, got some data back, annotate it as necessary.
    if (response.getHttpStatusCode() >= 400) {
      responseParams.logDetailedWarning(classname,"fetchNoThrow",MessageKeys.OAUTH_FETCH_FATAL_ERROR);
View Full Code Here

      responseParams.logDetailedWarning(classname,"fetchNoThrow",MessageKeys.OAUTH_FETCH_ERROR_REPROMPT);
      responseParams.setSendTraceToClient(true);
    }

    responseParams.addToResponse(response, null);
    return response.create();
  }

  /**
   * Fetch data, retrying in the event that that the service provider returns an error and we think
   * we can recover by restarting the protocol flow.
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.