<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6447184396655674320</id><updated>2012-02-16T14:59:40.354Z</updated><category term='juli'/><category term='logging'/><category term='undelete'/><category term='recovery'/><category term='J2ME'/><category term='hibernate'/><category term='jdbc'/><category term='java'/><category term='ju jutsu'/><category term='mysql'/><category term='tag library'/><category term='patterns'/><category term='rm'/><category term='p6spy'/><category term='Abstractec'/><category term='jstl'/><category term='ju jitsu'/><category term='skype'/><category term='tomcat'/><category term='martial arts'/><category term='bjjagb'/><category term='BlackBerry'/><category term='logitech'/><category term='null'/><category term='logitech quickcam ultra vision'/><category term='hakama'/><category term='EnhancerByCGLIB'/><category term='iPhone'/><category term='Pay At The Pump'/><category term='spring'/><category term='kempo'/><category term='PreparedStatement'/><category term='taglib'/><category term='bind variables'/><category term='ubuntu'/><category term='ClassCastException'/><category term='quickcam'/><title type='text'>Andy Kayley's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-4206956244913371676</id><published>2011-09-27T21:43:00.000+01:00</published><updated>2011-09-27T21:43:01.501+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='null'/><category scheme='http://www.blogger.com/atom/ns#' term='jstl'/><category scheme='http://www.blogger.com/atom/ns#' term='tag library'/><category scheme='http://www.blogger.com/atom/ns#' term='taglib'/><title type='text'>How To Pass A Null Value To A Custom Tag Library</title><content type='html'>&lt;p&gt;Today I found something very interesting.&amp;nbsp; I wanted to pass a &lt;code&gt;java.math.BigDecimal&lt;/code&gt; to a custom JSP Tag Library and format it as a percentage, however if the &lt;code&gt;BigDecimal&lt;/code&gt; was &lt;code&gt;null&lt;/code&gt; I didn't want to show it.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;Easy, I thought.  So I created a class similar to the following...&lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
package name.kayley.blog.taglib;

import java.io.IOException;
import java.math.BigDecimal;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class BigDecimalTagSupport extends TagSupport {

	private BigDecimal value;
	
	public void setValue(BigDecimal value) {
		this.value = value;
	}
	
	public int doEndTag() throws JspException {
	    try {
	    	if (value != null)
			    pageContext.getOut().print(formatAsPercentage(value));
		} catch (IOException e) {
			throw new JspException(e);
		}
		return EVAL_PAGE;
	}
...
}
&lt;/script&gt;&lt;br /&gt;
&lt;p&gt;However, when I called this taglib with a &lt;code&gt;null&lt;/code&gt; value I still got a value of 0.&lt;br /&gt;
&lt;/p&gt;&lt;script class="brush: xml; wrap-lines: false" type="syntaxhighlighter"&gt;
    &lt;mytag:bigDecimal value="${aBigDecimal}" /&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;p&gt;The output:&lt;br /&gt;
&lt;code&gt;0&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After a bit of trial and error I discovered that the JSP tab library framework does a little bit of magic on known classes, such as &lt;code&gt;String&lt;/code&gt;s and &lt;code&gt;Numeric&lt;/code&gt; objects.  Classes of &lt;code&gt;Numeric&lt;/code&gt; types that are &lt;code&gt;null&lt;/code&gt; get converted to &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;String&lt;/code&gt;s get converted into the empty string &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;I discovered that if you change your internal value to an &lt;code&gt;java.lang.Object&lt;/code&gt; instead of a &lt;code&gt;java.math.BigDecimal&lt;/code&gt; the magic doesn't know what to do and just passes &lt;code&gt;null&lt;/code&gt; to your class.&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;So the new class looks like the following...&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
package name.kayley.blog.taglib;

import java.io.IOException;
import java.math.BigDecimal;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class BigDecimalTagSupport extends TagSupport {

	private Object value;
	
	public void setValue(Object value) {
		this.value = value;
	}
	
	public int doEndTag() throws JspException {
	    try {
	    	if (value != null) {
	    		// Cast value to a BigDecimal if you need to.
			    pageContext.getOut().print(formatAsPercentage(value));
	    	}
		} catch (IOException e) {
			throw new JspException(e);
		}
		return EVAL_PAGE;
	}
...
}
&lt;/script&gt;&lt;br /&gt;
&lt;/p&gt;&lt;p&gt;So now when I use the tag and pass a &lt;code&gt;null BigDecimal&lt;/code&gt; to it I get the required result of no output.&lt;/p&gt;&lt;p&gt;WIN&lt;/p&gt;&lt;p&gt;I have an example web app demonstrating this, if anyone wants a copy just let me know.&lt;/p&gt; &lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/jstl" rel="tag"&gt;jstl&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/null" rel="tag"&gt;null&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/taglib" rel="tag"&gt;taglib&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/tag%20library" rel="tag"&gt;tag library&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-4206956244913371676?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/4206956244913371676/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=4206956244913371676' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/4206956244913371676'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/4206956244913371676'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2011/09/how-to-pass-null-value-to-custom-tag.html' title='How To Pass A Null Value To A Custom Tag Library'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-1018040448320718904</id><published>2010-06-28T19:26:00.000+01:00</published><updated>2010-06-28T19:26:29.124+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='J2ME'/><category scheme='http://www.blogger.com/atom/ns#' term='iPhone'/><category scheme='http://www.blogger.com/atom/ns#' term='Abstractec'/><category scheme='http://www.blogger.com/atom/ns#' term='Pay At The Pump'/><category scheme='http://www.blogger.com/atom/ns#' term='BlackBerry'/><title type='text'>Pay At The Pump and LPG Finder for BlackBerry(R)</title><content type='html'>For the past few months on and off I've been working on a project for my friend and former colleague &lt;a href="http://happydevilsnackshop.blogspot.com/" target="blank"&gt;John Haselden&lt;/a&gt; of &lt;a href="http://www.abstractec.co.uk/" target="blank"&gt;Abstractec&lt;/a&gt;.  He has made a website and an iPhone phone application which utilises web services of the website.  The project is called Fuelista, and the applications are &lt;a href="http://www.payatthepump.co.uk/" target="blank"&gt;Pay at the Pump&lt;/a&gt; and &lt;a href="http://www.whatsoniphone.com/reviews/ipayatthepump" target="blank"&gt;iPayAtThePump&lt;/a&gt; for iPhone,  (with variants for &lt;a href="http://www.lpgfinder.co.uk/" target="blank"&gt;LPG&lt;/a&gt; etc).&lt;br /&gt;
&lt;br /&gt;
The idea of the Pay at the Pump and LPG Finder applications is to provide a location based service to allow you to find petrol stations that provide a "pay at the pump" or "LPG" service.  The application does a GPS lookup on your location, and returns a list of garages that provide that service.  You can then navigate through and get more details of the garage, and if you require you can a route from your current location to the garage.&lt;br /&gt;
&lt;br /&gt;
Abstractec are trying out more platforms than just the iPhone.  They are investigating Android, BlackBerry and PalmPre.  I was asked if I would like a go at the BlackBerry port, so I thought "why not?"&lt;br /&gt;
&lt;br /&gt;
I wanted to get into writing iPhone applications for fun and maybe a bit of extra cash, I bought myself a Macbook Pro and an iPhone in mid 2009, but there is a lot to learn to get up and running with iPhone development, the applications are written in Objective-C and the development environment is quite difficult to get your head around when you're starting off, especially coming from a Java background.&lt;br /&gt;
BlackBerry applications however are written using Java.&lt;br /&gt;
&lt;br /&gt;
Research In Motion (RIM) provide a layer on top of J2ME providing their own classes and UI components specifically for the BlackBerry handsets.
&lt;br /&gt;
&lt;br /&gt;
The application is complete and also I have created the LPG equivalent.  Check out the video below for a demo of the application.  The GPS lookup on the handset that I have to test with is quite poor...Hence the timeout when the first lookup occurs.&lt;br /&gt;
&lt;br /&gt;
Enjoy...&lt;br /&gt;
&lt;br /&gt;
&lt;div style="text-align: center;"&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;object height="385" width="480"&gt;&lt;param name="movie" value="http://www.youtube.com/v/qRBemxmqxPk&amp;hl=en_US&amp;fs=1&amp;rel=0"&gt;
&lt;/param&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;/param&gt;
&lt;param name="allowscriptaccess" value="always"&gt;
&lt;/param&gt;
&lt;embed src="http://www.youtube.com/v/qRBemxmqxPk&amp;hl=en_US&amp;fs=1&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/BlackBerry" rel="tag"&gt;BlackBerry&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/J2ME" rel="tag"&gt;J2ME&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/payatthepump" rel="tag"&gt;Pay At The Pump&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/abstractec" rel="tag"&gt;Abstractec&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/iphone" rel="tag"&gt;iPhone&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-1018040448320718904?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/1018040448320718904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=1018040448320718904' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/1018040448320718904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/1018040448320718904'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2010/06/pay-at-pump-and-lpg-finder-for.html' title='Pay At The Pump and LPG Finder for BlackBerry(R)'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-990719597758264895</id><published>2009-05-22T00:54:00.015+01:00</published><updated>2010-06-28T22:50:14.441+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='hibernate'/><category scheme='http://www.blogger.com/atom/ns#' term='ClassCastException'/><category scheme='http://www.blogger.com/atom/ns#' term='patterns'/><category scheme='http://www.blogger.com/atom/ns#' term='spring'/><category scheme='http://www.blogger.com/atom/ns#' term='EnhancerByCGLIB'/><title type='text'>How to Avoid ClassCastExceptions when using Hibernate Proxied Objects</title><content type='html'>Recently at work I was faced with an issue on the live system.  A certain page within the application would only show the system's standard error message.  After looking in the logs I discovered there was a &lt;code&gt;ClassCastException&lt;/code&gt; being thrown, this was due to the fact that a lazily loaded List of objects retrieved by hibernate contained proxied objects.  The entities that were proxied were using a single table inheritance strategy, so there is a base class that is subclassed several times.  The entities once loaded were being sorted into separate lists that are typed according to the subclasses, they were being cast into the appropriate subclass but this cast was failing because instead of being an instance of say &lt;code&gt;Animal&lt;/code&gt; it was an instance of &lt;code&gt;Animal$$EnhancerByCGLIB$$10db1483&lt;/code&gt; i.e. A Hibernate Proxy.  Let me show you an example.&lt;br /&gt;
&lt;br /&gt;
So lets say we have a base class that has an inheritance strategy set...&lt;br /&gt;
&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

