@GET
 @Produces("text/plain")
 @Path("decoded/segment/{pathParam}")
 public String getDecodedSegmentPathParam(@PathParam("pathParam") PathSegment segment) {
   System.out.println("getDecodedSegmentPathParam(): decoded segment: " + segment.getPath());
   return segment.getPath();
 }
Example #2
0
 /**
  * Takes a list of path segments and returns an array of paths. Useful for gathering multiple
  * parameters in the form of /parameterlist/param1/param2/param3/param4 where the array would
  * contain param1-param4.
  *
  * @param parameters
  * @return
  */
 public static String[] pathSegmentToPathArray(final List<? extends PathSegment> parameters) {
   final List<String> pathParams = newList();
   for (final PathSegment segment : parameters) {
     pathParams.add(segment.getPath());
   }
   return pathParams.toArray(new String[pathParams.size()]);
 }
    String acc(PathSegment... ps) {
      String s = "";
      for (PathSegment p : ps) {
        s += p.getPath();
      }

      return s;
    }
 public static String toString(List<PathSegment> segments) {
   StringBuilder builder = new StringBuilder();
   String delim = ""; // $NON-NLS-1$
   for (PathSegment segment : segments) {
     builder.append(delim);
     builder.append(segment.toString());
     delim = "/"; // $NON-NLS-1$
   }
   return builder.toString();
 }
 @GET
 public String doGet(
     @PathParam("arg1") PathSegment arg1,
     @PathParam("arg2") PathSegment arg2,
     @PathParam("arg3") PathSegment arg3) {
   assertEquals("a", arg1.getPath());
   assertEquals("b", arg2.getPath());
   assertEquals("c", arg3.getPath());
   return "content";
 }
 @GET
 public String doGet(
     @PathParam("a") PathSegment a,
     @PathParam("b") PathSegment b,
     @PathParam("c") PathSegment c,
     @PathParam("d") PathSegment d) {
   assertEquals(a.getPath(), b.getPath());
   assertEquals(c.getPath(), d.getPath());
   return "content";
 }
Example #7
0
  URI getLocation(UriInfo info, String id) {
    List<PathSegment> segments = info.getPathSegments();
    List<PathSegment> patate = segments.subList(0, segments.size() - 1);
    StringBuilder root = new StringBuilder();
    for (PathSegment s : patate) {
      root.append('/').append(s.getPath());
    }
    root.append("/session");

    return info.getBaseUriBuilder().path(root.toString()).path(id).build();
  }
 @GET
 public String doGet(@PathParam("a") List<PathSegment> a) {
   StringBuilder s = new StringBuilder();
   for (PathSegment p : a) {
     if (p.getPath().length() == 0) {
       s.append('/');
     } else {
       s.append(p.getPath());
     }
   }
   return s.toString();
 }
Example #9
0
    @Produces(MediaType.TEXT_PLAIN)
    @GET
    @Path("/matrix/{id}")
    public String matrixparamtest(@PathParam("id") PathSegment id) {
      StringBuffer sb = new StringBuffer();
      sb.append("matrix=");

      sb.append("/" + id.getPath());
      MultivaluedMap<String, String> matrix = id.getMatrixParameters();
      Set<String> keys = matrix.keySet();
      for (Object key : keys) {
        sb.append(";" + key.toString() + "=" + matrix.getFirst(key.toString()));
      }
      return sb.toString();
    }
