<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Tech Per</title>
	
	<link>http://www.techper.net</link>
	<description>About Technology in My Life</description>
	<lastBuildDate>Mon, 26 Jul 2010 19:08:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TechPer" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="techper" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Aliasing Loopback on OSX</title>
		<link>http://www.techper.net/2010/07/26/aliasing-loopback-on-osx/</link>
		<comments>http://www.techper.net/2010/07/26/aliasing-loopback-on-osx/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 19:08:03 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[cassandra]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=348</guid>
		<description><![CDATA[aka&#8230;how to make it possible to use 127.0.0.2, 127.0.0.3, &#8230; on your Mac.
This post comes from a need I had to start cassandra in multiple instances on a single Mac (testing a cluster configuration out), and failing to do so. Previously on Linux, I had configured multiple instances to bind to 127.0.0.1 and 127.0.0.2 and [...]]]></description>
			<content:encoded><![CDATA[<p>aka&#8230;how to make it possible to use 127.0.0.2, 127.0.0.3, &#8230; on your Mac.</p>
<p>This post comes from a need I had to start <a href="http://cassandra.apache.org/">cassandra</a> in multiple instances on a single Mac (testing a cluster configuration out), and failing to do so. Previously on Linux, I had configured multiple instances to bind to 127.0.0.1 and 127.0.0.2 and it worked without any trouble. On the Mac though, I got the exception:</p>
<pre class="brush: plain;">
java.net.BindException: Can't assign requested address
	at sun.nio.ch.Net.bind(Native Method)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:52)
	at org.apache.cassandra.net.MessagingService.listen(MessagingService.java:138)
	at org.apache.cassandra.service.StorageService.initServer(StorageService.java:319)
	at org.apache.cassandra.thrift.CassandraDaemon.setup(CassandraDaemon.java:99)
	at org.apache.cassandra.thrift.CassandraDaemon.main(CassandraDaemon.java:177)
</pre>
<p>Until Jonathan Ellis and Peter Schuller on the cassandra list told me I could alias the extra addresses to loopback using this:</p>
<pre class="brush: plain;">
sudo ifconfig lo0 add 127.0.0.2
</pre>
<p>After that, ifconfig shows the added IP under the &#8220;lo0&#8243; device and cassandra can connect to it.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/nW1TpxeWgZM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/07/26/aliasing-loopback-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Non-Blocking Process.waitFor()</title>
		<link>http://www.techper.net/2010/07/16/a-non-blocking-process-waitfor/</link>
		<comments>http://www.techper.net/2010/07/16/a-non-blocking-process-waitfor/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 18:35:22 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=344</guid>
		<description><![CDATA[When calling java.lang.Process.waitFor() the call will block (wait()) until the process actually exits. The waitFor() call is blocking, which is pretty irritating sometimes, for instance when #&#038;%€! wine decides to hang itself, hereby stealing my tomcat execute threads and database connections in production  
Well, here&#8217;s a quick and dirty solution to creating a non-blocking [...]]]></description>
			<content:encoded><![CDATA[<p>When calling <a href="http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/lang/Process.html#waitFor()">java.lang.Process.waitFor()</a> the call will block (<tt>wait()</tt>) until the process actually exits. The <a href="http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/lang/Process.html#waitFor()">waitFor()</a> call is blocking, which is pretty irritating sometimes, for instance when #&#038;%€! <a href="http://www.winehq.org/">wine</a> decides to hang itself, hereby stealing my tomcat execute threads and database connections in production <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Well, here&#8217;s a quick and dirty solution to creating a <em>non-blocking</em> <tt>waitFor()</tt> call:</p>
<pre class="brush: java;">
  public boolean nonBlockingWaitFor(Process proc, long procMaxTimeoutMillis) throws InterruptedException {
    final long TIMESTAMP_BEFORE_EXECUTE = System.currentTimeMillis();
    boolean hasExited = false;
    while (!hasExited) {
      try {
        // set/calculate your own granularity of check, which fits your procMaxTimeoutMillis
        Thread.sleep(500);
        // using the IllegalThreadStateException side-effect of exitValue() if process hasn't exited
        proc.exitValue();
        hasExited = true;
      } catch (IllegalThreadStateException e) {
        if (System.currentTimeMillis() &gt; (TIMESTAMP_BEFORE_EXECUTE + procMaxTimeoutMillis)) {
          break;
        }
      }
    }
    return hasExited;
  }
</pre>
<p>This little block of code makes use of the fact, that <a href="http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/lang/Process.html#exitValue()">Process.exitValue()</a> will throw IllegalThreadStateException if one tries to peek at the exit value before the process has exited.</p>
<p>Is it nice? No!<br />
Does it work? Yes!</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/iwktDzc61yM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/07/16/a-non-blocking-process-waitfor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing CXF with Autowiring using Spring</title>
		<link>http://www.techper.net/2010/06/20/testing-cxf-with-autowiring-using-spring/</link>
		<comments>http://www.techper.net/2010/06/20/testing-cxf-with-autowiring-using-spring/#comments</comments>
		<pubDate>Sun, 20 Jun 2010 19:27:58 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cxf]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=341</guid>
		<description><![CDATA[Here is how to create a test for a CXF web service implementation class. The test use spring-mock base classes and hereby support stuff like transactions and autowiring through annotations. Neat.
I have a base class like this:

import org.springframework.test.jpa.AbstractJpaTests;

public abstract class AbstractCxfWsBeanTest extends AbstractJpaTests {
  public static final String[] SERVICE_CONFIG_LOCATION = new String[]{
   [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how to create a test for a <a href="http://cxf.apache.org/">CXF</a> web service implementation class. The test use spring-mock base classes and hereby support stuff like transactions and autowiring through annotations. Neat.</p>
<p>I have a base class like this:</p>
<pre class="brush: java;">
import org.springframework.test.jpa.AbstractJpaTests;

public abstract class AbstractCxfWsBeanTest extends AbstractJpaTests {
  public static final String[] SERVICE_CONFIG_LOCATION = new String[]{
      &quot;classpath*:/applicationContext.xml&quot;,
      &quot;classpath:/datasourceContext.xml&quot;,
      &quot;classpath:/cxf.xml&quot;,
  };

  @Override
  protected String[] getConfigLocations() {
    return SERVICE_CONFIG_LOCATION;
  }
}
</pre>
<p>One thing here: <tt>cxf.xml</tt> is loaded from classpath by the test code, but it resides in <tt>src/main/webapp/WEB-INF</tt> in my source tree, which is not exactly classpath stuff. I came around that with this little snippet in the <tt>&lt;build&gt;</tt> section of the maven <tt>pom.xml</tt>:</p>
<pre class="brush: xml;">
  &lt;build&gt;
    &lt;testResources&gt;
      &lt;testResource&gt;
        &lt;directory&gt;src/test/resources&lt;/directory&gt;
        &lt;includes&gt;
          &lt;include&gt;*&lt;/include&gt;
        &lt;/includes&gt;
      &lt;/testResource&gt;
      &lt;testResource&gt;
        &lt;directory&gt;src/main/webapp/WEB-INF&lt;/directory&gt;
        &lt;includes&gt;
          &lt;include&gt;cxf.xml&lt;/include&gt; &lt;!-- needed to make tests have cxf beans injected on them --&gt;
        &lt;/includes&gt;
      &lt;/testResource&gt;
    &lt;/testResources&gt;
  &lt;/build&gt;
</pre>
<p>And finally, I can write a test like this one:</p>
<pre class="brush: java;">
import org.springframework.beans.factory.annotation.Autowired;

public class TestMyWebService extends AbstractCxfWsBeanTest {

  @Autowired
  private MyWebService myWebService; // this is where I get my CXF WS impl injected

  public void testFoo() {
    assertEquals(&quot;bar&quot;, myWebService.foo());
  }
}
</pre>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/m5fvKvp7cf4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/06/20/testing-cxf-with-autowiring-using-spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One Pool to Rule Them All…in tomcat</title>
		<link>http://www.techper.net/2010/06/13/one-pool-to-rule-them-all-in-tomcat/</link>
		<comments>http://www.techper.net/2010/06/13/one-pool-to-rule-them-all-in-tomcat/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 08:41:39 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[pool]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=336</guid>
		<description><![CDATA[I am developing a system that gets deployed as a bunch of separate webapps but all in the same tomcat instance. Not long ago, we opened up production for a lot more users, which quickly led to some resource exhaustion-primarily on the database backend. In other words, &#8230; we were beating oracle to death.
After some [...]]]></description>
			<content:encoded><![CDATA[<p>I am developing a system that gets deployed as a bunch of separate webapps but all in the same <a href="http://tomcat.apache.org/">tomcat</a> instance. Not long ago, we opened up production for a lot more users, which quickly led to some resource exhaustion-primarily on the database backend. In other words, &#8230; we were beating oracle to death.</p>
<p>After some investigation we concluded, that, &#8230;the database was too loaded. Duh! Okay, so why? It turns out we hadn&#8217;t been using the insides of our heads that much. Each webapp deployed on tomcat had its own database pool defined in its own context. With many webapps, this summed up to a large max-value for how many connections we could open against oracle. Something that oracle couldn&#8217;t scale to.</p>
<p>So, to <em>maximize throughput and sacrificing a bit on individual request processing time</em>, we decided to define one single pool in tomcat, and let each webapp reference that pool. Here&#8217;s how it&#8217;s done:</p>
<p>In <tt>conf/server.xml</tt> in the <tt>&lt;GlobalNamingResources&gt;</tt> element, define the global database pool with a <tt>&lt;Resource&gt;</tt> element like we normally do inside each context. Something like this:</p>
<pre class="brush: xml;">
  &lt;GlobalNamingResources&gt;
     &lt;Resource name=&quot;jdbc/yourglobaldsname&quot; auth=&quot;Container&quot; type=&quot;javax.sql.DataSource&quot;
               maxActive=&quot;20&quot; maxIdle=&quot;5&quot; maxWait=&quot;20000&quot;
               username=&quot;scott&quot; password=&quot;tiger&quot; driverClassName=&quot;oracle.jdbc.OracleDriver&quot;
               url=&quot;jdbc:oracle:thin:@dbhostname:1521:sidname&quot; initialSize=&quot;0&quot; minIdle=&quot;1&quot;
               validationQuery=&quot;select count(*) from smalltable&quot;
               testOnReturn=&quot;false&quot; testOnBorrow=&quot;true&quot; timeBetweenEvictionRunsMillis=&quot;60000&quot;
               numTestsPerEvictionRun=&quot;20&quot; minEvictableIdleTimeMillis=&quot;120000&quot;/&gt;
  &lt;/GlobalNamingResources&gt;
</pre>
<p>Then, in each context you remove the resource definition of the per context pool, and <em>instead inserts a <tt>&lt;ResourceLink&gt;</tt> element</em>, to refence the global pool. Like this in <tt>conf/Catalina/localhost/yourcontext.xml</tt>:</p>
<pre class="brush: xml;">
    &lt;ResourceLink name=&quot;jdbc/yourdsname&quot; global=&quot;jdbc/yourglobalds&quot; type=&quot;javax.sql.DataSource&quot; /&gt;
</pre>
<p>With a lot less load on the database, all users get a chance to get their work done. So by actually lowering the amount of concurrent requests we allow against the database, we get both better throughput and better processing time pr. request.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/sC8qXHwX0eQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/06/13/one-pool-to-rule-them-all-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>@Grab Support in IntelliJ IDEA</title>
		<link>http://www.techper.net/2010/04/21/grab-support-in-intellij-idea/</link>
		<comments>http://www.techper.net/2010/04/21/grab-support-in-intellij-idea/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 19:37:20 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[grab]]></category>
		<category><![CDATA[grape]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[IDEA]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=333</guid>
		<description><![CDATA[Recently I wrote about the great Grape stuff in Groovy for use when deploying groovy scripts.
Just wanted to give a quick view on what IDEA can do for you with some of the latest JetGroovy support for @Grab annotations. With my projects I use maven for building, and as such, I have my dependencies in [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I wrote <a href="http://www.techper.net/2010/04/18/easy-groovy-script-deployment-with-grape/">about the great Grape stuff</a> in <a href="http://groovy.codehaus.org/">Groovy</a> for use when deploying groovy scripts.</p>
<p>Just wanted to give a quick view on what <a href="http://www.jetbrains.com/idea/">IDEA</a> can do for you with some of the latest <a href="http://confluence.jetbrains.net/display/GRVY/Groovy+Home">JetGroovy</a> support for <a href="http://groovy.codehaus.org/gapi/groovy/lang/Grab.html">@Grab</a> annotations. With my projects I use maven for building, and as such, I have my dependencies in the pom. I then use the excellent maven integration in IDEA by simply opening project from the pom.xml, hereby letting IDEA build dependencies for all modules. Works well.</p>
<p>With my groovy code module though, I have the dependencies listed as @Grab annotations instead, as that will help my deployment. What I do <em>not</em> want then, is to have to put them into the pom.xml too. In essence, IDEA should be able to add module dependencies by recoqnizing the @Grab annotations.</p>
<p>Luckily, this is under way, and you can already now try it out. There is a small extra <a href="http://plugins.intellij.net/plugin/?idea&amp;id=4702">Grab plugin</a>, that needs to be installed. When you have that plugin installed, you get an intention action for the @Grab annotations, saying if you would like to download. If executed, they will also appear on the module dependencies, nicely marked with &#8220;Grab: ..&#8221; names.</p>
<p>For further info see <a href="http://youtrack.jetbrains.net/issue/IDEA-49022">this issue</a> and <a href="http://plugins.intellij.net/plugin/?idea&amp;id=4702">the Grab plugin</a> can be found here.</p>
<p>One small note: If running maven-based projects in IDEA like me, you might need this Ivy dependency</p>
<pre class="brush: xml;">
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.ivy&lt;/groupId&gt;
        &lt;artifactId&gt;ivy&lt;/artifactId&gt;
        &lt;version&gt;2.1.0&lt;/version&gt;
    &lt;/dependency&gt;
</pre>
<p>&#8230;in your pom to make the plugin work. I think a fix is under way for this though <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/z4sRN1Odz7U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/04/21/grab-support-in-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy Grape – Adding Dependencies to Root ClassLoader</title>
		<link>http://www.techper.net/2010/04/19/groovy-grape-adding-dependencies-to-root-classloader/</link>
		<comments>http://www.techper.net/2010/04/19/groovy-grape-adding-dependencies-to-root-classloader/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 06:10:09 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[grab]]></category>
		<category><![CDATA[grape]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[jdbc]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=328</guid>
		<description><![CDATA[When using grape in groovy to download dependencies and add to classpath, they will by default be added to the GroovyClassLoader when the script is run. This can be a problem, if these dependencies needs to be uses from classes higher in the classloader hierarchy. One common example would be when loading JDBC drivers, because [...]]]></description>
			<content:encoded><![CDATA[<p>When <a href="http://www.techper.net/2010/04/18/easy-groovy-script-deployment-with-grape/">using grape in groovy to download dependencies and add to classpath</a>, they will by default be added to the <a href="http://groovy.codehaus.org/api/groovy/lang/GroovyClassLoader.html">GroovyClassLoader</a> when the script is run. This can be a problem, if these dependencies needs to be uses from classes higher in the classloader hierarchy. One common example would be when loading JDBC drivers, because these are loaded using <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#forName(java.lang.String)">Class.forName</a>. So, <em>this code will fail</em> with <tt>ClassNotFoundException</tt>:</p>
<pre class="brush: groovy;">
@Grapes([
   @Grab(group = 'oracle', module = 'ojdbc15', version = '11.2.0.1.0'),
])
class SqlTool {
  private sql;

  public SqlTool(url, driver, username, password) {
    this.sql = Sql.newInstance(url, username, password, driver)
    // ... do sql stuff
  }
}

new SqlTool(&quot;jdbc:oracle:thin:@dbhost:1521:dbsid&quot;, &quot;scott&quot;, &quot;tiger&quot;, &quot;oracle.jdbc.driver.OracleDriver&quot;)
</pre>
<p>Because the oracle driver will be in the <tt>GroovyClassLoader</tt>, which is down the hierarchy relative to <tt>java.lang.Class</tt>, which is up in the root classloader, the loading will fail.</p>
<p>The <a href="http://groovy.codehaus.org/api/groovy/lang/Grab.html">@Grab</a> annotation seems <em>not</em> to support the definition of which classloader to add the dependencies to, but luckily we have programmatic access to grape too. What we need to do is something like this:</p>
<pre class="brush: groovy;">
import groovy.sql.Sql

def classLoader = this.getClass().getClassLoader();
while (!classLoader.getClass().getName().equals(&quot;org.codehaus.groovy.tools.RootLoader&quot;)) {
  classLoader = classLoader.getParent()
}

// force grape to use the root classloader - to ensure that Class.forName works for dependencies
groovy.grape.Grape.grab(group:'oracle', module:'ojdbc15', version:'[11.2.0.1.0,)', classLoader: classLoader)

class SqlTool {
  private sql;

  public SqlTool(url, driver, username, password) {
    this.sql = Sql.newInstance(url, username, password, driver)
    // ... do sql stuff
  }
}

new SqlTool(&quot;jdbc:oracle:thin:@dbhost:1521:dbsid&quot;, &quot;oracle.jdbc.driver.OracleDriver&quot;, &quot;scott&quot;, &quot;tiger&quot;)
</pre>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/IX57CBz2i2Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/04/19/groovy-grape-adding-dependencies-to-root-classloader/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Easy Groovy Script Deployment with Grape</title>
		<link>http://www.techper.net/2010/04/18/easy-groovy-script-deployment-with-grape/</link>
		<comments>http://www.techper.net/2010/04/18/easy-groovy-script-deployment-with-grape/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 09:10:46 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[grab]]></category>
		<category><![CDATA[grape]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[ivy]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=323</guid>
		<description><![CDATA[You can use groovy for lots of stuff, but many of us use it for simple, one-off administration tasks like upgrading a database schema, doing some reporting or other small tasks. Given the absolute great integration of groovy into the Java platform, a groovy script quickly ends up utilizing a bunch of jar dependencies from [...]]]></description>
			<content:encoded><![CDATA[<p>You can use <a href="http://groovy.codehaus.org/">groovy</a> for lots of stuff, but many of us use it for simple, one-off administration tasks like upgrading a database schema, doing some reporting or other small tasks. Given the absolute great integration of groovy into the Java platform, a groovy script quickly ends up utilizing a bunch of jar dependencies from various open source frameworks. So, how to easy deploy a script, so that it can be started on the target platform with the least fiddling?</p>
<h2>Use Grape!</h2>
<p>With groovy comes <a href="http://groovy.codehaus.org/Grape">Grape</a> and the <a href="http://groovy.codehaus.org/gapi/groovy/lang/Grab.html">@Grab</a> anotation. Grape is capable of downloading dependencies from maven repositories, much like maven does at compile time, but Grape can do it at execution time of the groovy script. In addition to the automatic resolving and downloading of dependencies, Grape is also capable of adding the dependencies on the script classpath before running it. Cool eh!? Here&#8217;s a small example:</p>
<pre class="brush: groovy;">
package net.techper.foo.bar;

import org.jfree.chart.JFreeChart
import org.joda.time.DateMidnight

@Grapes([
   @Grab(group = 'jfree', module = 'jfreechart', version = '1.0.12'),
   @Grab(group = 'joda-time', module = 'joda-time', version = '1.6'),
])
class YourCoolTool {
   ....
}
</pre>
<p>This script use jfreechart and jodatime, both of which will be downloaded at runtime and added to classpath before the actual script execution.</p>
<h2>Grape Internal and Config</h2>
<p>Of course, dependencies only need to be downloaded the first time. The downloaded files are kept in <tt>$HOME/.groovy/grapes</tt> in a maven-like repository structure.</p>
<p>So what about dependencies that are not in the public repository? Well, you can get them too, as long as the target environment, in which the groovy script is executed, can reach the local repository, where you have these non-public dependencies stored.</p>
<p>Internally, Grape is implemented with <a href="http://en.wikipedia.org/wiki/Apache_Ivy">Ivy</a>. And Grape can be configured with a Ivy configuration file. Inside the jar distribution of standard groovy lies a default Ivy config, which has some of the major maven repositories predefined. You can provide your own though, by adding a file <tt>$HOME/.groovy/grapeConfig.xml</tt> which could look something like this:</p>
<pre class="brush: xml;">
&lt;ivysettings&gt;
  &lt;settings defaultResolver=&quot;downloadGrapes&quot;/&gt;
  &lt;resolvers&gt;
    &lt;chain name=&quot;downloadGrapes&quot;&gt;
      &lt;filesystem name=&quot;cachedGrapes&quot;&gt;
        &lt;ivy pattern=&quot;${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml&quot;/&gt;
        &lt;artifact pattern=&quot;${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]&quot;/&gt;
      &lt;/filesystem&gt;
      &lt;!-- todo add 'endorsed groovy extensions' resolver here --&gt;
      &lt;ibiblio name=&quot;codehaus&quot; root=&quot;http://repository.codehaus.org/&quot; m2compatible=&quot;true&quot;/&gt;
      &lt;ibiblio name=&quot;ibiblio&quot; m2compatible=&quot;true&quot;/&gt;
      &lt;ibiblio name=&quot;java.net2&quot; root=&quot;http://download.java.net/maven/2/&quot; m2compatible=&quot;true&quot;/&gt;
      &lt;ibiblio name=&quot;yourid&quot; root=&quot;http://your/local/maven/repository/&quot; m2compatible=&quot;true&quot;/&gt;
    &lt;/chain&gt;
  &lt;/resolvers&gt;
&lt;/ivysettings&gt;
</pre>
<p>Notice the extra ibiblio element, that is used to define a private repository!</p>
<p>All this makes it possible to write a small script in groovy, deploy it simply by copying it to the target environment, and then execute it at that place with no extra fuss.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/l1NbHOLnvgw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/04/18/easy-groovy-script-deployment-with-grape/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Selenium RC, Safari and Blocking Browser Pop-Ups</title>
		<link>http://www.techper.net/2010/02/13/selenium-rc-safari-and-blocking-browser-pop-ups/</link>
		<comments>http://www.techper.net/2010/02/13/selenium-rc-safari-and-blocking-browser-pop-ups/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 13:45:24 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=318</guid>
		<description><![CDATA[Just a quick note here:
If you are using selenium rc to remote control a Safari on a Mac, remember to turn off pop-up blocking, or else your tests will hang in &#8220;selenium.start()&#8221; somewhere deep down in HttpURLConnection.getResponseCode() because the selenium-rc server never returns with any content.
In Safari menu, de-select &#8220;Block Pop-Up Windows&#8221;.
Let&#8217;s just say this [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note here:</p>
<p>If you are using <a href="http://seleniumhq.org/projects/remote-control/">selenium rc</a> to remote control a Safari on a Mac, remember to<em> turn off pop-up blocking</em>, or else your tests will hang in &#8220;<tt>selenium.start()</tt>&#8221; somewhere deep down in <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/net/HttpURLConnection.html#getResponseCode%28%29">HttpURLConnection.getResponseCode()</a> because the selenium-rc server never returns with any content.</p>
<p>In Safari menu, de-select &#8220;Block Pop-Up Windows&#8221;.</p>
<p>Let&#8217;s just say this wasted some time on me, so hope this will help someone out there in the same starter problems <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/o4sRgTcnhJQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/02/13/selenium-rc-safari-and-blocking-browser-pop-ups/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debugging Hibernate AbstractFlushingEventListener Errors When Batching</title>
		<link>http://www.techper.net/2010/01/25/debugging-hibernate-abstractflushingeventlistener-errors-when-batching/</link>
		<comments>http://www.techper.net/2010/01/25/debugging-hibernate-abstractflushingeventlistener-errors-when-batching/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 19:10:25 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=310</guid>
		<description><![CDATA[Here is little trick for Hibernate users.
If you have Hibernate configured to use JDBC batching, then statements in the same transaction might be batched into one or few update trips to the server. In case of any errors when performing the batch operation, you wont be able to see which statement that failed. What you [...]]]></description>
			<content:encoded><![CDATA[<p>Here is little trick for Hibernate users.</p>
<p>If you have Hibernate configured to use JDBC batching, then statements in the same transaction might be batched into one or few update trips to the server. In case of any errors when performing the batch operation, you wont be able to see which statement that failed. What you will see is something in the lines of this stacktrace:</p>
<pre class="brush: plain;">
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
	...
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (XXX) violated
	at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10055)
	at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213)
	at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
	... 112 more
</pre>
<p>You can see the offending SQL exception, in this case a Oracle unique constraint violation, but you cannot see the SQL from the batch.</p>
<p>Hibernate uses a class called <a href="https://www.hibernate.org/hib_docs/v3/api/org/hibernate/util/JDBCExceptionReporter.html">org.hibernate.util.JDBCExceptionReporter</a> when logging JDBC exceptions. It either WARN of ERROR logs, and most people have at least ERROR level activated for something like hibernate. But, this little piece of the class is interesting:</p>
<pre class="brush: java;">
	public static void logExceptions(SQLException ex, String message) {
		if ( log.isErrorEnabled() ) {
			if ( log.isDebugEnabled() ) {
				message = StringHelper.isNotEmpty(message) ? message : DEFAULT_EXCEPTION_MSG;
				log.debug( message, ex );
			}
			while (ex != null) {
				StringBuffer buf = new StringBuffer(30)
						.append( &quot;SQL Error: &quot; )
				        .append( ex.getErrorCode() )
				        .append( &quot;, SQLState: &quot; )
				        .append( ex.getSQLState() );
				log.warn( buf.toString() );
				log.error( ex.getMessage() );
				ex = ex.getNextException();
			}
		}
	}
</pre>
<p>What is does is WARN and ERROR log a given exception and its causes. But it as has a part only executed, if DEBUG level has been turned on for this particular class/logger. It DEBUG logs the incoming parameter <tt>message</tt> and this message just so happens to be the offending SQL statement.</p>
<p>So, turn on DEBUG level for the <a href="https://www.hibernate.org/hib_docs/v3/api/org/hibernate/util/JDBCExceptionReporter.html">org.hibernate.util.JDBCExceptionReporter</a> logger and get more information on your failing SQL.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/-eA1cYT5sFA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/01/25/debugging-hibernate-abstractflushingeventlistener-errors-when-batching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Auth – Just Say No</title>
		<link>http://www.techper.net/2009/12/04/basic-auth-just-say-no/</link>
		<comments>http://www.techper.net/2009/12/04/basic-auth-just-say-no/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 20:02:58 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=304</guid>
		<description><![CDATA[One simply should not use basic auth. Period. And I am not talking about security here. Only functionality and what you can, and most importantly cannot do with basic auth.
Okay, I know that was a bit harsh, and I do use basic auth myself sometimes. Like for instance with something dead-simple on an intranet, where [...]]]></description>
			<content:encoded><![CDATA[<p>One simply should not use <a href="http://www.ietf.org/rfc/rfc2617">basic auth</a>. Period. And I am not talking about security here. Only functionality and what you can, and most importantly <em>cannot</em> do with basic auth.</p>
<p>Okay, I know that was a bit harsh, and I do use basic auth myself sometimes. Like for instance with something dead-simple on an intranet, where we just need to shut out the masses a bit.</p>
<p>But what is wrong with <a href="http://www.ietf.org/rfc/rfc2617">basic auth</a> then?</p>
<h2>Logout Not Possible</h2>
<p>Because the browser remember the authentication data and keep resending it for each request to the host authenticated against, there can be no logout, aside from closing the browser. Often, this is seen done with Javascript (closing the browser window), but a) it is not safe as the client can say no and b) some browsers deny it.</p>
<h2>It Does Not Present Itself Nicely to the Client</h2>
<p>It is the browser, that pops up a dialog. Basically, you cannot as a developer, control how this dialog looks and behaves. And it looks different in each browser. So, you cannot even determine if it needs to ask for &#8220;username&#8221;, &#8220;login&#8221; or &#8230;</p>
<p>Also, the application cannot show meaningful information to the client, when authentication goes wrong. This could be &#8220;you have xx tries left, before the login is locked&#8221;.</p>
<h2>No Way To Provide Extra Functionality</h2>
<p>Like a &#8220;change password&#8221; option, when the login has expired. Or a &#8220;remember me&#8221; option. Or whatever the application would like. Again, it is the browser, that does it all.</p>
<p>All this stems from the fact that it is the browser, that controls the authentication. It is the browser, that stores the authentication data and send it on with each request. And it does not have an API or the like to clear it, hook into missing auth or anything like it. The application is out of the loop.</p>
<p>Just say no! <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/QESTRRUCGEU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/12/04/basic-auth-just-say-no/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>CXF Method Not Found When Further Annotated</title>
		<link>http://www.techper.net/2009/12/03/cxf-method-not-found-when-further-annotated/</link>
		<comments>http://www.techper.net/2009/12/03/cxf-method-not-found-when-further-annotated/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 19:57:08 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[aspect]]></category>
		<category><![CDATA[cxf]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[spring-aop]]></category>
		<category><![CDATA[ws]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=292</guid>
		<description><![CDATA[When using CXF and the JAXWS annotations to publish web services, like this:

@WebService(targetNamespace = &#34;http://blah&#34;)
public class ClientData {
  @WebMethod
  public String getSomething() {
    return something;
  }
}

you can experience problems if you annotate the web service methods with something that spring-aop needs to process. Like when using perf4js nice @Profiled [...]]]></description>
			<content:encoded><![CDATA[<p>When using <a href="http://cxf.apache.org/">CXF</a> and the <a href="https://jax-ws.dev.java.net/">JAXWS</a> annotations to publish web services, like this:</p>
<pre class="brush: java;">
@WebService(targetNamespace = &quot;http://blah&quot;)
public class ClientData {
  @WebMethod
  public String getSomething() {
    return something;
  }
}
</pre>
<p>you can experience problems if you annotate the web service methods with something that spring-aop needs to process. Like when using <a href="http://perf4j.codehaus.org/">perf4j</a>s nice <a href="http://perf4j.codehaus.org/apidocs/org/perf4j/aop/Profiled.html">@Profiled aspect</a>, like this:</p>
<pre class="brush: java; highlight: [2];">
@WebService(targetNamespace = &quot;http://blah&quot;)
@Profiled
public class ClientData {
  @WebMethod
  public String getSomething() {
    return something;
  }
}
</pre>
<p>This is due to the fact, that spring <em>will produce a proxy</em> of the @Profiled bean, a <em>proxy that will not have the annotations of the proxied bean</em>. In turn, this will hide the annotations from CXF, which can come out and complain about missing methods on the server side. Like this:</p>
<p><code>org.apache.cxf.interceptor.Fault: Message part {http://blah}getSomething was not recognized.  (Does it exist in service WSDL?)</code></p>
<p>Solution?</p>
<p>Add the <tt>implementorClass</tt> attribute on the JAXWS endpoint definitions in your cxf bean definitions xml. This way you tell CXF which class to look for annotations on, instead of just looking on the class of the proxied instance it is passed at runtime.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/hMOfUIgTCYo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/12/03/cxf-method-not-found-when-further-annotated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Spinning Progress Indicator Component</title>
		<link>http://www.techper.net/2009/10/28/flex-spinning-progress-indicator-component/</link>
		<comments>http://www.techper.net/2009/10/28/flex-spinning-progress-indicator-component/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 20:48:58 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=282</guid>
		<description><![CDATA[Sometimes you need to indicate progress to users when the application is doing something, like calling a remote web-service or something. At times, it can be nice to incorporate this as an element in the UI, that operates in an unobtrusive way. For instance showing a small indicator on or besides the button, that initiated [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to indicate progress to users when the application is doing something, like calling a remote web-service or something. At times, it can be nice to incorporate this as an element in the UI, that operates in an unobtrusive way. For instance showing a small indicator on or besides the button, that initiated the operation in progress.</p>
<p><a href="http://www.techper.net/blog/wp-content/uploads/2009/10/spinningwheel1.swf">Here is a small spinning wheel</a> example on how to do this with an old style ASCII spinning wheel animation. Enter the <tt>LabelProgressIndicator.mxml</tt> component:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; ?&gt;
&lt;mx:HBox xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;&lt;![CDATA[
        [Bindable]
        private var statusText:String;

        [Bindable]
        private var progressText:String;

        private const SPIN_CHARS:String = &quot;/-\\|/-\\|&quot;;

        private var workingDotsTimer:Timer;
        private var progressCounter:int;

        public function startProgress(status:String):void {
            if (workingDotsTimer == null) {
                statusText = status;
                workingDotsTimer = new Timer(200);
                progressCounter = 0;
                workingDotsTimer.addEventListener(TimerEvent.TIMER, onWorkingDotsTimer);
                workingDotsTimer.start();
            }
        }

        public function stopProgress():void {
            if (workingDotsTimer != null) {
                workingDotsTimer.removeEventListener(TimerEvent.TIMER, onWorkingDotsTimer);
                workingDotsTimer.stop();
                workingDotsTimer = null;
                statusText = null;
                progressText = null;
            }
        }

        private function onWorkingDotsTimer(event:TimerEvent):void {
            if (progressCounter == SPIN_CHARS.length - 1) {
                progressCounter = 0;
            } else {
                progressCounter++;
            }
            progressText = SPIN_CHARS.charAt(progressCounter);
        }

        ]]&gt;&lt;/mx:Script&gt;

    &lt;mx:Label id=&quot;status&quot; text=&quot;{statusText}&quot;/&gt;
    &lt;mx:Label id=&quot;progress&quot; text=&quot;{progressText}&quot; fontFamily=&quot;courier&quot; fontWeight=&quot;bold&quot;/&gt;
&lt;/mx:HBox&gt;
</pre>
<p>and here is how to use it:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; xmlns:ui=&quot;*&quot;&gt;

    &lt;mx:Button click=&quot;progress.startProgress('working')&quot; label=&quot;Start&quot;/&gt;
    &lt;mx:Button click=&quot;progress.stopProgress()&quot; label=&quot;Stop&quot;/&gt;

    &lt;ui:LabelProgressIndicator id=&quot;progress&quot; /&gt;

&lt;/mx:Application&gt;
</pre>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/Lm9R64gwUc4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/10/28/flex-spinning-progress-indicator-component/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Flex Data Bindings – Behind The Scenes</title>
		<link>http://www.techper.net/2009/10/12/flex-data-bindings-behind-the-scenes/</link>
		<comments>http://www.techper.net/2009/10/12/flex-data-bindings-behind-the-scenes/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 20:20:04 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rich Internet Applications]]></category>
		<category><![CDATA[data binding]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=251</guid>
		<description><![CDATA[Ever wondered how flex data bindings actually work behind the scenes? I have, and sometimes I have had troubles with it, that made me wish I knew some more. This post is a writeup of the knowledge about flex data bindings I uncovered, when looking into the mxmlc generated code for bindings.
Vanilla Example
Here is a [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how flex data bindings actually work behind the scenes? I have, and sometimes I have had troubles with it, that made me wish I knew some more. This post is a writeup of the knowledge about flex data bindings I uncovered, when looking into the mxmlc generated code for bindings.</p>
<h2>Vanilla Example</h2>
<p>Here is a dead simple vanilla sample of flex that does a little bit of data binding:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; ?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;&lt;![CDATA[
        [Bindable] public var value: String = &quot;blah&quot;;
    ]]&gt;&lt;/mx:Script&gt;

    &lt;mx:TextInput id=&quot;textInput&quot; text=&quot;{value}&quot;/&gt;
&lt;/mx:Application&gt;
</pre>
<p>where <tt>value</tt> is bound into <tt>textInput.text</tt> will generate quite a bit of supporting code, when being mxmlc&#8217;ed. Basically, it seems like flex operates with two concepts behind the scenes: <em>Bindings</em> and <em>Watchers</em>.</p>
<h3>Bindings</h3>
<p>A Binding is a <em>one-way connection</em>, that can read a value from a source and set it on a destination, <em>but only when explicitly executed</em>. There is not listening for changes built into a binding as such, it is just a mechanism that can be executed by someone, to transfer a value between a source and a destination.</p>
<p>So, how does a binding get executed? It does so, when the Watchers it is connected to fires. A binding acts as listener for  <tt>watcherFired</tt> on a Watcher, which is how it gets executed when changes happen.</p>
<p>Here is the binding setup, that flex generates for the above example:</p>
<pre class="brush: as3;">
        binding = new mx.binding.Binding(this,
            function():String {
                var result:* = (value);
                var stringResult:String = (result == undefined ? null : String(result));
                return stringResult;
            },
            function(_sourceFunctionReturnValue:String):void {
                textInput.text = _sourceFunctionReturnValue;
            },
            &quot;textInput.text&quot;);
</pre>
<p>basically, it instantiates a <tt>mx.binding.Binding</tt> with the parameters:</p>
<ul>
<li><tt>this</tt> which is this context &#8211; pun intended &#8211; means the <tt>FlexTest</tt> application class</li>
<li>a function that can read the source value when executed</li>
<li>a function that can set the target property when executed</li>
<li>a textual string of the target (docs says it is used for validation)</li>
</ul>
<p>this sets up a &#8220;channel&#8221; from source to target.</p>
<h3>Watchers</h3>
<p>While Bindings only implement the reading of the source and setting into target, the other big part of flex data bindings is actually determining if and when, a binding should execute. This is where Watchers come in.</p>
<p>A Watcher can watch for changes on something, one typical example is a change of a property value. When such a change is detected, the watcher notifies its listeners (which are Binding instances) about the change. It is then up to the listener (the bindings), to actually read out the source and set the target (aka: Execute the binding). It is the Watcher, that determines if a value has actually changed.</p>
<p>Here is the watcher setup, that flex generates for the above example:</p>
<pre class="brush: as3;">
        watchers[0] = new mx.binding.PropertyWatcher(&quot;value&quot;,
            { propertyChange: true },
            [ bindings[0] ],
            propertyGetter);
</pre>
<p>as you can see, it instantiates a <tt>mx.binding.PropertyWatcher</tt> instance, as it is a property we are binding from, with the following parameters:</p>
<ul>
<li>a map of event names as keys, that are the event to listen for, when watching changes. This is what can be overridden with <tt>[Bindable("otherEventNameHere"])</tt></li>
<li>an array of listeners, that get called on their <tt>watcherFired</tt> method when the watcher detects a change (the listeners are <tt>Binding</tt> instances, and in this context <tt>bindings[0]</tt> is the exact binding that we saw the code for just before</li>
<li>and lastly <tt>propertyGetter</tt> is a method, that can return access to properties in the context watched</li>
</ul>
<p>I am sure you can image how this works then. By hey, &#8230; when is the &#8220;propertyChange&#8221; event being dispatched in our code. I mean, when you look at the initial example code, if I was to assign a new value to the <tt>value</tt> property, there sure ain&#8217;t any code there, which fires any events.</p>
<p>Well, it turns out mxmlc has generated code for that too:</p>
<pre class="brush: as3;">
    [Bindable(event=&quot;propertyChange&quot;)]
    public function get value():String {
        return this._111972721value;
    }

    public function set value(value:String):void {
    	var oldValue:Object = this._111972721value;
        if (oldValue !== value) {
            this._111972721value = value;
            this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this, &quot;value&quot;, oldValue, value));
        }
    }
</pre>
<p>it simply moves the original <tt>value</tt> property to a generated name <tt>_111972721value</tt> and adds a get/set pair on the <tt>value</tt> name instead. Clever. And hey, look into that setter. It dispatches the <tt>propertyChange</tt> event, when changed.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/h0ielJBZu28" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/10/12/flex-data-bindings-behind-the-scenes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AppleScript to Check Image Ratio on a Bunch of Files</title>
		<link>http://www.techper.net/2009/10/07/applescript-to-check-image-ratio-on-a-bunch-of-files/</link>
		<comments>http://www.techper.net/2009/10/07/applescript-to-check-image-ratio-on-a-bunch-of-files/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 20:32:49 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Photography]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[crop]]></category>
		<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=246</guid>
		<description><![CDATA[Faced with the tedious task of checking a large bunch of image files for the correct ratio before uploading to a print service website, I set out to write a small AppleScript application that could do it for me. It turned out to be quite fun and at the same time I got my feet [...]]]></description>
			<content:encoded><![CDATA[<p>Faced with the tedious task of checking a large bunch of image files for the correct ratio before uploading to a print service website, I set out to write a small AppleScript application that could do it for me. It turned out to be quite fun and at the same time I got my feet wet for the first time in AppleScript.</p>
<p>This is what the script does:</p>
<ul>
<li>Ask the user for an input folder and an output folder</li>
<li>Ask the user for which ratio he wants to check against (e.g. 1.5 if you want a 2:3 ratio)</li>
<li>Run throug all image files in the input folder, check if the ratio is the requested, and if not, moves files to output folder</li>
</ul>
<p>All I have to do then, is to crop the files moved to the output folder, to my requested ratio. Actually, the &#8220;Image Events&#8221; library that I use to check dimensions can also crop, but it does so from the center. I want to control what is cropped myself.</p>
<p>And respect to Apple for giving us such an easy to use yet still powerful tool like AppleScript. I used the AppleScript Editor to write the script, and then noticed how I could just save it as an application. Cool!<br />
Here&#8217;s the script:</p>
<pre class="brush: plain;">
-- ask for input folder containing images
set theInputFolder to (choose folder with prompt &quot;Pick the folder containing the images to check ratio against&quot;) as string

-- ask for output folder to move files that does not fulfill ratio
set theOutputFolder to (choose folder with prompt &quot;Move image files not fulfilling ratio where?&quot; without multiple selections allowed and invisibles) as string

-- check folders are not the same
if theInputFolder is equal to theOutputFolder then
	error &quot;Input and output folder may not be the same&quot; number 500
end if

-- ask user for the ratio
display dialog &quot;Enter image ratio&quot; default answer &quot;1.5&quot;
set theRatio to text returned of result as real

tell application &quot;System Events&quot;
	set theImageFiles to every file of folder theInputFolder whose name does not start with &quot;.&quot; and (file type is &quot;TIFF&quot; or file type is &quot;JPEG&quot; or name extension is &quot;tiff&quot; or name extension is &quot;tif&quot; or name extension is &quot;jpeg&quot; or name extension is &quot;jpg&quot;)
end tell

repeat with i from 1 to the count of theImageFiles
	set theImgFile to (item i of theImageFiles as alias)
	tell application &quot;Image Events&quot;
		set theImg to open theImgFile
		set theDimensions to dimensions of theImg
		set theWidth to item 1 of theDimensions
		set theHeight to item 2 of theDimensions
		set min to theHeight
		set max to theWidth
		if (theWidth &lt; theHeight) then
			set min to theWidth
			set max to theHeight
		end if
		close theImg
	end tell

	-- a little rounding
	set theImgRatio to (((max / min) * 10) as integer) / 10

	if (theImgRatio is not equal to theRatio) then
		tell application &quot;Finder&quot;
			move theImgFile to theOutputFolder
		end tell
	end if
end repeat

display dialog &quot;Done&quot; buttons {&quot;OK&quot;} default button 1
</pre>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/6XCllV0gBQE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/10/07/applescript-to-check-image-ratio-on-a-bunch-of-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Photography Challenges Can Do To You</title>
		<link>http://www.techper.net/2009/09/06/what-photography-challenges-can-do-to-you/</link>
		<comments>http://www.techper.net/2009/09/06/what-photography-challenges-can-do-to-you/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 19:53:45 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=242</guid>
		<description><![CDATA[Recently, I got inspired by a post on DPS about photography projects to spark ones creativity, and I committed myself to do one self portrait every day for 30 days in a row. Now, only 6 days into my challenge, I can speak for some of the great things following such a challenge do to [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I got inspired by <a href="http://digital-photography-school.com/7-photography-projects-to-jumpstart-your-creativity">a post</a> on <a href="http://digital-photography-school.com/">DPS</a> about <a href="http://digital-photography-school.com/7-photography-projects-to-jumpstart-your-creativity">photography projects to spark ones creativity</a>, and I committed myself to do <a href="http://www.flickr.com/photos/polesen/sets/72157622084588287/">one self portrait every day for 30 days</a> in a row. Now, only 6 days into my challenge, I can speak for some of the great things following such a challenge do to you and your photography.</p>
<h2>Sparks Creativity</h2>
<p>Well, that one was kind of obvious, as that was one of the main reasons I started doing it. Nevertheless, it is pretty important.</p>
<p>Okay, I could have gone for a 365 days challenge, but that just seemed too much for me. Anyways, faced with the task of doing 30 self portraits in a row, one has to come up with some ideas. For starters, I have some myself, but what I also did (and do) was to go out there on the net, and see what others have done. Searching flickr for self portraits has proven really helpful, and sparked many ideas to new ways of doing portraits.</p>
<h2>Force Learning of Techniques</h2>
<p>Even though I have had a DSLR for some years now, it is only within the last copuple of months, that I bought myself a decent tripod. And even then, I haven&#8217;t taken that many shots using it yet. Going into self portraits, I am using my tripod for many of the shots. And already now, I feel much more confident using the tripod, setting it up, knowing what it can do and what it cannot, etc.</p>
<p>Another learning experience I am into currently, is setting up flashes. Not long ago, I bough some cheap wireless Cactus triggers and an extra cheap-o Hong-Kong flash. These are really fun to play with. More and more, I am starting to think lighting into my pictures. And that does not only go for the portaits, but for all shots. I acknowledge, that I should have done this long ago, but I haven&#8217;t.</p>
<h2>Opportunity to Gear Up</h2>
<p>We all know it. Photography is a gear sport <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  and I simply <em>had</em> to buy a wireless remote trigger for this project. Still eagerly awaiting it though, &#8230; from Hong-Kong again.</p>
<p>So, if you are into photography, I can only recommend <a href="http://digital-photography-school.com/7-photography-projects-to-jumpstart-your-creativity">taking up a photography challenge</a> of some sort. You can follow the results of my challenge in <a href="http://www.flickr.com/photos/polesen/sets/72157622084588287/">my flickr set here</a>.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/R3ddzXH2Qi0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/09/06/what-photography-challenges-can-do-to-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dead Easy Informal Restrospectives</title>
		<link>http://www.techper.net/2009/08/22/dead-easy-informal-restrospectives/</link>
		<comments>http://www.techper.net/2009/08/22/dead-easy-informal-restrospectives/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 12:42:55 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Software Process]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[retrospective]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=239</guid>
		<description><![CDATA[Recently, I was introduced to restrospectives by a wise colleague of mine. Something I had heard about, but really not gotten around to using in my software development process yet. After participating, I found the retrospective really useful, hence I thought I would share.
A restrospective in an agile process is the simple idea about &#8220;stepping [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was introduced to restrospectives by <a href="http://sthen.blogspot.com/">a wise colleague of mine</a>. Something I had heard about, but really not gotten around to using in my software development process yet. After participating, I found the retrospective really useful, hence I thought I would share.</p>
<p>A restrospective in an agile process is the simple idea about &#8220;stepping back and looking at the process&#8221;. What we did, was take out 30-45 minutes, where:</p>
<ol>
<li>the development team meet up</li>
<li>an <em>outsider</em> acts as facilitator</li>
</ol>
<p>I like agile processes for software development, but aside from that, I do not care much for a lot of process. I like my time spent on development &#8211; designing and writing code. This is also why I liked (and was surprised that) an agile restrospective can be so short and lightweight.</p>
<p>In the retrospective I participated in, I acted as the facilitator. As such, I was not a part of the development team. I had some, albeit little, knowledge of what they were developing, but that turned out to matter less. In short, this is what we did:</p>
<ul>
<li>on the morning of the retrospective day, we agreed on time to meet later</li>
<li>at that time, the team and I met up in a meeting room &#8211; pretty much blank and unprepared</li>
<li>I, the facilitator, started asking questions against the process</li>
<li>the team answered and discussed back and forth</li>
</ul>
<p>The whole thing took around 30 minutes. The questions asked were stuff like:</p>
<ul>
<li>what went well in the last sprint?</li>
<li>what did not go that well?</li>
<li>what to take with us and repeat in coming sprints?</li>
<li>what to do better in coming sprints?</li>
<li>&#8230;</li>
</ul>
<p>but the really nice thing is, that having a project-external facilitator proved to be really helpful in the way that:</p>
<ul>
<li>He (the external facilitator) will ask the questions, that lies as implicit knowledge in team members, and hence wouldn&#8217;t be touched upon. Like, when I asked &#8220;how do you do your etimates&#8221;, which led to a discussion on diffent ways to do estimation.</li>
<li>The team being retrospected can get new input from the knowledge of the facilitator &#8211; <em>and the other way around</em>, making the facilitator take something with him too (a true win-win)</li>
<li>The facilitator gets insight into how other projects in the organisation is run and what they do. This is knowledge and project-status sharing while retrospecting.</li>
</ul>
<p>All in all, I had the fealing that this was helpful. As a consequence of this, I repeated it on a project at a client where I was part of the team, and we brought in another party as facilitator &#8211; a developer on another project, but from the same organization.</p>
<p><strong>Some important rules I feel compelled to emphasize</strong>:</p>
<ol>
<li>Keep the retrospective short (less than 60 min), and</li>
<li>Come largely unprepared and resist documenting the output.</li>
</ol>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/eBdjXvmGV1E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/08/22/dead-easy-informal-restrospectives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Codecs Should Be Patent Free</title>
		<link>http://www.techper.net/2009/08/20/codecs-should-be-patent-free/</link>
		<comments>http://www.techper.net/2009/08/20/codecs-should-be-patent-free/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 12:33:23 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[codec]]></category>
		<category><![CDATA[DRM]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=236</guid>
		<description><![CDATA[In the times we currently live in, where the music, video and tele industries are in constant battle with the consumers, trying to make them pay, it should be obvious that patented codecs are a bad thing.
Now, do not get me wrong. I think everybody should pay for what they use. I think pirates are [...]]]></description>
			<content:encoded><![CDATA[<p>In the times we currently live in, where the music, video and tele industries are in constant battle with the consumers, trying to make them pay, it should be obvious that <em>patented codecs are a bad thing</em>.</p>
<p>Now, do not get me wrong. I think everybody should pay for what they use. I think pirates are a bad thing. But we need an open solution, that everyone are free to provide implementations of, without the need to buy specs or pay roalties for the use or implementation of a certain codec.</p>
<p>This is also why I think <a href="http://www.opera.com/">Opera</a> and <a href="http://www.mozilla.org/">The Mozilla Foundation</a> are <a href="http://www.infoq.com/news/2009/07/HTML-5-Video-Codec">doing the right thing</a> when speaking about which video codec to choose for the open web platform. Of course, either H.264 should be patent free or everybody should team up around an open, patent free codec like <a href="http://www.theora.org/">Ogg Theora</a>.</p>
<p>If not, consumers will pay. Less products/players to choose from. No free players or encoders. Platform locked features. Etc. For instance, currently I have no way to use the SF Anytime VOD service on my Mac, because they have choosen to tie it to the Windows Media format and player. I understand their choice, given the current availability of DRM solutions around.</p>
<p>If everybody would just team up on an open, patent free codec, like <a href="http://www.theora.org/">Theora</a>, I am sure there would be viable DRM solutions around too. Solutions that would play on all major platforms, and not just in one specific player on one specific platform. Instead of battling patents with eachother, the major players should battle on providing the best implementation and best products with the coolest features. Stuff that would really give the users a better experience.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/Gl9SVCaRfi8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/08/20/codecs-should-be-patent-free/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Color Coding Source Files</title>
		<link>http://www.techper.net/2009/08/20/color-coding-source-files/</link>
		<comments>http://www.techper.net/2009/08/20/color-coding-source-files/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 12:09:34 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[IDEA]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=234</guid>
		<description><![CDATA[This upcoming feature about color coding file scopes in IntelliJ IDEA Maia looks awfully lot like a plugin idea I and a colleague had once. We had the idea, that different &#8220;layers&#8221; or &#8220;modules&#8221; of the source of an application could be color coded differently inside IDEA. This way, one would have a direct visual [...]]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://blogs.jetbrains.com/idea/2009/07/more-colors-with-maia/">upcoming feature about color coding file scopes</a> in IntelliJ IDEA Maia looks awfully lot like a plugin idea I and a colleague had once. We had the idea, that different &#8220;layers&#8221; or &#8220;modules&#8221; of the source of an application could be color coded differently inside IDEA. This way, one would have a direct visual indication, if one for instance were editing core domain source or maybe some web layer source.</p>
<p>Nice to see JetBrains are thinking some of the same thoughts, considering we never followed through on our own idea way back.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/pNW1CYTITa4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/08/20/color-coding-source-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IDEAs Deep Flex-Mojos Support</title>
		<link>http://www.techper.net/2009/08/20/ideas-deep-flex-mojos-support/</link>
		<comments>http://www.techper.net/2009/08/20/ideas-deep-flex-mojos-support/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 11:51:44 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex-mojos]]></category>
		<category><![CDATA[IDEA]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=232</guid>
		<description><![CDATA[If you are writing Flex applications using IntelliJ IDEA, you should also choose the Flexmojos maven plugin for building (if you build with maven, that is) and not the other alternatives. Why? Well, for once, it seems to be the best plugin around for flex building, but also because IDEA has deep support for it.
Currently, [...]]]></description>
			<content:encoded><![CDATA[<p>If you are writing Flex applications using IntelliJ IDEA, you should also choose the <a href="http://flexmojos.sonatype.org/">Flexmojos</a> maven plugin for building (if you build with maven, that is) and not the other alternatives. Why? Well, for once, it seems to be the best plugin around for flex building, but also because IDEA has deep support for it.</p>
<p>Currently, with the IDEA8, there is some support for importing POMs that use <a href="http://flexmojos.sonatype.org/">flexmojos</a>. With the upcoming Maia release, this <a href="http://blogs.jetbrains.com/idea/2009/08/flexmojos-in-dian/">integration is further enhanced</a>.</p>
<p>In <a href="http://blogs.jetbrains.com/idea/2009/08/flexmojos-in-dian/">this blogpost</a>, JetBrains explains how to import for POM, and there are some good pointers, that I need to remember for my next POM import. Most notably, enabling the generation of a compiler config file, to have the same settings used by IDEA as flexmojos do at compilation.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/cY88m7mHRsg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/08/20/ideas-deep-flex-mojos-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple iPhoto Libraries</title>
		<link>http://www.techper.net/2009/08/15/multiple-iphoto-libraries/</link>
		<comments>http://www.techper.net/2009/08/15/multiple-iphoto-libraries/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 19:38:10 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Photography]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[iphoto]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=227</guid>
		<description><![CDATA[Just discovered a cool feature of iPhoto (&#8217;08) that I did not know about. It can handle multiple iPhoto libraries.
Due to serious color-related limitations on the display of my wifes laptop, she currently imports her pictures onto my Mac. In addition, my oldest child is taking more and more pictures with her camera, all of [...]]]></description>
			<content:encoded><![CDATA[<p>Just discovered a cool feature of iPhoto (&#8217;08) that I did not know about. It can handle multiple iPhoto libraries.</p>
<p>Due to serious color-related limitations on the display of my wifes laptop, she currently imports her pictures onto my Mac. In addition, my oldest child is taking more and more pictures with her camera, all of which also goes onto my Mac. To avoid &#8220;polluting&#8221; my own iPhoto library, I wanted to create and manage separate libraries.</p>
<p>It turns out, that if you hold down the Option-key (Alt-key) while starting iPhoto, it will popup a dialog with the options to either create a new library or choose an existing one.</p>
<p><a href="http://www.techper.net/blog/wp-content/uploads/2009/08/multiple-iphoto-libs.png"><img class="alignnone size-medium wp-image-229" title="Multiple iPhoto Libraries" src="http://www.techper.net/blog/wp-content/uploads/2009/08/multiple-iphoto-libs-300x83.png" alt="" width="500" height="138" /></a></p>
<p>Nice!</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/z9w0DOCYwvs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2009/08/15/multiple-iphoto-libraries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
