<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>Always Crispy</title><generator>Tumblr (3.0; @verycrispy)</generator><link>http://chrisjordan.ca/</link><item><title>After having worked at Gilt for a couple years, I think I can...</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lxi1kwHMgO1qkke85o1_500.png"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;After having worked at Gilt for a couple years, I think I can safely say that Seattle has a different sense of fashion.&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15529139869</link><guid>http://chrisjordan.ca/post/15529139869</guid><pubDate>Sun, 08 Jan 2012 16:41:19 -0500</pubDate><category>Seattle</category><category>Folk Art</category></item><item><title>So I have been in Seattle for about 24 hours now and I am...</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lxhy0sTIaF1qkke85o1_500.png"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;So I have been in Seattle for about 24 hours now and I am starting to figure out the quirks about where I am living. There are drastically fewer people here than in New York which is great during the day but makes me worried about zombies at night (thank you AMC Walking Dead). I discovered this morning while shopping for home goods that there is a monorail that goes between the downtown core and my place. Magnets now hurdle me between where I sleep and where I shop.&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15524859271</link><guid>http://chrisjordan.ca/post/15524859271</guid><pubDate>Sun, 08 Jan 2012 15:24:27 -0500</pubDate><category>Seattle</category></item><item><title>Get the size of a Postgresql table</title><description>&lt;a href="http://postgresql.cc/postgres-table-size"&gt;Get the size of a Postgresql table&lt;/a&gt;: &lt;p&gt;From time to time, you need to figure out how much data is in a table. This bit of SQL, specific to Postgres, gets you the size of the one that you specify. &lt;/p&gt;
&lt;p&gt;&lt;code&gt; SELECT pg_size_pretty(pg_relation_size('your_table')); &lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15345791488</link><guid>http://chrisjordan.ca/post/15345791488</guid><pubDate>Thu, 05 Jan 2012 09:41:00 -0500</pubDate><category>postgresql</category></item><item><title>Configuring Apache Tika's HtmlParser</title><description>&lt;p&gt;So in my previous post about Apache Tika, I showed off a small Hello World program that demonstrated how you can quickly use it to parse HTML files. One of the first issues you will probably encounter using Tika though is that its HtmlParser does not immediately handle all tags. For example, the code tag is not recognized. To deal with that, you need to create a custom HtmlMapper. In the code example below, I created an HtmlMapper that accepts all tags. In addition to expanding the number of tags that the HtmlParser can handle, custom HtmlMappers are great for isolate specific blocks that you are interested in by discarding ones that you do not care about.&lt;/p&gt;
&lt;p&gt;&lt;code&gt; import java.io.InputStream;&lt;br/&gt; import java.net.URL;&lt;br/&gt;&lt;br/&gt; import org.apache.tika.metadata.Metadata;&lt;br/&gt; import org.apache.tika.parser.ParseContext;&lt;br/&gt; import org.apache.tika.parser.html.HtmlMapper;&lt;br/&gt; import org.apache.tika.parser.html.HtmlParser;&lt;br/&gt; import org.apache.tika.sax.ToHTMLContentHandler;&lt;br/&gt;&lt;br/&gt; public class HelloApacheTika2 {&lt;br/&gt;     public static void main (String args[]) throws Exception {&lt;br/&gt;         URL url = new URL("http://chrisjordan.ca/post/15345467825/configuring-apache-tikas-htmlparser");&lt;br/&gt;         InputStream input = url.openStream();&lt;br/&gt;&lt;br/&gt;         ToHTMLContentHandler toHTMLHandler = new ToHTMLContentHandler();&lt;br/&gt;         Metadata metadata = new Metadata();&lt;br/&gt;         ParseContext parseContext = new ParseContext();&lt;br/&gt;         parseContext.set(HtmlMapper.class, AllTagMapper.class.newInstance());&lt;br/&gt;         HtmlParser parser = new HtmlParser();&lt;br/&gt;&lt;br/&gt;         parser.parse(input, toHTMLHandler, metadata, parseContext);&lt;br/&gt;         System.out.println(toHTMLHandler.toString());&lt;br/&gt;     }&lt;br/&gt; }&lt;br/&gt;&lt;br/&gt; /**&lt;br/&gt;  * A HtmlMapper that accepts all tags and tributes. &lt;br/&gt;  *&lt;br/&gt;  */&lt;br/&gt; class AllTagMapper implements HtmlMapper {&lt;br/&gt;  &lt;br/&gt;     @Override&lt;br/&gt;     public String mapSafeElement(String name) {&lt;br/&gt;         return name.toLowerCase();&lt;br/&gt;     }&lt;br/&gt;&lt;br/&gt;     @Override&lt;br/&gt;     public boolean isDiscardElement(String name) {&lt;br/&gt;         return false;&lt;br/&gt;     }&lt;br/&gt;&lt;br/&gt;     @Override&lt;br/&gt;     public String mapSafeAttribute(String elementName, String attributeName) {&lt;br/&gt;         return attributeName.toLowerCase();&lt;br/&gt;     }&lt;br/&gt;&lt;br/&gt; }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt; &lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15345467825</link><guid>http://chrisjordan.ca/post/15345467825</guid><pubDate>Thu, 05 Jan 2012 09:28:00 -0500</pubDate><category>java</category><category>apache tika</category><category>text parsing</category></item><item><title>Parsing HTML with Apache Tika</title><description>&lt;p&gt;Every now and then, I have to parse some HTML files. There are a lot of ways you can go about doing that. Recently, I have started using Apache Tika and it does a pretty reasonable job (i.e. better than what I have done before). There is not a lot of documentation on Tika so I had to do a bit of hacking to get my head around it.&lt;/p&gt;
&lt;p&gt;A good start is this quick Hello World Tika program I put together. It parses this article. The TeeContentHandler passes data from the HtmlParser to ContentHandlers that it has been initialized with. For the purposes of this example, I am showing off three different handlers. The LinkContentHandler is great for extracting links; useful for crawlers. The ContentHandler strips out all the text on a page; useful for indexers. The ToHTMLContentHandler produces XHTML; useful for extracting specific blocks of text which is also good for indexers. One thing to be aware of when using the HtmlParser is that natively, it does not support all tags. For example, it currently skips over the code tag. My next post will explain how to configure the HtmlParser to not do that :-)&lt;/p&gt;
&lt;p&gt;&lt;code&gt; import java.io.InputStream;&lt;br/&gt; import java.net.URL;&lt;br/&gt; import org.apache.tika.metadata.Metadata;&lt;br/&gt; import org.apache.tika.parser.ParseContext;&lt;br/&gt; import org.apache.tika.parser.html.HtmlParser;&lt;br/&gt; import org.apache.tika.sax.BodyContentHandler;&lt;br/&gt; import org.apache.tika.sax.LinkContentHandler;&lt;br/&gt; import org.apache.tika.sax.TeeContentHandler;&lt;br/&gt; import org.apache.tika.sax.ToHTMLContentHandler;&lt;br/&gt; import org.xml.sax.ContentHandler;&lt;br/&gt;&lt;br/&gt; public class HelloApacheTika {&lt;br/&gt;&lt;br/&gt;     public static void main (String args[]) throws Exception {&lt;br/&gt;         URL url = new URL("http://chrisjordan.ca/post/15219674437/parsing-html-with-apache-tika");&lt;br/&gt;         InputStream input = url.openStream();&lt;br/&gt;         LinkContentHandler linkHandler = new LinkContentHandler();&lt;br/&gt;         ContentHandler textHandler = new BodyContentHandler();&lt;br/&gt;         ToHTMLContentHandler toHTMLHandler = new ToHTMLContentHandler();&lt;br/&gt;         TeeContentHandler teeHandler = new TeeContentHandler(linkHandler, textHandler, toHTMLHandler);&lt;br/&gt;         Metadata metadata = new Metadata();&lt;br/&gt;         ParseContext parseContext = new ParseContext();&lt;br/&gt;         HtmlParser parser = new HtmlParser();&lt;br/&gt;         parser.parse(input, teeHandler, metadata, parseContext);&lt;br/&gt;         System.out.println("title:\n" + metadata.get("title"));&lt;br/&gt;         System.out.println("links:\n" + linkHandler.getLinks());&lt;br/&gt;         System.out.println("text:\n" + textHandler.toString());&lt;br/&gt;         System.out.println("html:\n" + toHTMLHandler.toString());&lt;br/&gt;     }&lt;br/&gt; }&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you are using Maven, you need to add the following dependencies:&lt;/p&gt;
&lt;p&gt;&lt;code&gt; &amp;lt;!-- Apache Tika --&amp;gt;&lt;br/&gt; &amp;lt;dependency&amp;gt;&lt;br/&gt;     &amp;lt;groupId&amp;gt;org.apache.tika&amp;lt;/groupId&amp;gt;&lt;br/&gt;     &amp;lt;artifactId&amp;gt;tika-core&amp;lt;/artifactId&amp;gt;&lt;br/&gt;     &amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;&lt;br/&gt; &amp;lt;/dependency&amp;gt;&lt;br/&gt;&lt;br/&gt; &amp;lt;dependency&amp;gt;&lt;br/&gt;     &amp;lt;groupId&amp;gt;org.apache.tika&amp;lt;/groupId&amp;gt;&lt;br/&gt;     &amp;lt;artifactId&amp;gt;&lt;span&gt;tika&lt;/span&gt;-parsers&amp;lt;/artifactId&amp;gt;&lt;br/&gt;     &amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;&lt;br/&gt;&amp;lt;/dependency&amp;gt;&lt;br/&gt;&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15219674437</link><guid>http://chrisjordan.ca/post/15219674437</guid><pubDate>Mon, 02 Jan 2012 21:56:00 -0500</pubDate><category>java</category><category>Apache Tika</category><category>text parsing</category></item><item><title>Characteristics of slow SQL Queries</title><description>&lt;a href="http://stackoverflow.com/questions/8309773/characteristics-of-slow-sql-queries/8310320#8310320"&gt;Characteristics of slow SQL Queries&lt;/a&gt;: &lt;p&gt;I actually forgot I posted this answer on Stack Overflow until today when my cousin complimented me on it :-)&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15203931655</link><guid>http://chrisjordan.ca/post/15203931655</guid><pubDate>Mon, 02 Jan 2012 17:15:00 -0500</pubDate><category>SQL</category><category>Stack Overflow</category></item><item><title>So... new city, new website... again!</title><description>&lt;p&gt;Hey all,&lt;/p&gt;
&lt;p&gt;I have changed cities and websites again! A bit of a coincidence that I have done both at the same time again. I have migrated off of Drupal and onto Tumblr. Drupal has been good to me but I just do not have time to maintain it on my server anymore especially since I only had a single Website running on it. I really like Tumblr as a platform and it is super convenient so that is why I am using it for now.&lt;/p&gt;
&lt;p&gt;You will notice that I was able to import all my old blog posts. Tumblr does not import blog posts natively so I wrote a Web app to do it for me. I posted it to my GitHub, &lt;a href="https://github.com/cpjordan79/Blog-Teleporter"&gt;Blog Teleporter&lt;/a&gt;. It is a pretty simple app that crawls Drupal blogs (for now) and posts them to Tumblr. There are a few things I need to tighten up on it but it runs end to end and can be easily extended to crawl other blog platforms. I think I am going to add in one more platform before I declare it a version 1.0. You might notice that all of my old posts have a new tag, &lt;a href="http://verycrispy.tumblr.com/tagged/teleporter"&gt;teleporter&lt;/a&gt;. My app added it so you can easily see which posts you have imported. That allows for easy rollbacks on Tumblr in case there is a problem importing. &lt;/p&gt;
&lt;p&gt;That is basically why I have not made any posts in the past few months. The combination of me getting a new job, handing off the old one, and promising myself to not post until I migrated off of Drupal did it. There are a lot of goodies in my Blog Teleporter though and I will be posting about them shortly.&lt;/p&gt;
&lt;p&gt;If you want to migrate your blog onto Tumblr and my Blog Teleporter does not support your platform, just let me know. I am happy to add it as another feature.&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15099335652</link><guid>http://chrisjordan.ca/post/15099335652</guid><pubDate>Sat, 31 Dec 2011 16:52:12 -0500</pubDate><category>java</category><category>blog-teleporter</category><category>Spring</category></item><item><title>Creating and Managing Threads in Java </title><description>&lt;p&gt;Threading in the early days of Java use to be a pain. Since Java 1.5 and the introduction of the ExecutorService, it is much easier to start up and manage them. Code that you want executed in a separate thread must be encapsulated in a class that implements Runnable. An instance of that class can then be passed to an ExecutorService that will handle its execution. Below is a trivial example but it demonstrates how to use the ExecutorService and thread pools.&lt;/p&gt;

