Package org.apache.shindig.gadgets.http

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


  HttpResponse rewrite(HttpResponse original)
      throws IOException, ImageReadException {
    HttpResponseBuilder builder = new HttpResponseBuilder(original);
    new PNGOptimizer(new OptimizerConfig(), builder).rewrite(
         Sanselan.getBufferedImage(original.getResponse()));
    return builder.create();
  }
}
View Full Code Here


  private HttpResponse sendErrorResponse(final Throwable t, final OAuth2Error error,
          final String contextMessage, final String errorUri) {
    final HttpResponseBuilder responseBuilder = this.getErrorResponseBuilder(t, error,
            contextMessage, errorUri);
    return responseBuilder.create();
  }

  private static OAuth2Token haveAccessToken(final OAuth2Accessor accessor) {
    final boolean isLogging = BasicOAuth2Request.LOG.isLoggable();
    if (isLogging) {
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

    params.setAznUrl("aznurl");
    OAuthRequestException e = new OAuthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION, "whoa there cowboy");

    HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
    params.addToResponse(responseBuilder, e);
    HttpResponse response = responseBuilder.create();
    assertEquals("BAD_OAUTH_CONFIGURATION", response.getMetadata().get("oauthError"));
    String errorText = response.getMetadata().get("oauthErrorText");
    checkStringContains("error text returned", errorText, "whoa there cowboy");
    assertEquals("aznurl", response.getMetadata().get("oauthApprovalUrl"));
    assertNotNull(response.getMetadata().get("oauthState"));
View Full Code Here

    params.addRequestTrace(null, null);
    params.addRequestTrace(null, null);

    HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
    params.addToResponse(responseBuilder, e);
    HttpResponse response = responseBuilder.create();

    String errorText = response.getMetadata().get("oauthErrorText");
    assertEquals("whoa there cowboy", errorText);

    params.setSendTraceToClient(true);
View Full Code Here

    String errorText = response.getMetadata().get("oauthErrorText");
    assertEquals("whoa there cowboy", errorText);

    params.setSendTraceToClient(true);
    params.addToResponse(responseBuilder, e);
    response = responseBuilder.create();
    errorText = response.getMetadata().get("oauthErrorText");
    checkStringContains("includes error text", errorText, "whoa there cowboy");
    checkStringContains("Request 1 logged", errorText, "Sent request 1:\n\n");
    checkStringContains("Request 2 logged", errorText, "Sent request 2:\n\n");
  }
View Full Code Here

  @Test
  public void testAddEmptyParams() {
    HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
    params.addToResponse(responseBuilder, null);
    HttpResponse response = responseBuilder.create();
    assertTrue(response.getMetadata().isEmpty());
  }

  @Test
  public void testSawErrorResponse() {
View Full Code Here

  private String verifyStrip(String body) {
    HttpResponseBuilder resp = new HttpResponseBuilder()
        .setHttpStatusCode(200)
        .setHeader("Date", "Date: Fri, 09 Jan 2009 00:35:08 GMT")
        .setResponseString(body);
    String out = OAuthResponseParams.filterSecrets(resp.create().toString());
    if (out.contains("oauth_token_secret")) {
      checkStringContains("should remove secret", out, "oauth_token_secret=REMOVED");
    }
    if (out.contains("oauth_session_handle")) {
      checkStringContains("should remove handle", out, "oauth_session_handle=REMOVED");
View Full Code Here

    for (ResponseRewriter rewriter : rewriters) {
      rewriter.rewrite(req, builder, gadget);
    }

    // Returns the original HttpResponse if no changes have been made.
    return builder.create();
  }
}
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

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.