Mercurial > lada > lada-server
annotate src/main/java/de/intevation/rest/LProbeRESTService.java @ 16:823a417cb8e5
Configured which datasource to use in the project. The datasource is
configured as datasource in JBoss.
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Fri, 26 Apr 2013 13:13:20 +0200 |
parents | 624611a29348 |
children | 4ed66a87c0c4 |
rev | line source |
---|---|
8
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.rest; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
2 |
15
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
3 import java.util.List; |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
4 |
8
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
5 import javax.enterprise.context.RequestScoped; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
6 import javax.inject.Inject; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
7 import javax.ws.rs.GET; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
8 import javax.ws.rs.Path; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
9 import javax.ws.rs.Produces; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
10 |
15
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
11 import de.intevation.data.LProbeRepository; |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
12 import de.intevation.model.LProbe; |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
13 |
8
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
14 /** |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
15 * JAX-RS Example |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
16 * |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
17 * This class produces a RESTful service to read the contents of the members table. |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
18 */ |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
19 |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
20 @Path("/proben") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
21 @RequestScoped |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
22 public class LProbeRESTService { |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
23 |
15
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
24 @Inject |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
25 private LProbeRepository repository; |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
26 |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
27 @Inject |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
28 private Logger log; |
8
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
29 |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
30 @GET |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
31 @Produces("text/plain") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
32 public String listAllMembers() { |
15
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
33 final List<LProbe> result = repository.findAll(); |
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
34 System.out.println(result); |
8
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
35 return "Probenliste"; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
36 } |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
37 |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
38 @GET |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
39 @Path("/{id:[0-9][0-9]*}") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
40 @Produces("text/plain") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
41 public String loadById() { |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
42 return "Eine Probe!"; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
43 } |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
44 |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
45 //@GET |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
46 //@Produces("text/xml") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
47 //public List<Member> listAllMembers() { |
15
624611a29348
Provide GET method to load a list of proben.
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
8
diff
changeset
|
48 // // Us @SupressWarnings to force IDE to ignore warnings about "genericizing" the results of |
8
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
49 // // this query |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
50 // @SuppressWarnings("unchecked") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
51 // // We recommend centralizing inline queries such as this one into @NamedQuery annotations on |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
52 // // the @Entity class |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
53 // // as described in the named query blueprint: |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
54 // // https://blueprints.dev.java.net/bpcatalog/ee5/persistence/namedquery.html |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
55 // final List<Member> results = em.createQuery("select m from Member m order by m.name").getResultList(); |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
56 // return results; |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
57 //} |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
58 |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
59 //@GET |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
60 //@Path("/{id:[0-9][0-9]*}") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
61 //@Produces("text/xml") |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
62 //public Member lookupMemberById(@PathParam("id") long id) { |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
63 // return em.find(Member.class, id); |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
64 //} |
1016bcc08bb3
Added stub for REST service for Proben
Torsten Irländer <torsten.irlaender@intevation.de>
parents:
diff
changeset
|
65 } |