import javax.persistence.*;

@Entity
@Table(name="animals")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
    name="animal_type_id",
    discriminatorType=DiscriminatorType.INTEGER
)
public class Animal {

    @Id
    @GeneratedValue
    private Long id;
    
    @Column
    private String name;
    
    @Column
    private Integer age;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}]]&gt;
&lt;/script&gt;
And then we had 2 subclasses of this &lt;code&gt;Animal&lt;/code&gt; class, lets say, &lt;code&gt;Cat&lt;/code&gt; and &lt;code&gt;Dog&lt;/code&gt;...&lt;br /&gt;
&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
@DiscriminatorValue("1")
public class Cat extends Animal {
   // some cat specific attributes
}
]]&gt;
&lt;/script&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
@DiscriminatorValue("2")
public class Dog extends Animal {
   // some dog specific attributes
}
]]&gt;
&lt;/script&gt;

As you can see the discriminator column is &lt;code&gt;animal_type_id&lt;/code&gt;, which I have defined 2 to be &lt;code&gt;Dog&lt;/code&gt; and 1 to be &lt;code&gt;Cat&lt;/code&gt;.  So now we should make sure we have some data in a database table called animals...&lt;br /&gt;
&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
SELECT id,animal_type_id,name,age FROM animals a LIMIT 0,1000

'id', 'animal_type_id', 'name', 'age'
1, 2, 'Scooby', 3
2, 1, 'Felix', 4
3, 1, 'Garfield', 4
]]&gt;
&lt;/script&gt;

Right so to recreate a similar situation I will show you a unit test that will pass!  What I am trying to do is to retrieve the list of animals and sort them in the java into separate lists, a list of dogs and a list of cats..&lt;br /&gt;
&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
public void testCGLibInstanceOfError() throws Exception {

    List&lt;dog&gt; dogs = new ArrayList&lt;dog&gt;();
    List&lt;cat&gt; cats = new ArrayList&lt;cat&gt;();

    Iterator&lt;animal&gt; it = hibernateDao.createQuery("from Animal").iterate();

    while (it.hasNext()) {

        Animal animal = it.next();
        assertTrue(animal.getClass().getName().contains("Animal$$EnhancerByCGLIB$$"));
                    
        if (animal instanceof Cat) {
            cats.add((Cat) animal);
        } 
        else if (animal instanceof Dog) {
            dogs.add((Dog) animal);
        }
    }
    assertEquals(0, dogs.size());
    assertEquals(0, cats.size());
}
]]&gt;
&lt;/script&gt;

Now using the data in the database we want a list of 1 dog and a list of 2 cats.  Here I'm being particularly evil and using instanceof to differentiate these.  The &lt;code&gt;assertEquals&lt;/code&gt; at the end of the test pass, even though the code looks like it should be adding items to these lists based on what is in the Adatabase.  This is because animal is not an &lt;code&gt;instanceof Cat&lt;/code&gt; or &lt;code&gt;Dog&lt;/code&gt; but an &lt;code&gt;instanceof Animal$$EnhancerByCGLIB$$10db1483&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
So how do we solve this issue?&lt;br /&gt;
&lt;br /&gt;
I first thought about using &lt;code&gt;Hibernate.initialize(animal);&lt;/code&gt; which will force the animal class to become the actual object, not the proxy.  I felt this approach to be dirty and it is really polluting code that shouldn't really know anything about hibernate.&lt;br /&gt;
&lt;br /&gt;
So I did some googling and after reading &lt;a href="https://www.hibernate.org/280.html" target="_blank"&gt;the hibernate documentation&lt;/a&gt; and then &lt;a href="http://en.wikipedia.org/wiki/Visitor_pattern" target="_blank"&gt;this&lt;/a&gt; I set about using the Gang Of Four Visitor Pattern.&lt;br /&gt;
&lt;br /&gt;
First we need a visitor interface that we can implement in your test...&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

public interface AnimalEntityVisitor {
    void visit(Dog dog);
    void visit(Cat cat);
}
]]&gt;
&lt;/script&gt;

Next we need is an interface for our &lt;code&gt;Animal&lt;/code&gt; class to implement...&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

public interface AnimalEntity {
    void accept(AnimalEntityVisitor visitor);
}
]]&gt;
&lt;/script&gt;

Now we make our &lt;code&gt;Animal&lt;/code&gt; class I showed earlier implement the &lt;code&gt;AnimalEntity&lt;/code&gt;...&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

import javax.persistence.*;

@Entity
@Table(name="animals")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
    name="animal_type_id",
    discriminatorType=DiscriminatorType.INTEGER
)
public abstract class Animal implements AnimalEntity {
   ...
   // see top of post
   ...
}
]]&gt;
&lt;/script&gt;

And next implement the method in the subclasses..&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
@DiscriminatorValue("1")
public class Cat extends Animal {
   // some cat specific attributes

   public void accept(AnimalEntityVisitor visitor) {
      visitor.visit(this);
   }
}
]]&gt;
&lt;/script&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.cglibexample;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

@Entity
@DiscriminatorValue("2")
public class Dog extends Animal {
   // some dog specific attributes

   public void accept(AnimalEntityVisitor visitor) {
      visitor.visit(this);
   }
}
]]&gt;
&lt;/script&gt;

All we need to do is implement the visitor in our test...&lt;br /&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
public class MyTest extends
        AbstractTransactionalDataSourceSpringContextTests implements AnimalEntityVisitor {

        ...
    // some spring setup     
        ...

    private List&lt;dog&gt; dogs = new ArrayList&lt;dog&gt;();
    private List&lt;cat&gt; cats = new ArrayList&lt;cat&gt;();
    
    public void testCGLibUsingVisitor() throws Exception {

        Iterator&lt;animal&gt; it = hibernateDao.createQuery("from Animal").iterate();

        while (it.hasNext()) {

            Animal animal = it.next();

            assertTrue(animal.getClass().getName().contains("Animal$$EnhancerByCGLIB$$"));

            animal.accept(this);
            
        }
        assertEquals(1, dogs.size());
        assertEquals(2, cats.size());
    }

    public void visit(Dog dog) {
        dogs.add(dog);
    }

    public void visit(Cat cat) {
        cats.add(cat);
    }
}
]]&gt;
&lt;/script&gt;

