RestApplication.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package microfolies;
  2. import java.net.URI;
  3. import java.util.Date;
  4. import java.util.logging.Logger;
  5. import javax.ws.rs.GET;
  6. import javax.ws.rs.PathParam;
  7. import javax.ws.rs.Produces;
  8. import javax.ws.rs.core.UriBuilder;
  9. import org.glassfish.jersey.jdkhttp.JdkHttpServerFactory;
  10. import org.glassfish.jersey.server.ResourceConfig;
  11. import com.sun.net.httpserver.HttpServer;
  12. @Path("/microfolies")
  13. @Produces("text/plain")
  14. public class RestApplication {
  15. private static Logger LOGGER = Logger.getLogger("jai.jaxrs");
  16. @Path("/badge/{id}/{espace}")
  17. @GET
  18. public String validerBadge(@PathParam("id") String id, @PathParam("espace") String espace) {
  19. LOGGER.info("validation du badge " + id + " a l'espace " + espace);
  20. return "Success";
  21. }
  22. @Path("freq/{espace}/{from}/{to}")
  23. @GET
  24. public int frequence(@PathParam("espace") String espace, @PathParam("from") Date from, @PathParam("to") Date to) {
  25. LOGGER.info("frequence de " + from + " a " + to + " espace " + espace);
  26. return "Graphe";
  27. }
  28. @Path("profile/{id}")
  29. @GET
  30. public int profil(@PathParam("id")String id) {
  31. LOGGER.info("profil " +id);
  32. return "Profil";
  33. }
  34. public static void main(String[] args) {
  35. URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
  36. ResourceConfig config = new ResourceConfig(RestApplication.class);
  37. HttpServer server = JdkHttpServerFactory.createHttpServer(baseUri, config);
  38. }
  39. }