&lt;p&gt;	&lt;code&gt;import java.util.concurrent.ExecutorService;&lt;br clear="none"/&gt;

	import java.util.concurrent.Executors;&lt;br clear="none"/&gt;

	import java.util.concurrent.TimeUnit;&lt;br clear="none"/&gt;

	import org.apache.log4j.Logger;&lt;br clear="none"/&gt;

	public class ExecutorServiceExample {&lt;br clear="none"/&gt;

	    public static void main (String args[]) {&lt;br clear="none"/&gt;

	        final Logger logger = Logger.getLogger(ExecutorServiceExample.class);&lt;br clear="none"/&gt;

	        ExecutorService threadExecutor = Executors.newFixedThreadPool( 10 );&lt;br clear="none"/&gt;

	        for (int i = 0; i &amp;lt; 20; i++) {&lt;br clear="none"/&gt;

	            threadExecutor.execute(new Runnable() {&lt;br clear="none"/&gt;

	                @Override&lt;br clear="none"/&gt;

	                public void run() {&lt;br clear="none"/&gt;

	                    try {&lt;br clear="none"/&gt;

	                        logger.info("This thread is going to sleep");&lt;br clear="none"/&gt;

	                        Thread.sleep((long)(Math.random() * 10000));&lt;br clear="none"/&gt;

	                    } catch (InterruptedException e) {&lt;br clear="none"/&gt;

	                        logger.error("Oh noes... interruptted thread?!",e);&lt;br clear="none"/&gt;

	                    }&lt;br clear="none"/&gt;

	                }&lt;br clear="none"/&gt;

	            });&lt;br clear="none"/&gt;

	        }&lt;br clear="none"/&gt;

	        threadExecutor.shutdown();&lt;br clear="none"/&gt;

	        try {&lt;br clear="none"/&gt;

	            threadExecutor.awaitTermination(5, TimeUnit.MINUTES);&lt;br clear="none"/&gt;

	            logger.info("All threads done");&lt;br clear="none"/&gt;

	        } catch (InterruptedException e) {&lt;br clear="none"/&gt;

	            logger.error("Oh noes... interruptted thread?!",e);&lt;br clear="none"/&gt;

	        }&lt;br clear="none"/&gt;

	    }&lt;br clear="none"/&gt;

	}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	In the example above, I created an ExecutorService that manages a pool of 10 threads. It then executes 20 anonymous classes which log an info message and sleep between 0 and 10 seconds. After that, it waits for the threads to finish executing and then logs another info message.&lt;/p&gt;

