Added web deployment description, context configuration, service, and song endpoint implementations.
This commit is contained in:
		| @@ -0,0 +1,12 @@ | |||||||
|  | package com.jdbernard.nlsongs.rest | ||||||
|  |  | ||||||
|  | import javax.ws.rs.GET; | ||||||
|  | import javax.ws.rs.Path; | ||||||
|  | import javax.ws.rs.Produces; | ||||||
|  |  | ||||||
|  | @Path("v1/ping") | ||||||
|  | public class PingResource { | ||||||
|  |  | ||||||
|  |     @GET | ||||||
|  |     @Produces("text/plain") | ||||||
|  |     public String ping() { return "pong" } } | ||||||
| @@ -0,0 +1,57 @@ | |||||||
|  | package com.jdbernard.nlsongs.rest; | ||||||
|  |  | ||||||
|  | import java.util.Date; | ||||||
|  | import java.util.List; | ||||||
|  | import javax.ws.rs.GET; | ||||||
|  | import javax.ws.rs.POST; | ||||||
|  | import javax.ws.rs.PUT; | ||||||
|  | import javax.ws.rs.Consumes; | ||||||
|  | import javax.ws.rs.Path; | ||||||
|  | import javax.ws.rs.PathParam; | ||||||
|  | import javax.ws.rs.Produces; | ||||||
|  | import javax.ws.rs.core.MediaType; | ||||||
|  |  | ||||||
|  | import com.jdbernard.nlsongs.servlet.NLSongsContext; | ||||||
|  | import com.jdbernard.nlsongs.model.Service; | ||||||
|  |  | ||||||
|  | @Path("v1/services") | ||||||
|  | @Produces({MediaType.APPLICATION_JSON}) | ||||||
|  | @Consumes({MediaType.APPLICATION_JSON}) | ||||||
|  | public class ServicesResource { | ||||||
|  |  | ||||||
|  |     @GET | ||||||
|  |     public List<Service> getServices() { | ||||||
|  |         return NLSongsContext.songsDB.findAllServices(); } | ||||||
|  |  | ||||||
|  |     @POST | ||||||
|  |     public Service postService(Service service) { | ||||||
|  |         return NLSongsContext.songsDB.create(service); } | ||||||
|  |  | ||||||
|  |     @GET @Path("/{serviceId}") | ||||||
|  |     public Service getService(@PathParam("serviceId") int serviceId) { | ||||||
|  |         return NLSongsContext.songsDB.findService(serviceId); } | ||||||
|  |  | ||||||
|  |     @PUT @Path("/{serviceId}") | ||||||
|  |     public Service putService(@PathParam("serviceId") int serviceId, | ||||||
|  |     Service service) { | ||||||
|  |         service.setId(serviceId); | ||||||
|  |         NLSongsContext.songsDB.update(service); | ||||||
|  |         return service; } | ||||||
|  |  | ||||||
|  |     @GET @Path("/withSong/{songId}") | ||||||
|  |     public List<Service> getServicesForSong(@PathParam("songId") int songId) { | ||||||
|  |         return NLSongsContext.songsDB.findServicesForSongId(songId); } | ||||||
|  |  | ||||||
|  |     @GET @Path("/byDate/after/{date}") | ||||||
|  |     public List<Service> getServicesAfter(@PathParam("date") Date date) { | ||||||
|  |         return NLSongsContext.songsDB.findServicesAfter(date); } | ||||||
|  |  | ||||||
|  |     @GET @Path("/byDate/before/{date}") | ||||||
|  |     public List<Service> getServicesBefore(@PathParam("date") Date date) { | ||||||
|  |         return NLSongsContext.songsDB.findServicesBefore(date); } | ||||||
|  |  | ||||||
|  |     @GET @Path("/byDate/between/{b}/{e}") | ||||||
|  |     public List<Service> getServicesBetween | ||||||
|  |     (@PathParam("b") Date b, @PathParam("e") Date e) { | ||||||
|  |         return NLSongsContext.songsDB.findServicesBetween(b, e); } | ||||||
|  | } | ||||||
| @@ -0,0 +1,46 @@ | |||||||
|  | package com.jdbernard.nlsongs.rest; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  | import javax.ws.rs.GET; | ||||||
|  | import javax.ws.rs.POST; | ||||||
|  | import javax.ws.rs.PUT; | ||||||
|  | import javax.ws.rs.Consumes; | ||||||
|  | import javax.ws.rs.Path; | ||||||
|  | import javax.ws.rs.PathParam; | ||||||
|  | import javax.ws.rs.Produces; | ||||||
|  | import javax.ws.rs.core.MediaType; | ||||||
|  |  | ||||||
|  | import com.jdbernard.nlsongs.servlet.NLSongsContext; | ||||||
|  | import com.jdbernard.nlsongs.model.Song; | ||||||
|  |  | ||||||
|  | @Path("v1/songs") | ||||||
|  | @Produces({MediaType.APPLICATION_JSON}) | ||||||
|  | @Consumes({MediaType.APPLICATION_JSON}) | ||||||
|  | public class SongsResource { | ||||||
|  |  | ||||||
|  |     @GET | ||||||
|  |     public List<Song> getSongs() { | ||||||
|  |         return NLSongsContext.songsDB.findAllSongs(); } | ||||||
|  |  | ||||||
|  |     @POST | ||||||
|  |     public Song postSong(Song song) { | ||||||
|  |         return NLSongsContext.songsDB.create(song); } | ||||||
|  |  | ||||||
|  |     @GET @Path("/{songId}") | ||||||
|  |     public Song getSong(@PathParam("songId") int songId) { | ||||||
|  |         return NLSongsContext.songsDB.findSong(songId); } | ||||||
|  |  | ||||||
|  |     @PUT @Path("/{songId}") | ||||||
|  |     public Song putSong(@PathParam("songId") int songId, Song song) { | ||||||
|  |         song.setId(songId); | ||||||
|  |         NLSongsContext.songsDB.update(song); | ||||||
|  |         return song; } | ||||||
|  |  | ||||||
|  |     @GET @Path("/forService/{serviceId}") | ||||||
|  |     public List<Song> getSongsForService(@PathParam("serviceId") int serviceId) { | ||||||
|  |         return NLSongsContext.songsDB.findSongsForServiceId(serviceId); } | ||||||
|  |  | ||||||
|  |     @GET @Path("/byArtist/{artist}") | ||||||
|  |     public List<Song> getSongsForArtist(@PathParam("artist") String artist) { | ||||||
|  |         return NLSongsContext.songsDB.findSongsByArtist(artist); } | ||||||
|  | } | ||||||
| @@ -0,0 +1,7 @@ | |||||||
|  | package com.jdbernard.nlsongs.servlet | ||||||
|  |  | ||||||
|  | import com.jdbernard.nlsongs.db.NLSongsDB | ||||||
|  |  | ||||||
|  | public class NLSongsContext { | ||||||
|  |  | ||||||
|  |     public static NLSongsDB songsDB } | ||||||
							
								
								
									
										9
									
								
								src/main/webapp/WEB-INF/classes/newlifesongs.properties
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/main/webapp/WEB-INF/classes/newlifesongs.properties
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | dataSourceClassName=com.impossibl.postgres.jdbc.PGDataSource | ||||||
|  | dataSource.user=jdbernard | ||||||
|  | dataSource.password=wh!73bl@k | ||||||
|  | dataSource.database=nlsongs | ||||||
|  | dataSource.host=localhost | ||||||
|  | #dataSource.cachePrepStmts=true | ||||||
|  | #dataSource.prepStmtCacheSize=250 | ||||||
|  | #dataSource.prepStmtCacheSqlLimit=2048 | ||||||
|  | #dataSource.useServerPrepStmts=true | ||||||
							
								
								
									
										32
									
								
								src/main/webapp/WEB-INF/web.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/main/webapp/WEB-INF/web.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <!-- This web.xml file is not required when using Servlet 3.0 container, | ||||||
