Package org.apache.shindig.gadgets

Examples of org.apache.shindig.gadgets.GadgetException


        BasicOAuthStoreConsumerKeyAndSecret cks = consumerInfos.get(pk);
        if (cks == null) {
            cks = defaultKey;
        }
        if (cks == null) {
            throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR,
                    "No key for gadget " + securityToken.getAppUrl() + " and service " + serviceName);
        }
        OAuthConsumer consumer = null;
        if (cks.getKeyType() == BasicOAuthStoreConsumerKeyAndSecret.KeyType.RSA_PRIVATE) {
            consumer = new OAuthConsumer(null, cks.getConsumerKey(), null, provider);
View Full Code Here


  }

  private HttpResponse fetch(HttpGadgetContext context) throws GadgetException {

    if (context.getUrl() == null) {
      throw new GadgetException(Code.INVALID_PARAMETER, "Missing url paramater",
          HttpResponse.SC_BAD_REQUEST);
    }

    HttpRequest request = new HttpRequest(context.getUrl())
        .setIgnoreCache(context.getIgnoreCache())
View Full Code Here

    // Rewrite the response
    if (contentRewriterRegistry != null) {
      try {
        results = contentRewriterRegistry.rewriteHttpResponse(rcr, results);
      } catch (RewritingException e) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e,
            e.getHttpStatusCode());
      }
    }

    // Serialize the response
View Full Code Here

    if (headerData.length() > 0) {
      String[] headerList = StringUtils.split(headerData, '&');
      for (String header : headerList) {
        String[] parts = StringUtils.splitPreserveAllTokens(header, '=');
        if (parts.length != 2) {
          throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
              "Malformed header param specified:" + header, HttpResponse.SC_BAD_REQUEST);
        }
        String headerName = Utf8UrlCoder.decode(parts[0]);
        if (!HttpRequestHandler.BAD_HEADERS.contains(headerName.toUpperCase())) {
          req.addHeader(headerName, Utf8UrlCoder.decode(parts[1]));
View Full Code Here

          .getBytes(encoding.toUpperCase()));
    } catch (UnsupportedEncodingException e) {
      // We might consider enumerating at least a small list of encodings
      // that we must always honor. For now, we return SC_BAD_REQUEST since
      // the encoding parameter could theoretically be anything.
      throw new GadgetException(Code.HTML_PARSE_ERROR, e, HttpResponse.SC_BAD_REQUEST);
    }   
  }
View Full Code Here

   */
  private SecurityToken extractAndValidateToken(HttpServletRequest request) throws GadgetException {
    SecurityToken token = new AuthInfo(request).getSecurityToken();
    if (token == null) {
      // TODO: Determine appropriate external error code for this.
      throw new GadgetException(GadgetException.Code.INVALID_SECURITY_TOKEN);
    }
    return token;
  }
View Full Code Here

  }

  public void normalizeProtocol(HttpRequest request) throws GadgetException {
    // Normalize the protocol part of the URI
    if (request.getUri().getScheme()== null) {
      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
          "Url " + request.getUri().toString() + " does not include scheme",
          HttpResponse.SC_BAD_REQUEST);
    } else if (!"http".equals(request.getUri().getScheme()) &&
        !"https".equals(request.getUri().getScheme())) {
      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
          "Invalid request url scheme in url: " + Utf8UrlCoder.encode(request.getUri().toString()) +
            "; only \"http\" and \"https\" supported.",
            HttpResponse.SC_BAD_REQUEST);
    }
  }
View Full Code Here

      try {
        inlineJs.append(ResourceLoader.getContent(dateTimeConstantsResource))
            .append('\n').append(ResourceLoader.getContent(numberConstantsResource));
        i18nConstantsCache.put(locale, inlineJs.toString());
      } catch (IOException e) {
        throw new GadgetException(GadgetException.Code.INVALID_CONFIG,
            "Unexpected inability to load i18n data for locale: " + localeName,
            HttpResponse.SC_INTERNAL_SERVER_ERROR);
      }
    }
    Element inlineTag = headTag.getOwnerDocument().createElement("script");
View Full Code Here

      int retcode = response.getHttpStatusCode();
      if (retcode == HttpResponse.SC_INTERNAL_SERVER_ERROR) {
        // Convert external "internal error" to gateway error:
        retcode = HttpResponse.SC_BAD_GATEWAY;
      }
      throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
          "Unable to retrieve template library xml. HTTP error " +
          response.getHttpStatusCode(), retcode);     
    }
   
    String content = response.getResponseAsString();
    try {
      String key = null;
      Element element = null;
      if (!context.getIgnoreCache()) {
        try {
          key = HashUtil.rawChecksum(content.getBytes("UTF-8"));
          element = parsedXmlCache.getElement(key);
        } catch (UnsupportedEncodingException e) {
          // this won't happen, but if it does, cache won't be used.
        }
      }
     
      if (element == null) {
        element = XmlUtil.parse(content);
        if (key != null) {
          parsedXmlCache.addElement(key, element);
        }
      }

      return new XmlTemplateLibrary(uri, element, content);
    } catch (XmlException e) {
      throw new GadgetException(GadgetException.Code.MALFORMED_XML_DOCUMENT, e,
          HttpResponse.SC_BAD_REQUEST);
    }
  }
View Full Code Here

      if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
        StringBuilder err = new StringBuilder();
        for (Message m : mq.getMessages()) {
          err.append(m.toString()).append("\n");
        }
        throw new GadgetException(GadgetException.Code.HTML_PARSE_ERROR, err.toString(),
            HttpResponse.SC_BAD_REQUEST);
      }
      return fragment;
    } catch (ParseException e) {
      throw new GadgetException(
          GadgetException.Code.HTML_PARSE_ERROR, e.getCajaMessage().toString(),
          HttpResponse.SC_BAD_REQUEST);
    }
  }
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.