&lt;p&gt;	As you can see from the output below, the 10 threads in the pool execute one after the other. After that though, as different threads complete execution before others, they begin executing out of order due to their availability.&lt;/p&gt;

&lt;p&gt;	Output:&lt;br clear="none"/&gt;&lt;code&gt; 2011-09-13 22:07:19,511 [pool-1-thread-1] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,512 [pool-1-thread-3] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,511 [pool-1-thread-2] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,512 [pool-1-thread-4] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,512 [pool-1-thread-5] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,512 [pool-1-thread-6] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,512 [pool-1-thread-7] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,513 [pool-1-thread-8] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,513 [pool-1-thread-9] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,513 [pool-1-thread-10] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:19,619 [pool-1-thread-1] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:21,424 [pool-1-thread-6] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:21,815 [pool-1-thread-2] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:22,567 [pool-1-thread-10] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:23,474 [pool-1-thread-10] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:23,863 [pool-1-thread-9] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:24,473 [pool-1-thread-8] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:24,569 [pool-1-thread-7] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:25,506 [pool-1-thread-5] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:27,492 [pool-1-thread-4] INFO  ExecutorServiceExample - This thread is going to sleep&lt;br clear="none"/&gt;

	2011-09-13 22:07:34,308 [main] INFO  ExecutorServiceExample - All threads done&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052396935</link><guid>http://chrisjordan.ca/post/15052396935</guid><pubDate>Tue, 13 Sep 2011 23:37:00 -0400</pubDate><category>teleporter</category><category>java</category></item><item><title>Java SFTP</title><description>&lt;p&gt;Believe it or not, there are very few options currently when it comes to implementing SFTP in Java. I believe that the Apache Mina project will eventually provide support for it (&lt;a shape="rect" href="http://mina.apache.org/sshd/index.html"&gt;&lt;a href="http://mina.apache.org/sshd/index.html"&gt;http://mina.apache.org/sshd/index.html&lt;/a&gt;&lt;/a&gt;) however, the project is still at version 0.5 and I have not found any good documentation for it. jCraft&amp;#8217;s JSch package is the most straightforward library that I have used so far and in this article, I am going to provide a sample implementation. &lt;br clear="none"/&gt;

	JSch: &lt;a shape="rect" href="http://www.jcraft.com/jsch/"&gt;&lt;a href="http://www.jcraft.com/jsch/"&gt;http://www.jcraft.com/jsch/&lt;/a&gt;&lt;/a&gt;&lt;br clear="none"/&gt;

	JSch download: &lt;a shape="rect" href="http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.44/jsch-0.1.44.jar/download"&gt;&lt;a href="http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.44/jsch-0.1.44.jar/download"&gt;http://sourceforge.net/projects/jsch/files/jsch.jar/0.1.44/jsch-0.1.44.jar/download&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;	Something to keep in mind here is that SFTP is not FTPS. SFTP is SSH FTP hence why I am hoping that Apache Mina will eventually support it. FTPS is FTP SSL which you can interact with using Apache FtpServer (&lt;a shape="rect" href="http://mina.apache.org/ftpserver/"&gt;&lt;a href="http://mina.apache.org/ftpserver/"&gt;http://mina.apache.org/ftpserver/&lt;/a&gt;&lt;/a&gt;). Until there is a mature Apache project, I recommend JSch. Actually, I recommend that you first try using SSH Fuse (&lt;a shape="rect" href="http://fuse.sourceforge.net/sshfs.html"&gt;&lt;a href="http://fuse.sourceforge.net/sshfs.html"&gt;http://fuse.sourceforge.net/sshfs.html&lt;/a&gt;&lt;/a&gt;) to mount your SFTP account on your file system and if you cannot set it up, then use JSch.&lt;br clear="none"/&gt;&lt;code&gt; import com.jcraft.jsch.ChannelSftp;&lt;br clear="none"/&gt;

	import com.jcraft.jsch.JSch;&lt;br clear="none"/&gt;

	import com.jcraft.jsch.Session;&lt;br clear="none"/&gt;

	import com.jcraft.jsch.SftpProgressMonitor; &lt;br clear="none"/&gt;

	public class SFTPExample {&lt;br clear="none"/&gt;

	    public static void main(String args[]) throws Exception {&lt;br clear="none"/&gt;

	        String user = "enter user name";&lt;br clear="none"/&gt;

	        String password = "enter password";&lt;br clear="none"/&gt;

	        String host = "enter host";&lt;br clear="none"/&gt;

	        int port = 22;&lt;br clear="none"/&gt;

	        String knownHostsFilename = "/path/to/.ssh/known_hosts";        &lt;br clear="none"/&gt;

	        String sourcePath = "/path/to/test_file";&lt;br clear="none"/&gt;

	        String destPath = "test_file";        &lt;br clear="none"/&gt;

	        JSch jsch = new JSch();&lt;br clear="none"/&gt;

	        jsch.setKnownHosts(knownHostsFilename);&lt;br clear="none"/&gt;

	        Session session = jsch.getSession(user, host, port);&lt;br clear="none"/&gt;

	        session.setPassword(password);&lt;br clear="none"/&gt;

	        session.connect(); &lt;br clear="none"/&gt;

	        ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");&lt;br clear="none"/&gt;

	        sftpChannel.connect();&lt;br clear="none"/&gt;

	        System.out.println("Uploading test file");&lt;br clear="none"/&gt;

	        sftpChannel.put(sourcePath, destPath, new ExampleProgressMonitor());      &lt;br clear="none"/&gt;

	        System.out.println("Downloading test file");&lt;br clear="none"/&gt;

	        sftpChannel.get(destPath, sourcePath + ".new",  new ExampleProgressMonitor());        &lt;br clear="none"/&gt;

	        System.out.println("Remove test file");&lt;br clear="none"/&gt;

	        sftpChannel.rm(destPath);     &lt;br clear="none"/&gt;

	        sftpChannel.exit();&lt;br clear="none"/&gt;

	        session.disconnect();&lt;br clear="none"/&gt;

	    }&lt;br clear="none"/&gt;

	} &lt;br clear="none"/&gt;

	class ExampleProgressMonitor implements SftpProgressMonitor {&lt;br clear="none"/&gt;

	    private double count;&lt;br clear="none"/&gt;

	    private double max;&lt;br clear="none"/&gt;

	    private String src;&lt;br clear="none"/&gt;

	    private int percent;&lt;br clear="none"/&gt;

	    private int lastDisplayedPercent; &lt;br clear="none"/&gt;

	    ExampleProgressMonitor() {&lt;br clear="none"/&gt;

	        count = 0;&lt;br clear="none"/&gt;

	        max = 0;&lt;br clear="none"/&gt;

	        percent = 0;&lt;br clear="none"/&gt;

	        lastDisplayedPercent = 0;&lt;br clear="none"/&gt;

	    }&lt;br clear="none"/&gt;

	    public void init(int op, String src, String dest, long max) {&lt;br clear="none"/&gt;

	        this.max = max;&lt;br clear="none"/&gt;

	        this.src = src;&lt;br clear="none"/&gt;

	        count = 0;&lt;br clear="none"/&gt;

	        percent = 0;&lt;br clear="none"/&gt;

	        lastDisplayedPercent = 0;&lt;br clear="none"/&gt;

	        status();&lt;br clear="none"/&gt;

	    }&lt;br clear="none"/&gt;

	    public boolean count(long count) {&lt;br clear="none"/&gt;

	        this.count += count;&lt;br clear="none"/&gt;

	        percent = (int) ((this.count / max) * 100.0);&lt;br clear="none"/&gt;

	        status();&lt;br clear="none"/&gt;

	        return true;&lt;br clear="none"/&gt;

	    } &lt;br clear="none"/&gt;

	    public void end() {&lt;br clear="none"/&gt;

	        percent = (int) ((count / max) * 100.0);&lt;br clear="none"/&gt;

	        status();&lt;br clear="none"/&gt;

	    } &lt;br clear="none"/&gt;

	    private void status() {&lt;br clear="none"/&gt;

	        if (lastDisplayedPercent &amp;lt;= percent - 10) {&lt;br clear="none"/&gt;

	            System.out.println(src + ": " + percent + "% " + ((long) count) + "/" + ((long) max));&lt;br clear="none"/&gt;

	            lastDisplayedPercent = percent;&lt;br clear="none"/&gt;

	        }&lt;br clear="none"/&gt;

	    }&lt;br clear="none"/&gt;

	} &lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052396308</link><guid>http://chrisjordan.ca/post/15052396308</guid><pubDate>Sun, 28 Aug 2011 22:14:00 -0400</pubDate><category>teleporter</category><category>java</category><category>sftp</category></item><item><title>Formatting JSON from command line</title><description>&lt;p&gt;So when working on REST services that return JSON, I often hit them from command line using curl. If the JSON message that is returned is rather large, it can be a pain to read. Python provides a nice little tool though for formatting it. You can pipe a JSON message returned from a curl to it like so:&lt;br clear="none"/&gt;&lt;code&gt;curl &lt;a shape="rect" href="http://my.rest.service.org" title="http://my.rest.service.org"&gt;&lt;a href="http://my.rest.service.org"&gt;http://my.rest.service.org&lt;/a&gt;&lt;/a&gt; | python -mjson.tool | less&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052396008</link><guid>http://chrisjordan.ca/post/15052396008</guid><pubDate>Thu, 25 Aug 2011 22:09:00 -0400</pubDate><category>teleporter</category><category>JSON</category></item><item><title>Using Dependency Injection To Incorporate A/B Testing Into Your Applications</title><description>&lt;p&gt;I posted this article to my company&amp;#8217;s tech blog a few weeks back. I am reposting it here because&amp;#8230; well&amp;#8230; I wrote it :-) &lt;/p&gt;

&lt;p&gt;	&lt;a shape="rect" href="http://tech.gilt.com/post/8391205906/using-dependency-injection-to-incorporate-a-b-testing"&gt;&lt;a href="http://tech.gilt.com/post/8391205906/using-dependency-injection-to-incorporate-a-b-testing"&gt;http://tech.gilt.com/post/8391205906/using-dependency-injection-to-incorporate-a-b-testing&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;	If you work at an e-commerce company, chances are you’ve probably come across the term “A/B testing”. We all know that it has something to do with testing out new features on users and seeing which ones are “better”. A/B testing is really the practice of comparing the effect that a feature (“treatment” in statistical terms) has on different groups of users. For instance, you might be developing a new navigation bar for your Website. You can see if it improves how long users stay on your site by testing it on a group of users (A) and comparing them to users in another group (B) that are using the original navigation bar. Again in statistical lingo, group B would be considered your “control group”. It’s important to note that you can test a variety of navigation bars here and not violate the principles behind A/B testing since your treatment is the type of bar you are exposing.&lt;/p&gt;

&lt;p&gt;	Now you are probably wondering how dependency injection (DI) factors into A/B testing. DI is the design principle where your objects are assigned references to their dependencies at runtime. Generally speaking, objects using DI refer to their dependencies through interfaces or super classes so they are indifferent to how those dependencies are actually implemented and instantiated. There are a few frameworks in Java that leverage DI. For the work that we do at Gilt, we use Java Spring. The example in this post is in Spring but it’s general enough that it can be applied to other frameworks.&lt;/p&gt;

&lt;p&gt;	So now that we know what DI is, let’s apply it to make A/B testing a part of your applications. In A/B testing, groups of users are exposed to a given treatment. That means we need to have a mapping between groups of users and the treatment that they are receiving. Java Spring makes that very easy; in your Spring configuration, you can create such a mapping using the map tag. For example:&lt;/p&gt;

&lt;p&gt;	&lt;code&gt;&amp;lt;util:map id="ABTestMapping"&amp;gt;&lt;br clear="none"/&gt;

	  &amp;lt;entry&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;key&amp;gt;&lt;br clear="none"/&gt;

	      &amp;lt;value&amp;gt;group 1&amp;lt;/value&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;/key&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;ref bean="baseline_nav" /&amp;gt;&lt;br clear="none"/&gt;

	  &amp;lt;/entry&amp;gt;&lt;br clear="none"/&gt;

	  &amp;lt;entry&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;key&amp;gt;&lt;br clear="none"/&gt;

	      &amp;lt;value&amp;gt;group 2&amp;lt;/value&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;/key&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;ref bean="test_nav1" /&amp;gt;&lt;br clear="none"/&gt;

	  &amp;lt;/entry&amp;gt;&lt;br clear="none"/&gt;

	  &amp;lt;entry&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;key&amp;gt;&lt;br clear="none"/&gt;

	      &amp;lt;value&amp;gt;group 3&amp;lt;/value&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;/key&amp;gt;&lt;br clear="none"/&gt;

	    &amp;lt;ref bean="test_nav2" /&amp;gt;&lt;br clear="none"/&gt;

	  &amp;lt;/entry&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;/util:map&amp;gt;&lt;br clear="none"/&gt;

	 &lt;br clear="none"/&gt;

	&amp;lt;bean id="baseline_nav" class="com.gilt.examples.BaselineNavBar"/&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;bean id="test_nav1"    class="com.gilt.examples.NewNavBar1"/&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;bean id="test_nav2"    class="com.gilt.examples.NewNavBar2"/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	So in this map, our keys are different test groups of users and their corresponding values are the different navigation bar we will expose to them. This example is a bit contrived but it illustrates the point quite well. Instead of having to code A/B testing into your application, you can externalize it in a configuration. Java Spring instantiates this map and your application can use it to determine which navigation bar a user should see. A nifty trick in Spring is to use the import tag in your configuration. &lt;/p&gt;

&lt;p&gt;	&lt;code&gt;&amp;lt;import resource="file:test_buckets.xml"/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	This tag allows you to put your A/B testing configuration into a separate file which is very powerful. Doing so allows you to change which groups receive various treatments without having to recompile or redeploy your code. &lt;/p&gt;

&lt;p&gt;	Simple. Fast. Very Useful.&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052395551</link><guid>http://chrisjordan.ca/post/15052395551</guid><pubDate>Sat, 20 Aug 2011 15:54:00 -0400</pubDate><category>teleporter</category><category>java</category><category>Spring</category></item><item><title>Now in Java 1.7 - Support for Strings in switch statements</title><description>&lt;p&gt;With the release of Java 1.7, some cool new features have been added to the language. One of them is the support for Strings in switch statements (finally eh!). Prior to 1.7, the cases labels could be a byte, short, char, or int and their corresponding wrapper classes. Support for enum types is implied and have made it possible to provide more meaningful representations for primitive data types however, sometimes you just want to use String case labels and now you finally can.&lt;/p&gt;

&lt;p&gt;	&lt;a shape="rect" href="http://download.oracle.com/javase/tutorial/java/nutsandbolts/switch.html"&gt;&lt;a href="http://download.oracle.com/javase/tutorial/java/nutsandbolts/switch.html"&gt;http://download.oracle.com/javase/tutorial/java/nutsandbolts/switch.html&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052395266</link><guid>http://chrisjordan.ca/post/15052395266</guid><pubDate>Sat, 30 Jul 2011 20:47:00 -0400</pubDate><category>teleporter</category><category>java</category></item><item><title>Product Recommendations at Gilt</title><description>&lt;p&gt;A while back, I posted an article on the Gilt Groupe tech blog. It is about the recommendation engine I developed. I am pretty proud of it as it is based on some of my PhD work. Below is a re-blog. The original article with images can be found &lt;a shape="rect" href="http://tech.gilt.com/post/6251275107/product-recommendations-at-gilt"&gt;here&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;	Product recommendations at Gilt work a little differently than they do at other companies.  For example, at Amazon they enjoy the benefit of having a relatively static and large inventory so they can do things like &lt;em&gt;collaborative filter&lt;/em&gt; – where you can recommend a product based on what other people have bought or looked at. Gilt is unique because our inventory is in constant flux. The products we have one week are gone the next and there is a chance we won’t have them again.&lt;/p&gt;

&lt;p&gt;	At Gilt, we’ve employed a technique called &lt;em&gt;contextual retrieval&lt;/em&gt;. Contextual retrieval is a search method where we take elements from the user context to help them conduct a search. When someone sees a product that is sold out and they decide to waitlist it, we can infer a lot of things about the user. One is that they really want that product. Another is that we know everything about the product they are interested in. In fact, we use that product as a search query to find related ones that we have in our inventory whether they are currently on sale or not.&lt;/p&gt;

&lt;p&gt;	So the steps involved in setting up a contextual retrieval based recommendation service are as follows:&lt;/p&gt;

&lt;p&gt;	·      &lt;em&gt;First, you are going to have to create a search index of your products.&lt;/em&gt; &lt;br clear="none"/&gt;

	Apache Lucene is a great piece of open source technology for doing just that. You are going to want to create an index that contains all the fields that you have describing your products. Those fields are basically the metadata that you need to find similar ones.&lt;/p&gt;

&lt;p&gt;	·      &lt;em&gt;The second step is search query manufacturing. &lt;/em&gt;&lt;br clear="none"/&gt;

	This is where the recommendation magic really happens. When you construct your search from a product, not all fields are going to be equally important. In fact, it is very likely that different genres of products will have different fields that are going to be more valuable than others. To that end, you need to devise a weighting scheme where you boost the value of some fields over others.&lt;/p&gt;

&lt;p&gt;	·      &lt;em&gt;The third step is caching those recommendations.&lt;/em&gt; &lt;br clear="none"/&gt;

	You can quite easily get away with caching all your recommendations because unlike a search engine, you already know all the search queries that you are going to encounter – they are the products you have for sale. At Gilt, since we have new products every day, we generate and cache our recommendations once a day.&lt;/p&gt;

&lt;p&gt;	·      &lt;em&gt;The fourth (and most rewarding) step is using those recommendations in ways to help your users. &lt;/em&gt;&lt;br clear="none"/&gt;

	One of our customer pain points is that the product at Gilt sells out quickly.  When a user has decided that they want an item so much that they are willing to sign up for it on a waitlist, we want to do everything in our power to try to find them another product that they will be happy with.&lt;/p&gt;

&lt;p&gt;	That’s pretty much what we aim to achieve at Gilt – Simple, Fast and Fun!&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052394526</link><guid>http://chrisjordan.ca/post/15052394526</guid><pubDate>Thu, 28 Jul 2011 00:26:00 -0400</pubDate><category>teleporter</category><category>Gilt</category><category>Research</category></item><item><title>Woo hoo - my first Mahout contributions</title><description>&lt;p&gt;So ya, it has been crazy busy at work and I have been neglecting my blog :-/ Tragic I know for all of the 3 people that actually check it (me, myself, and I). Anyhow, I thought I would throw up a quick post here and hopefully have a big one over the weekend.&lt;/p&gt;

&lt;p&gt;	I made my first contributions to Apache Mahout this week. I have been using it at work to do our text mining and there were a couple things I developed to make it more Java framework friendly. Here are my contributions for the interested three:&lt;/p&gt;

&lt;p&gt;	&lt;a shape="rect" href="https://issues.apache.org/jira/browse/MAHOUT-671"&gt;&lt;a href="https://issues.apache.org/jira/browse/MAHOUT-671"&gt;https://issues.apache.org/jira/browse/MAHOUT-671&lt;/a&gt;&lt;/a&gt;&lt;br clear="none"/&gt;&lt;a shape="rect" href="https://issues.apache.org/jira/browse/MAHOUT-675"&gt;&lt;a href="https://issues.apache.org/jira/browse/MAHOUT-675"&gt;https://issues.apache.org/jira/browse/MAHOUT-675&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052394053</link><guid>http://chrisjordan.ca/post/15052394053</guid><pubDate>Fri, 22 Apr 2011 10:39:00 -0400</pubDate><category>teleporter</category><category>java</category><category>mahout</category></item><item><title>Setting up postfix to relay through your gmail account </title><description>&lt;p&gt;So this is kind of an odd topic. Why would you want to setup postfix to relay through your gmail. Well if you are using Verizon as an ISP for your home internet, you will find that they do not allow you send email from a locally running SMTP server, like postfix on your linux box or mac. They just block it. It is probably to prevent spammers however, if you need to write some email code, you will have to setup a relay through an SMTP server that you have access to, like gmail.&lt;/p&gt;

&lt;p&gt;	Here are the steps involved:&lt;/p&gt;

&lt;p&gt;	1. Create a Simple Authentication and Security Layer (SASL) password file at /etc/postfix/sasl_passwd. Enter in your gmail account info as it is shown below:&lt;br clear="none"/&gt;&lt;code&gt;smtp.gmail.com:587 enter_account@gmail.com:enter_password&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	2. Create a Postfix lookup table for your password file&lt;br clear="none"/&gt;&lt;code&gt;sudo postmap /etc/postfix/sasl_passwd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	3. Add the following to your /etc/postfix/main.cf. Depending on your installation, these configurations may be commented out so all you need to do is uncomment them and enter in the appropriate values&lt;br clear="none"/&gt;&lt;code&gt; # Minimum Postfix-specific configurations.&lt;br clear="none"/&gt;

	mydomain_fallback = localhost&lt;br clear="none"/&gt;

	mail_owner = _postfix&lt;br clear="none"/&gt;

	setgid_group = _postdrop&lt;br clear="none"/&gt;

	relayhost=smtp.gmail.com:587&lt;br clear="none"/&gt;

	# Enable SASL authentication in the Postfix SMTP client.&lt;br clear="none"/&gt;

	smtp_sasl_auth_enable=yes&lt;br clear="none"/&gt;

	smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd&lt;br clear="none"/&gt;

	smtp_sasl_security_options=&lt;br clear="none"/&gt;

	# Enable Transport Layer Security (TLS), i.e. SSL.&lt;br clear="none"/&gt;

	smtp_use_tls=yes&lt;br clear="none"/&gt;

	smtp_tls_security_level=encrypt&lt;br clear="none"/&gt;

	tls_random_source=dev:/dev/urandom&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	4. Start postfix&lt;br clear="none"/&gt;&lt;code&gt;sudo postfix start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	You can test out your configuration by sending yourself a quick email from the command line.&lt;br clear="none"/&gt;&lt;code&gt;echo "Hello World" | mail -s Hello enter_your_address@here.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	If you do not get the email, you can check to see if has actually sent using the following command&lt;br clear="none"/&gt;&lt;code&gt;mailq&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	To clear your mail queue, use this command&lt;br clear="none"/&gt;&lt;code&gt;sudo postsuper -d ALL&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052398373</link><guid>http://chrisjordan.ca/post/15052398373</guid><pubDate>Sat, 12 Feb 2011 11:07:00 -0500</pubDate><category>teleporter</category><category>email</category><category>postfix</category></item><item><title>Using the ClassLoader to access files in your classpath </title><description>&lt;p&gt;Here is a quick tid-bit about how to access files in Java that are in your classpath. For example, suppose you have a text file that you want to parse and it is packaged in your &lt;a shape="rect" href="http://www.chrisjordan.ca/node/18"&gt;jar&lt;/a&gt;. You can access it through the ClassLoader using either the method getResource(), that returns an instance of URL, or getResourceAsStream, that returns an instance of InputStream. Below is a simple coding example:&lt;/p&gt;