Example #10
0
  /** Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}. */
  @Test
  public void testGetPathSegmentsMultipleMatrix() {
    final UriInfo ui = createContext("/p;x=1;x=2;x=3", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(1, segments.size());

    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;

    segment = psi.next();
    MultivaluedMap<String, String> m = segment.getMatrixParameters();
    List<String> values = m.get("x");
    for (int i = 0; i < m.size(); i++) {
      assertEquals(Integer.valueOf(i + 1).toString(), values.get(i));
    }
  }
 @GET
 @Produces("text/plain")
 public String get(
     @MatrixParam("firstname") String firstname,
     @MatrixParam("lastname") String lastname,
     @Context UriInfo uriInfo) {
   final List<PathSegment> pathSegents = uriInfo.getPathSegments();
   final PathSegment lastPathSegm = pathSegents.get(0);
   final MultivaluedMap<String, String> mp = lastPathSegm.getMatrixParameters();
   if (mp.isEmpty()) {
     final ResponseBuilder rb = Response.status(Status.NOT_FOUND);
     rb.entity("matrix parameters are empty");
     throw new WebApplicationException(rb.build());
   }
   return firstname + " " + lastname;
 }
Example #12
0
  /** Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}. */
  @Test
  public void testGetPathSegmentsGeneral() {
    final UriInfo ui = createContext("/p1;x=1;y=1/p2;x=2;y=2/p3;x=3;y=3", "GET");

    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(3, segments.size());

    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;

    segment = psi.next();
    assertEquals("p1", segment.getPath());
    MultivaluedMap<String, String> m = segment.getMatrixParameters();
    assertEquals("1", m.getFirst("x"));
    assertEquals("1", m.getFirst("y"));

    segment = psi.next();
    assertEquals("p2", segment.getPath());
    m = segment.getMatrixParameters();
    assertEquals("2", m.getFirst("x"));
    assertEquals("2", m.getFirst("y"));

    segment = psi.next();
    assertEquals("p3", segment.getPath());
    m = segment.getMatrixParameters();
    assertEquals("3", m.getFirst("x"));
    assertEquals("3", m.getFirst("y"));
  }
Example #13
0
 @GET
 @Path("/{id}/{id1}/{id2}/{id3}")
 public String quard(
     @PathParam("id") double id,
     @PathParam("id1") boolean id1,
     @PathParam("id2") byte id2,
     @PathParam("id3") PathSegment id3) {
   return "quard=" + id + id1 + id2 + id3.getPath();
 }
Example #14
0
 @GET
 @Path("/{id}/{id1}/{id2}/{id3}/{id4}")
 public String penta(
     @PathParam("id") long id,
     @PathParam("id1") String id1,
     @PathParam("id2") short id2,
     @PathParam("id3") boolean id3,
     @PathParam("id4") PathSegment id4) {
   return "penta=" + id + id1 + id2 + id3 + id4.getPath();
 }
  @Path("{itemName}")
  public AbstractContextResource addNameParameter(
      @Context UriInfo ui, @PathParam("itemName") PathSegment itemName) throws Exception {

    logger.debug("ServiceResource.addNameParameter");

    logger.debug("Current segment is {}", itemName.getPath());

    if (itemName.getPath().startsWith("{")) {
      Query query = Query.fromJsonString(itemName.getPath());
      if (query != null) {
        addParameter(getServiceParameters(), query);
      }
    } else {
      addParameter(getServiceParameters(), itemName.getPath());
    }

    addMatrixParams(getServiceParameters(), ui, itemName);

    return getSubResource(ServiceResource.class);
  }
  public static List<ServiceParameter> addMatrixParams(
      List<ServiceParameter> parameters, UriInfo ui, PathSegment ps) throws Exception {

    MultivaluedMap<String, String> params = ps.getMatrixParameters();

    if (params != null) {
      Query query = Query.fromQueryParams(params);
      if (query != null) {
        parameters = addParameter(parameters, query);
      }
    }

    return parameters;
  }
  @Path("{entityId: [A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}}")
  public AbstractContextResource addIdParameter(
      @Context UriInfo ui, @PathParam("entityId") PathSegment entityId) throws Exception {

    logger.debug("ServiceResource.addIdParameter");

    UUID itemId = UUID.fromString(entityId.getPath());

    addParameter(getServiceParameters(), itemId);

    addMatrixParams(getServiceParameters(), ui, entityId);

    return getSubResource(ServiceResource.class);
  }
 @GET
 @Produces("text/plain")
 @Path("decoded/segment/matrix/{params}")
 public String getDecodedSegmentMatrixParam(@PathParam("params") PathSegment segment) {
   MultivaluedMap<String, String> map = segment.getMatrixParameters();
   Iterator<String> it = map.keySet().iterator();
   System.out.println("getDecodedSegmentMatrixParam(): decoded matrix params: ");
   StringBuilder builder = new StringBuilder();
   while (it.hasNext()) {
     String key = it.next();
     System.out.println("  " + key + "->" + map.getFirst(key));
     builder.append(map.getFirst(key));
   }
   return builder.toString();
 }
 @Path("{e}-{f}")
 @GET
 public String doGetSub(
     @PathParam("a") PathSegment a,
     @PathParam("b") PathSegment b,
     @PathParam("c") PathSegment c,
     @PathParam("d") PathSegment d,
     @PathParam("e") PathSegment e,
     @PathParam("f") PathSegment f) {
   assertEquals(a.getPath(), b.getPath());
   assertEquals(c.getPath(), d.getPath());
   assertEquals(e.getPath(), f.getPath());
   return "sub-content";
 }
    @GET
    public String doGet(@PathParam("a") List<PathSegment> a, @PathParam("b") List<PathSegment> b) {
      StringBuilder s = new StringBuilder();
      for (PathSegment p : a) {
        if (p.getPath().isEmpty()) {
          s.append('/');
        } else {
          s.append(p.getPath());
        }
      }
      s.append('-');
      for (PathSegment p : b) {
        if (p.getPath().isEmpty()) {
          s.append('/');
        } else {
          s.append(p.getPath());
        }
      }

      return s.toString();
    }
 @GET
 public String doGet(@PathParam("a") PathSegment a) {
   return a.getPath();
 }
 @GET
 public String doGet(@PathParam("a") PathSegment a, @PathParam("b") PathSegment b) {
   return a.getPath() + "-" + b.getPath();
 }
 public static PathSegmentImpl decode(PathSegment segment) {
   PathSegmentImpl clone = new PathSegmentImpl();
   clone.path = UriEncoder.decodeString(segment.getPath());
   clone.matrixParams = UriEncoder.decodeMultivaluedMap(segment.getMatrixParameters(), true);
   return clone;
 }
 @GET
 @Path("/{id}")
 public String getSub(@PathParam("id") PathSegment id) {
   return id.getPath();
 }
 public int compareTo(PathSegment o) {
   return path.compareTo(o.getPath());
 }
 private PathSegment mockPathSegment(final String segment) {
   PathSegment pathSegment = mock(PathSegment.class);
   when(pathSegment.getPath()).thenReturn(segment);
   return pathSegment;
 }
 @GET
 public String get() {
   return ps.getPath();
 }
Example #28
0
  /** Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}. */
  @Test
  public void testGetPathSegmentsMultipleSlash() {
    final UriInfo ui = createContext("/p//p//p//", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(7, segments.size());

    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;

    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());

    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());

    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());

    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());

    segment = psi.next();
    assertEquals("p", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());

    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());

    segment = psi.next();
    assertEquals("", segment.getPath());
    assertEquals(0, segment.getMatrixParameters().size());
  }
 @GET
 public String get(@PathParam("id") PathSegment id) {
   return id.getPath();
 }
Example #30
0
 @GET
 @Path("/{id}/{id1}/{id2}")
 public String triple(
     @PathParam("id") int id, @PathParam("id1") PathSegment id1, @PathParam("id2") float id2) {
   return "triple=" + id + id1.getPath() + id2;
 }