Skip to content

Instantly share code, notes, and snippets.

@koert
Created July 5, 2015 07:52
Show Gist options
  • Select an option

  • Save koert/0f1d1edd6e7c477adaa7 to your computer and use it in GitHub Desktop.

Select an option

Save koert/0f1d1edd6e7c477adaa7 to your computer and use it in GitHub Desktop.
Example REST service implemented with JAX RS
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