Exemplo n.º 1
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"));
  }
  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;
  }
 @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();
 }
Exemplo n.º 4
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();
    }
Exemplo n.º 5
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));
    }
  }
Exemplo n.º 6
0
 @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;
 }
Exemplo n.º 7
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());
  }
 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;
 }