Package org.apache.shindig.gadgets.http

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


  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


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

    // OK, got some data back, annotate it as necessary.
    if (response.getHttpStatusCode() >= 400) {
      responseParams.logDetailedWarning("OAuth fetch fatal error");
View Full Code Here

      responseParams.setSendTraceToClient(true);
    }

    responseParams.addToResponse(response);

    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

      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 {
    info.message.validateMessage(accessor, new FakeTimeOAuthValidator());
View Full Code Here

      boolean isOversizedImage = isImageTooLarge(imageInfo);
      if (isResizeRequested && isOversizedImage) {
        HttpResponseBuilder rejectedResponseBuilder = new HttpResponseBuilder()
            .setHttpStatusCode(HttpResponse.SC_FORBIDDEN)
            .setResponseString(RESIZE_IMAGE_TOO_LARGE);
        return rejectedResponseBuilder.create();
      }

      // Don't handle animations.
      // TODO: This doesn't work as current Sanselan doesn't return accurate image counts.
      // See animated GIF detection below.
View Full Code Here

    byte[] imageBytes = outputter.toBytes(image);
    HttpResponseBuilder newResponseBuilder = new HttpResponseBuilder(response)
        .setResponse(imageBytes)
        .setHeader(CONTENT_TYPE, CONTENT_TYPE_IMAGE_PNG)
        .setHeader(CONTENT_LENGTH, String.valueOf(imageBytes.length));
    return newResponseBuilder.create();
  }

  private boolean isUsableParameter(Integer parameterValue) {
    if (parameterValue == null) {
      return true;
View Full Code Here

    params.setAznUrl("aznurl");
    params.oauthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION, "whoa there cowboy");

    HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
    params.addToResponse(responseBuilder);
    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.oauthRequestException(OAuthError.BAD_OAUTH_CONFIGURATION, "whoa there cowboy");

    HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
    params.addToResponse(responseBuilder);
    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);
    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);
    HttpResponse response = responseBuilder.create();
    assertTrue(response.getMetadata().isEmpty());
  }

  @Test
  public void testSawErrorResponse() {
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.