So instead of using &lt;code&gt;instanceof&lt;/code&gt; or having to cast anything (which is what was happening in the live code I talked about) which can cause weird side effects and &lt;coded&gt;ClassCastExceptions, you can just use this visitor pattern.  What happens is the test is implementing the &lt;code&gt;AnimalEntityVisitor&lt;/code&gt;, so when &lt;code&gt;animal.accept(this);&lt;/code&gt; is called, it calls the appropriate visit method on "this".  In our case the visit method is just adding the object to a list.  So I've updated the &lt;code&gt;assertEquals&lt;/code&gt; calls to be what I now expect and the test passes.&lt;/coded&gt;&lt;br /&gt;
Happy days, enjoy!&lt;br /&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/EnhancerByCGLIB" rel="tag"&gt;EnhancerByCGLIB&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/Hibernate" rel="tag"&gt;Hibernate&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/ClassCastException" rel="tag"&gt;ClassCastException&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/hibernate" rel="tag"&gt;hibernate&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/spring" rel="tag"&gt;spring&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-990719597758264895?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/990719597758264895/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=990719597758264895' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/990719597758264895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/990719597758264895'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2009/05/how-to-avoid-classcastexceptions-when.html' title='How to Avoid ClassCastExceptions when using Hibernate Proxied Objects'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-900850987246465808</id><published>2009-02-20T00:17:00.004Z</published><updated>2010-06-28T23:01:09.238+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rm'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='recovery'/><category scheme='http://www.blogger.com/atom/ns#' term='undelete'/><category scheme='http://www.blogger.com/atom/ns#' term='ubuntu'/><title type='text'>How to Undelete files removed with "rm" in Ubuntu</title><content type='html'>&lt;p&gt;Recently I found myself in a situation where I needed to recover some files I accidentally deleted.  I had written a program in Java to read off a JBoss Messaging Dead Letter Queue, and save them in a format that could be re-inputted back into the system.&lt;/p&gt;

&lt;p&gt;So my program was writing files into a directory within my home directory, and while I was testing the program I was not committing back to JMS so ensure the messages stayed there.  When I was confident that the program was correct, I added the commit, I then removed the files that my tests had produce by using "rm *".&lt;/p&gt;

&lt;p&gt;I then ran my program for real.  In the directory I was expecting files to appear I typed the usual "ls -ltr" to see a list of files.  I pressed the up key to run the last command i.e. "ls -ltr" to see some more files created.  I repeated this a few times, until I accidentally pressed the up key twice.....yep you guessed it...."rm *", the files were deleted and the commit to JMS means they were no longer on the queue.  My heart sank.&lt;/p&gt;

&lt;p&gt;Now I rememebered on the old days of DOS there was an UNDELETE command, so I was looking around the web to see if there was something similar for Linux.  I was in luck, especially as my program was still running.&lt;/p&gt;

&lt;p&gt;Basically thanks to &lt;a href="http://www.oreillynet.com/pub/h/363" target="_blank"&gt;this information&lt;/a&gt;, I recovered my deleted files with relative ease. :-)&lt;/p&gt;

&lt;p&gt;Ok so to do this, I believe you need to be as fortunate as I was and still have the program that created the deleted files still running, so let's create a Java program that will write to a file and then keep running...&lt;/p&gt;

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.undeletefiletest;

import java.io.FileWriter;
import java.io.PrintWriter;

public class UndeleteFileTest {
 public static void main(String[] args) throws Exception {  
  FileWriter writer = new FileWriter("/tmp/testFile.txt");
  
  PrintWriter printer = new PrintWriter(writer);
  
  printer.append("hello this file is going to be deleted.");
  printer.flush();
  Object lock = new Object();
  
  synchronized(lock) {
   lock.wait();
  }
 }
}
]]&gt;&lt;/script&gt;

&lt;p&gt;Ok, now run that program and it will create a file in /tmp called testFile.txt, so lets see it..&lt;/p&gt;

&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
andy@andy-laptop:/tmp$ ls -ltr *.txt
-rw-r--r-- 1 andy andy 39 2009-02-13 18:54 testFile.txt
]]&gt;&lt;/script&gt;

&lt;p&gt;So we can see the file is there, lets delete it to see if we can recover it...&lt;/p&gt;

&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
andy@andy-laptop:/tmp$ rm testFile.txt
]]&gt;&lt;/script&gt;

&lt;p&gt;Now the file is gone.  So how do we get it back?  Well first we need to find the PID of the process that created the file that was deleted.  We know that it was a java program that created it so we'll use the lsof and search for java..&lt;/p&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
andy@andy-laptop:/tmp$ lsof | grep java
.....[lots of things listed]
java      9048       andy    4r      REG        8,1       39 1622029 /tmp/testFile.txt (deleted)
]]&gt;&lt;/script&gt;

&lt;p&gt;No now we know the PID is 9048 lets find the file... so there should be a directory /proc/[PID]/fd...&lt;/p&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
andy@andy-laptop:/tmp$ cd /proc/9048/fd
andy@andy-laptop:/proc/9048/fd$ ls-ltr
total 0
lr-x------ 1 andy andy 64 2009-02-13 18:54 4 -&gt; /tmp/testFile.txt (deleted)
l-wx------ 1 andy andy 64 2009-02-13 18:54 3 -&gt; /usr/local/jdk1.6.0_07/jre/lib/rt.jar
l-wx------ 1 andy andy 64 2009-02-13 18:54 2 -&gt; pipe:[43665]
l-wx------ 1 andy andy 64 2009-02-13 18:54 1 -&gt; pipe:[43664]
lr-x------ 1 andy andy 64 2009-02-13 18:54 0 -&gt; pipe:[43663]
]]&gt;&lt;/script&gt;
&lt;p&gt;Bingo!  We have found the deleted file, so now all we need to do is cat the link to a new file, so here I put it into my home directory...&lt;/p&gt;

&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
andy@andy-laptop:/proc/9048/fd$ cat 4 &gt; ~/testFile.txt
]]&gt;&lt;/script&gt;
&lt;p&gt;Next, I go to my home folder and have a look at the file, and hey presto...its restored...&lt;/p&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
andy@andy-laptop:/proc/9048/fd$ cd
andy@andy-laptop:~$ less testFile.txt 
hello this file is going to be deleted.
testFile.txt (END) 
]]&gt;&lt;/script&gt;

&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/Java" rel="tag"&gt;Java&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/Ubuntu" rel="tag"&gt;Ubuntu&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/Undelete" rel="tag"&gt;Undelete&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/rm" rel="tag"&gt;rm&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/recovery" rel="tag"&gt;recovery&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;Andy Kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-900850987246465808?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/900850987246465808/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=900850987246465808' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/900850987246465808'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/900850987246465808'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2009/02/how-to-undelete-files-removed-with-rm.html' title='How to Undelete files removed with &quot;rm&quot; in Ubuntu'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-2909241200946650425</id><published>2008-07-30T00:52:00.006+01:00</published><updated>2010-06-28T23:11:08.548+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='hibernate'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='p6spy'/><category scheme='http://www.blogger.com/atom/ns#' term='PreparedStatement'/><category scheme='http://www.blogger.com/atom/ns#' term='jdbc'/><category scheme='http://www.blogger.com/atom/ns#' term='bind variables'/><title type='text'>How to Print Out Bind Variables in Java Prepared Statements.</title><content type='html'>Ever been frustrated by the fact that when you use (as you should do!) bind variables within a java prepared statement you cannot see the actual values that get put into those bind variables?  I know I have.  For example if you had a class that had some JDBC calls that did the following....

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
Class.forName("com.mysql.jdbc.Driver");

connection = DriverManager.getConnection("jdbc:mysql://localhost/message_board", "root", "");

statement = connection.prepareStatement("select * from messages where id = ?");
statement.setLong(1,1L);

resultSet = statement.executeQuery();
]]&gt;&lt;/script&gt;

There is no nice out the box way to find out what the ?'s will be resolved to.  I've always wanted a method on PreparedStatement that would address this, but alas there still is none.  Traditionally I would have done something like the following...

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
long id = 1L;
String sql = "select * from messages where id = ?"
logger.info(sql + "; ?1=" + id);

statement = connection.prepareStatement(sql);
statement.setLong(1,id);
]]&gt;&lt;/script&gt;

Or write your own convoluted method for replacing each ? with the value which is prone to bugs and not being database agnostic.
&lt;br/&gt;&lt;br/&gt;
When using an old jdbc based in-house framework this really wasn't an issue for me, as we had such a  method that was prone to bugs but for the most part it worked ok.  Since then the work I have been doing has been much more hibernate based.  This is where the issue came for me, you can turn on sql logging either by configuring your favourite logging framework to do so, or by turning on the hibernate.show_sql property, which will give you the following output...

&lt;script class="brush: sql; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
select message0_.id as id2_, message0_.email_address as email2_2_, message0_.inserted_at as inserted3_2_, message0_.remote_host as remote4_2_, message0_.text as text2_ from messages message0_ where message0_.id=?
]]&gt;&lt;/script&gt;

This sql was generated from the following hql 

&lt;script class="brush: sql; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
from Message where id = ?
]]&gt;&lt;/script&gt;

