annotate src/main/java/de/intevation/rest/RESTService.java @ 21:f4bc98fb8aac

Added new links to trigger creation and deletion
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 26 Apr 2013 15:00:08 +0200
parents 5dcccaf3d007
children
rev   line source
4
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
1 package de.intevation.rest;
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
2
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
3 import javax.enterprise.context.RequestScoped;
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
4 import javax.ws.rs.GET;
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
5 import javax.ws.rs.Path;
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
6 import javax.ws.rs.Produces;
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
7
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
8 @Path("/default")
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
9 @RequestScoped
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
10 public class RESTService {
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
11
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
12 @GET
5
27839a25ee4c Fixed return type
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 4
diff changeset
13 @Produces("text/plain")
4
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
14 public String listAll() {
6
5dcccaf3d007 Changed return string
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 5
diff changeset
15 return "Hallo Welt!";
4
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
16 }
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
17 }
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
18
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
19 /**
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
20 * JAX-RS Example
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
21 *
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
22 * This class produces a RESTful service to read the contents of the members table.
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
23
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
24 @Path("/members")
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
25 @RequestScoped
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
26 public class MemberResourceRESTService {
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
27 @Inject
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
28 private EntityManager em;
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
29
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
30 @GET
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
31 @Produces("text/xml")
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
32 public List<Member> listAllMembers() {
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
33 // Use @SupressWarnings to force IDE to ignore warnings about "genericizing" the results of
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
34 // this query
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
35 @SuppressWarnings("unchecked")
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
36 // We recommend centralizing inline queries such as this one into @NamedQuery annotations on
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
37 // the @Entity class
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
38 // as described in the named query blueprint:
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
39 // https://blueprints.dev.java.net/bpcatalog/ee5/persistence/namedquery.html
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
40 final List<Member> results = em.createQuery("select m from Member m order by m.name").getResultList();
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
41 return results;
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
42 }
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
43
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
44 @GET
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
45 @Path("/{id:[0-9][0-9]*}")
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
46 @Produces("text/xml")
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
47 public Member lookupMemberById(@PathParam("id") long id) {
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
48 return em.find(Member.class, id);
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
49 }
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
50 }
39b0b108036f Added test RESTService to play around.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff changeset
51 */
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)