Created
July 5, 2015 07:52
-
-
Save koert/0f1d1edd6e7c477adaa7 to your computer and use it in GitHub Desktop.
Example REST service implemented with JAX RS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javax.annotation.ManagedBean; | |
| import javax.inject.Inject; | |
| import javax.ws.rs.GET; | |
| import javax.ws.rs.Path; | |
| import javax.ws.rs.Produces; | |
| import javax.ws.rs.QueryParam; | |
| import javax.xml.bind.annotation.XmlRootElement; | |
| /** | |
| * JAX RS implementation of REST logfile service. | |
| * @author Koert Zeilstra | |
| */ | |
| @Path("/test") | |
| @ManagedBean | |
| public class TestService { | |
| @Inject | |
| private HelloRepository helloRepository; | |
| @GET | |
| @Path("/hello") | |
| @Produces({"application/xml", "application/json"}) | |
| public Greeting test(@QueryParam(value = "name") String name) { | |
| Greeting greeting = new Greeting(); | |
| greeting.message = helloRepository.getGreeting(name); | |
| return greeting; | |
| } | |
| @XmlRootElement(name = "greeting") | |
| public static class Greeting { | |
| public String message; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment