Package org.apache.shindig.gadgets

Examples of org.apache.shindig.gadgets.GadgetException


      } else if ("res".equals(uri.getScheme())) {
        return loadResource(uri.getPath(), attribs);
      }
      return loadUri(uri, attribs);
    } catch (IOException e) {
      throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, e);
    }
  }
View Full Code Here


   * @return A URI representing a validated form of the url.
   * @throws GadgetException If the url is not valid.
   */
  protected Uri validateUrl(String urlToValidate) throws GadgetException {
    if (urlToValidate == null) {
      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
          "url parameter is missing.", HttpResponse.SC_BAD_REQUEST);
    }
    try {
      UriBuilder url = UriBuilder.parse(urlToValidate);
      if (!"http".equals(url.getScheme()) && !"https".equals(url.getScheme())) {
        throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
            "Invalid request url scheme in url: " + Utf8UrlCoder.encode(urlToValidate) +
            "; only \"http\" and \"https\" supported.", HttpResponse.SC_BAD_REQUEST);
      }
      if (url.getPath() == null || url.getPath().length() == 0) {
        url.setPath("/");
      }
      return url.toUri();
    } catch (IllegalArgumentException e) {
      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
          "url parameter is not a valid url: " + urlToValidate, HttpResponse.SC_BAD_REQUEST);
    }
  }
View Full Code Here

      refreshInterval = 0;
    } else if (request.getParameter(REFRESH_PARAM) != null) {
      try {
        refreshInterval =  Integer.valueOf(request.getParameter(REFRESH_PARAM));
      } catch (NumberFormatException nfe) {
        throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
            "refresh parameter is not a number", HttpResponse.SC_BAD_REQUEST);
      }
    } else {
      refreshInterval = Math.max(60 * 60, (int)(results.getCacheTtl() / 1000L));
    }
View Full Code Here

  public ParsedFeature parse(Uri parent, String xml) throws GadgetException {
    Element doc;
    try {
      doc = XmlUtil.parse(xml);
    } catch (XmlException e) {
      throw new GadgetException(GadgetException.Code.MALFORMED_XML_DOCUMENT, e);
    }

    String name = null;
    List<String> deps = Lists.newArrayList();
    List<ParsedFeature.Bundle> bundles = Lists.newArrayList();
View Full Code Here

  public void testConcatBadException() throws Exception {
    final Uri URL4 = Uri.parse("http://example.org/4.js");

    HttpRequest req = new HttpRequest(URL4);
    expect(pipeline.execute(req)).andThrow(
        new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes();

    String results = addComment(SCRT1, URL1.toString())
        + "/* ---- Start http://example.org/4.js ---- */\r\n"
        + "HTML_PARSE_ERROR concat(http://example.org/4.js) null";

View Full Code Here

  public void testAsJsonConcatException() throws Exception {
    final Uri URL4 = Uri.parse("http://example.org/4.js");

    HttpRequest req = new HttpRequest(URL4);
    expect(pipeline.execute(req)).andThrow(
        new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT)).anyTimes();

    expect(request.getParameter("json")).andReturn("_js").once();
    String results = "_js={\r\n"
        + addVar(URL1.toString(), SCRT1_ESCAPED)
        + "/* ---- End http://example.org/4.js 404 ---- */\r\n"
 
View Full Code Here

  public void testAsJsonConcatBadException() throws Exception {
    final Uri URL4 = Uri.parse("http://example.org/4.js");

    HttpRequest req = new HttpRequest(URL4);
    expect(pipeline.execute(req)).andThrow(
        new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes();

    expect(request.getParameter("json")).andReturn("_js").once();
    String results = "_js={\r\n"
        + addVar(URL1.toString(), SCRT1_ESCAPED)
        + addVar(URL4.toString(),"")
View Full Code Here

  }

  @Test
  public void testNextFetchThrowsGadgetException() throws Exception {
    serviceProvider.setThrow(
        new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "mildly wrong"));
    MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
    HttpResponse response = client.sendGet(FakeOAuthServiceProvider.ACCESS_TOKEN_URL);
    assertEquals("UNKNOWN_PROBLEM", response.getMetadata().get("oauthError"));
    assertEquals("", response.getResponseAsString());
    String oauthErrorText = response.getMetadata().get("oauthErrorText");
View Full Code Here

    Uri uri = Uri.parse("http://apache.org/resource.js");
    Map<String, String> attribs = Maps.newHashMap();
    attribs.put("inline", "true");
    HttpFetcher fetcher = createMock(HttpFetcher.class);
    expect(fetcher.fetch(eq(new HttpRequest(uri))))
        .andThrow(new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT));
    replay(fetcher);
    loader.setHttpFetcher(fetcher);
    FeatureResource resource = loader.load(uri, attribs);
    assertNull(resource.getContent());
    assertNull(resource.getDebugContent());
View Full Code Here

  @Test
  public void testDoGetException() throws Exception {
    setupBasic();
    expect(pipeline.execute(internalRequest)).andThrow(
        new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE));
    replay();

    servlet.doGet(request, recorder);

    assertEquals(HttpServletResponse.SC_BAD_REQUEST, recorder.getHttpStatusCode());
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.GadgetException

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.