&lt;p&gt;	&lt;code&gt;import java.util.Scanner;&lt;br clear="none"/&gt;

	public class ExampleFileLoader {&lt;br clear="none"/&gt;

	  public static void main (String args[]) {&lt;br clear="none"/&gt;

	    Scanner scan = new Scanner (ExampleFileLoader.class.getClassLoader().getResourceAsStream("test_file.txt"));&lt;br clear="none"/&gt;

	    while (scan.hasNextLine())&lt;br clear="none"/&gt;

	      System.out.println(scan.nextLine());&lt;br clear="none"/&gt;

	  }&lt;br clear="none"/&gt;

	}&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052398587</link><guid>http://chrisjordan.ca/post/15052398587</guid><pubDate>Sat, 05 Feb 2011 13:22:00 -0500</pubDate><category>teleporter</category><category>java</category></item><item><title>JDBC fetch size and Postgresql</title><description>&lt;p&gt;Every now and then, you need to pull a massive amount of data from a database, more than can fit into memory reasonably. To this end, you can set the fetch size for your statement so that the database driver will pull back more manageable chunks of data. For example, if you set the fetch size to 100, the driver should pull back 100 row chunks. A new chunk is pulled when needed as you iterator over the corresponding result set.&lt;/p&gt;

&lt;p&gt;	Now setting the fetch size for most databases should be sufficient however, not for Postgresql. If you want to enable fetching, you also have to turn auto commit off as well. The reason has to deal with how Postgresql fetches chunks of data; it requires a transaction block and if auto commit is on, it cannot get one. You would think that the Postgresql JDBC driver would be smart enough to turn auto commit off if the fetch size is set to anything other than 0. Anyhow, as per usual, some example code is below:&lt;/p&gt;

&lt;p&gt;	&lt;code&gt;import java.sql.Connection;&lt;br clear="none"/&gt;

	import java.sql.DriverManager;&lt;br clear="none"/&gt;

	import java.sql.ResultSet;&lt;br clear="none"/&gt;

	import java.sql.SQLException;&lt;br clear="none"/&gt;

	import java.sql.Statement;&lt;br clear="none"/&gt;

	import java.util.Properties;&lt;br clear="none"/&gt;

	public class BigQueryExample {&lt;br clear="none"/&gt;

	   public static void main (String args[]) {&lt;br clear="none"/&gt;

	      Properties connectionProps = new Properties();&lt;br clear="none"/&gt;

	      connectionProps.put("user", "enter username");&lt;br clear="none"/&gt;

	      connectionProps.put("password", "enter password");&lt;br clear="none"/&gt;

	      Connection conn = null;&lt;br clear="none"/&gt;

	      Statement statement = null;&lt;br clear="none"/&gt;

	      ResultSet rs = null;&lt;br clear="none"/&gt;

	      try {&lt;br clear="none"/&gt;

	         conn = DriverManager.getConnection("enter url", connectionProps);&lt;br clear="none"/&gt;

	         conn.setAutoCommit(false);&lt;br clear="none"/&gt;

	         statement = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);&lt;br clear="none"/&gt;

	         statement.setFetchSize(100);&lt;br clear="none"/&gt;

	         rs = statement.executeQuery("SELECT name FROM giant_table_of_users");&lt;br clear="none"/&gt;

	         while (rs.next()) {&lt;br clear="none"/&gt;

	            System.out.println("Hi " + rs.getString("name"));&lt;br clear="none"/&gt;

	         }&lt;br clear="none"/&gt;

	      }&lt;br clear="none"/&gt;

	      catch (SQLException se) {&lt;br clear="none"/&gt;

	         System.err.println("some sort of jdbc error encountered");&lt;br clear="none"/&gt;

	         throw new RuntimeException(("some sort of jdbc error encountered", se);&lt;br clear="none"/&gt;

	      }&lt;br clear="none"/&gt;

	      finally {&lt;br clear="none"/&gt;

	         rs.close();&lt;br clear="none"/&gt;

	         statement.close();&lt;br clear="none"/&gt;

	         conn.close();&lt;br clear="none"/&gt;

	      }&lt;br clear="none"/&gt;

	   }&lt;br clear="none"/&gt;

	} &lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052397722</link><guid>http://chrisjordan.ca/post/15052397722</guid><pubDate>Thu, 03 Feb 2011 08:33:00 -0500</pubDate><category>teleporter</category><category>java</category><category>postgresql</category></item><item><title>How to setup SSL on Apache</title><description>&lt;p&gt;Setting up SSL on your Apache server is a pretty good idea even if you are only just hosting your own website with a CMS like drupal. With SSL enabled, you can now securely login, make updates, and post blog entries like me :-). Here is what you have to do:&lt;/p&gt;

&lt;p&gt;	Step 1. Generate an SSL certificate. All you really need is a self signed certificate unless of course you are doing something for work. The command below should do the trick. Just fill out the fields that it prompts you for.&lt;br clear="none"/&gt;&lt;code&gt;apache2-ssl-certificate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	Step 2. Enable the SSL module. The following command should do it:&lt;br clear="none"/&gt;&lt;code&gt;a2enmod ssl&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	Step 3. Configure SSL in your virtual host. You will need to add these two lines to your virtual host configuration.&lt;br clear="none"/&gt;&lt;code&gt; SSLEngine on&lt;br clear="none"/&gt;

	SSLCertificateFile /path/to/your.pem&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	Here is an example of what a virtual host configuration using SSL:&lt;br clear="none"/&gt;&lt;code&gt; NameVirtualHost *:443&lt;br clear="none"/&gt;

	NameVirtualHost *:80&lt;br clear="none"/&gt;

	&amp;lt;VirtualHost *:80&amp;gt;&lt;br clear="none"/&gt;

	        ServerName your.domain.com&lt;br clear="none"/&gt;

	        DocumentRoot /var/www/&lt;br clear="none"/&gt;

	        ErrorLog /var/log/apache2/error.log&lt;br clear="none"/&gt;

	        CustomLog /var/log/apache2/access.log combined&lt;br clear="none"/&gt;

	&amp;lt;/VirtualHost&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;VirtualHost *:443&amp;gt;&lt;br clear="none"/&gt;

	        ServerName your.domain.com&lt;br clear="none"/&gt;

	        DocumentRoot /var/www/&lt;br clear="none"/&gt;

	        ErrorLog /var/log/apache2/error.log&lt;br clear="none"/&gt;

	        CustomLog /var/log/apache2/access.log combined&lt;br clear="none"/&gt;

	        SSLEngine on&lt;br clear="none"/&gt;

	        SSLCertificateFile /path/to/your.pem&lt;br clear="none"/&gt;

	&amp;lt;/VirtualHost&amp;gt;&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052405324</link><guid>http://chrisjordan.ca/post/15052405324</guid><pubDate>Sat, 29 Jan 2011 20:04:00 -0500</pubDate><category>teleporter</category><category>apache</category></item><item><title>External Spring Config Files </title><description>&lt;p&gt;Most of the time when you are creating a Spring app, you end up packaging the XML config files with the war/jar. Sometimes though, it is quite beneficial to have a configuration file external to your built package. That allows you to configure your Spring app without having to rebuild or redeploy it; trust me, your system engineers/admins will love you for that. Using an external spring config is quite easy. You can use the import tag.&lt;/p&gt;

&lt;p&gt;	For example:&lt;code&gt;&lt;br clear="none"/&gt;

	&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;br clear="none"/&gt;

	       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br clear="none"/&gt;

	       xsi:schemaLocation="http://www.springframework.org/schema/beans &lt;a shape="rect" href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd%22&amp;gt;" title='http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&amp;gt;'&gt;&lt;a href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&lt;/a&gt;"&amp;gt;&lt;/a&gt;&lt;br clear="none"/&gt;

	   &amp;lt;import resource="file:/path/to/external/config.xml"/&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;/beans&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;	The above Spring config will import /path/to/external/config.xml. Having an external file will allow you to configure beans without having to rebuilding your main war/jar. Furthermore, an external Spring config allows you to create map configurations, something that you cannot do in traditional unix style property files. Below is an example map instance you can create in your external config:&lt;/p&gt;

&lt;p&gt;	&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;br clear="none"/&gt;

	       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br clear="none"/&gt;

	       xmlns:util="http://www.springframework.org/schema/util"&lt;br clear="none"/&gt;

	       xsi:schemaLocation="http://www.springframework.org/schema/beans &lt;a shape="rect" href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" title="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;&lt;a href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&lt;/a&gt;&lt;/a&gt;&lt;br clear="none"/&gt;

	                           &lt;a shape="rect" href="http://www.springframework.org/schema/util" title="http://www.springframework.org/schema/util"&gt;&lt;a href="http://www.springframework.org/schema/util"&gt;http://www.springframework.org/schema/util&lt;/a&gt;&lt;/a&gt; &lt;a shape="rect" href="http://www.springframework.org/schema/util/spring-util-3.0.xsd%22&amp;gt;" title='http://www.springframework.org/schema/util/spring-util-3.0.xsd"&amp;gt;'&gt;&lt;a href="http://www.springframework.org/schema/util/spring-util-3.0.xsd"&gt;http://www.springframework.org/schema/util/spring-util-3.0.xsd&lt;/a&gt;"&amp;gt;&lt;/a&gt;&lt;br clear="none"/&gt;

	   &amp;lt;util:map id="sampleMap"&amp;gt;&lt;br clear="none"/&gt;

	     &amp;lt;entry&amp;gt;&lt;br clear="none"/&gt;

	        &amp;lt;key&amp;gt;&lt;br clear="none"/&gt;

	           &amp;lt;value&amp;gt;Hello&amp;lt;/value&amp;gt;&lt;br clear="none"/&gt;

	        &amp;lt;/key&amp;gt;&lt;br clear="none"/&gt;

	           &amp;lt;value&amp;gt;World&amp;lt;/value&amp;gt;&lt;br clear="none"/&gt;

	      &amp;lt;/entry&amp;gt;&lt;br clear="none"/&gt;

	   &amp;lt;/util:map&amp;gt;&lt;br clear="none"/&gt;

	&amp;lt;/beans&amp;gt;&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052399506</link><guid>http://chrisjordan.ca/post/15052399506</guid><pubDate>Sat, 29 Jan 2011 19:19:00 -0500</pubDate><category>teleporter</category><category>java</category><category>Spring</category></item><item><title>Programatically logging a user out in Spring Security</title><description>&lt;p&gt;So I use Spring Security to handle user authentication in most of my Web applications. Every now and then, you need to log a user out programmatically. For example, users perform some sort of operation that redirects to a success page and logs them out. Logging a user out is quite simple. You need use the logout method for the relevant LogoutHandlers in your application. You are always going to have to use the SecurityContextLogoutHandler. I generally use the &amp;#8220;remember me token&amp;#8221; so I also have to use the PersistentTokenBasedRememberMeServices. Below is a sample method that you could have in your controller.&lt;/p&gt;

&lt;p&gt;	&lt;code&gt;import javax.servlet.http.HttpServletRequest;&lt;br clear="none"/&gt;

	import javax.servlet.http.HttpServletResponse;&lt;br clear="none"/&gt;

	import org.springframework.security.Authentication;&lt;br clear="none"/&gt;

	import org.springframework.security.context.SecurityContextHolder;&lt;br clear="none"/&gt;

	import org.springframework.security.ui.logout.SecurityContextLogoutHandler;&lt;br clear="none"/&gt;

	import org.springframework.security.ui.rememberme.PersistentTokenBasedRememberMeServices; import org.springframework.stereotype.Controller;&lt;br clear="none"/&gt;

	import org.springframework.web.bind.annotation.RequestMapping;&lt;br clear="none"/&gt;

	@Controller&lt;br clear="none"/&gt;

	public class SampleController {&lt;br clear="none"/&gt;

	   @RequestMapping(value="/some_page.htm")&lt;br clear="none"/&gt;

	   public String somePage (HttpServletRequest request, HttpServletResponse response) {&lt;br clear="none"/&gt;

	        /* some business logic code */&lt;br clear="none"/&gt;

	      Authentication auth = SecurityContextHolder.getContext().getAuthentication();&lt;br clear="none"/&gt;

	      if (auth != null){    &lt;br clear="none"/&gt;

	         new SecurityContextLogoutHandler().logout(request, response, auth);&lt;br clear="none"/&gt;

	         new PersistentTokenBasedRememberMeServices().logout(request, response, auth);&lt;br clear="none"/&gt;

	      }&lt;br clear="none"/&gt;

	   }&lt;br clear="none"/&gt;

	}&lt;/code&gt;&lt;/p&gt;</description><link>http://chrisjordan.ca/post/15052400009</link><guid>http://chrisjordan.ca/post/15052400009</guid><pubDate>Fri, 31 Dec 2010 20:26:00 -0500</pubDate><category>teleporter</category><category>java</category><category>security</category><category>Spring</category><category>Spring Security</category></item></channel></rss>

