Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-275

@PathParam fails injecting List<PathSegment

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.2.RC1
    • 1.1.GA
    • None
    • None

      @Path("/cars/

      {make}

      ")
      public class CarResource
      {
      public static enum Color

      { red, white, blue, black }

      @GET
      @Path("/matrixparam/

      {model}/{year}")
      @Produces("text/plain")
      public String getFromMatrixParam(@PathParam("make") String make,
      @PathParam("model") PathSegment car,
      @MatrixParam("color") Color color,
      @PathParam("year") String year) { return "A " + color + " " + year + " " + make + " " + car.getPath(); }


      @GET
      @Path("/pathsegment/{model}

      /

      {year}")
      @Produces("text/plain")
      public String getFromPathSegment(@PathParam("make") String make,
      @PathParam("model") PathSegment car,
      @PathParam("year") String year) { String carColor = car.getMatrixParameters().getFirst("color"); return "A " + carColor + " " + year + " " + make + " " + car.getPath(); }
      @GET
      @Path("/pathsegments/{model : .+}/year/{year}

      ")
      @Produces("text/plain")
      public String getFromMultipleSegments(@PathParam("make") String make,
      @PathParam("model") List<PathSegment> car,
      @PathParam("year") String year) {
      String output = "A " + year + " " + make;
      for (PathSegment segment : car)

      { output += " " + segment.getPath(); }

      return output;
      }

      @GET
      @Path("/uriinfo/

      {model}

      /

      {year}

      ")
      @Produces("text/plain")
      public String getFromUriInfo(@Context UriInfo info)

      { String make = info.getPathParameters().getFirst("make"); String year = info.getPathParameters().getFirst("year"); PathSegment model = info.getPathSegments().get(1); String color = model.getMatrixParameters().getFirst("color"); return "A " + color + " " + year + " " + make + " " + model.getPath(); }

      }

      public class InjectionTest
      {
      @Test
      public void testCarResource() throws Exception
      {
      DefaultHttpClient client = new DefaultHttpClient();

      System.out.println("**** Via @MatrixParam ***");
      HttpGet get = new HttpGet("http://localhost:9095/cars/mercedes/matrixparam/e55;color=black/2006");
      HttpResponse response = client.execute(get);
      Assert.assertEquals(200, response.getStatusLine().getStatusCode());
      BufferedReader reader = new BufferedReader(new
      InputStreamReader(response.getEntity().getContent()));

      String line = reader.readLine();
      while (line != null)

      { System.out.println(line); line = reader.readLine(); }

      System.out.println("**** Via PathSegment ***");
      get = new HttpGet("http://localhost:9095/cars/mercedes/pathsegment/e55;color=black/2006");
      response = client.execute(get);
      Assert.assertEquals(200, response.getStatusLine().getStatusCode());
      reader = new BufferedReader(new
      InputStreamReader(response.getEntity().getContent()));

      line = reader.readLine();
      while (line != null)
      { System.out.println(line); line = reader.readLine(); }

      System.out.println("**** Via PathSegments ***");
      get = new HttpGet("http://localhost:9095/cars/mercedes/pathsegments/e55/amg/year/2006");
      response = client.execute(get);
      Assert.assertEquals(200, response.getStatusLine().getStatusCode());
      reader = new BufferedReader(new
      InputStreamReader(response.getEntity().getContent()));

      line = reader.readLine();
      while (line != null)

      { System.out.println(line); line = reader.readLine(); }

      System.out.println("**** Via PathSegment ***");
      get = new HttpGet("http://localhost:9095/cars/mercedes/uriinfo/e55;color=black/2006");
      response = client.execute(get);
      Assert.assertEquals(200, response.getStatusLine().getStatusCode());
      reader = new BufferedReader(new
      InputStreamReader(response.getEntity().getContent()));

      line = reader.readLine();
      while (line != null)
      { System.out.println(line); line = reader.readLine(); }

      }

            patriot1burke@gmail.com Bill Burke (Inactive)
            patriot1burke@gmail.com Bill Burke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: