Skip to content

Instantly share code, notes, and snippets.

@bmchild
bmchild / ToStringUtil.java
Created November 7, 2011 23:11
toString Utility
package com.mypackage;
import java.lang.reflect.Method;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class ToStringUtil {
@bmchild
bmchild / log4j.xml
Created November 8, 2011 21:16
log4j base
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<!-- Pattern to output the caller's file name and line number -->
<param name="ConversionPattern" value="%d{ISO8601} [%p] %m [(%M)%c]%n" />
</layout>
@bmchild
bmchild / cluster-config.xml
Created November 11, 2011 20:45
Cluster Config
<Cluster channelSendOptions="8" className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" domainReplication="true" notifyListenersOnReplication="true" />
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
</Sender>
@bmchild
bmchild / applicationContext.xml
Created November 16, 2011 21:19
maven-war-plugin using environments
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
@bmchild
bmchild / context.xml
Created November 17, 2011 23:08
Context.xml example with Connecter J PLugin
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- maxActive: Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to -1 for no limit.
-->
<!-- maxIdle: Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
@bmchild
bmchild / CustomMethodSecurityExpressionHandler.java
Created January 19, 2012 21:15
Custom regex lookup access Expression with Spring Security 3.1. The lookup, hasRegexRole, is available on the JSP or on the method.
package com.bmchild.security.access.expression;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;
import org.springframework.security.access.expression.SecurityExpressionRoot;
import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler;
import org.springframework.security.core.Authentication;
/**
* @author bchild
@bmchild
bmchild / springRepoTest.java
Created March 1, 2012 23:27
An example of using @configuration for testing spring repositories
package com.bmchild.repository;
/*imports
*.
*.
*.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class)
@bmchild
bmchild / CallingMyCollectionsUtil.java
Created March 16, 2012 19:39
Join a Collection on any POJO with a Data Extractor
com.bmchild;
//imports
public class CallingMyCollectionsUtil {
private class Pojo {
private String field;
public String getField() {
@bmchild
bmchild / file.java
Created April 9, 2012 13:15
Get Entity Class from spring JpaRepository
@SuppressWarnings("rawtypes")
public static Class<?> getEntity(JpaRepository repo) {
Type clazzes = getGenericType(repo.getClass())[0];
Type[] jpaClass = getGenericType(getClass(clazzes));
return getClass( ((ParameterizedType)jpaClass[0]).getActualTypeArguments()[0]);
}
public static Type[] getGenericType(Class<?> target) {
if (target == null)
return new Type[0];
@bmchild
bmchild / org.springframework.ide.eclipse.core.springbuilder.launch
Created June 12, 2012 13:52
Spring Project Builder Disabled in STS 2.9.2
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_DISABLED_BUILDER" value="org.springframework.ide.eclipse.core.springbuilder"/>
<mapAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>