Package org.cruxframework.crux.core.server.rest.spi

Examples of org.cruxframework.crux.core.server.rest.spi.UriInfo


    return pathExpression;
  }

  protected void populatePathParams(HttpRequest request, Matcher matcher, String path)
  {
    UriInfo uriInfo = (UriInfo) request.getUri();
    for (Group group : groups)
    {
      String value = matcher.group(group.group);
      uriInfo.addEncodedPathParameter(group.name, value);
      int index = matcher.start(group.group);

      int start = 0;
      if (path.charAt(0) == '/')
        start++;
      int segmentIndex = 0;

      if (start < path.length())
      {
        int count = 0;
        for (int i = start; i < index && i < path.length(); i++)
        {
          if (path.charAt(i) == '/')
            count++;
        }
        segmentIndex = count;
      }

      int numSegments = 1;
      for (int i = 0; i < value.length(); i++)
      {
        if (value.charAt(i) == '/')
          numSegments++;
      }

      if (segmentIndex + numSegments > request.getUri().getPathSegments().size())
      {

        throw new BadRequestException("Number of matched segments greater than actual", "Can not invoke requested service");
      }
      PathSegment[] encodedSegments = new PathSegment[numSegments];
      PathSegment[] decodedSegments = new PathSegment[numSegments];
      for (int i = 0; i < numSegments; i++)
      {
        decodedSegments[i] = request.getUri().getPathSegments().get(segmentIndex + i);
        encodedSegments[i] = request.getUri().getPathSegments(false).get(segmentIndex + i);
      }
      uriInfo.getEncodedPathParameterPathSegments().add(group.name, encodedSegments);
      uriInfo.getPathParameterPathSegments().add(group.name, decodedSegments);
    }
  }
View Full Code Here


    }
  }

  public ResourceMethod matchPattern(HttpRequest request, String path, int start)
  {
    UriInfo uriInfo = (UriInfo) request.getUri();
    Matcher matcher = pattern.matcher(path);
    matcher.region(start, path.length());

    if (matcher.matches())
    {
      // we consumed entire path string
      ResourceMethod invoker = match(request.getHttpMethod(), request);
      if (invoker == null)
      {
        throw new NotFoundException("Could not find resource for relative : " + path + " of full path: " + request.getUri().getRequestUri());
      }
      uriInfo.pushMatchedURI(path, Encode.decode(path));
      populatePathParams(request, matcher, path);
      return invoker;
    }
    throw new NotFoundException("Could not find resource for relative : " + path + " of full path: " + request.getUri().getRequestUri());
  }
View Full Code Here

      return segment;
   }

   public ResourceMethod matchSimple(HttpRequest request, String path, int start)
   {
      UriInfo uriInfo = request.getUri();
      if (start + segment.length() == path.length()) // we've reached end of string
      {
        ResourceMethod invoker = match(request.getHttpMethod(), request);
         if (invoker == null)
            throw new NotFoundException("Could not find resource for relative : " + path + " of full path: " + request.getUri().getRequestUri());

         uriInfo.pushMatchedURI(path, Encode.decode(path));
         return invoker;
      }
      else
      {
           return matchChildren(request, path, start + segment.length() + 1); // + 1 to ignore '/'
View Full Code Here

    if (!RestServiceFactoryInitializer.isFactoryInitialized())
    {
      RestServiceFactoryInitializer.initialize(getServletContext());
    }
    HttpHeaders headers = null;
    UriInfo uriInfo = null;
    try
    {
      headers = HttpUtil.extractHttpHeaders(req);
      uriInfo = HttpUtil.extractUriInfo(req);
    }
View Full Code Here

    if (!RestServiceFactoryInitializer.isFactoryInitialized())
    {
      RestServiceFactoryInitializer.initialize(getServletContext());
    }
    HttpHeaders headers = null;
    UriInfo uriInfo = null;
    try
    {
      headers = HttpUtil.extractHttpHeaders(req);
      uriInfo = HttpUtil.extractUriInfo(req);
    }
View Full Code Here

TOP

Related Classes of org.cruxframework.crux.core.server.rest.spi.UriInfo

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.