Archive for the ‘Code’ Category

Ubuntu 9.10 – Apache2 + Tomcat6

Posted on December 23rd, 2009 in Code | 1 Comment »

1) sudo apt-get install apache2 tomcat6 libapache2-mod-jk
2) sudo vim /etc/apache2/workers.properties
and type/past in:
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

3) sudo vim /etc/apache2/apache2.conf
and type/past in:
# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Declare the module for (remove this line on Apache 2.x)
#AddModule mod_jk.c
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /var/log/apache2/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the timestamp log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y] ”

6) sudo vim /etc/apache2/sites-enabled/000-default
Delete “DocumentRoot /var/www”
And type in
JkMount / worker1
JkMount /* worker1
note, you can use JkUnMount to define directories you want apache to serve

7) Enable port 8009 on tomcat
sudo vim /etc/tomcat6/server.xml
remove the “” that is a line below

8) restart tomcat
sudo /etc/init.d/tomcat6 restart

9) restart apache
sudo /etc/init.d/apache2 restart

10) wget localhost
You should see the default tomcat page

Courtesy of: http://rcpeters.blogspot.com/2009/05/installing-apache2-and-tomcat6-on.html

ActiveMQ Clustered and Bulletproof

Posted on November 3rd, 2009 in Code | 2 Comments »

It’s easy to create a clustered instance of ActiveMQ and have your clients connect via multicast. This gives you the ability to create ActiveMQ instances all over the place, have them autodiscover each other and failover seamlessly and automatically. Here’s the ActiveMQ configuration.


<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:amq="http://activemq.apache.org/schema/core"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  		http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
  		http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />

	<broker xmlns="http://activemq.apache.org/schema/core" brokerName="MyBroker" dataDirectory="${activemq.base}/data">

		<destinations>
			<queue physicalName="MyQueue" />
		</destinations>

		<transportConnectors>
			<transportConnector name="openwire" uri="tcp://localhost:0" discoveryUri="multicast://default"/>
		</transportConnectors>

		<networkConnectors>
      		<networkConnector uri="multicast://default"/>
    	</networkConnectors>

	    <persistenceAdapter>
	      	<memoryPersistenceAdapter/>
	    </persistenceAdapter>

	</broker>

	<jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161"/>
        </connectors>

        <handlers>
            <webAppContext contextPath="/admin" resourceBase="${activemq.base}/webapps/admin" logUrlOnStart="true"/>
        </handlers>
    </jetty>

</beans>

And here is the Spring code for the client.


<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
 		<property name="brokerURL">
 			<value>discovery:(multicast://default)</value>
 		</property>
 	</bean>

 	<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
 		<constructor-arg index="0">
 			<value>MyQueue</value>
 		</constructor-arg>
 	</bean>

 	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
 		<property name="connectionFactory">
 			<bean class="org.springframework.jms.connection.SingleConnectionFactory">
 				<property name="targetConnectionFactory" ref="jmsConnectionFactory" />
 			</bean>
 		</property>
 	</bean>

If you will notice, the ActiveMQ client uses the discovery mechanisms for finding the queue, which allows it to connect to any piece of hardware without actually having to know physical locations. You can replace your multicast://default (which happens to be multicast://239.255.2.3:6155) with whatever multicast address you would like. You could even DNS-it-up and have a url look like multicast://MyBroker.mydomain.com:6166.

Enjoy.

http://activemq.apache.org/multicast-transport-reference.html

Maven and the Enterprise

Posted on April 8th, 2009 in Code | No Comments »

Sounds like a band from the 70’s, huh? Here’s a quick picture for part of a presentation I am putting together for my colleagues.

maven-enterprise

Here’s a basic drawing describing a minimum development environment for any company. The “servers” can be consolidated to a certain point, especially if you are using virtualization software.

Also, the source control, continuous integration and maven repository manager can realistically all run on a single server. You MIGHT be able to get away with running the actual builds on the box but might run into some performance issues, particularly if you are running a big build and simultaneously checking in a bunch of source code.

Requirements Documents are the suck.

Posted on March 26th, 2009 in Code | No Comments »

http://www.scottberkun.com/blog/2009/why-requirements-stink/

10 Papers Every Software Architect Should Read (At Least Twice)

Posted on March 10th, 2009 in Code | No Comments »

http://www.rgoarchitects.com/nblog/2009/02/27/10PapersEverySoftwareArchitectShouldReadAtLeastTwice.aspx

Pics from Corporate Cup

Posted on March 10th, 2009 in Code | No Comments »

Running with the coworkers.

Big Ball of Mud

Posted on March 10th, 2009 in Code | No Comments »

http://www.laputan.org/mud/

My personal favorite is “Keep It Working”.

Must read for people who “prototype”.

Small Batches

Posted on February 21st, 2009 in Code | No Comments »

Great article on small batches and continuous integration.

http://startuplessonslearned.blogspot.com/2009/02/work-in-small-batches.html

Beautiful Font for Programmers

Posted on February 16th, 2009 in Code | No Comments »

http://www.ms-studio.com/FontSales/anonymous.html

TestNG, Spring, Maven – Quick and Easy

Posted on February 9th, 2009 in Code | No Comments »

First, you need the dependencies. TestNG requires you to have a classifier for the jdk.

<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">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.stephennimmo</groupId>
	<artifactId>demo</artifactId>
	<packaging>jar</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>domain</name>
	<dependencies>
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>5.8</version>
			<classifier>jdk15</classifier>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>2.5.6</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring</artifactId>
			<version>2.5.6</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.14</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.4</version>
				<configuration>
					<suiteXmlFiles>
						<suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>
					</suiteXmlFiles>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

Now the testng.xml that is located in your test resources dir.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="domain" verbose="5">

	<test name="DomainObjectFactoryTests">
		<packages>
			<package name="com.stephennimmo.domain.test" />
		</packages>
	</test>

</suite>

Here’s the test class. Pay attention that it extends the AbstractTestNGSpringContextTests. If you want transactions involved, extend AbstractTransactionalTestNGSpringContextTests and set it up in the @BeforeClass.

@ContextConfiguration(locations={"classpath:ServiceFactoryContext.xml"})
public class TestPersonService extends AbstractTestNGSpringContextTests {

	@Autowired
	private PersonService personService;

	@Test(groups = { "service" })
	public void testPersonService(){
		long id = 1000;
		Person p = personService.find(id);
		assertNotNull(p);
		assertEquals(p.getId(), id);
	}

}

Thanks to Josh Long.
http://www.joshlong.com/jl/entry/testng_spring_testcontext_and_maven