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
| package helloworld;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
/**
* REST Web Service
*
* @author mkuchtiak
*/
@Stateless
@Path("/helloWorld")
public class HelloWorldResource {
@EJB
private NameStorageBean nameStorage;
/**
* Retrieves representation of an instance of helloworld.HelloWorldResource
* @return an instance of java.lang.String
*/
@GET
@Produces("text/html")
public String getXml() {
return "<html><body><h1>Hello mehdi "+nameStorage.getName()+"!</h1></body></html>";
}
/**
* PUT method for updating an instance of HelloWorldResource
* @param content representation for the resource
* @return an HTTP response with content of the updated or created resource.
*/
@PUT
@Consumes("text/plain")
public void putXml(String content) {
nameStorage.setName(content);
}
} |
Partager