Package org.apache.shindig.gadgets

Examples of org.apache.shindig.gadgets.GadgetException


          builder.append(token.text);
        }
      }
      parsedCss.add(builder.toString());
    } catch (ParseException pe) {
      throw new GadgetException(GadgetException.Code.CSS_PARSE_ERROR, pe);
    }
    return parsedCss;
  }
View Full Code Here


    assertEquals(BASIC_HTML_CONTENT, gadget.getCurrentView().getContent());
  }

  @Test(expected = ProcessingException.class)
  public void handlesGadgetExceptionGracefully() throws Exception {
    gadgetSpecFactory.exception = new GadgetException(GadgetException.Code.INVALID_PATH);
    processor.process(makeContext("url"));
  }
View Full Code Here

      long parseMillis = System.currentTimeMillis() - parseStart;

      output("Serializing [" + parseMillis + " ms total: " +
            ((double) parseMillis) / numRuns + "ms/run]");
    } catch (Exception e) {
      throw new GadgetException(GadgetException.Code.HTML_PARSE_ERROR, e);
    }

    try {
      // Create an "identity" transformer - copies input to output
      Transformer t = TransformerFactory.newInstance().newTransformer();
      t.setOutputProperty(OutputKeys.METHOD, "html");

      long parseStart = System.currentTimeMillis();
      for (int i = 0; i < numRuns; ++i) {
        StringWriter sw = new StringWriter((content.length() * 11) / 10);
        t.transform(new DOMSource(document), new StreamResult(sw));
        sw.toString();
      }
      long parseMillis = System.currentTimeMillis() - parseStart;

      output("Serializing DOM Transformer [" + parseMillis + " ms total: " +
            ((double) parseMillis) / numRuns + "ms/run]");
     
    } catch (Exception e) {
      throw new GadgetException(GadgetException.Code.HTML_PARSE_ERROR, e);
    }
  }
View Full Code Here

    public HttpResponse execute(HttpRequest request) throws GadgetException {
      lastHttpRequest = request;

      if (request.getGadget() == null) {
        throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
            "No gadget associated with rendering request.");
      }

      if (request.getContainer() == null) {
        throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
            "No container associated with rendering request.");
      }

      if (request.getSecurityToken() == null) {
        throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
            "No security token associated with rendering request.");
      }

      if (request.getOAuthArguments() == null) {
        throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
            "No oauth arguments associated with rendering request.");
      }

      assertTrue(request.getOAuthArguments().isProxiedContentRequest());
     
      HttpResponse response;
      switch (request.getAuthType()) {
        case NONE:
          response = plainResponses.get(request.getUri());
          break;
        case SIGNED:
          response = signedResponses.get(request.getUri());
          break;
        case OAUTH:
          response = oauthResponses.get(request.getUri());
          break;
        default:
          response = null;
          break;
      }
      if (response == null) {
        throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
            "Unknown file: " + request.getUri());
      }
      return response;
    }
View Full Code Here

  }

  @Test
  public void handlesRuntimeWrappedGadgetExceptionGracefully() {
    htmlRenderer.runtimeException = new RuntimeException(
        new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "oh no!"));
    RenderingResults results = renderer.render(makeContext("html"));
    assertEquals(RenderingResults.Status.ERROR, results.getStatus());
    assertEquals("oh no!", results.getErrorMessage());
  }
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

  }

  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

  }

  public void testDoGetException() throws Exception {
    setupGet();
    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

  }

  public void testDoPostException() throws Exception {
    setupPost();
    expect(pipeline.execute(internalRequest)).andThrow(
        new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, ERROR_MESSAGE));
    replay();

    servlet.doPost(request, recorder);

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

    public HttpResponse fetch(HttpRequest request) throws GadgetException {
      fetchCount++;
      this.request = request;
      if (response == null) {
        throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT);
      }
      return response;
    }
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.