1 |
package dk.thoerup.webservice; |
package dk.thoerup.webservice; |
2 |
|
|
3 |
|
import java.io.Serializable; |
4 |
|
|
5 |
import javax.ws.rs.GET; |
import javax.ws.rs.GET; |
6 |
import javax.ws.rs.Path; |
import javax.ws.rs.Path; |
7 |
import javax.ws.rs.Produces; |
import javax.ws.rs.Produces; |
8 |
import javax.ws.rs.core.MediaType; |
import javax.ws.rs.core.MediaType; |
9 |
|
import javax.xml.bind.annotation.XmlRootElement; |
10 |
|
|
11 |
@Path("/Rest") |
@Path("/samples") |
12 |
public class RestSimpleJerseyTest { |
public class RestSimpleJerseyTest { |
13 |
|
|
14 |
public static class TestResponse { |
|
15 |
public int id; |
@Path("/simple") |
|
public String name; |
|
|
|
|
|
public TestResponse(int i, String n) { |
|
|
this.id = i; |
|
|
this.name = n; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
@Path("/Simple") |
|
16 |
@GET |
@GET |
17 |
@Produces(MediaType.TEXT_PLAIN) |
@Produces(MediaType.TEXT_PLAIN) |
18 |
public String getIt() { |
public String getIt() { |
19 |
return "Got it!"; |
return "Got it!"; |
20 |
} |
} |
21 |
|
|
22 |
@Path("/Object") |
@Path("/json") |
23 |
|
@GET |
24 |
|
@Produces(MediaType.APPLICATION_JSON) |
25 |
|
public TestResponse getJSON() { |
26 |
|
return new TestResponse(1, "Hej"); |
27 |
|
} |
28 |
|
|
29 |
|
@Path("/xml") |
30 |
@GET |
@GET |
31 |
@Produces({"application/xml", "application/json"}) |
@Produces(MediaType.APPLICATION_XML) |
32 |
public TestResponse getObj() { |
public TestResponse getXML() { |
33 |
return new TestResponse(1, "Hej"); |
return new TestResponse(1, "Hej"); |
34 |
} |
} |
35 |
|
|