Added another context configuration file. Made the datasource config property more obvious.

This commit is contained in:
Jonathan Bernard 2015-03-23 04:08:54 -05:00
parent fb722a898e
commit a83d8e4dd8
8 changed files with 29 additions and 8 deletions

View File

@ -0,0 +1 @@
nlsongs.media.baseUrl=https://s3.amazonaws.com/new-life-austin-songs/public

View File

@ -4,10 +4,15 @@
<!-- PRODUCTION -->
<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-name>datasource.config.file</param-name>
<param-value>/datasource.properties</param-value>
</context-param>
<context-param>
<param-name>context.config.file</param-name>
<param-value>/context.properties</param-value>
</context-param>
<listener>
<listener-class>com.jdbernard.nlsongs.servlet.NLSongsContextListener</listener-class>
</listener>

View File

@ -0,0 +1 @@
nlsongs.media.baseUrl=https://s3.amazonaws.com/new-life-austin-songs/public

View File

@ -1,10 +1,16 @@
<?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 -->
<!-- PRODUCTION -->
<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>datasource.config.file</param-name>
<param-value>/datasource.properties</param-value>
</context-param>
<context-param>
<param-name>context.config.file</param-name>
<param-value>/datasource.test.properties</param-value>
<param-value>/context.properties</param-value>
</context-param>
<listener>

View File

@ -8,9 +8,10 @@ public class NLSongsContext {
public static NLSongsDB songsDB
public static String mediaUrlBase
public static String mediaBaseUrl
public static String makeUrl(Service service, Song song) {
return mediaUrlBase + service.@date.toString('yyyy-MM-dd') +
'/' + song.name.replaceAll(/\s/, '') + '.ogg' }
return mediaBaseUrl + '/' + service.@date.toString('yyyy-MM-dd') + '_' +
service.serviceType.name().toLowerCase() + '_' +
song.name.replaceAll(/[\s'"\\\/\?!]/, '') + '.ogg' }
}

View File

@ -14,9 +14,15 @@ public final class NLSongsContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
def context = event.servletContext
// Load the context configuration.
Properties props = new Properties()
NLSongsContextListener.getResourceAsStream(
context.getInitParameter('context.config.file')).withStream { is ->
props.load(is) }
// Create the pooled data source
HikariConfig hcfg = new HikariConfig(
context.getInitParameter("context.config.file"))
context.getInitParameter('datasource.config.file'))
HikariDataSource hds = new HikariDataSource(hcfg)
@ -24,7 +30,8 @@ public final class NLSongsContextListener implements ServletContextListener {
NLSongsDB songsDB = new NLSongsDB(hds)
context.setAttribute('songsDB', songsDB)
NLSongsContext.songsDB = songsDB }
NLSongsContext.songsDB = songsDB
NLSongsContext.mediaBaseUrl = props["nlsongs.media.baseUrl"] }
public void contextDestroyed(ServletContextEvent event) {
def context = event.servletContext

View File

@ -85,7 +85,7 @@ public class NLSongsDBTest {
// Create Hikari datasource
HikariConfig hcfg = new HikariConfig(
"resources/test/WEB-INF/classes/datasource.test.properties")
"resources/test/WEB-INF/classes/datasource.properties")
HikariDataSource dataSource = new HikariDataSource(hcfg)