Package org.apache.shindig.gadgets

Examples of org.apache.shindig.gadgets.GadgetException


   */
  private SecurityToken extractAndValidateToken(HttpServletRequest request) throws GadgetException {
    SecurityToken token = AuthInfoUtil.getSecurityTokenFromRequest(request);
    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


    boolean getSummaries = Boolean.parseBoolean(getParameter(req, GET_SUMMARIES_PARAM, "false"));
    int numEntries;
    try {
      numEntries = Integer.valueOf(getParameter(req, NUM_ENTRIES_PARAM, DEFAULT_NUM_ENTRIES));
    } catch (NumberFormatException e) {
      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
              "numEntries paramater is not a number", HttpResponse.SC_BAD_REQUEST);
    }
    return feedProcessorProvider.get().process(url, xml, getSummaries, numEntries).toString();
  }
View Full Code Here

      refreshInterval = 0;
    } else if (getParameter(request, Param.REFRESH.getKey(), null) != null) {
      try {
        refreshInterval = Integer.valueOf(getParameter(request, Param.REFRESH.getKey(), null));
      } 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

    if (!fetchedResponse.isError() && !request.getIgnoreCache() && request.getCacheTtl() != 0) {
      try {
        fetchedResponse = responseRewriterRegistry.rewriteHttpResponse(request, fetchedResponse, null);
      } catch (RewritingException e) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e, e.getHttpStatusCode());
      }
    }

    // Set response hash value in metadata (used for url versioning)
    fetchedResponse = HttpResponseMetadataHelper.updateHash(fetchedResponse, metadataHelper);
View Full Code Here

  }

  protected 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

            + " made to wrong domain " + host;
        if (LOG.isLoggable(Level.INFO)) {
          LOG.logp(Level.INFO, classname, "processRequest", MessageKeys.EMBEDED_IMG_WRONG_DOMAIN,
            new Object[] { resourceUri != null ? resourceUri.toString() : "n/a", host });
        }
        throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, msg,
          HttpResponse.SC_BAD_REQUEST);
      }
      if ("POST".equalsIgnoreCase(request.getMethod())) {
        StringBuffer buffer = getPOSTContent(request);
        response = proxyHandler.fetch(proxyUri, buffer.toString());
      } else {
        response = proxyHandler.fetch(proxyUri);
      }
    } catch (GadgetException e) {
      response = ServletUtil.errorResponse(new GadgetException(e.getCode(), e.getMessage(),
          HttpServletResponse.SC_BAD_REQUEST));
    }

    ServletUtil.copyToServletResponseAndOverrideCacheHeaders(response, servletResponse);
  }
View Full Code Here

      return UseToken.IF_AVAILABLE;
    }
    if ("never".equals(useTokenStr)) {
      return UseToken.NEVER;
    }
    throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
        "Unknown use token value " + useTokenStr);
  }
View Full Code Here

    HttpRequest request = new HttpRequest(uri);
    // 5 minute TTL.
    request.setCacheTtl(300);
    HttpResponse response = pipeline.execute(request);
    if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
      throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
          "Unable to retrieve template library xml. HTTP error " +
          response.getHttpStatusCode());     
    }
   
    String content = response.getResponseAsString();
    try {
      String key = null;
      Element element = null;
      if (!context.getIgnoreCache()) {
        key = HashUtil.rawChecksum(content.getBytes());
        element = parsedXmlCache.getElement(key);
      }
     
      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);
    }
  }
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");
    } 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.");
    }
  }
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.");
    }
    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.");
      }
      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);
    }
  }
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.