Examples of GadgetException


Examples of org.apache.shindig.gadgets.GadgetException

        featureRegistryProvider.get(jsUri.getRepository())).build(jsUri, null);
    JsResponse jsResponse;
    try {
      jsResponse = jsServingPipeline.execute(jsRequest);
    } catch (JsException e) {
      throw new GadgetException(Code.JS_PROCESSING_ERROR, e, e.getStatusCode());
    }
    return jsResponse.toJsString();
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

      this.cache.clearTokens();
    } catch (final OAuth2PersistenceException e) {
      if (isLogging) {
        BasicOAuth2Store.LOG.log("Error clearing OAuth2 cache", e);
      }
      throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error clearing OAuth2 cache", e);
    }

    if (isLogging) {
      BasicOAuth2Store.LOG.exiting(BasicOAuth2Store.LOG_CLASS, "clearCache", true);
    }
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

        }
      } catch (final OAuth2PersistenceException e) {
        if (isLogging) {
          BasicOAuth2Store.LOG.log("Error loading OAuth2 client ", e);
        }
        throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error loading OAuth2 client "
            + serviceName, e);
      }
    }

    if (isLogging) {
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

        token = this.persister.findToken(gadgetUri, serviceName, user, scope, type);
        if (token != null) {
          this.cache.storeToken(token);
        }
      } catch (final OAuth2PersistenceException e) {
        throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error loading OAuth2 token " + index,
            e);
      }
    }

    if (isLogging) {
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

      if (isLogging) {
        BasicOAuth2Store.LOG.log("clients = {0}", clients);
      }
      this.cache.storeClients(clients);
    } catch (final OAuth2PersistenceException e) {
      throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error loading OAuth2 clients", e);
    }

    try {
      final Set<OAuth2Token> tokens = this.persister.loadTokens();
      if (isLogging) {
        BasicOAuth2Store.LOG.log("tokens = {0}", tokens);
      }
      this.cache.storeTokens(tokens);
    } catch (final OAuth2PersistenceException e) {
      throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error loading OAuth2 tokens", e);
    }

    if (isLogging) {
      BasicOAuth2Store.LOG.exiting(BasicOAuth2Store.LOG_CLASS, "init", true);
    }
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

      return token;
    } catch (final OAuth2PersistenceException e) {
      if (isLogging) {
        BasicOAuth2Store.LOG.log("Error loading OAuth2 token ", e);
      }
      throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error loading OAuth2 token "
          + serviceName, e);
    }
  }
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

        this.cache.storeToken(token);
      } catch (final OAuth2CacheException e) {
        if (isLogging) {
          BasicOAuth2Store.LOG.log("Error storing OAuth2 token " + index, e);
        }
        throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error storing OAuth2 token " + index,
            e);
      } catch (final OAuth2PersistenceException e) {
        if (isLogging) {
          BasicOAuth2Store.LOG.log("Error storing OAuth2 token " + index, e);
        }
        throw new GadgetException(Code.OAUTH_STORAGE_ERROR, "Error storing OAuth2 token " + index,
            e);
      }
    }

    if (isLogging) {
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

    HttpRequest rcr = buildHttpRequest(request);
    String container = rcr.getContainer();
    final Uri gadgetUri = rcr.getGadget();
    if (gadgetUri == null) {
      throw new GadgetException(GadgetException.Code.MISSING_PARAMETER,
              "Unable to find gadget in request", HttpResponse.SC_FORBIDDEN);
    }

    Gadget gadget;
    GadgetContext context = new HttpGadgetContext(request) {
      @Override
      public Uri getUrl() {
        return gadgetUri;
      }
      @Override
      public boolean getIgnoreCache() {
        return getParameter("bypassSpecCache").equals("1");
      }
    };
    try {
      gadget = processor.process(context);
    } catch (ProcessingException e) {
      throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR,
              "Error processing gadget", e, HttpResponse.SC_BAD_REQUEST);
    }

    // Validate gadget is correct for the host.
    // Ensures that the gadget has not hand crafted this request to represent itself as
    // another gadget in a locked domain environment.
    if (!lockedDomainService.isGadgetValidForHost(context.getHost(), gadget, container)) {
      throw new GadgetException(GadgetException.Code.GADGET_HOST_MISMATCH,
              "The gadget is incorrect for this request", HttpResponse.SC_FORBIDDEN);
    }

    if (!gadgetAdminStore.isWhitelisted(container, gadgetUri.toString())) {
      throw new GadgetException(GadgetException.Code.NON_WHITELISTED_GADGET,
              "The requested content is unavailable", HttpResponse.SC_FORBIDDEN);
    }

    // Serialize the response
    HttpResponse results = requestPipeline.execute(rcr);

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

    // Serialize the response