Now apart from this sql being particularly hideous to look at, the question mark is still there, we have no way of possibly knowing what those bind variables were without printing them out at the time the hql is executed.
&lt;br/&gt;&lt;br/&gt;
Enter p6spy.
&lt;br/&gt;&lt;br/&gt;
I did a bit of googling about and found other people had the same issue.  And there is an answer to this problem, and its called p6spy.  P6spy is a jdbc driver that is a proxy for your real driver.  I've only just started to use it, I believe it is capable of many cool things, but the one that I am interested in allows you to print out sql from prepared statements with - yep, you guessed it - the bind variables substituted for the real values.
&lt;br/&gt;&lt;br/&gt;
You can download it from &lt;a href="http://www.p6spy.com" target="_blank"&gt;http://www.p6spy.com&lt;/a&gt;, it must be fairly stable as the last release was in 2003 (I'm so annoyed that I didn't know about this earlier).  There seems to be a little problem with their website as when you click download you get an error while trying to fill in or ignore their survey.  Don't panic, once you've ignored the survey go back to the main page and click download again and the files will be there waiting for you to download.
&lt;br/&gt;&lt;br/&gt;
So how do we configure this little beauty?  Well the download is &lt;b&gt;p6spy-install.zip&lt;/b&gt;, unzip this somewhere safe (and keep in mind that all the files are in the root of the zip file, so you might want to create a directory to unzip it to first).  The files we're interested in are &lt;b&gt;p6spy.jar&lt;/b&gt; and &lt;b&gt;spy.properties&lt;/b&gt;.  Copy the jar file into the lib folder of your project and copy the spy.properties file into somewhere that will be on the classpath.
&lt;br/&gt;&lt;br/&gt;
If you look inside spy.properties you will see that it's really very well documented and tells you all you really need to know on how to configure it.  Although one thing to note in there is that they have said that the real driver you configure in your application should be set to &lt;b&gt;&lt;code&gt;com.p6spy.engine.P6SpyDriver&lt;/code&gt;&lt;/b&gt; which is actually incorrect, it should be &lt;b&gt;&lt;code&gt;com.p6spy.engine.spy.P6SpyDriver&lt;/code&gt;&lt;/b&gt;, the first one doesn't exist and you will get a ClassNotFoundException.
&lt;br/&gt;&lt;br/&gt;
So what I did... In my spy.properties I set the realdriver...

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
# mysql Connector/J driver
realdriver=com.mysql.jdbc.Driver
]]&gt;&lt;/script&gt;

(note by default the open source mysql driver is uncommented which was a gotcha for me at first, so i commented it out, and uncommented the above)
&lt;br/&gt;&lt;br/&gt;
Next I altered my code in the first example to the following...

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
Class.forName("com.p6spy.engine.spy.P6SpyDriver");

connection = DriverManager.getConnection("jdbc:mysql://localhost/message_board", "root", "");

statement = connection.prepareStatement("select * from messages where id = ?");
statement.setLong(1,1L);

resultSet = statement.executeQuery();
]]&gt;&lt;/script&gt;
And low and behold in the root of my eclipse project on the file system a file called spy.log has appeared. and in it the following...

&lt;script class="brush: sql; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
1217374504582|6|0|statement|select * from messages where id = ?|select * from messages where id = 1
1217374504595|-1||resultset|select * from messages where id = 1|email_address = myemail@nospam.com, id = 1, inserted_at = 2008-07-29 00:00:00.0, remote_host = localhost, text = Thank you for showing me the wonders of p6spy
]]&gt;&lt;/script&gt;

There is lots of other stuff in the log file as well but as you can see its very handy, as it shows you the statement with question marks and with the real values substituted, and also shows you the results set which is passed back :-) Beautiful lol.
&lt;br/&gt;&lt;br/&gt;
And the hql of
&lt;script class="brush: sql; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
from Message where id = ?
]]&gt;&lt;/script&gt;
is output as:

&lt;script class="brush: sql; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
1217374913350|5|2|statement|select message0_.id as id2_, message0_.email_address as email2_2_, message0_.inserted_at as inserted3_2_, message0_.remote_host as remote4_2_, message0_.text as text2_ from messages message0_ where message0_.id=?|select message0_.id as id2_, message0_.email_address as email2_2_, message0_.inserted_at as inserted3_2_, message0_.remote_host as remote4_2_, message0_.text as text2_ from messages message0_ where message0_.id=1
1217374913369|-1||resultset|select message0_.id as id2_, message0_.email_address as email2_2_, message0_.inserted_at as inserted3_2_, message0_.remote_host as remote4_2_, message0_.text as text2_ from messages message0_ where message0_.id=1|email2_2_ = myemail@nospam.com, remote4_2_ = localhost
]]&gt;&lt;/script&gt;

Still ugly but at least I can now see what the bind variables are going to be :-)
&lt;br/&gt;&lt;br/&gt;
You can also configure it so it comes out in your normal logging file, the spy.properties file details how you do that. 
&lt;br/&gt;&lt;br/&gt;
Oh how I wish I'd have known this 4 years ago.
&lt;br/&gt;&lt;br/&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/jdbc" rel="tag"&gt;jdbc&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/mysql" rel="tag"&gt;mysql&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/hibernate" rel="tag"&gt;hibernate&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/p6spy" rel="tag"&gt;p6spy&lt;/a&gt;,&lt;a href="http://www.technorati.com/tags/PreparedStatement" rel="tag"&gt;PreparedStatement&lt;/a&gt;,&lt;a href="http://www.technorati.com/tags/bind%20variables" rel="tag"&gt;bind variables&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-2909241200946650425?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/2909241200946650425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=2909241200946650425' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/2909241200946650425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/2909241200946650425'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2008/07/how-to-print-out-bind-variables-in-java.html' title='How to Print Out Bind Variables in Java Prepared Statements.'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-3860604520025910504</id><published>2008-07-28T22:32:00.008+01:00</published><updated>2010-06-28T23:18:24.989+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='skype'/><category scheme='http://www.blogger.com/atom/ns#' term='logitech'/><category scheme='http://www.blogger.com/atom/ns#' term='quickcam'/><category scheme='http://www.blogger.com/atom/ns#' term='logitech quickcam ultra vision'/><category scheme='http://www.blogger.com/atom/ns#' term='ubuntu'/><title type='text'>How to get Logitech QuickCam Ultra Vision working in Ubuntu</title><content type='html'>I have recently removed Windows from my Dell Inspiron 9400, and replaced it with Ubuntu, which is a flavour of Linux (or GNU/Linux if you're picky).
&lt;br/&gt;&lt;br/&gt;
I was surprised at how easy the installation was, almost everything worked out of the box, wireless, all the media keys and 95% of the fn keys.  (I'm having trouble with fn+f8 and fn+10 not working correctly)
&lt;br/&gt;&lt;br/&gt;
Anyway I am very happy with the Installation, I love the effects you have on the windows, it looks really pretty.
&lt;br/&gt;&lt;br/&gt;
I wanted to get my Logitech QuickCam Ultra Vision working with Ubuntu, so I could use it on Skype.  I plugged it in and nothing happened...ho hum... on windows it would have picked it up and installed it, and asked for the driver cd, but anyway, after a bit of googling around I found this &lt;a href="https://answers.launchpad.net/ubuntu/+question/3743"&gt;thread&lt;/a&gt;, and I followed the advise of Andrew Barber on there.
&lt;br/&gt;&lt;br/&gt;

Make sure first you have all the tools for the job:

&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
sudo apt-get install linux-headers-`uname -r` linux-restricted-modules-`uname -r` build-essential subversion
]]&gt;&lt;/script&gt;

Once you have got all them you will need to use subversion to get the driver from the svn repo..

&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
svn checkout http://svn.berlios.de/svnroot/repos/linux-uvc/
]]&gt;&lt;/script&gt;
Then you need to compile and install

&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
cd linux-uvc/linux-uvc/trunk
make
sudo make install
]]&gt;&lt;/script&gt;

Plug the camera in and take a look at dmesg. It may [hopefully] give you the device listing for it... eg /dev/video1

Point your application at that device and see if it works.

&lt;br/&gt;
I checked dmseg to see what had happened...&lt;br/&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
$ dmesg | grep -i vid
[    0.000000] BIOS-provided physical RAM map:
[    8.445959] Boot video device is 0000:00:02.0
[   26.441798] input: Video Bus as /devices/LNXSYSTM:00/device:00/PNP0A03:00/device:2b/LNXVIDEO:00/input/input7
[   26.489145] ACPI: Video Device [VID] (multi-head: yes  rom: no  post: no)
[   26.497079] input: Video Bus as /devices/LNXSYSTM:00/device:00/PNP0A03:00/LNXVIDEO:01/input/input8
[   26.537089] ACPI: Video Device [VID1] (multi-head: yes  rom: no  post: no)
[   26.537246] input: Video Bus as /devices/LNXSYSTM:00/device:00/PNP0A03:00/LNXVIDEO:02/input/input9
[   26.585000] ACPI: Video Device [VID2] (multi-head: yes  rom: no  post: no)
[ 2902.096243] Linux video capture interface: v2.00
[ 2902.175522] uvcvideo: Found UVC 1.00 device &amp;lt;unnamed&amp;gt; (046d:08c9)
[ 2902.189674] usbcore: registered new interface driver uvcvideo
[ 2902.189683] USB Video Class driver (v0.1.0)
]]&gt;&lt;/script&gt;
&lt;br/&gt;
After that it worked in skype, I needed to set the sound in device to be the microphone of the web cam in the options of skype...
&lt;br/&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
Sound In:   USB Device 0x46d:0x8c9 (hw:U0x46d0x8c9,0)
Sound Out:  Default device(default)
Ringing:    Default device(default)
]]&gt;&lt;/script&gt;
&lt;br/&gt;
and in the video settings of skype...
&lt;br/&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
Select webcam: UVC Camera (0x46d:0x8c9) (/dev/video0)
]]&gt;&lt;/script&gt;
&lt;br/&gt;
I am still currently having a weird issue where it seems that skype takes over the sound of all other applications.  If I try and play some music after a skype call then it won't play until I reboot.  Also it seems I'm allowed a max of 1 skype call before the sound in skype doesn't work, and therefore doesn't let me make or receive anymore calls.  Again it only seems at the moment that a reboot will fix it.  For the moment I will live with this as I don't use skype that often anyway.  (If anyone has any advice for this part please leave a comment)
&lt;br/&gt;&lt;br/&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/ubuntu" rel="tag"&gt;ubuntu&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/skype" rel="tag"&gt;skype&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/Logitech%20QuickCam%20Ultra%20Vision" rel="tag"&gt;Logitech QuickCam Ultra Vision&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/logitech" rel="tag"&gt;logitech&lt;/a&gt;,&lt;a href="http://www.technorati.com/tags/quickcam" rel="tag"&gt;quickcam&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-3860604520025910504?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/3860604520025910504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=3860604520025910504' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/3860604520025910504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/3860604520025910504'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2008/07/how-to-get-logitech-quickcam-ultra.html' title='How to get Logitech QuickCam Ultra Vision working in Ubuntu'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-5954556380060780250</id><published>2008-06-29T16:37:00.009+01:00</published><updated>2010-06-28T23:24:53.638+01:00</updated><title type='text'>How to Inject Spring Beans into Servlets Revisited.</title><content type='html'>Back in November I wrote a post about &lt;a href="http://andykayley.blogspot.com/2007/11/how-to-inject-spring-beans-into.html" target="_blank"&gt;How to Inject Spring Beans into Servlets&lt;/a&gt;, since then one of the comments made on the post by &lt;a href="http://www.blogger.com/profile/09435493279526225197" target="_blank"&gt;angel&lt;/a&gt;, mentioned an interface and Servlet that comes with spring that does this the proper spring way.  Thank you very much angel, this is what I was looking for before I wrote the last post :)&lt;br/&gt;
&lt;br/&gt;
The proper way how this should be achieved is to write a class that implements &lt;a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/HttpRequestHandler.html" target="_blank"&gt;HttpRequestHandler&lt;/a&gt; and define this class in your applicationContext.xml.  Then you define a servlet in web.xml with a class of &lt;a href="http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/context/support/HttpRequestHandlerServlet.html" target="_blank"&gt;HttpRequestHandlerServlet&lt;/a&gt; and make sure the name of the servlet is the same as the bean you defined in applicationContext.xml.&lt;br/&gt;
&lt;br/&gt;
First lets write a class that we want to inject into a servlet...&lt;br/&gt;

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.httprequesthandlertest;

public interface ServiceToInject {

  public String someMethod();
}
]]&gt;&lt;/script&gt;

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.httprequesthandlertest;

public class ServiceToInjectImpl implements ServiceToInject {

  public String someMethod() {
      return "someMethod called";
  }
}
]]&gt;&lt;/script&gt;


Next we'll write a class that implements the HttpRequestHandler this is basically our servlet.


&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.httprequesthandlertest;
public class MyHttpRequestHandler implements HttpRequestHandler {

   private ServiceToInject serviceToInject;

   public void setServiceToInject(ServiceToInject serviceToInject) {
       this.serviceToInject = serviceToInject;
   }

   public void handleRequest(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException {

       System.out.println("******* HELLO *******");
       System.out.println(serviceToInject.someMethod());
   }
}
]]&gt;&lt;/script&gt;

Next all we need to do is configure our web.xml and applicationContext.xml...

First applicationContext.xml...
&lt;script class="brush: xml; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;beans xmlns="http://www.springframework.org/schema/beans"
       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"&amp;gt;

    &amp;lt;bean id="serviceToInject" class="name.kayley.httprequesthandlertest.ServiceToInjectImpl"&amp;gt;

    &amp;lt;bean id="myhttprequesthandler" class="name.kayley.httprequesthandlertest.MyHttpRequestHandler"&amp;gt;
        &amp;lt;property name="serviceToInject" ref="serviceToInject"&amp;gt;
    &amp;lt;/bean&amp;gt;

&amp;lt;/beans&amp;gt;
]]&gt;&lt;/script&gt;

And finally configure your web.xml ...

&lt;script class="brush: xml; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
           version="2.5"&amp;gt;

    &amp;lt;context-param&amp;gt;
        &amp;lt;param-name&amp;gt;contextConfigLocation&amp;lt;/param-name&amp;gt;
        &amp;lt;param-value&amp;gt;/WEB-INF/applicationContext.xml&amp;lt;/param-value&amp;gt;
    &amp;lt;/context-param&amp;gt;
    &amp;lt;listener&amp;gt;
        &amp;lt;listener-class&amp;gt;org.springframework.web.context.ContextLoaderListener&amp;lt;/listener-class&amp;gt;
    &amp;lt;/listener&amp;gt;
    &amp;lt;servlet&amp;gt;
        &amp;lt;servlet-name&amp;gt;myhttprequesthandler&amp;lt;/servlet-name&amp;gt;
        &amp;lt;servlet-class&amp;gt;org.springframework.web.context.support.HttpRequestHandlerServlet&amp;lt;/servlet-class&amp;gt;
    &amp;lt;/servlet&amp;gt;
    &amp;lt;servlet-mapping&amp;gt;
        &amp;lt;servlet-name&amp;gt;myhttprequesthandler&amp;lt;/servlet-name&amp;gt;
        &amp;lt;url-pattern&amp;gt;/MyServlet&amp;lt;/url-pattern&amp;gt;
    &amp;lt;/servlet-mapping&amp;gt;
&amp;lt;/web-app&amp;gt;
]]&gt;&lt;/script&gt;

Now run your web app and go to http://localhost:8080/MyServlet&lt;br/&gt;

You should see in your console log the output of your injected servlet...&lt;br/&gt;
&lt;br/&gt;
******* HELLO *******&lt;br/&gt;
someMethod called&lt;br/&gt;
&lt;br/&gt;
Brilliant :-)  Thanks again angel.
&lt;br/&gt;&lt;br/&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/spring" rel="tag"&gt;spring&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/servlet" rel="tag"&gt;servlet&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/dependency%20injection" rel="tag"&gt;dependency injection&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-5954556380060780250?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/5954556380060780250/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=5954556380060780250' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/5954556380060780250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/5954556380060780250'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2008/06/how-to-inject-spring-beans-into.html' title='How to Inject Spring Beans into Servlets Revisited.'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-4804851129554822913</id><published>2008-05-30T00:17:00.011+01:00</published><updated>2008-05-30T01:20:31.388+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='martial arts'/><category scheme='http://www.blogger.com/atom/ns#' term='ju jutsu'/><category scheme='http://www.blogger.com/atom/ns#' term='ju jitsu'/><category scheme='http://www.blogger.com/atom/ns#' term='hakama'/><category scheme='http://www.blogger.com/atom/ns#' term='kempo'/><category scheme='http://www.blogger.com/atom/ns#' term='bjjagb'/><title type='text'>How to fold your Hakama</title><content type='html'>Some of you may or may not be aware that this coming Sunday I will be taking my Black Belt 2nd Dan (or Nidan in Japanese) grading in Ju Jitsu.  The style of Ju Jitsu I do is called Go-shin Kempo Ju Jitsu and is based mainly at the &lt;a href="http://www.mma.uk.com/" target="_blank"&gt;Masters of Martial Arts&lt;/a&gt; academy in Accrington, Lancashire, UK.  The association is a affiliated to the &lt;a href="http://www.bjjagb.com/" target="_blank"&gt;British Ju Jitsu Association Governing Body&lt;/a&gt; (BJJAGB).
&lt;br/&gt;&lt;br/&gt;
We will be required to wear Hakamas for part of the grading, mainly to do Kata, then we'll get changed back into the usual Gi (The name given for the Karate Style Pyjama suit for those of you not in the know).  One of the criteria for the 2nd Dan grading is demonstrating that you can fold the Hakama correctly.
&lt;br/&gt;&lt;br/&gt;
While I was searching the web I couldn't find anywhere that resembled the way our Sensei's wanted us to fold them.
&lt;br/&gt;&lt;br/&gt;
I found this site which is a similar way but not exactly the same...
&lt;br/&gt;&lt;br/&gt;
&lt;a href="http://www.elovirta.com/2002/03/14/hakama/" target="_blank"&gt;http://www.elovirta.com/2002/03/14/hakama/&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
And then I found this one too, which at the bottom shows a way very similar to the way we have been shown...
&lt;br/&gt;&lt;br/&gt;
&lt;a href="http://www.mushinkankendo.com/kendo_uniform.html" target="_blank"&gt;http://www.mushinkankendo.com/kendo_uniform.html&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
So after practising folding a few times last night I thought I'd share my frustrations and show you this way to fold the Himo(the straps) of the Hakama.  I start at this point because there are plenty of examples of how to get to this point on the web, including the two resources I mention above.
&lt;br/&gt;&lt;br/&gt;
Step 1.
&lt;br/&gt;&lt;br/&gt;
Starting with the left side, take the long straps and fold them up and place them in a cross shape across the folded hakama...
&lt;br/&gt;&lt;br/&gt;
&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LhbhKZNGwok/SD86Kk4Pb4I/AAAAAAAAAAM/7VrrR4cJE88/s1600-h/DSC00365.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_LhbhKZNGwok/SD86Kk4Pb4I/AAAAAAAAAAM/7VrrR4cJE88/s320/DSC00365.JPG" alt="" id="BLOGGER_PHOTO_ID_5205943647636254594" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 2.
&lt;br/&gt;&lt;br/&gt;
Bring the left short strap over the top of the hakama and place it over the two longer folded straps as shown in the photo.
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_LhbhKZNGwok/SD86K04Pb5I/AAAAAAAAAAU/fU4zqcN3uUc/s1600-h/DSC00366.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_LhbhKZNGwok/SD86K04Pb5I/AAAAAAAAAAU/fU4zqcN3uUc/s320/DSC00366.JPG" alt="" id="BLOGGER_PHOTO_ID_5205943651931221906" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 3.
&lt;br/&gt;&lt;br/&gt;
Thread the shorter strap underneath both of the longer straps and upwards as shown below...
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_LhbhKZNGwok/SD86LE4Pb6I/AAAAAAAAAAc/sOQrVkofpio/s1600-h/DSC00367.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_LhbhKZNGwok/SD86LE4Pb6I/AAAAAAAAAAc/sOQrVkofpio/s320/DSC00367.JPG" alt="" id="BLOGGER_PHOTO_ID_5205943656226189218" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 4.
&lt;br/&gt;&lt;br/&gt;
Take the left strap and move it back over itself to the left as shown...
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LhbhKZNGwok/SD86LU4Pb7I/AAAAAAAAAAk/eNbn2WsQyyQ/s1600-h/DSC00369.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_LhbhKZNGwok/SD86LU4Pb7I/AAAAAAAAAAk/eNbn2WsQyyQ/s320/DSC00369.JPG" alt="" id="BLOGGER_PHOTO_ID_5205943660521156530" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 5.
&lt;br/&gt;&lt;br/&gt;
Thread the strap under both the short and long straps and diagonally upwards as shown...
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LhbhKZNGwok/SD86Lk4Pb8I/AAAAAAAAAAs/1mZJYv1MAhA/s1600-h/DSC00371.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_LhbhKZNGwok/SD86Lk4Pb8I/AAAAAAAAAAs/1mZJYv1MAhA/s320/DSC00371.JPG" alt="" id="BLOGGER_PHOTO_ID_5205943664816123842" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 6.
&lt;br/&gt;&lt;br/&gt;
Place the strap along the diagonal line of the long strap, if its too long, tuck it under.  This side is now finished...
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LhbhKZNGwok/SD869k4Pb9I/AAAAAAAAAA0/EnM0A4eE8HY/s1600-h/DSC00372.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_LhbhKZNGwok/SD869k4Pb9I/AAAAAAAAAA0/EnM0A4eE8HY/s320/DSC00372.JPG" alt="" id="BLOGGER_PHOTO_ID_5205944523809583058" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 7.
&lt;br/&gt;&lt;br/&gt;
Bring the right short strap over the top of the hakama and place it over the two longer folded straps as shown in the photo.
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_LhbhKZNGwok/SD86-E4Pb-I/AAAAAAAAAA8/S8rK2hDQBrA/s1600-h/DSC00373.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_LhbhKZNGwok/SD86-E4Pb-I/AAAAAAAAAA8/S8rK2hDQBrA/s320/DSC00373.JPG" alt="" id="BLOGGER_PHOTO_ID_5205944532399517666" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 8.
&lt;br/&gt;&lt;br/&gt;
Again thread the shorter strap underneath both of the longer straps and upwards as shown below...
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LhbhKZNGwok/SD86-U4Pb_I/AAAAAAAAABE/DhqP2cMqKyg/s1600-h/DSC00374.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_LhbhKZNGwok/SD86-U4Pb_I/AAAAAAAAABE/DhqP2cMqKyg/s320/DSC00374.JPG" alt="" id="BLOGGER_PHOTO_ID_5205944536694484978" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 9.
&lt;br/&gt;&lt;br/&gt;
Take the right strap and move it back over itself to the right as shown...
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_LhbhKZNGwok/SD86-k4PcAI/AAAAAAAAABM/HpHMGgqPp7A/s1600-h/DSC00375.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://3.bp.blogspot.com/_LhbhKZNGwok/SD86-k4PcAI/AAAAAAAAABM/HpHMGgqPp7A/s320/DSC00375.JPG" alt="" id="BLOGGER_PHOTO_ID_5205944540989452290" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 10.
&lt;br/&gt;&lt;br/&gt;
Thread the strap under both the short and long straps and diagonally upwards as shown...
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_LhbhKZNGwok/SD86_E4PcBI/AAAAAAAAABU/r-haFLfSink/s1600-h/DSC00376.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://1.bp.blogspot.com/_LhbhKZNGwok/SD86_E4PcBI/AAAAAAAAABU/r-haFLfSink/s320/DSC00376.JPG" alt="" id="BLOGGER_PHOTO_ID_5205944549579386898" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Step 11.
&lt;br/&gt;&lt;br/&gt;
Place the strap along the diagonal line of the long strap but thread it under the existing hoop from the left side, if its too long, tuck it under.
&lt;br/&gt;&lt;br/&gt;
&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_LhbhKZNGwok/SD87MU4PcCI/AAAAAAAAABc/ZvCls2EjsfM/s1600-h/DSC00378.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://2.bp.blogspot.com/_LhbhKZNGwok/SD87MU4PcCI/AAAAAAAAABc/ZvCls2EjsfM/s320/DSC00378.JPG" alt="" id="BLOGGER_PHOTO_ID_5205944777212653602" border="0" /&gt;&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
And that's that.
&lt;br/&gt;&lt;br/&gt;
Hope this helps someone.
&lt;br/&gt;&lt;br/&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/martial%20arts" rel="tag"&gt;martial arts&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/ju%20jitsu" rel="tag"&gt;ju jitsu&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/ju%20jutsu" rel="tag"&gt;ju jutsu&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/hakama" rel="tag"&gt;hakama&lt;/a&gt;,&lt;a href="http://www.technorati.com/tags/kempo" rel="tag"&gt;kempo&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/bjjagb" rel="tag"&gt;bjjagb&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/bjja" rel="tag"&gt;bjja&lt;/a&gt;,&lt;a href="http://www.technorati.com/tags/british%20ju%20jitsu%20association%20governing%20body" rel="tag"&gt;british ju jitsu association governing body&lt;/a&gt;,&lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-4804851129554822913?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/4804851129554822913/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=4804851129554822913' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/4804851129554822913'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/4804851129554822913'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2008/05/how-to-fold-your-hakama.html' title='How to fold your Hakama'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_LhbhKZNGwok/SD86Kk4Pb4I/AAAAAAAAAAM/7VrrR4cJE88/s72-c/DSC00365.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-5384621694977728032</id><published>2008-01-05T09:08:00.001Z</published><updated>2010-06-28T23:33:00.205+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='juli'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='logging'/><category scheme='http://www.blogger.com/atom/ns#' term='tomcat'/><title type='text'>How to configure Tomcat 5.0.x to use Java Logging</title><content type='html'>If you are using java logging and a version of tomcat previous to tomcat 5.5, you have to use the deprecated Logger declarations in your server.xml or
context.xml files.  The are deprecated in tomcat 5.0 and have actually been removed in tomcat 5.5.
&lt;br/&gt;&lt;br/&gt;
This is used to achieve separate log files for separate virtual hosts/web applications for example in your server xml you may have...
&lt;br/&gt;
&lt;script class="brush: xml; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&amp;lt;Host name="myapp.mydomain.com" debug="0" appBase="webapps/myapp"&lt;br/&gt;
      unpackWARs="true" autoDeploy="true"&lt;br/&gt;
      xmlValidation="false" xmlNamespaceAware="false"&amp;gt;
&lt;br/&gt;
      &amp;lt;Logger className="org.apache.catalina.logger.FileLogger"&lt;br/&gt;
              directory="logs"  prefix="myapp." suffix=".log"&lt;br/&gt;
              timestamp="true"/&amp;gt;
&lt;br/&gt;
&amp;lt;/Host&amp;gt;
]]&gt;&lt;/script&gt;      
&lt;br/&gt;
This will log the myapp.timestamp.log file with all the contents of the webapp "myapp".  
&lt;br/&gt;&lt;br/&gt;
If you are using log4j you can simply omit this and use the log4j.properties (or log4j.xml file) within your webapp to specify what the logging levels are and where
to log to etc.
&lt;br/&gt;&lt;br/&gt;
Java logging lacks this functionality.  The java logging configuration file logging.properies is a jvm-wide properties file, and therefore traditionally
you would have to use the Logger feature to get separate log file per webapp.
&lt;br/&gt;&lt;br/&gt;
In tomcat 5.5 apache introduced juli which is an implementation of the java logger that addresses the shortcomings of the logging.properties file.
i.e. with tomcat 5.5 and above you can have a logging.properties file within your webapp.
&lt;br/&gt;&lt;br/&gt;
Now if you are tied to tomcat 5.0 for your deploys you can actually add juli logging to tomcat 5.0 quite easily, here's what you do...
&lt;br/&gt;&lt;br/&gt;
Firstly download the tomcat 5.5 core binary distribution. (from http://tomcat.apache.org/download-55.cgi) 
From this apache-tomcat-5.5.25.zip file extract the following two files...
&lt;br/&gt;
&lt;pre&gt;apache-tomcat-5.5.25/bin/tomcat-juli.jar&lt;/pre&gt; into &lt;pre&gt;jakarta-tomcat-5.0.28/bin&lt;/pre&gt;
and
&lt;pre&gt;apache-tomcat-5.5.25/conf/logging.properties&lt;/pre&gt; into &lt;pre&gt;jakarta-tomcat-5.0.28/conf&lt;/pre&gt;
&lt;br/&gt;
Next we need to edit our catalina startup script to tell java logging about the juli logging jar and properties file.
&lt;br/&gt;&lt;br/&gt;
if you are using a flavour of linux/unix edit
jakarta-tomcat-5.0.28/bin/catalina.sh
&lt;br/&gt;&lt;br/&gt;
and under the cygwin section add the following...
&lt;br/&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
# Set juli LogManager if it is present
if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
 JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
fi
]]&gt;&lt;/script&gt;
and then after the classpath section add...
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
 CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/tomcat-juli.jar
fi]]&gt;&lt;/script&gt;
if you are using windows edit
jakarta-tomcat-5.0.28\bin\catalina.bat
&lt;br/&gt;&lt;br/&gt;
After the setenv.bat section add...
&lt;br/&gt;
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuliProps
set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
:noJuliProps
]]&gt;&lt;/script&gt;
and then after the classpath section add...
&lt;script class="brush: bash; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
if not exist "%CATALINA_HOME%\bin\tomcat-juli.jar" goto noJuli
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar
:noJuli
]]&gt;&lt;/script&gt;
And voila that's it!
&lt;br/&gt;&lt;br/&gt;
All you need now in your webapp is add your own specific logging.properties file to the WEB-INF/classes directory of the war, an example of which....
&lt;br/&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
####### --------- logging.properties --------- #############
handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

org.apache.juli.FileHandler.level=FINEST
org.apache.juli.FileHandler.directory=/var/log/tomcat
org.apache.juli.FileHandler.prefix=myapp.

java.util.logging.ConsoleHandler.level=FINEST
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
]]&gt;&lt;/script&gt;

&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/tomcat" rel="tag"&gt;tomcat&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/logging" rel="tag"&gt;logging&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/juli" rel="tag"&gt;juli&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-5384621694977728032?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/5384621694977728032/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=5384621694977728032' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/5384621694977728032'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/5384621694977728032'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2007/12/how-to-configure-tomcat-50x-to-use-java.html' title='How to configure Tomcat 5.0.x to use Java Logging'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-1306153655228203804</id><published>2007-12-05T19:09:00.001Z</published><updated>2010-06-28T23:35:29.179+01:00</updated><title type='text'>Clob Handling Made Easy in Java with Oracle 10g</title><content type='html'>I found out a pretty neat thing last week about the JDBC Driver for Oracle 10g.
&lt;br/&gt;&lt;br/&gt;
Previously when I've had to use a CLOB (Character Large OBject) in Java using Oracle
&lt;br/&gt;&lt;br/&gt;
I've had to use the Oracle specific classes, rather than use the javax.sql classes.
&lt;br/&gt;&lt;br/&gt;
i.e...

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
String sql = "SELECT DATA FROM MY_TABLE WHERE ID = ? FOR UPDATE";

PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, primaryKey);
ResultSet res = stmt.executeQuery();

oracle.sql.CLOB clob = (oracle.sql.CLOB)res.getClob(1);
]]&gt;&lt;/script&gt;
Then you had to use methods on the CLOB class that are not available on javax.sql.Clob to stream the bytes to / from the database.  
If you tried to use the methods that should have been used on the javax.sql.Clob class you got some sort of error, an Unsupported Driver Operation or the like (Haven't done this for a while and my memory's a bit rusty on it)
&lt;br/&gt;&lt;br/&gt;
Since the 10g driver the oracle CLOB and BLOB classes both implement the jdbc interface properly, so you can just use the jdbc classes/interfaces
instead of putting oracle specific classes in your code.
&lt;br/&gt;&lt;br/&gt;
This allows you to use 
&lt;br/&gt;&lt;br/&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
javax.sql.Clob clob = res.getClob(1);
]]&gt;&lt;/script&gt;

and for writing using the jdbc methods...

&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
out = clob.setAsciiStream(0);
]]&gt;&lt;/script&gt;

and for reading ...
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
in = new BufferedInputStream(clob.getAsciiStream());
]]&gt;&lt;/script&gt;

Recently I've had to use a clob again, and I have always wondered why can't I just go stmt.setClob() and rs.getClob() without having to use a load of byte streaming code.
Well the nice guys n gals at Oracle have done something similar for the 10g driver which I think is fantastic.
&lt;br/&gt;&lt;br/&gt;
No more selecting for update, all you do is use the setString and getString methods on PreparedStatement and ResultSet.
&lt;br/&gt;&lt;br/&gt;
You will need to set some oracle specific settings in the driver properties if you want to put data in that's bigger than 32k.
&lt;br/&gt;&lt;br/&gt;
I found this information out &lt;a href="http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/clob10g/handlingclobsinoraclejdbc10g.html"&gt;here&lt;/a&gt;
&lt;br/&gt;&lt;br/&gt;
Nice one oracle, its about time :) I wonder if they've done something similar for Blob handling!!
&lt;br/&gt;&lt;br/&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/jdbc" rel="tag"&gt;jdbc&lt;/a&gt;, &lt;a 
href="http://www.technorati.com/tags/oracle" rel="tag"&gt;oracle&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/clob" rel="tag"&gt;clob&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-1306153655228203804?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/1306153655228203804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=1306153655228203804' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/1306153655228203804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/1306153655228203804'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2007/12/clob-handling-made-easy-in-java-with.html' title='Clob Handling Made Easy in Java with Oracle 10g'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-1971773936813609356</id><published>2007-11-20T23:58:00.004Z</published><updated>2010-06-28T23:39:42.908+01:00</updated><title type='text'>@Deprecated: How to Inject Spring Beans into Servlets.</title><content type='html'>&lt;b&gt;This post has been Deprecated, see &lt;a href="http://andykayley.blogspot.com/2008/06/how-to-inject-spring-beans-into.html"&gt;this post instead&lt;/a&gt;&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;

A couple of months ago I was working on an application that used Servlets as entry points to an application, sort of like a web service.  This was a new application and I decided to use the Spring framework for dependancy injection and to make using Hibernate easier.
&lt;br/&gt;&lt;br/&gt;
I am fairly new to Spring and never needed to inject any spring beans into  servlet before, and I thought there must be a way to do it. However after browsing through a number of websites, blog posts and forum posts, it appeared that there wasn't a clean spring way to do this.
&lt;br/&gt;&lt;br/&gt;
&lt;span style="font-weight: bold;"&gt;Solution 1&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;
In the end I read somewhere that you could inject spring beans into the ServletContext, so I took this route.
&lt;br/&gt;&lt;br/&gt;
With this you have to declare this little piece in your applicationContext.xml
&lt;br/&gt;&lt;br/&gt;
&lt;script class="brush: xml; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
&amp;lt;bean class="org.springframework.web.context.support.ServletContextAttributeExporter"&amp;gt;
 &amp;lt;property name="attributes"&amp;gt;
     &amp;lt;map&amp;gt;
         &amp;lt;!-- inject the following beans into the servlet
