Skip to content

Instantly share code, notes, and snippets.

@bmchild
bmchild / .gitignore
Created December 4, 2012 20:07
GitIgnore for a Java Eclipse project
# Directories #
/build/
/bin/
target/
# OS Files #
.DS_Store
*.class
@bmchild
bmchild / template.txt
Created June 26, 2013 13:06
Eclipse Template for Equals and Hashcode
@Override
public int hashCode() {
${hashBuilderType:newType(org.apache.commons.lang.builder.HashCodeBuilder)} builder = new ${hashBuilderType}();
builder.append(${field});${cursor}
return ${builder}.toHashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
@bmchild
bmchild / PredicateChain.java
Created August 31, 2015 14:57
A Nonfunctional way of chaining java 8 Predicates together of different generic types.
package com.bmchild.utils;
import java.util.Objects;
import java.util.function.Predicate;
/**
* Non functional way of chaining predicates together
* @author brettchild
*
* @param <T>
@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 / 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 / MyReflectionTestUtils.java
Created July 11, 2012 15:45
Use reflection to compare getters on two objects
/**
*
*/
package com.mypackage.utilities;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.builder.EqualsBuilder;
@bmchild
bmchild / NotEquals.java
Created September 14, 2012 20:02
NotEquals Validator
/**
*
*/
package com.bmchild.validation.constraints;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
@bmchild
bmchild / 1-generated.xml
Last active March 10, 2020 15:27
Dom4J example of creating an XML document from xpath and value information. Dependencies: Dom4J, Jaxen, Apache Commons, Log4J
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<data>
<discharge_status>ACTIVE</discharge_status>
<suspension_rec>
<start>0815</start>
<end>0115</end>
</suspension_rec>
<suspension_rec>
package com.bmchild.stack.commons.utilities.security;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
@bmchild
bmchild / Controller.java
Last active September 18, 2018 23:56
Example of how to wire up a chunked response and how to consume it via angular.
@RequestMapping(value = "/runJobAndGetLogs", method = RequestMethod.GET)
public ResponseEntity<StreamingResponseBody> runJobAndGetLogs() throws IOException {
final InputStream inputStream = someService.runJobAndGetReportProgress();
StreamingResponseBody body = StreamingResponseBody body = (outputStream) -> {
try (BufferedInputStream br = new BufferedInputStream(inputStream)) {
// just copying to the outputstream
byte[] contents = new byte[1024];
int bytesRead = 0;
while ((bytesRead = br.read(contents)) != -1) {