<?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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Java Thinking</title>
	
	<link>http://www.javathinking.com</link>
	<description>Java and software development related thoughts</description>
	<lastBuildDate>Wed, 22 Feb 2012 05:55:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</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/JavaThinking" /><feedburner:info uri="javathinking" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>When tests become hard</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/efJgqGhDlVI/</link>
		<comments>http://www.javathinking.com/2012/02/when-tests-become-hard/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 05:55:48 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Corporate Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[layers]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=615</guid>
		<description><![CDATA[A friend contacted me for advice. He was having trouble writing a test for some code. I asked him to send me the code and the test so I could see what was going on.
I encounter this problem quite frequently, so I thought I&#8217;d post one of my responses&#8230;
Okay, here is where I think you [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>A friend contacted me for advice. He was having trouble writing a test for some code. I asked him to send me the code and the test so I could see what was going on.</p>
<p>I encounter this problem quite frequently, so I thought I&#8217;d post one of my responses&#8230;</p>
<blockquote><p>Okay, here is where I think you are going wrong, and when writing tests becomes hard, it’s usually because of this.</p>
<ul>
<li> It’s important to layer your applications. Web/Services/DB – at least conceptually.</li>
<li>What you have is a class that does everything. Web and Service. No-one can reuse your file processing logic without using the web, not even tests!</li>
</ul>
<p>A nice way to code would be to:</p>
<ul>
<li>Write a UNIT test that attempts to process a file. It passes in a file X and asserts that the result is Y. It won’t compile because you haven’t written the file processing code yet!</li>
<li>Now you write the service which processes the file</li>
<li>The test will compile and run now, but probably fail because you forgot something.</li>
<li>Now you can fix your service</li>
<li>And eventually the test will pass. You might think of more scenarios you want to add, so you create more tests.</li>
</ul>
<p>Now you say, “I&#8217;ve got this service that can process these files, but I need to access it via web services”. So, you write another class which is the web service – but it only knows about web things, and just  calls the service so it doesn&#8217;t know anything about processing files.</p>
<ul>
<li>Now, you may choose to write an INTEGRATION test which really only needs to test the WebService stuff – because you’ve already tested the excel processing code</li>
<li>OR, you may choose to write a UI test which tests the deployed application</li>
</ul>
<p>It really depends on the resources you have available, and what make sense to test.</p>
<p>But what you end up with is re-usable and easily testable code. Which is good right?</p></blockquote>
<p>There&#8217;s nothing new here. <a href="http://en.wikipedia.org/wiki/Extreme_programming" target="_blank">Extreme Programming</a> and various design patterns/best practices cover off all of this. But the usual philosophy holds here:</p>
<blockquote><p>If what you are doing seems too hard, its usually because you are doing the wrong thing.</p></blockquote>
<p>This is extremely relevant when considering testing. I&#8217;ve seen tests become extremely convoluted because the design was wrong. Test First Programming can help the design because you&#8217;ll find bad (hard to test) code early. I&#8217;ve got much more to say about this, but I don&#8217;t have the time right now!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/4kCdEMcVCicRLGxUlshpnzd6Yfw/0/da"><img src="http://feedads.g.doubleclick.net/~a/4kCdEMcVCicRLGxUlshpnzd6Yfw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/4kCdEMcVCicRLGxUlshpnzd6Yfw/1/da"><img src="http://feedads.g.doubleclick.net/~a/4kCdEMcVCicRLGxUlshpnzd6Yfw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/efJgqGhDlVI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2012/02/when-tests-become-hard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2012/02/when-tests-become-hard/</feedburner:origLink></item>
		<item>
		<title>Solved – Trouble with the Samsung Galaxy S 1 phone</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/y5f_wFsnT_4/</link>
		<comments>http://www.javathinking.com/2012/02/solved-trouble-with-the-samsung-galaxy-1/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 12:11:42 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[galaxy]]></category>
		<category><![CDATA[phone]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=610</guid>
		<description><![CDATA[My wife has had a Samsung Galaxy S1 Android phone for over a year now and its been great. Recently though, she&#8217;d been having terrible battery performance and had noticed that after charging the phone overnight, it was only at 50% in the morning. My first thought was to buy a new battery, but then [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>My wife has had a <a href="http://www.samsung.com/au/smartphone/galaxys/">Samsung Galaxy</a> S1 Android phone for over a year now and its been great. Recently though, she&#8217;d been having terrible battery performance and had noticed that after charging the phone overnight, it was only at 50% in the morning. My first thought was to buy a new battery, but then I figured I&#8217;d try updating the firmware first.</p>
<p>Thats when I discovered that windows couldn&#8217;t recognise the device!! This was a big issue &#8211; how could I get all of her photos off the phone?</p>
<p>Solutions:</p>
<ol>
<li>Quite by accident, she plugged her phone into an iCoustic USB charger that we got with an iPod accessory pack &#8211; this fully charged the battery and now there are no battery issues. She&#8217;d been using my iPad USB charger previously and for some reason, this makes a difference.</li>
<li>I realized that when syncing the phone with Kies I wasn&#8217;t using the original USB cable that came with the phone. We&#8217;d been using a third party cable we&#8217;d bought after losing the original one. Since we&#8217;d found the original cable I tried that and there were no problems &#8211; Windows found the drivers, installed them and recognised the phone. Kies worked fine after that.</li>
</ol>
<p>So, all is good now &#8211; the phone works fine, running Android 2.3 (Gingerbread).</p>

<p><a href="http://feedads.g.doubleclick.net/~a/bNYC88ZiTQ_gUqm3Nkw__VevMzU/0/da"><img src="http://feedads.g.doubleclick.net/~a/bNYC88ZiTQ_gUqm3Nkw__VevMzU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bNYC88ZiTQ_gUqm3Nkw__VevMzU/1/da"><img src="http://feedads.g.doubleclick.net/~a/bNYC88ZiTQ_gUqm3Nkw__VevMzU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/y5f_wFsnT_4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2012/02/solved-trouble-with-the-samsung-galaxy-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2012/02/solved-trouble-with-the-samsung-galaxy-1/</feedburner:origLink></item>
		<item>
		<title>Grooveshark for listening to music</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/-UbnnwfkVuY/</link>
		<comments>http://www.javathinking.com/2012/01/grooveshark-for-listening-to-music/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 21:38:43 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Media center]]></category>
		<category><![CDATA[grooveshark]]></category>
		<category><![CDATA[music]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=604</guid>
		<description><![CDATA[I&#8217;ve just started using Grooveshark.com for listening to music. Running in the browser, its a great cross platform solution &#8211; no installs necessary. I&#8217;m just running the browser on my MythTV media center, with the sound via the TV. The quality seems great, even though I&#8217;ve got it on the lower quality, and I&#8217;m hoping [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve just started using <a href="http://grooveshark.com/">Grooveshark.com</a> for listening to music. Running in the browser, its a great cross platform solution &#8211; no installs necessary. I&#8217;m just running the browser on my MythTV media center, with the sound via the TV. The quality seems great, even though I&#8217;ve got it on the lower quality, and I&#8217;m hoping its just what I need to find some new and interesting music.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/ErrskdAGqjyaXJvmJOjzTJxEHuA/0/da"><img src="http://feedads.g.doubleclick.net/~a/ErrskdAGqjyaXJvmJOjzTJxEHuA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ErrskdAGqjyaXJvmJOjzTJxEHuA/1/da"><img src="http://feedads.g.doubleclick.net/~a/ErrskdAGqjyaXJvmJOjzTJxEHuA/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/-UbnnwfkVuY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2012/01/grooveshark-for-listening-to-music/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2012/01/grooveshark-for-listening-to-music/</feedburner:origLink></item>
		<item>
		<title>Fixing browser sound on Ubuntu 11.04</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/Boc8Yxpg4No/</link>
		<comments>http://www.javathinking.com/2012/01/fixing-browser-sound-on-ubuntu-11-04/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 21:29:29 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=602</guid>
		<description><![CDATA[I&#8217;ve finally fixed sound via the browser on my Ubuntu 11.04 MythTV media center. MythTV was working fine, but the browsers never even tried to play sound (the sound settings would show NO applications using sound, when Chrome or Firefox should have been).
The information I needed was here and I had no /etc/asound.conf so I [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve finally fixed sound via the browser on my Ubuntu 11.04 MythTV media center. MythTV was working fine, but the browsers never even tried to play sound (the sound settings would show NO applications using sound, when Chrome or Firefox should have been).</p>
<p>The information I needed was <a href="http://ubuntuforums.org/showpost.php?p=9438109&amp;postcount=7" target="_blank">here</a> and I had no /etc/asound.conf so I had to put the following in ~/.asoundrc -</p>
<blockquote>
<pre dir="ltr">pcm.pulse { type pulse }
ctl.pulse { type pulse }
pcm.!default { type pulse }
ctl.!default { type pulse }</pre>
</blockquote>

<p><a href="http://feedads.g.doubleclick.net/~a/mMGd9X9AA4sODgrZ8QUxuNif4cw/0/da"><img src="http://feedads.g.doubleclick.net/~a/mMGd9X9AA4sODgrZ8QUxuNif4cw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/mMGd9X9AA4sODgrZ8QUxuNif4cw/1/da"><img src="http://feedads.g.doubleclick.net/~a/mMGd9X9AA4sODgrZ8QUxuNif4cw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/Boc8Yxpg4No" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2012/01/fixing-browser-sound-on-ubuntu-11-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2012/01/fixing-browser-sound-on-ubuntu-11-04/</feedburner:origLink></item>
		<item>
		<title>Could not complete schema update</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/cPTrhEm5ASk/</link>
		<comments>http://www.javathinking.com/2011/11/could-not-complete-schema-update/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 02:34:42 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=598</guid>
		<description><![CDATA[I recently mapped a JPA entity to a view, and encountered this error while using hibernate to update the database schema:
ORA-01702: a view is not appropriate here
[SchemaUpdate.execute] could not complete schema update
I was using the Oracle JDBC drivers 10.1.3.3 &#8211; luckily, the solution was to upgrade the drivers &#8211; when using 11.2.0.2.0 it works fine.
Download [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I recently mapped a JPA entity to a view, and encountered this error while using hibernate to update the database schema:</p>
<blockquote><p>ORA-01702: a view is not appropriate here</p>
<p>[SchemaUpdate.execute] could not complete schema update</p></blockquote>
<p>I was using the Oracle JDBC drivers 10.1.3.3 &#8211; luckily, the solution was to upgrade the drivers &#8211; when using 11.2.0.2.0 it works fine.</p>
<div id="_mcePaste">Download ojdbc6.jar from here:</div>
<blockquote>
<div><a href="http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html " target="_blank"> http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html </a></div>
</blockquote>
<blockquote>
<div id="_mcePaste">ojdbc6.jar (2,152,051 bytes) &#8211; Classes for use with JDK 1.6. It contains the JDBC driver classes except classes for NLS support in Oracle Object and Collection types.</div>
</blockquote>

<p><a href="http://feedads.g.doubleclick.net/~a/MLKYatLUQaiLN1KrtMDZzCeYkO8/0/da"><img src="http://feedads.g.doubleclick.net/~a/MLKYatLUQaiLN1KrtMDZzCeYkO8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MLKYatLUQaiLN1KrtMDZzCeYkO8/1/da"><img src="http://feedads.g.doubleclick.net/~a/MLKYatLUQaiLN1KrtMDZzCeYkO8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/cPTrhEm5ASk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2011/11/could-not-complete-schema-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2011/11/could-not-complete-schema-update/</feedburner:origLink></item>
		<item>
		<title>On to some exciting stuff</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/LwY02qcLIDA/</link>
		<comments>http://www.javathinking.com/2011/10/on-to-some-exciting-stuff/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 11:17:05 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[ddd]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[wakaleo]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=592</guid>
		<description><![CDATA[I went to a Agile Sydney meetup recently &#8211; &#8220;Automated web tests as a team communication tool&#8221; &#8211; by John Smart of Wakaleo Consulting. It was great stuff, and the presentation is now online.
There is a  nice story here in that the project feature set is documented via
easily readable and executable tests, and the [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I went to a <a href="http://www.meetup.com/Agile-Sydney/events/25570671/">Agile Sydney meetup</a> recently &#8211; &#8220;Automated web tests as a team communication tool&#8221; &#8211; by John Smart of <a href="http://www.wakaleo.com/">Wakaleo Consulting</a>. It was great stuff, and the presentation is now <a href="http://www.slideshare.net/wakaleo/completing-the-circle-automated-web-tests-as-a-team-communication-tool">online</a>.</p>
<p>There is a  nice story here in that the project feature set is documented via<br />
easily readable and executable tests, and the reporting shows which features are<br />
implemented and which aren&#8217;t.</p>
<p>More information on the the Thucydides tool he references can be found at:</p>
<ul>
<li><a href="https://github.com/thucydides-webtests/thucydides/wiki">https://github.com/thucydides-webtests/thucydides/wiki</a></li>
</ul>
<p>While reading that presentation online, I found more gold here in some of his other presentations:</p>
<ul>
<li><a href="http://www.slideshare.net/wakaleo/junit-kung-fu-getting-more-out-of-your-unit-tests">JUnit Kung Fu: Getting More Out of Your Unit Tests</a></li>
<li><a href="http://www.slideshare.net/wakaleo/introduction-toddd">Introduction to Domain Driven Design</a></li>
</ul>
<p>They are a great read and are great pointers in the right direction to improve your software development.</p>
<p>(If you haven&#8217;t seen them before, check out <a href="http://www.wakaleo.com/training">Wakaleo&#8217;s training courses</a>. I haven&#8217;t been on them, but based on the course content, they look to be the most relevant courses I&#8217;ve come across)</p>
<p>The last couple of projects I&#8217;ve been on I&#8217;ve been frustrated by a few things about the code base that I couldn&#8217;t quite put my finger on, and the DDD presentation hit a nerve.</p>
<p>I searched around for more about DDD and found some more excellent resources:</p>
<ul>
<li><a href="http://www.infoq.com/minibooks/domain-driven-design-quickly">Domain driven design quickly</a></li>
<li><a href="http://dddsample.sourceforge.net/index.html">DDD sample application</a></li>
<li><a href="http://sourceforge.net/projects/timeandmoney/">Time and Money</a></li>
</ul>
<p>I still have to absorb all of this material and try it out but I can instantly recognise that it addresses some if not most of the code problems that have frustrated me.</p>
<p>So, exciting times are ahead. Its always refreshing to find new tricks and efficient ways of improving software development!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/dpp2asyfjzrtqs-CgYeZL90gKmU/0/da"><img src="http://feedads.g.doubleclick.net/~a/dpp2asyfjzrtqs-CgYeZL90gKmU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/dpp2asyfjzrtqs-CgYeZL90gKmU/1/da"><img src="http://feedads.g.doubleclick.net/~a/dpp2asyfjzrtqs-CgYeZL90gKmU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/LwY02qcLIDA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2011/10/on-to-some-exciting-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2011/10/on-to-some-exciting-stuff/</feedburner:origLink></item>
		<item>
		<title>Using the Crystal Reports Java API to generate PDF</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/u7bfMN2XI68/</link>
		<comments>http://www.javathinking.com/2011/09/using-the-crystal-reports-java-api-to-generate-pdf/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 03:56:01 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[businessobjects]]></category>
		<category><![CDATA[crystal]]></category>
		<category><![CDATA[report]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=582</guid>
		<description><![CDATA[I recently had to investigate how to generate a PDF from a Crystal Report created by another team. Without knowing anything about Crystal Reports, I had to google around for information and piece it all together. It turns out to be really simple once you know how.
We were using Business Objects 4.0, and probably the [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I recently had to investigate how to generate a PDF from a Crystal Report created by another team. Without knowing anything about Crystal Reports, I had to google around for information and piece it all together. It turns out to be really simple once you know how.</p>
<p>We were using Business Objects 4.0, and probably the most important thing was to get the Java library &#8211; download &#8216;SAP Crystal Reports for Java runtime components &#8211; Java Reporting Component (JRC)&#8217; from<br />
<a href="http://www.businessobjects.com/campaigns/forms/downloads/crystal/eclipse/datasave.asp">http://www.businessobjects.com/campaigns/forms/downloads/crystal/eclipse/datasave.asp</a></p>
<p>There are a lot of samples on the web to look at &#8211; you might find something to help here:<br />
<a href="http://wiki.sdn.sap.com/wiki/display/BOBJ/Java+Reporting+Component++SDK+Samples">http://wiki.sdn.sap.com/wiki/display/BOBJ/Java+Reporting+Component++SDK+Samples</a></p>
<p>A good example to start with is “JRC EXPORT REPORT”:<br />
<a href="http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d580ce-bd66-2b10-95b0-cc4d3f2dcaef">http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40d580ce-bd66-2b10-95b0-cc4d3f2dcaef</a></p>
<p>If you have an RPT file, the java to generate the report is relatively simple &#8211; :</p>
<pre>
ReportClientDocument reportClientDoc = new ReportClientDocument();
reportClientDoc.open("My crystal report.rpt", 0);
ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);
reportClientDoc.close();
</pre>
<p>The report I dealt with was developed by another team, and expected a data source called ‘TESTDB’ to be available. Without that data source present, I would get the following error:</p>
<pre>com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: Error finding JNDI name (TESTDB)---- Error code:-2147467259 Error code name:failed</pre>
<p>Setting a data source up in Tomcat is trivial, just by adding a resource to context.xml:</p>
<pre>
&lt;Context&gt;
    &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;

    &lt;Resource name="jdbc/TESTDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="user" password="passwd" driverClassName="oracle.jdbc.OracleDriver"
               url="jdbc:oracle:thin:@dbserver:1521:db1"/&gt;
&lt;/Context&gt;
</pre>
<p>Now the data source is set up, there’s another problem &#8211; the report expects a parameter and we get this error:</p>
<pre>com.crystaldecisions.sdk.occa.report.lib.ReportSDKParameterFieldException: InternalFormatterException---- Error code:-2147217394 Error code name:missingParameterValueError</pre>
<p>Adding the report parameter is simple once you know how:</p>
<pre>
ParameterFieldController paramController = reportClientDoc.getDataDefController().getParameterFieldController();
paramController.setCurrentValue("","MyParamName","MyParamValue");
</pre>
<p>There’s probably a lot of subtle information and detail missing here, but it works &#8211; I can generate the PDF via java code so its now at a stage where it can be integrated into our application.</p>
<p>So, the final spike test code looks like:</p>
<pre>
&lt;%@page contentType="text/html"%&gt;
&lt;%@page pageEncoding="UTF-8"%&gt;

&lt;%//Crystal Java Reporting Component (JRC) imports.%&gt;
&lt;%@page import="com.crystaldecisions.reports.sdk.*" %&gt;
&lt;%@page import="com.crystaldecisions.sdk.occa.report.lib.*" %&gt;
&lt;%@page import="com.crystaldecisions.sdk.occa.report.exportoptions.*" %&gt;

&lt;%//Java imports. %&gt;
&lt;%@page import="java.io.*" %&gt;

&lt;%

try {

	//Open report.
	ReportClientDocument reportClientDoc = new ReportClientDocument();
	reportClientDoc.open("MyReport.rpt", 0);
	ParameterFieldController paramController = reportClientDoc.getDataDefController().getParameterFieldController();
	paramController.setCurrentValue("","MyParamName","MyParamValue");
	ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);
	reportClientDoc.close();

	writeToBrowser(byteArrayInputStream, response, "application/pdf");

} catch(Exception ex) {
	out.println(ex);
}
%&gt;

&lt;%!
   /*
	* Utility method that demonstrates how to write an input stream to the server's local file system.
	*/
	private void writeToBrowser(ByteArrayInputStream byteArrayInputStream, HttpServletResponse response, String mimetype) throws Exception {

		//Create a byte[] the same size as the exported ByteArrayInputStream.
		byte[] buffer = new byte[byteArrayInputStream.available()];
		int bytesRead = 0;

		//Set response headers to indicate mime type and inline file.
		response.reset();
		response.setHeader("Content-disposition", "inline;filename=report.pdf");
		response.setContentType(mimetype);

		//Stream the byte array to the client.
		while((bytesRead = byteArrayInputStream.read(buffer)) != -1) {
			response.getOutputStream().write(buffer, 0, bytesRead);
		}

		//Flush and close the output stream.
		response.getOutputStream().flush();
		response.getOutputStream().close();

	}
%&gt;
</pre>
<p>Note, implementing this in a JSP was just a simple and quick shortcut to investigate the API. </p>
<p>I put a simple CRConfig.xml in WEB-INF/classes:</p>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;CrystalReportEngine-configuration&gt;
    &lt;reportlocation&gt;..&lt;/reportlocation&gt;
    &lt;timeout&gt;0&lt;/timeout&gt;
    &lt;ExternalFunctionLibraryClassNames&gt;
    	&lt;classname&gt;&lt;/classname&gt;
    &lt;/ExternalFunctionLibraryClassNames&gt;
&lt;/CrystalReportEngine-configuration&gt;
</pre>
<p>Note that this specified a report location of .. which meant I had to put MyReport.rpt in the WEB-INF directory of my application (i.e. [web-root]/WEB-INF/classes/.. = [web-root]/WEB-INF) &#8211; contents of the WEB-INF directory should not be available for download.</p>
<p>If the rpt file cannot be found, you’ll see an error like:</p>
<pre>com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: Report file /[path-to-webapps]/webapps/cr/WEB-INF/MyReport.rpt not found---- Error code:-2147215356 Error code name:fileNotOpened</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/9rJk7ZAUi2cSPTe-rBTqf-QvH_Q/0/da"><img src="http://feedads.g.doubleclick.net/~a/9rJk7ZAUi2cSPTe-rBTqf-QvH_Q/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/9rJk7ZAUi2cSPTe-rBTqf-QvH_Q/1/da"><img src="http://feedads.g.doubleclick.net/~a/9rJk7ZAUi2cSPTe-rBTqf-QvH_Q/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/u7bfMN2XI68" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2011/09/using-the-crystal-reports-java-api-to-generate-pdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2011/09/using-the-crystal-reports-java-api-to-generate-pdf/</feedburner:origLink></item>
		<item>
		<title>Easy classpaths with Java 6</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/0RPcXWTA3dQ/</link>
		<comments>http://www.javathinking.com/2011/09/easy-classpaths-with-java-6/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 12:35:56 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[classpath]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=569</guid>
		<description><![CDATA[Back in the day it used to be a bit more difficult than it is now to dynamically generate your java application classpath &#8211; you&#8217;d have to write a script to loop over all the jar files in a directory, appending them to your classpath variable &#8211; like this.
Since Java 6 though, its been a [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Back in the day it used to be a bit more difficult than it is now to dynamically generate your java application classpath &#8211; you&#8217;d have to write a script to loop over all the jar files in a directory, appending them to your classpath variable &#8211; like <a href="http://stackoverflow.com/questions/524081/bat-file-to-create-java-classpath">this</a>.</p>
<p>Since Java 6 though, its been a lot easier &#8211; you can use wildcards to specify all jars in a directory. See the &#8220;Understanding class path wildcards&#8221; in the <a href="http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html">Java SE 6 documentation</a>.</p>
<p>Now its as simple as:</p>
<pre>
java -cp /my/lib/dir/* MyClass
</pre>
<p>Simple! As it should be!</p>

<p><a href="http://feedads.g.doubleclick.net/~a/qS3afTJR5VxXhQTxS25aSBVaFQ8/0/da"><img src="http://feedads.g.doubleclick.net/~a/qS3afTJR5VxXhQTxS25aSBVaFQ8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qS3afTJR5VxXhQTxS25aSBVaFQ8/1/da"><img src="http://feedads.g.doubleclick.net/~a/qS3afTJR5VxXhQTxS25aSBVaFQ8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/0RPcXWTA3dQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2011/09/easy-classpaths-with-java-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2011/09/easy-classpaths-with-java-6/</feedburner:origLink></item>
		<item>
		<title>Turning off JDK logging</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/_O0xzV0qsvI/</link>
		<comments>http://www.javathinking.com/2011/09/turning-off-jdk-logging/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 00:12:38 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=561</guid>
		<description><![CDATA[I&#8217;ve been developing a simple little command line application and one of the libraries I&#8217;m using seems to log debug information to the console. To clean up the console output, I had to turn off the JDK by using:


        LogManager.getLogManager().reset();

This seemed to do the trick for me, but [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve been developing a simple little command line application and one of the libraries I&#8217;m using seems to log debug information to the console. To clean up the console output, I had to turn off the JDK by using:</p>
<pre name="code" class="java">

        LogManager.getLogManager().reset();
</pre>
<p>This seemed to do the trick for me, but it sounds like in some cases you may need to go a bit further and turn off logging at the global logger level:</p>
<pre name="code" class="java">

        LogManager.getLogManager().reset();
        Logger globalLogger = Logger.getLogger(java.util.logging.Logger.GLOBAL_LOGGER_NAME);
        globalLogger.setLevel(java.util.logging.Level.OFF);
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/qULchfddWPjBeJprrHz9Zb3dRWY/0/da"><img src="http://feedads.g.doubleclick.net/~a/qULchfddWPjBeJprrHz9Zb3dRWY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qULchfddWPjBeJprrHz9Zb3dRWY/1/da"><img src="http://feedads.g.doubleclick.net/~a/qULchfddWPjBeJprrHz9Zb3dRWY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/_O0xzV0qsvI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2011/09/turning-off-jdk-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2011/09/turning-off-jdk-logging/</feedburner:origLink></item>
		<item>
		<title>JUnit parameterized test with Spring autowiring AND transactions</title>
		<link>http://feedproxy.google.com/~r/JavaThinking/~3/W-ZX33-Jo6w/</link>
		<comments>http://www.javathinking.com/2011/09/junit-parameterized-test-with-spring-autowiring-and-transactions/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 02:32:13 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[transaction]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=551</guid>
		<description><![CDATA[I&#8217;ve been writing JUnit Parameterized tests (a nice intro here &#8211; also see Theories) to do some data driven API testing. Now, when introducing Spring into the mix there are a couple of extra things to do. I came unstuck though because I was trying to do Transactional tests &#8211; since I&#8217;m now using @RunWith(Parameterized.class) and [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve been writing JUnit Parameterized tests (a nice intro <a href="http://ourcraft.wordpress.com/2008/08/27/writing-a-parameterized-junit-test/" target="_blank">here</a> &#8211; also see <a href="http://blog.schauderhaft.de/2010/01/31/new-feature-of-junit-theories/" target="_blank">Theories</a>) to do some data driven API testing. Now, when introducing Spring into the mix there are a couple of <a href="http://bmocanu.ro/coding/320/combining-junit-theoriesparameterized-tests-with-spring/" target="_blank">extra things to do</a>. I came unstuck though because I was trying to do Transactional tests &#8211; since I&#8217;m now using @RunWith(Parameterized.class) and setting up my Spring TestContextManager manually the @Transaction annotations caused an exception:</p>
<pre>java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given</pre>
<p>I couldn&#8217;t find any built in solution, so I&#8217;ve gone with manual transaction management in my test, using doInTransaction:</p>
<pre>
@RunWith(Parameterized.class)
@ContextConfiguration(locations = "classpath*:/testContext.xml")
public class MyTest {

    @Autowired
    PlatformTransactionManager transactionManager;

    private TestContextManager testContextManager;

    public MyTest (... parameters for test) {
        // store parameters in instance variables
    }

    @Before
    public void setUpSpringContext() throws Exception {
        testContextManager = new TestContextManager(getClass());
        testContextManager.prepareTestInstance(this);
    }

    @Parameterized.Parameters
    public static Collection<Object[]> generateData() throws Exception {
        ArrayList list = new ArrayList();
        // add data for each test here
        return list;
    }

    @Test
    public void validDataShouldLoadFully() throws Exception {
        new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
            public Object doInTransaction(TransactionStatus status) {
                status.setRollbackOnly();
                try {
                    ... do cool stuff here

                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                return null;
            }
        });

    }</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/QzThtRQoaIHjfkbUe35qJk9JLxo/0/da"><img src="http://feedads.g.doubleclick.net/~a/QzThtRQoaIHjfkbUe35qJk9JLxo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/QzThtRQoaIHjfkbUe35qJk9JLxo/1/da"><img src="http://feedads.g.doubleclick.net/~a/QzThtRQoaIHjfkbUe35qJk9JLxo/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JavaThinking/~4/W-ZX33-Jo6w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2011/09/junit-parameterized-test-with-spring-autowiring-and-transactions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.javathinking.com/2011/09/junit-parameterized-test-with-spring-autowiring-and-transactions/</feedburner:origLink></item>
	</channel>
</rss>

