-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleRest.java
More file actions
46 lines (39 loc) · 1.08 KB
/
SimpleRest.java
File metadata and controls
46 lines (39 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.javaee7.services;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
// Set the PATH to http://host:port/application/rest/simplerest/
@Path("/simplerest")
public class SimpleRest {
private String message = "Hello from a simple REST Service";
private String htmlMessage = "<p><b>" + message + "</b></p>";
@GET
// Produces plain text message
@Produces("text/plain")
public String getPlainMessage() {
return message;
}
@GET
// Produces plain text message
@Produces("text/html")
public String getHTMLMessage() {
return htmlMessage;
}
@PUT
@Path("add")
@Consumes("text/plain")
public String add(@QueryParam("text") String text) {
this.message = text;
return message;
}
@Path("{user}")
@GET
@Produces("text/html")
public String getUserMessage(@PathParam("user") String user) {
return "Greetings " + "<b>" + user + "</b>";
}
}