Skip to content

Instantly share code, notes, and snippets.

View andrewharmellaw's full-sized avatar

Andrew Harmel-Law andrewharmellaw

View GitHub Profile
@andrewharmellaw
andrewharmellaw / web.xml
Created June 17, 2013 10:24
Example web.xml showing load of the Spring context and exposure of Web Services via a CXFServlet
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>YourAppName Web App</display-name>
<!-- Location of Spring XML files -->
<context-param>
<param-name>contextConfigLocation</param-name>
@andrewharmellaw
andrewharmellaw / pom.xml
Created June 17, 2013 10:19
Maven 3.0 POM snippets showing properties, spring web dependency and maven plugins
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<packaging>war</packaging>
<properties>
<spring.version>3.2.2.RELEASE</spring.version>
<compileSource>1.7</compileSource>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@andrewharmellaw
andrewharmellaw / activemq-config.xml
Created June 17, 2013 09:54
Example ActiveMQ Spring config showing a queue-specific policy entry with explicit DLQ, message expiry, and named DLQ.
<?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:broker="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.8.0.xsd">
<broker:broker useJmx="true" persistent="true" brokerName="${activemq.broker.name}">
<broker:transportConnectors>
<!-- expose a VM transport for in-JVM transport between AMQ and Camel on the server side -->
@andrewharmellaw
andrewharmellaw / SpringBeanPropertiesExample.java
Created June 17, 2013 09:37
Simple example showing usage of properties read from a file in a Spring Bean
package com.mycompany.myapp.serviceactivator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class ThirdPartyService {
/** specified in env-infr-dev.properties:
* thirdparty.theirapp.accounts.useraccount=FRED|12345
@andrewharmellaw
andrewharmellaw / MyThirdPartyService.java
Created June 17, 2013 08:03
Example @component Spring bean which wraps an interface to a Third Party system and allows routes to use it via the ServiceActivator pattern (.beanRef("xx", "..."))
package com.mycompany.myproject.serviceactivator;
import java.util.ArrayList;
import java.util.List;
import org.apache.camel.Body;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@andrewharmellaw
andrewharmellaw / TransactionFailureTest.java
Created June 13, 2013 15:15
JUnit test showing Camel's Transactions and Testing of the same
package com.mycompany.olpsubscriber;
import java.net.ConnectException;
import javax.sql.DataSource;
import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.RouteDefinition;
@andrewharmellaw
andrewharmellaw / log4j.properties
Last active December 18, 2015 11:19
Example log4j.properties file with Camel, Spring and Chainsaw bits and pieces
#
# The logging properties used
#
log4j.rootLogger=INFO, out, chainsaw-file, chainsaw-socket
#log4j.rootCategory=DEBUG, Default, Chainsaw
# uncomment the following line to turn on Camel debugging
#log4j.logger.org.apache.camel=DEBUG
log4j.logger.org.springframework=WARN
@andrewharmellaw
andrewharmellaw / SimpleConsumerTemplateExampleTest.java
Last active June 24, 2025 01:44
Simple JUnit test illustrating usage of ProducerTemplate to read from Endpoints when we can't / won't mock them
package com.mycompany.myapp.serviceactivator;
import java.io.File;
import java.util.Scanner;
import com.mycompany.myapp.route.MyRoute;
import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
package com.mycompany.myapp.serviceactivator;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.Mockito.anyList;
import static org.mockito.Mockito.anyInt;
@andrewharmellaw
andrewharmellaw / MyRouteTest3.java
Last active December 18, 2015 11:09
JUnit class showing accessing a Spring Bean via the Spring context, and @DirtiesContext anotation.
package com.mycompany.myapp.route;
import org.apache.camel.CamelContext;
import org.apache.camel.test.spring.CamelSpringJUnit4ClassRunner;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;