Package org.apache.shindig.common.uri

Examples of org.apache.shindig.common.uri.Uri


    if (httpApiRequest.href == null) {
      throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST, "href parameter is missing");
    }

    // Canonicalize the path
    Uri href = normalizeUrl(httpApiRequest.href);
    try {
      HttpRequest req = new HttpRequest(href);
      req.setMethod(method);
      if (httpApiRequest.body != null) {
        req.setPostBody(httpApiRequest.body.getBytes());
      }

      // Copy over allowed headers
      for (Map.Entry<String, List<String>> header : httpApiRequest.headers.entrySet()) {
        if (!BAD_HEADERS.contains(header.getKey().trim().toUpperCase())) {
          for (String value : header.getValue()) {
            req.addHeader(header.getKey(), value);
          }
        }
      }

      // Extract the gadget URI from the request or the security token
      final Uri gadgetUri = getGadgetUri(requestItem.getToken(), httpApiRequest);
      if (gadgetUri == null) {
        throw new ProtocolException(HttpServletResponse.SC_BAD_REQUEST,
            "Gadget URI not specified in request");
      }
      req.setGadget(gadgetUri);
View Full Code Here


  public void fetch(HttpServletRequest request, HttpServletResponse response)
          throws GadgetException, IOException {

    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
View Full Code Here

    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);
View Full Code Here

    if (request.getHeader("If-Modified-Since") != null) {
      servletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
      return;
    }

    Uri reqUri = new UriBuilder(request).toUri();

    HttpResponse response;
    try {
      // Parse request uri:
      ProxyUriManager.ProxyUri proxyUri = proxyUriManager.process(reqUri);

      // TODO: Consider removing due to redundant logic.
      String host = request.getHeader("Host");
      if (!lockedDomainService.isSafeForOpenProxy(host)) {
        // Force embedded images and the like to their own domain to avoid XSS
        // in gadget domains.
        Uri resourceUri = proxyUri.getResource();
        String msg = "Embed request for url " + (resourceUri != null ? resourceUri.toString() : "n/a")
            + " 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())) {
View Full Code Here

  public VisitStatus visit(Gadget gadget, Node node) throws RewritingException {
    Attr nodeAttr = getUriAttributeFromNode(node, tagsToMakeAbsolute);

    if (nodeAttr != null) {
      try {
        Uri nodeUri = Uri.parse(nodeAttr.getValue());
        Uri baseUri = getBaseResolutionUri(gadget, node);

        Uri resolved = baseUri.resolve(nodeUri);

        if (!resolved.equals(nodeUri)) {
          nodeAttr.setValue(resolved.toString());
          return VisitStatus.MODIFY;
        }
      } catch (Uri.UriException e) {
        // UriException on illegal input. Ignore.
      }
View Full Code Here

   * @param node The current node being processed.
   * @return The uri to resolve non absolute uri's relative to.
   */
  private Uri getBaseResolutionUri(Gadget gadget, Node node) {
    if (baseUri == null) {
      Uri pageUri = gadget.getSpec().getUrl();
      Uri baseTagUri = getBaseUri(node.getOwnerDocument());
      baseUri = baseTagUri != null ? baseTagUri : pageUri;
    }
    return baseUri;
  }
View Full Code Here

  private void loadTemplateLibraries(GadgetContext context, Feature feature,
      List<TagRegistry> registries, List<TemplateLibrary> librariesthrows GadgetException {
    Collection<String> urls = feature.getParams().get(REQUIRE_LIBRARY_PARAM);
    if (urls != null) {
      for (String url : urls) {
        Uri uri = Uri.parse(url.trim());
        uri = context.getUrl().resolve(uri);

        try {
          TemplateLibrary library = libraryFactory.loadTemplateLibrary(context, uri);
          registries.add(library.getTagRegistry());
View Full Code Here

          throws UriFetchException {
        if (LOG.isLoggable(Level.INFO)) {
          LOG.logp(Level.INFO, CLASS_NAME, "makeFetcher", MessageKeys.RETRIEVE_REFERENCE,
              new Object[] {ref.toString()});
        }
        Uri resourceUri = gadgetUri.resolve(Uri.fromJavaUri(ref.getUri()));
        HttpRequest request =
            new HttpRequest(resourceUri).setContainer(container).setGadget(gadgetUri);
        try {
          HttpResponse response = requestPipeline.execute(request);
          byte[] responseBytes = IOUtils.toByteArray(response.getResponse());
View Full Code Here

        response = new HttpResponseBuilder()
           .setHttpStatusCode(HttpServletResponse.SC_FORBIDDEN)
           .setResponseString("Security token missing")
           .create();
      } else {
        Uri uri = getSocialUri(context, token);

        String socialRequestsJson = JsonSerializer.serialize(socialRequests);
        HttpRequest request = new HttpRequest(uri)
            .setIgnoreCache(context.getIgnoreCache())
            .setSecurityToken(context.getToken())
View Full Code Here

     */
    public RequestAuthenticationInfo evaluate(Expressions expressions, ELContext context)
        throws ELException {
      String hrefString = String.valueOf(expressions.parse(href, String.class)
          .getValue(context));
      final Uri evaluatedHref = base.resolve(Uri.parse(hrefString));

      final Map<String, String> evaluatedAttributes = Maps.newHashMap();
      for (Map.Entry<String, String> attr : attributes.entrySet()) {
        ValueExpression expression = expressions.parse(attr.getValue(), String.class);
        evaluatedAttributes.put(attr.getKey(),
View Full Code Here

TOP

Related Classes of org.apache.shindig.common.uri.Uri

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.