|  |      see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> | ||||||
|  | <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> | ||||||
|  |     <context-param> | ||||||
|  |         <param-name>context.config.file</param-name> | ||||||
|  |         <param-value>/newlifesongs.properties</param-value> | ||||||
|  |     </context-param> | ||||||
|  |  | ||||||
|  |     <listener> | ||||||
|  |         <listener-class>com.jdbernard.nlsongs.servlet.NLSongsContextListener</listener-class> | ||||||
|  |     </listener> | ||||||
|  |  | ||||||
|  |     <servlet> | ||||||
|  |  | ||||||
|  |         <servlet-name>New Life Songs REST API</servlet-name> | ||||||
|  |         <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> | ||||||
|  |  | ||||||
|  |         <init-param> | ||||||
|  |             <param-name>jersey.config.server.provider.packages</param-name> | ||||||
|  |             <param-value>com.jdbernard.nlsongs.rest</param-value> | ||||||
|  |         </init-param> | ||||||
|  |  | ||||||
|  |         <load-on-startup>1</load-on-startup> | ||||||
|  |     </servlet> | ||||||
|  |  | ||||||
|  |     <servlet-mapping> | ||||||
|  |         <servlet-name>New Life Songs REST API</servlet-name> | ||||||
|  |         <url-pattern>/api/*</url-pattern> | ||||||
|  |     </servlet-mapping> | ||||||
|  |  | ||||||
|  | </web-app> | ||||||
		Reference in New Issue
	
	Block a user