Skip to content

Instantly share code, notes, and snippets.

View prule's full-sized avatar

Paul Rule prule

View GitHub Profile
@prule
prule / gist:5648830
Created May 25, 2013 11:49
Maven dependencies for adding Jersey support to your spring based web application.
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
@prule
prule / gist:5648809
Created May 25, 2013 11:42
A REST controller which can be used to expose the version of a WAR application built with Maven. Useful when used with vsConsole to monitor the versions of you applications deployed to various environments. See http://vs-console.appspot.com/
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import java.io.IOException;
@prule
prule / gist:5572715
Created May 14, 2013 00:36
Sometimes its useful to expose the version of your web application - I find it useful so vsConsole can display the version of the deployed application for each environment on the dashboard. If you build your app with Maven, you can use this code to get the version, and simply wire up a controller/rest endpoint to return it as text/plain.
private static final String VERSION_KEY = "version";
private static final String POM_PROPS_PATH_MF = "/META-INF/maven/{0}/{1}/pom.properties";
public static String getMavenWarVersion(ServletContext context, String groupId, String artifactId) {
String resourceName = MessageFormat.format(POM_PROPS_PATH_MF, new Object[]{groupId, artifactId});
Properties properties = loadProperties(context.getResourceAsStream(resourceName));
if (properties != null) {
return properties.getProperty(VERSION_KEY);
}
return "unknown";
@prule
prule / gist:5523826
Created May 6, 2013 07:37
Spring application context showing how to reference JNDI resources exposed by a container
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
@prule
prule / gist:5523793
Last active December 17, 2015 00:49
Tomcat context.xml sample showing database, mail server, and string properties definitions
<?xml version='1.0' encoding='utf-8'?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="sa" password="" driverClassName="org.h2.Driver"
url="jdbc:h2:tcp://localhost/~/test"/>
<Resource name="mail/session" auth="Container"
@prule
prule / gist:5480080
Last active December 16, 2015 18:48
Maven POM configuration to deploy to tomcat - use 'mvn tomcat7:redeploy'
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
...
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
@prule
prule / gist:5480058
Created April 29, 2013 06:43
Maven settings file for tomcat server definition - in ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>dev-tomcat</id>
<username>tomcat</username>
<password>password</password>
</server>
</servers>
</settings>
@prule
prule / gist:5480031
Last active December 16, 2015 18:48
Content for TOMCAT_HOME/conf/tomcat-users.xml to set up and admin user so we can use Maven to deploy an application
<?xml version='1.0' encoding='cp1252'?>
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="password" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>
@prule
prule / gist:5175603
Created March 16, 2013 09:08
Show the columns that are missing from 'owner1' when compared to 'owner2' for tables that match the prefix
SELECT table_name, column_name, data_type FROM all_tab_cols
WHERE lower(owner)=lower(:owner1)
AND table_name LIKE :prefix
AND column_name NOT LIKE 'SYS%'
AND table_name||'-'||column_name NOT IN
(SELECT table_name||'-'||column_name FROM all_tab_cols
WHERE lower(owner)=lower(:owner2)
)
ORDER BY table_name, column_name;
@prule
prule / gist:5070470
Created March 2, 2013 10:44
Integration testing griffon services
import griffon.test.GriffonUnitTestCase
/**
* Date: 18/02/13
*/
class ReportServiceTests extends GriffonUnitTestCase {
GriffonApplication app
ReportService reportService
ImporterService importerService