<?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>Sun, 30 Oct 2011 08:18:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<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>Xcode 4.2 + iOS5 building armv6+armv7 binary problems</title>
		<link>http://www.techper.net/2011/10/30/xcode-4-2-ios5-building-armv6armv7-binary-problems/</link>
		<comments>http://www.techper.net/2011/10/30/xcode-4-2-ios5-building-armv6armv7-binary-problems/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 08:18:22 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=420</guid>
		<description><![CDATA[After upgrading to Xcode4.2 and iOS5, we had problems building the binary for submission to AppStore. The final binary did not include both armv6 and armv7 architectures, so it was rejected. When linking, the linker told us about this warning: I think the use of this Xcode setting &#8220;$(ARCHS_STANDARD_32_BIT)&#8221; has changed its meaning since,..sometime. We [...]]]></description>
			<content:encoded><![CDATA[<p>After upgrading to Xcode4.2 and iOS5, we had problems building the binary for submission to AppStore. The final binary did not include both armv6 and armv7 architectures, so it was rejected. When linking, the linker told us about this warning:</p>
<pre class="brush: plain; title: ; notranslate">
warning: iPhone/iPod Touch: application executable is missing a required architecture.
At least one of the following architecture(s) must be present: armv6 (-19033)
</pre>
<p>I think the use of this Xcode setting &#8220;$(ARCHS_STANDARD_32_BIT)&#8221; has changed its meaning since,..sometime. We solved this by doing this:</p>
<ul>
<li>Goto <tt>Project-&gt;Build Settings</tt></li>
<li>Find <tt>Architectures</tt> and change it from <tt>$(ARCHS_STANDARD_32_BIT)</tt> to <em>two</em> new values <tt>armv6</tt> and <tt>armv7</tt></li>
<li>While you are there, you can also check that <tt>Build Active Architecture Only</tt> has been set to <tt>No</tt> for the AdHoc and AppStore targets</li>
</ul>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/3rjb3PE-4Jo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/10/30/xcode-4-2-ios5-building-armv6armv7-binary-problems/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>iOS Gotcha: Empty NSArray Optimization</title>
		<link>http://www.techper.net/2011/10/28/ios-gotcha-empty-nsarray-optimization/</link>
		<comments>http://www.techper.net/2011/10/28/ios-gotcha-empty-nsarray-optimization/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 19:47:08 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=414</guid>
		<description><![CDATA[I got bitten by a little iOS optimization the other day. It turns out, that NSArray has been optimized to represent the empty array with the same singleton object, no matter how instantiated. This code: says: which indicates, that even though it looks like we instantiate 2 objects, the &#8220;a1&#8243; and &#8220;a2&#8243; variables point to [...]]]></description>
			<content:encoded><![CDATA[<p>I got bitten by a little iOS optimization the other day. It turns out, that NSArray has been optimized to represent the empty array with the same singleton object, no matter how instantiated.</p>
<p>This code:</p>
<pre class="brush: objc; title: ; notranslate">
NSArray *a1 = [[NSArray alloc] init];
NSArray *a2 = [[NSArray alloc] init];
NSLog(@&quot;a1 == a2 =&gt; %d&quot;, (a1 == a2));
</pre>
<p>says:</p>
<pre class="brush: plain; title: ; notranslate">
a1 == a2 =&gt; 1
</pre>
<p>which indicates, that even though it looks like we instantiate 2 objects, the &#8220;a1&#8243; and &#8220;a2&#8243; variables point to the same object.</p>
<p>It doesn&#8217;t matter much how we instantiate the empty NSArray. We could also do:</p>
<pre class="brush: objc; title: ; notranslate">
NSArray *emptyArr = [[NSArray alloc] init];
NSArray *a1 = [NSArray arrayWithArray:emptyArr];
NSArray *a2 = [NSArray arrayWithArray:emptyArr];

// or

NSArray *a1 = [NSArray array];
NSArray *a2 = [NSArray array];

// or

NSArray *a1 = [NSArray arrayWithObjects:nil];
NSArray *a2 = [NSArray arrayWithObjects:nil];
</pre>
<p>I guess it is because NSArray is immutable, that this optimization was found okay to make. If I add just one object, I can&#8217;t reproduce it. So this:</p>
<pre class="brush: objc; title: ; notranslate">
NSArray *a1 = [NSArray arrayWithObject:@&quot;foo&quot;];
NSArray *a2 = [NSArray arrayWithObject:@&quot;foo&quot;];
NSLog(@&quot;a1 == a2 =&gt; %d&quot;, (a1 == a2));
</pre>
<p>yields:</p>
<pre class="brush: plain; title: ; notranslate">
a1 == a2 =&gt; 0
</pre>
<p>and maybe more surprising, this code:</p>
<pre class="brush: objc; title: ; notranslate">
NSArray *a1 = [NSArray arrayWithObject:@&quot;foo&quot;];
NSArray *a2 = [NSArray arrayWithArray:a1];
NSLog(@&quot;a1 == a2 =&gt; %d&quot;, (a1 == a2));
</pre>
<p>also yields:</p>
<pre class="brush: plain; title: ; notranslate">
a1 == a2 =&gt; 0
</pre>
<p>I would&#8217;ve guessed, that &#8220;[NSArray arrayWithArray:a1]&#8221; simply returned &#8220;a1&#8243;, because after all, NSArray is immutable. But it seems not to, when the given array isn&#8217;t an empty array.</p>
<p>Anyways, I got bitten because I had some code in a setter method with an optimization that went something like this:</p>
<pre class="brush: objc; title: ; notranslate">
if (_ivarArray != newArray) {
   // work the magic
}
</pre>
<p>and I really wanted to &#8220;work the magic&#8221;, even though &#8220;_ivarArray&#8221; previously also was an empty array.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/azvRnfA4qws" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/10/28/ios-gotcha-empty-nsarray-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dead Simple dos2unix “command”</title>
		<link>http://www.techper.net/2011/10/10/dead-simple-dos2unix-command/</link>
		<comments>http://www.techper.net/2011/10/10/dead-simple-dos2unix-command/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 19:32:45 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=403</guid>
		<description><![CDATA[The web is floating over (well, .. nearly) with various one-liners that can convert newlines of a text file from the dos/windows way to the unix way. These use tools like sed, tr, perl, .. to do the trick, and here is another one &#8211; using vim: $ vi your-dos-newline-file.txt :set fileformat=unix :wq and you [...]]]></description>
			<content:encoded><![CDATA[<p>The web is floating over (well, .. nearly) with various one-liners that can convert newlines of a text file from the dos/windows way to the unix way. These use tools like sed, tr, perl, .. to do the trick, and here is another one &#8211; using vim:</p>
<pre>$ vi your-dos-newline-file.txt
:set fileformat=unix
:wq</pre>
<div>and you are done. And I am pretty sure this can be one-lined too, with the proper <strong>v</strong>(h)<strong>im</strong>-sical command tooling <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </div>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/mE40X50u-EI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/10/10/dead-simple-dos2unix-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Universal Library with both Simulator and iOS Architectures</title>
		<link>http://www.techper.net/2011/08/22/universal-library-with-both-simulator-and-ios-architectures/</link>
		<comments>http://www.techper.net/2011/08/22/universal-library-with-both-simulator-and-ios-architectures/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 19:58:03 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=398</guid>
		<description><![CDATA[Just a quick note to myself, because today I had to dig out from my brain, how it was I once built a Mach-O Universal library with both Simulator (i386) architecture and iOS (armv6+7) architectures in it. The final fat library created by &#8220;lipo&#8221; can now be used to link both Simulator and iOS builds. [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note to myself, because today I had to dig out from my brain, how it was I once built a Mach-O Universal library with both Simulator (i386) architecture and iOS (armv6+7) architectures in it.</p>
<pre class="brush: bash; title: ; notranslate">
xcodebuild -configuration Release -target my -sdk iphonesimulator4.0 clean build
xcodebuild -configuration Release -target my -sdk iphoneos4.3 clean build
lipo -create -output build/libmy.a build/Release-iphonesimulator/libmy.a build/Release-iphoneos/libmy.a
</pre>
<p>The final fat library created by &#8220;lipo&#8221; can now be used to link both Simulator and iOS builds.</p>
<p>When you construct the above lines for your project, a couple of xcodebuild commands that list info about a given xcode project, might come in handy:</p>
<pre class="brush: bash; title: ; notranslate">
xcodebuild -list yourProjectName
xcodebuild -showsdks
</pre>
<p>Where &#8220;-list&#8221; list information like &#8220;targets&#8221; and &#8220;build configurations&#8221; about given project and &#8220;-showsdks&#8221; shows the possible sdk names to use.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/mrZQE9oCtdQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/08/22/universal-library-with-both-simulator-and-ios-architectures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate MultipleHiLoPerTableGenerator deadlock and TableGenerator.allocationSize</title>
		<link>http://www.techper.net/2011/08/15/hibernate-multiplehilopertablegenerator-deadlock-and-tablegenerator-allocationsize/</link>
		<comments>http://www.techper.net/2011/08/15/hibernate-multiplehilopertablegenerator-deadlock-and-tablegenerator-allocationsize/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 20:25:33 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jpa]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=391</guid>
		<description><![CDATA[The other week I had the pleasure of visiting a former client, which had a problem with the connection pool being completely drained for connections, and as a consequence of that, their system pretty much locking up. A dump of the stacks of all threads when the system locked up, told us the culprit was [...]]]></description>
			<content:encoded><![CDATA[<p>The other week I had the pleasure of visiting a former client, which had a problem with the connection pool being completely drained for connections, and as a consequence of that, their system pretty much locking up.</p>
<p>A dump of the stacks of all threads when the system locked up, told us the culprit was a specific web-service call, and all the stacks were dead in a call to hibernates <a href="http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/id/MultipleHiLoPerTableGenerator.html" title="MultipleHiLoPerTableGenerator">MultipleHiLoPerTableGenerator</a>.generate method. Like this:</p>
<pre class="brush: plain; title: ; notranslate">
38018:http-7555-140, state=BLOCKED
	org.hibernate.id.MultipleHiLoPerTableGenerator.generate(MultipleHiLoPerTableGenerator.java:204)
	org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
	org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
	org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
	org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
	org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
	org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:800)
	org.hibernate.impl.SessionImpl.persist(SessionImpl.java:774)
	org.hibernate.impl.SessionImpl.persist(SessionImpl.java:778)
	org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:668)
	sun.reflect.GeneratedMethodAccessor553.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
	$Proxy62.persist(Unknown Source)
	sun.reflect.GeneratedMethodAccessor553.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
	$Proxy62.persist(Unknown Source)
	org.springframework.orm.jpa.JpaTemplate$5.doInJpa(JpaTemplate.java:264)
	org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
	org.springframework.orm.jpa.JpaTemplate.persist(JpaTemplate.java:262)
</pre>
<p>What&#8217;s interesting of this particular web-service call is, that it generates a lot of new rows of a specific <a href="http://download.oracle.com/javaee/5/api/index.html?javax/persistence/package-summary.html" title="JPA">JPA</a> mapped entity in the system. Hence, it calls the id-generator a lot of times. And when the system is under heavy load, this particular web-service method is called often, which generates lots of parallel transactions, all trying to generate a lot of ids.</p>
<p>The class was mapped like this:</p>
<pre class="brush: java; title: ; notranslate">
@Entity
public class DetailRow implements Serializable {

  private Long id;

  @Id
  @Column(unique = true, nullable = false)
  @GeneratedValue(strategy = GenerationType.TABLE, generator = &quot;DetailRow.id&quot;)
  @TableGenerator(name = &quot;DetailRow.id&quot;, table = &quot;IdSequence&quot;, pkColumnName = &quot;Name&quot;, valueColumnName = &quot;WaterMark&quot;, pkColumnValue = &quot;DetailRow&quot;, allocationSize = 1)
  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }
}</pre>
<p>Now, it turns out others have had this problem too. The problem is with the <a href="http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/id/MultipleHiLoPerTableGenerator.html" title="MultipleHiLoPerTableGenerator">MultipleHiLoPerTableGenerator</a> of hibernate, which allocates new ids in a separate transaction (which it must, so that&#8217;s kinda okay). But, because it grabs an extra connection while holding an existing connection, it can deadlock when other calls do the same at the same time. The calls can end up hold the one connection all the others need. This is no news, and people have filed bugs (<a href="https://hibernate.onjira.com/browse/HB-1246">HB-1246</a> and <a href="https://hibernate.onjira.com/browse/HHH-1739">HHH-1739</a>) in the hibernate bug-db for it. None of them with a fix though.</p>
<p>I myself have no final fix for it. But I have an easy solution, which, at least for us, made the probability for the deadlock so small, that it stopped happening.</p>
<h2>Solution</h2>
<p>The use of <a href="http://download.oracle.com/javaee/5/api/javax/persistence/TableGenerator.html" title="JPA TableGenerator annotation">@TableGenerator</a> with <a href="http://hibernate.org/">hibernate</a> as ORM provider, maps underneath to <a href="http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/id/MultipleHiLoPerTableGenerator.html" title="MultipleHiLoPerTableGenerator">MultipleHiLoPerTableGenerator</a>. I think we got that covered by now <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  But, there is an interesting parameter &#8220;allocationSize&#8221; to @TableGenerator. This makes the generator work in &#8220;chunks of ids&#8221;. Given the &#8220;IdSequence&#8221; table have a watermark of &#8220;123&#8243;, and we have set allocationSize to &#8220;1000&#8243;, the generator will increment watermark to &#8220;124&#8243; ONCE and then for the next 1000 ids allocate 123000, 123001, 123002, ..123999 and first THEN, will it touch the &#8220;IdSequence&#8221; table again, to increment the watermark.</p>
<p>Setting &#8220;allocationSize&#8221; on @TableGenerator severely lowers the number of times an extra connection is needed, hence also making it a lot less probable, that it will end up in a deadlock. The &#8220;bug&#8221; is still there, because, technically, it still can happen. But practically, it won&#8217;t happen, if setting &#8220;allocationSize&#8221; high enough.</p>
<h2>Caveat</h2>
<p>Not many.</p>
<p>Remember that &#8220;allocationSize&#8221; is multiplied onto the &#8220;watermark&#8221; value, so to avoid a large unused hole of ids when deploying a new version with a larger &#8220;allocationSize&#8221;, you should divide the watermark with &#8220;allocationSize&#8221;.</p>
<p>Also, there can (will) be holes in the sequence, as unused ids from a &#8220;chunk&#8221; are lost when process dies. No big deal for us. Might be for some.</p>
<p>And what is a &#8220;high enough&#8221; value for &#8220;allocationSize&#8221; then? Well, it depends on your system. How many rows are created, and at which rate, and with how many concurrent transactions, related to your connection pool size. Do the math for loaded scenarios and try setting it to what you think is &#8220;high enough&#8221;.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/NcyJITKeLSM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/08/15/hibernate-multiplehilopertablegenerator-deadlock-and-tablegenerator-allocationsize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problems with require ‘mongo_mapper’ on cloudfoundry</title>
		<link>http://www.techper.net/2011/06/10/problems-with-require-mongo_mapper-on-cloudfoundry/</link>
		<comments>http://www.techper.net/2011/06/10/problems-with-require-mongo_mapper-on-cloudfoundry/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 20:31:10 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cloudfoundry]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sinatra]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=381</guid>
		<description><![CDATA[I&#8217;ve been playing a bit with cloudfoundry today, and I wanted to do a simple example that connected to a mongodb service from ruby. Should be simple but I had some trouble. Some of the trouble I am sure stems from the fact that my ruby skills are somewhat rusty. Other from a somewhat alpha-like [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing a bit with <a href="http://www.cloudfoundry.com/">cloudfoundry</a> today, and I wanted to do a simple example that connected to a mongodb service from ruby. Should be simple but I had some trouble. Some of the trouble I am sure stems from the fact that my ruby skills are somewhat rusty. Other from a somewhat alpha-like experience of the <a href="http://www.cloudfoundry.com/">cloudfoundry</a> product, which is supposed to be in beta <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I started out simple, with these ruby require lines in the top of my ruby sinatra app:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'sinatra'
require 'json'
require 'mongo'
require 'mongo_mapper'
</pre>
<p>Unfortunately, that made <tt>vmc update</tt> of my app fail. Cloudfoundry couldn&#8217;t start the app, and there were no logs or crashlogs to be seen <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  A little trial-n-error told me that it was the require of &#8216;mongo_mapper&#8217;, that made it fail. After some more trial-n-errors and a lot of googling, I could put together the needed bits.</p>
<p><a href="http://support.cloudfoundry.com/entries/20019747-ruby-and-cloudfoundry-things-to-know">This page</a> at the cloudfoundry site has good info on what is required (and what they know won&#8217;t work) when running ruby apps on cloudfoundry. It also said, that I should be using <a href="http://gembundler.com/">Bundler</a> and a <a href="http://gembundler.com/man/gemfile.5.html">Gemfile</a> to describe my gem dependencies and package the app before deployment. So, I ended up with this Gemfile:</p>
<pre class="brush: ruby; title: ; notranslate">
source &quot;http://rubygems.org&quot;
gem 'sinatra'
gem 'json'
gem 'mongo'
gem 'mongo_mapper'
</pre>
<p>and changed the require-lines in the sinatra application ruby file with this single line:</p>
<pre class="brush: ruby; title: ; notranslate">
Bundler.require
</pre>
<p>When using bundler we then need to do these two steps before <tt>vmc push</tt> or <tt>update</tt> (each time dependencies have changed):</p>
<pre class="brush: ruby; title: ; notranslate">
bundle package
bundle install
</pre>
<p>If you don&#8217;t have bundler, you can simply do:</p>
<pre class="brush: ruby; title: ; notranslate">
sudo gem install bundler
</pre>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/V7O3RKOeDBQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/06/10/problems-with-require-mongo_mapper-on-cloudfoundry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Springified Servlets, Listeners and Filters</title>
		<link>http://www.techper.net/2011/03/05/springified-servlets-listeners-and-filters/</link>
		<comments>http://www.techper.net/2011/03/05/springified-servlets-listeners-and-filters/#comments</comments>
		<pubDate>Sat, 05 Mar 2011 08:37:23 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=373</guid>
		<description><![CDATA[Here are some short, but fully functional, templates for when you have a need for HttpServlet, ContextListener or Filter implementations, that also need spring bean dependencies. You use them by subclassing them and calling the getBean method when a dependency is needed, like this: Okay, here they come.. SpringHttpServlet SpringContextListener SpringFilter]]></description>
			<content:encoded><![CDATA[<p>Here are some short, but fully functional, templates for when you have a need for <a href="http://download.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html">HttpServlet</a>, <a href="http://download.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html">ContextListener</a> or <a href="http://download.oracle.com/javaee/6/api/javax/servlet/Filter.html">Filter</a> implementations, that also need spring bean dependencies.</p>
<p>You use them by subclassing them and calling the <tt>getBean</tt> method when a dependency is needed, like this:</p>
<pre class="brush: java; title: ; notranslate">
// ..blah blah..inside subclass
MyService myService = getBean(&quot;myService&quot;);
</pre>
<p>Okay, here they come..</p>
<h2>SpringHttpServlet</h2>
<pre class="brush: java; title: ; notranslate">
package net.techper.server.web;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public abstract class SpringHttpServlet extends HttpServlet {

  private ApplicationContext context;

  @Override
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    context = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
  }

  @Override
  public void destroy() {
    context = null;
    super.destroy();
  }

  protected &lt;T&gt; T getBean(String beanName) {
    return (T) context.getBean(beanName);
  }
}
</pre>
<h2>SpringContextListener</h2>
<pre class="brush: java; title: ; notranslate">
package net.techper.server.web;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public abstract class SpringContextListener implements ServletContextListener {

  private ApplicationContext context;

  @Override
  public void contextInitialized(ServletContextEvent sce) {
    context = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
  }

  @Override
  public void contextDestroyed(ServletContextEvent sce) {
    context = null;
  }

  protected &lt;T&gt; T getBean(String beanName) {
    return (T) context.getBean(beanName);
  }
}
</pre>
<h2>SpringFilter</h2>
<pre class="brush: java; title: ; notranslate">
package net.techper.server.web;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

public abstract class SpringFilter implements Filter {

  private ApplicationContext context;

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    context = WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext());
  }

  @Override
  public void destroy() {
    context = null;
  }

  protected &lt;T&gt; T getBean(String beanName) {
    return (T) context.getBean(beanName);
  }
}
</pre>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/QbgIiwGc-hQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/03/05/springified-servlets-listeners-and-filters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Session Issues with Grails Command Objects</title>
		<link>http://www.techper.net/2011/02/05/session-issues-with-grails-command-objects/</link>
		<comments>http://www.techper.net/2011/02/05/session-issues-with-grails-command-objects/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 19:33:21 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=365</guid>
		<description><![CDATA[I&#8217;ve been doing a bit of Grails programming lately, and I must say it has been a nice experience so far. I really like the near instant turn-around time where I fix something in the controller or the view, and a refresh in the browser shows the new code running. But&#8230; I started using grails [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a bit of <a href="http://www.grails.org/">Grails</a> programming lately, and I must say it has been a nice experience so far. I really like the near instant turn-around time where I fix something in the controller or the view, and a refresh in the browser shows the new code running.</p>
<p>But&#8230;</p>
<p>I started using grails <a href="http://www.grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.1.10 Command Objects">command objects</a> (a bit like Struts form beans) to have the submitted form data data-bound and validated to an object different from the model. Like this:</p>
<pre class="brush: groovy; title: ; notranslate">
class UploadDataSetController {
  def uploadDataSetFile = { UploadDataSetFileCommand cmd -&gt;
    if (cmd.hasErrors()) {
      // foo
    } else {
      // bar
      session[&quot;UploadDataSetController.UploadDataSetFileCommand&quot;] = cmd
    }
  }
}

class UploadDataSetFileCommand {
   // blah blah
}
</pre>
<p>As you can see above, I defined the command class inside the file of the controller, which is what <a href="http://www.grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.1.10 Command Objects">the documentation</a> recommends.</p>
<p>But, have a look at what I do in the else block. I <em>put the command instance into session storage</em>. And what is the problem with that? Well, when I change something (no matter what) in the controller file, Grails will recompile it on the fly (which is what I like). But, recompiling will make the class file of the command class different from the class of the instance in the session, giving me <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ClassCastException.html">ClassCastException</a> when reloading in the browser <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<p>I tried moving the command class definition into its own file, which works fine. Only thing is, these won&#8217;t be recompiled at runtime, so I need to take the server down and up all the time, when I develop on the command class to get the changes. Not nice.</p>
<p>Actually, I tried something different. I tried keeping the command class definition in the file of the controller, but also providing it with a <tt>serialVersionUID</tt> definition. But it still failed on me. I think the reason for this being the classloader changing on recompile/refresh.</p>
<p>What I ended up with was the command class definition in the controller when developing heavily on it, and moving it into a separate file after it stabilized, which opened up for changes to the controller without problems.</p>
<p>Any good ideas for better solutions on this?</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/7UkGAmOzEfM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/02/05/session-issues-with-grails-command-objects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>“ls” Command Slow on Very Large Directories</title>
		<link>http://www.techper.net/2011/01/25/ls-command-slow-on-very-large-directories/</link>
		<comments>http://www.techper.net/2011/01/25/ls-command-slow-on-very-large-directories/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 20:11:22 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[gpfs]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=361</guid>
		<description><![CDATA[I had some problems with listing files on linux from a directory with pretty many files in it (around 700.000 files now and still counting). Doing a simple ls on the directory never returned (or at least I killed it after a couple of hours waiting). Now, actually I did know this could be a [...]]]></description>
			<content:encoded><![CDATA[<p>I had some problems with listing files on linux from a directory with pretty many files in it (around 700.000 files now and still counting). Doing a simple <a href="http://en.wikipedia.org/wiki/Ls">ls</a> on the directory never returned (or at least I killed it after a couple of hours waiting).</p>
<p>Now, actually I did know this could be a problem, because unix-like filesystems have had this scaling problem with very large directories for some time now. But I thought I was in the clear, as I was only doing a simple &#8220;ls&#8221;, which should be able to read all the filenames directly from the directory file. (As opposed to an &#8220;ls -l&#8221; which actually needs to <a href="http://en.wikipedia.org/wiki/Stat_(Unix)">stat()</a> each inode to get to the extra information needed to present the long listing.)</p>
<p>Another thing that I thought could help me was the fact, that it was a <a href="http://en.wikipedia.org/wiki/IBM_General_Parallel_File_System">gpfs</a> filesystem, which should have support for very large directories.</p>
<p>The &#8220;solution&#8221; turned out to be simple. It all dawned on me when I was trying to kill the &#8220;ls&#8221; command that was hanging. I did a &#8220;ps&#8221; + &#8220;grep&#8221; after it, and got this command listing from &#8220;ps&#8221; output:</p>
<p><code>/bin/ls -N --color=tty -T 0 /my/large/dir</code></p>
<p>Ahh, an &#8220;alias&#8221;. On my system, &#8220;ls&#8221; was an alias to <tt>"/bin/ls $LS_OPTIONS"</tt>, and <tt>LS_OPTIONS</tt> was set to <tt>-N --color=tty -T 0</tt>. I am not sure, but I suspect it being the <tt>"--color=tty"</tt> option, because to color files according to their types and attributes must incur a <a href="http://en.wikipedia.org/wiki/Stat_(Unix)">stat()</a> on each inode.</p>
<p>And <a href="http://en.wikipedia.org/wiki/IBM_General_Parallel_File_System">gpfs</a> actually does seem to scale well with very large directories. I mean, maybe it is okay that it takes for ages to <a href="http://en.wikipedia.org/wiki/Stat_(Unix)">stat()</a> 700.000+ inodes, but each single <a href="http://en.wikipedia.org/wiki/Stat_(Unix)">stat()</a> call is pretty quick, if you know the exact filename in advance.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/zJHIqupNwWE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2011/01/25/ls-command-slow-on-very-large-directories/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wine Slow to Start – Fontconfig Issue</title>
		<link>http://www.techper.net/2010/11/11/wine-slow-to-start-fontconfig-issue/</link>
		<comments>http://www.techper.net/2010/11/11/wine-slow-to-start-fontconfig-issue/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 21:04:07 +0000</pubDate>
		<dc:creator>polesen</dc:creator>
				<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[fontconfig]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[wine]]></category>

		<guid isPermaLink="false">http://www.techper.net/?p=351</guid>
		<description><![CDATA[Here is a solution to a problem we&#8217;ve had with wine that someone might find helpful, in case they experienced the same. Part of a web application we&#8217;ve build is dispatching some calculation functionality to a windows based cmdline program. Because we are hosting the application on linux, we are using wine for execution of [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a solution to a problem we&#8217;ve had with <a href="http://www.winehq.org/">wine</a> that someone might find helpful, in case they experienced the same.</p>
<p>Part of a web application we&#8217;ve build is dispatching some calculation functionality to a windows based cmdline program. Because we are hosting the application on linux, we are using wine for execution of the calculation program. Suddenly one day, after applying a bunch of bugfix patches, wine became painfully slow to startup. We are talking 25 seconds or so, for what used to take around 1-2 seconds.</p>
<p>After a lot of digging and searching, we found that wine was using a lot of resources on reading fonts. Okay, but why? No new fonts had been installed. After some further digging, in turned out that rebuilding the <a href="http://www.fontconfig.org/">fontconfig</a> cache, made wine slow. Hugh! A cache of fonts should make it faster.</p>
<p>Yes, using a font cache will make font resolve much faster &#8211; if the cache is in a format, that the program using fontconfig understand. It turned out, that the <a href="http://www.novell.com/products/server/">SLES</a> 10 we are running, is using a dead-old 2.3.x version of fontconfig. And this old version of fontconfig only has one set of cache files in &#8220;<tt>/var/cache/fontconfig</tt>&#8220;. But, fontconfig builds the cache differently for 32bit and 64bit architectures. Building with 64bit version of <tt>fc-cache</tt> overwrites the 32bit cache files and vice versa. Our SLES installation and machine architecture is 64bit, but wine is a 32bit program.</p>
<p><strong>Short term solution</strong>: Simply build the fontcache with <tt>fc-cache32</tt>. Luckily, it seems we do not have other important software running on that server, that depends on the 64bit cache.</p>
<p><strong>Long term solution</strong>: Upgrade the fontconfig libraries to a not so dead-old version. Newer versions of fontconfig have different cache files for 32bit and 64bit on the same installation.</p>
<img src="http://feeds.feedburner.com/~r/TechPer/~4/tg9GIT5oPHo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.techper.net/2010/11/11/wine-slow-to-start-fontconfig-issue/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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 [...]]]></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; title: ; notranslate">
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; title: ; notranslate">
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 waitFor() [...]]]></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; title: ; notranslate">
  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>1</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: One thing here: cxf.xml is loaded from classpath by the test code, but it resides in src/main/webapp/WEB-INF [...]]]></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; title: ; notranslate">
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; title: ; notranslate">
  &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; title: ; notranslate">
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 [...]]]></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; title: ; notranslate">
  &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; title: ; notranslate">
    &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 [...]]]></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; title: ; notranslate">
    &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; title: ; notranslate">
@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; title: ; notranslate">
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>4</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; title: ; notranslate">
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; title: ; notranslate">
&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 [...]]]></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>5</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 [...]]]></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; title: ; notranslate">
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; title: ; notranslate">
	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, [...]]]></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>
	</channel>
</rss>

