Package org.apache.shindig.gadgets.http

Examples of org.apache.shindig.gadgets.http.HttpRequest


  @Test
  public void testExplicitHeaders() throws Exception {
    String headerString = "X-Foo=bar&X-Bar=baz%20foo";

    HttpRequest expected = new HttpRequest(REQUEST_URL)
        .addHeader("X-Foo", "bar")
        .addHeader("X-Bar", "baz foo");
    expect(pipeline.execute(expected)).andReturn(new HttpResponse(RESPONSE_BODY));
    expect(request.getParameter(MakeRequestHandler.HEADERS_PARAM)).andReturn(headerString);
    replay();
View Full Code Here


  public void testSignedGetRequest() throws Exception {
    expect(request.getAttribute(AuthInfoUtil.Attribute.SECURITY_TOKEN.getId()))
        .andReturn(DUMMY_TOKEN).atLeastOnce();
    expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM))
        .andReturn(AuthType.SIGNED.toString()).atLeastOnce();
    HttpRequest expected = new HttpRequest(REQUEST_URL)
        .setAuthType(AuthType.SIGNED);
    expect(pipeline.execute(expected))
        .andReturn(new HttpResponse(RESPONSE_BODY));
    expectParameters(request, MakeRequestHandler.AUTHZ_PARAM);
    replay();
View Full Code Here

    assertTrue(rewriter.responseWasRewritten());
  }

  @Test
  public void testBadHttpResponseIsPropagated() throws Exception {
    HttpRequest internalRequest = new HttpRequest(REQUEST_URL);
    expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.error());
    replay();

    handler.fetch(request, recorder);
    JSONObject results = extractJsonFromResponse();
View Full Code Here

    handler.fetch(request, recorder);
  }

  @Test
  public void testMetadataCopied() throws Exception {
    HttpRequest internalRequest = new HttpRequest(REQUEST_URL);
    HttpResponse response = new HttpResponseBuilder()
        .setResponse("foo".getBytes("UTF-8"))
        .setMetadata("foo", RESPONSE_BODY)
        .create();
View Full Code Here

      this.parsedXmlCache = cacheProvider.createCache(PARSED_XML_CACHE);
    }
  }

  public TemplateLibrary loadTemplateLibrary(GadgetContext context, Uri uri) throws GadgetException {
    HttpRequest request = new HttpRequest(uri);
    // 5 minute TTL.
    request.setCacheTtl(300);
    HttpResponse response = pipeline.execute(request);
    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
      int retcode = response.getHttpStatusCode();
      if (retcode == HttpResponse.SC_INTERNAL_SERVER_ERROR) {
        // Convert external "internal error" to gateway error:
View Full Code Here

      // avoid overwhelming a server down on its heels.
      long now = System.currentTimeMillis();
      if (fetcher != null && now > (lastLoadTryMs + (60 * 1000))) {
        lastLoadTryMs = now;
        try {
          HttpRequest request = new HttpRequest(uri);
          HttpResponse response = fetcher.fetch(request);
          if (response.getHttpStatusCode() == HttpResponse.SC_OK) {
            content = response.getResponseAsString();
          } else {
            if (LOG.isLoggable(Level.WARNING)) {
View Full Code Here

  public Map<String, String> getExtensionParams() {
    return extensionParams;
  }

  public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException {
    HttpRequest req = new HttpRequest(targetUri)
        .setIgnoreCache(isNoCache())
        .setContainer(getContainer());
    if (!Strings.isNullOrEmpty(getGadget())) {
      try {
        req.setGadget(Uri.parse(getGadget()));
      } catch (IllegalArgumentException e) {
        throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
            "Invalid " + Param.GADGET.getKey() + " param: " + getGadget(),
            HttpResponse.SC_BAD_REQUEST);
      }
    }
    if (getRefresh() != null && getRefresh() >= 0) {
      req.setCacheTtl(getRefresh());
    }

    // Allow the rewriter to use an externally forced MIME type. This is needed
    // allows proper rewriting of <script src="x"/> where x is returned with
    // a content type like text/html which unfortunately happens all too often
    if (rewriteMimeType != null) {
      req.setRewriteMimeType(getRewriteMimeType());
    }
    req.setSanitizationRequested(sanitizeContent());
    req.setCajaRequested(cajoleContent());

    return req;
  }
View Full Code Here

    }

    @Override
    public HttpRequest makeHttpRequest(Uri targetUri)
        throws GadgetException {
      HttpRequest req = super.makeHttpRequest(targetUri);
      // Set image params:
      req.setParam(Param.RESIZE_HEIGHT.getKey(), resizeHeight);
      req.setParam(Param.RESIZE_WIDTH.getKey(), resizeWidth);
      req.setParam(Param.RESIZE_QUALITY.getKey(), resizeQuality);
      req.setParam(Param.NO_EXPAND.getKey(), resizeNoExpand ? "1" : "0");

      req.setParam(Param.RETURN_ORIGINAL_CONTENT_ON_ERROR.getKey(),
                   returnOriginalContentOnError);
      req.setParam(Param.HTML_TAG_CONTEXT.getKey(), htmlTagContext);
      return req;
    }
View Full Code Here

    return ImmutableList.of();
  }

  private Set<String> retrieveServices(String endpoint) {
    Uri url = Uri.parse(endpoint + "?method=" + SYSTEM_LIST_METHODS_METHOD);
    HttpRequest request = new HttpRequest(url);
    try {
      HttpResponse response = fetcher.fetch(request);
      if (response.getHttpStatusCode() == HttpResponse.SC_OK) {
        return getServicesFromJsonResponse(response.getResponseAsString());
      } else {
View Full Code Here

        Uri resourceUri = Uri.fromJavaUri(ref.getUri());
        if (contextUri != null) {
          resourceUri = contextUri.resolve(resourceUri);
        }

        HttpRequest request = new HttpRequest(resourceUri)
                .setContainer(req.getContainer())
                .setGadget(req.getGadget());

        try {
          HttpResponse response = requestPipeline.execute(request);
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.http.HttpRequest

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.