-
Bug
-
Resolution: Done
-
Major
-
1.1.GA
-
None
-
None
@Path("/cars/
{make}")
public class CarResource
{
public static enum Color
@GET
@Path("/matrixparam/
@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)
return output;
}
@GET
@Path("/uriinfo/
/
{year}")
@Produces("text/plain")
public String getFromUriInfo(@Context UriInfo info)
}
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("**** 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("**** 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(); }
}