context so the servlets can access them. --&amp;gt;
         &amp;lt;entry key="myBeanFromSpring"&amp;gt;
             &amp;lt;ref bean="myBeanFromSpring"/&amp;gt;
         &amp;lt;/entry&amp;gt;
     &amp;lt;/map&amp;gt;
 &amp;lt;/property&amp;gt;
&amp;lt;/bean&amp;gt;
]]&gt;&lt;/script&gt;
&lt;br/&gt;&lt;br/&gt;
As you can see this puts the spring bean&lt;span style="font-family: monospace;"&gt; &lt;/span&gt;myBeanFromSpring into the servlet context.  Therefore in your servlet code you can do the following...
&lt;br/&gt;&lt;br/&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
protected void doGet(HttpServletRequest reqest, HttpServletResponse response)
                                         throws ServletException, IOException {

   MyBeanFromSpring myBean = MyBeanFromSpring)getServletContext().getAttribute("myBeanFromSpring");
   myBean.someOperation();
   ...
}
]]&gt;&lt;/script&gt;
&lt;br/&gt;&lt;br/&gt;
Although this works it still doesn't feel very spring like. 
&lt;br/&gt;&lt;br/&gt;
&lt;span style="font-weight: bold;"&gt;Solution 2&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;
There is another way to achieve the same thing.  You can use WebApplicationContext and get the beans directly from Spring without having to inject anything into the servlet context.
&lt;br/&gt;&lt;br/&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
protected void doGet(HttpServletRequest reqest, HttpServletResponse response)
                                         throws ServletException, IOException {

   WebApplicationContext springContext =
       WebApplicationContextUtils.getWebApplicationContext(getServletContext());
   MyBeanFromSpring myBean =(MyBeanFromSpring)springContext.getBean("myBeanFromSpring");
   myBean.someOperation();
   ...
}
]]&gt;&lt;/script&gt;
&lt;br/&gt;&lt;br/&gt;
Although this achieves the same thing and is probably more concise than &lt;span style="font-weight: bold;"&gt;Solution 1&lt;/span&gt;, it still is not achieving what I initially wanted, which was dependancy injection into the servlet.
&lt;br/&gt;&lt;br/&gt;
&lt;span style="font-weight: bold;"&gt;Solution 3&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;
Although I stayed with Solution 1 for the application it got me thinking.  So I set out to write a sub class of HttpServlet that would use the servletContext solution and use reflection to figure out if the servlet had any setters on that spring should call.
&lt;br/&gt;&lt;br/&gt;
My original servlet that had to do all the stuff with getting the servlet context suddenly looks a lot more spring-like...
&lt;br/&gt;&lt;br/&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
import name.kayley.springutils.SpringDependencyInjectionServlet;

public class MyServlet extends SpringDependencyInjectionServlet {

   private MyBeanFromSpring myBean;

   public void setMyBeanFromSpring(MyBeanFromSpring myBean) {
       this.myBean = myBean;
   }

   protected void doGet(HttpServletRequest reqest, HttpServletResponse response)
                                           throws ServletException, IOException {

       myBean.someOperation();
   }
}
]]&gt;&lt;/script&gt;
&lt;br/&gt;&lt;br/&gt;
And here is the source of the SpringDependencyInjectionServlet, go easy on it, Its the first version and it passes the unit tests i have written for it, use it at your own risk or as a starting point, but like I said it appears to work ok so far. 
&lt;br/&gt;&lt;br/&gt;
I have attempted to keep in with the spring autowiring of giving 2 options, autowire by type and by name, so you can override autowireByType if you want to autowire by name.  I think they need some work as I believe that autowire by name should go off the name of the parameter to the setter method and not the setter method name itself... keep coming back for updates.
&lt;br/&gt;&lt;br/&gt;
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
package name.kayley.springutils;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

public class SpringDependencyInjectionServlet extends HttpServlet {

   private static final Logger logger =
Logger.getLogger(SpringDependencyInjectionServlet.class.getName());


   protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
       Enumeration attributeNames = getServletContext().getAttributeNames();

       while (attributeNames.hasMoreElements()) {

           String name = (String) attributeNames.nextElement();
           logger.log(Level.INFO, "attempting to autowire " + name);

           autowire(name);
       }

       super.service(request, response);
   }

   protected boolean autowireByType() {
       return true;
   }

   private void autowire(String name) {
       if (name != null) {
           Object attribute = getServletContext().getAttribute(name);
           Class c = getClass();
           while (c != null &amp;&amp; c != c.getSuperclass()) {
               try {
                   if (autowireByType()) {
                       if (byType(c, attribute)) {
                           break;
                       }
                       else {
                           c = c.getSuperclass();
                       }
                   }
                   else {
                       if (byName(c, name, attribute)) {
                           break;
                       }
                       else {
                           c = c.getSuperclass();
                       }
                   }
               }
               catch (NoSuchMethodException e) {
                   c = c.getSuperclass();
               }
           }
       }
   }

   private boolean byName(Class c, String name, Object attribute)
       throws NoSuchMethodException {
       boolean success = false;

       if (attribute != null) {

           Method[] methods = c.getDeclaredMethods();
           for (Method method : methods) {
               if (method.getName().equals(getMethodName(name))) {
                   Class[] paramTypes = method.getParameterTypes();

                   if (paramTypes.length == 1) {
                       success = invokeSpringBeanSetter(method, attribute);
                   }
               }
           }
       }
       return success;
   }

   private boolean byType(Class c, Object attribute) {
       boolean success = false;

       if (attribute != null) {
           Method[] methods = c.getDeclaredMethods();

           for (Method method : methods) {
               Class[] paramTypes = method.getParameterTypes();

               Class attributeClass = attribute.getClass();
               if (paramTypes.length == 1 &amp;&amp;
          paramTypes[0].equals(attributeClass)) {
                   boolean succeeded = invokeSpringBeanSetter(method,attribute);
                   if (!success &amp;&amp; succeeded) {
                       success = succeeded;
                   }
               }
           }
       }
       return success;
   }

   private boolean invokeSpringBeanSetter(Method method, Object attribute) {
       boolean success = false;
       try {
           method.invoke(this, attribute);
           success = true;
       }
       catch (Exception e) {
           // TODO do we care?
       }
       return success;
   }

   private String getMethodName(String contextName) {
       return "set" + StringUtils.capitalize(contextName);
   }
}
]]&gt;&lt;/script&gt;
&lt;br/&gt;&lt;br/&gt;
&lt;span class="technoratitag"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tags/java" rel="tag"&gt;java&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/spring" rel="tag"&gt;spring&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/servlet" rel="tag"&gt;servlet&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/dependency%20injection" rel="tag"&gt;dependency injection&lt;/a&gt;, &lt;a href="http://www.technorati.com/tags/andy%20kayley" rel="tag"&gt;andy kayley&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-1971773936813609356?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/1971773936813609356/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=1971773936813609356' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/1971773936813609356'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/1971773936813609356'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2007/11/how-to-inject-spring-beans-into.html' title='@Deprecated: How to Inject Spring Beans into Servlets.'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6447184396655674320.post-2575389977691647189</id><published>2007-11-15T19:12:00.002Z</published><updated>2010-06-28T23:43:30.997+01:00</updated><title type='text'>Hello World!</title><content type='html'>I'm new to all this blogging malarkey, I have been advised to do so by my friend and colleague &lt;a href="http://www.andrewbeacock.com/"&gt;Andrew Beacock&lt;/a&gt;.  It appears I am worthy of sharing some of my knowledge of all things java and software development related to the world.

So lets start with a bit of geeky fun...
&lt;script class="brush: java; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
public class FirstBlogPost {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public FirstBlogPost() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;System.out.println("Hello World!");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}
]]&gt;&lt;/script&gt;
&lt;script class="brush: ruby; wrap-lines: false" type="syntaxhighlighter"&gt;
&lt;![CDATA[
class FirstBlogPost
&amp;nbsp;&amp;nbsp;def initialize
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;puts 'Hello World!'
&amp;nbsp;&amp;nbsp;end
end
]]&gt;&lt;/script&gt;
Maybe I should have named this post "Hello World in Java and Ruby" :o)

That's all for now, check back later for more in depth advice and discoveries.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6447184396655674320-2575389977691647189?l=andykayley.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://andykayley.blogspot.com/feeds/2575389977691647189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6447184396655674320&amp;postID=2575389977691647189' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/2575389977691647189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6447184396655674320/posts/default/2575389977691647189'/><link rel='alternate' type='text/html' href='http://andykayley.blogspot.com/2007/11/hello-world.html' title='Hello World!'/><author><name>Andy Kayley</name><uri>http://www.blogger.com/profile/02677580444705293617</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://2.bp.blogspot.com/-tAJD3RAJ13A/Tyczhjmeo4I/AAAAAAAAAt0/ZRi60fvns2w/s220/me.jpg'/></author><thr:total>1</thr:total></entry></feed>