View Full Code Here

Examples of org.apache.shindig.gadgets.GadgetException

   * @throws GadgetException
   */
  protected HttpRequest buildHttpRequest(HttpServletRequest request) throws GadgetException {
    String urlStr = getParameter(request, Param.URL.getKey(), null);
    if (urlStr == null) {
      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, Param.URL.getKey()
              + " parameter is missing.", HttpResponse.SC_BAD_REQUEST);
    }

    Uri url;
    try {
      url = ServletUtil.validateUrl(Uri.parse(urlStr));
    } catch (IllegalArgumentException e) {
      throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid "
              + Param.URL.getKey() + " parameter", HttpResponse.SC_BAD_REQUEST);
    }

    SecurityToken token = AuthInfoUtil.getSecurityTokenFromRequest(request);
    String container = null;
    Uri gadgetUri = null;
    if ("1".equals(getParameter(request, MULTI_PART_FORM_POST, null))) {
      // This endpoint is being used by the proxied-form-post feature.
      // Require a token.
      if (token == null) {
        throw new GadgetException(GadgetException.Code.INVALID_SECURITY_TOKEN);
      }
    }

    // If we have a token, we should use it.
    if (token != null && !token.isAnonymous()) {
      container = token.getContainer();
      String appurl = token.getAppUrl();
      if (appurl != null) {
        gadgetUri = Uri.parse(appurl);
      }
    } else {
      container = getContainer(request);
      String gadgetUrl = getParameter(request, Param.GADGET.getKey(), null);
      if (gadgetUrl != null) {
        gadgetUri = Uri.parse(gadgetUrl);
      }
    }

    HttpRequest req = new HttpRequest(url).setMethod(getParameter(request, METHOD_PARAM, "GET"))
            .setContainer(container).setGadget(gadgetUri);

    if ("POST".equals(req.getMethod()) || "PUT".equals(req.getMethod())) {
      setPostData(container, request, req);
    }

    String headerData = getParameter(request, HEADERS_PARAM, "");
    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

Examples of org.apache.shindig.gadgets.GadgetException

   * and defaulted to utf8 Override the function if different behavior is needed.
   */
  protected void setPostData(String container, HttpServletRequest request, HttpRequest req)
          throws GadgetException {
    if (maxPostSizes.get(container) < request.getContentLength()) {
      throw new GadgetException(GadgetException.Code.POST_TOO_LARGE, "Posted data too large.",
          HttpResponse.SC_REQUEST_ENTITY_TOO_LARGE);
    }

    String encoding = request.getCharacterEncoding();
    if (encoding == null) {
      encoding = "UTF-8";
    }
    try {
      String contentType = request.getHeader("Content-Type");
      if (contentType != null && contentType.startsWith("multipart/form-data")) {
        // TODO: This will read the entire posted response in server memory.
        // Is there a way to stream this even with OAUTH flows?
        req.setPostBody(request.getInputStream());
      } else {
        req.setPostBody(getParameter(request, POST_DATA_PARAM, "").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);
    } catch (IOException e) {
      // Something went wrong reading the request data.
      // TODO: perhaps also support a max post size and enforce it by throwing and catching
      // exceptions here.
      throw new GadgetException(Code.INTERNAL_SERVER_ERROR, e, HttpResponse.SC_BAD_REQUEST);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.