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

<channel>
	<title>tmro &#187; Java</title>
	<atom:link href="http://www.tmro.net/category/software/languages/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tmro.net</link>
	<description>Mobilise your business</description>
	<lastBuildDate>Tue, 01 Jun 2010 08:55:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Mac OS and Java Me SDK 3.0</title>
		<link>http://www.tmro.net/2009/11/mac-os-and-java-me-sdk-3-0/</link>
		<comments>http://www.tmro.net/2009/11/mac-os-and-java-me-sdk-3-0/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 01:38:21 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[feedback]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[javame]]></category>
		<category><![CDATA[WTF]]></category>

		<guid isPermaLink="false">http://www.tmro.net/?p=213</guid>
		<description><![CDATA[Sun have released not too long ago a Java ME SDK 3.0 that finally brings an official Wireless Toolkit Emulator to the Mac platform. I have been dealing with SUN ]]></description>
			<content:encoded><![CDATA[<p>Sun have released not too long ago a Java ME SDK 3.0 that finally brings an official Wireless Toolkit Emulator to the Mac platform.</p>
<p>I have been dealing with SUN software for a while now and I was not expecting this to be a smooth ride. Those who&#8217;d dealt with the WTK on Windows/Linux platform are well aware of the limitations of these emulators. What I was not prepared for was to get so much clutter that would just not work more than a couple of times.</p>
<p>First impression: this wtk looks like the most polished emulator ever released by Sun.</p>
<p>Sadly, after using the thing for a few days I discovered that the old habits had not changed:</p>
<ul>
<li>there is no menu entry to run an existing jad/jar pair. You have to right click on an emulator instance and then run it&#8230;</li>
<li>you cannot set-up a project starting from a jad/jar pair. There used to be an option to do this back in wtk 2.2&#8230;</li>
<li>after running a couple of apps the whole thing crashes an burns</li>
<li>when closing down the wtk a process is left lingering. Run this in a terminal:  <em>ps aux | grep device-manager.app</em></li>
<li>switching the verbose mode when launching the emulator kills the whole thing dead!</li>
<li>they bundled ant 1.7.1 with the distro although ant is built in Mac OS</li>
<li>Permgen errors are thrown if you try to launch the app too often. LOL</li>
</ul>
<p>Here&#8217;s what happened when I created a new project and tried to run it:</p>
<p><span style="color: #ff0000;">*** Error ***</span></p>
<p><span style="color: #ff0000;">Failed to connect to device 0!</span></p>
<p><span style="color: #ff0000;">Reason:</span></p>
<p><span style="color: #ff0000;">Emulator 0 terminated while waiting for it to register!</span></p>
<p>The same thing happens with Emulator 1 and 2 and 3 and 4 and 5 and 6 and &#8230; you get the picture.</p>
<p>Googling did return lots of forum posts, but hardly any answers&#8230;</p>
<p>So after wasting more than 2 hours on this issue I did the unthinkable: rebooted my mac! To my surprise the miracle happened during the reboot: I was finally able to run the project again.</p>
<p>Needless to say I am very disappointed but not surprised by the quality of this, early access, Java ME SDK.</p>
<p>Cheers&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2009/11/mac-os-and-java-me-sdk-3-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jersey and Websphere 6.1</title>
		<link>http://www.tmro.net/2009/08/jersey-and-websphere-6-1/</link>
		<comments>http://www.tmro.net/2009/08/jersey-and-websphere-6-1/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 23:37:34 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.tmro.net/?p=158</guid>
		<description><![CDATA[If you landed on this page it probably means that you&#8217;ve attempted to deploy a Jersey RESTful web service in IBM&#8217;s Websphere app server. First of all: what were you ]]></description>
			<content:encoded><![CDATA[<p>If you landed on this page it probably means that you&#8217;ve attempted to deploy a Jersey RESTful web service in IBM&#8217;s Websphere app server.<br />
First of all: what were you thinking?!?</p>
<p>Secondly: it probably wasn&#8217;t your decision and you just need to make it work and move on. That was our case anyway&#8230;</p>
<p>So rather than bore you to death with how we ended up debugging the JVM and discovering that a <strong>java.lang.TypeNotPresentException</strong> is thrown when calling <strong>class.isAnnotationPresent</strong> from within the cores (com.ibm.oti.reflect.AnnotationHelper.getAnnotation) of the IBM J9 JVM rather than a plain true / false, I will just give you a bullet list of the things that need to happen to keep Websphere happy.</p>
<ul>
<li>Get your versions right! Jersey 1.0.3 and Websphere AS 6.1.0.25 (including 6.1.0.25 Fix Pack for Web Services) (Getting here is a blog post in itself and I will not do it here)</li>
<li>Make sure that the enterprise app that contains your Jersey resources uses &#8220;Classes loaded with parent class loader first&#8221; and &#8220;Single class loader for application&#8221; (That is in your application&#8217;s &#8220;Class loading and update detection&#8221; section.)</li>
<li>In your web xml configure the Jersey servlet to search for resources using ClassNames rather than packages. Basically make sure your web.xml looks similar to what I have below.</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jersey Web Application<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.spi.container.servlet.ServletContainer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.config.property.resourceConfigClass<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.api.core.ClassNamesResourceConfig<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.config.property.classnames<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				net.tmro.MyRESTfulResource
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jersey Web Application<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/json/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<ul>
<li>Okay, some clarification: the reason ClassNamesResourceConfig is used rather than PackagesResourceConfig is that when the packages are browsed for the actual @Path annotated classes an actual jar browsing is done which throws and swallows a nasty SecurityException&#8230; I invite you (more like dare you) to try using ClasspathResourceConfig and let me know if it works.</li>
</ul>
<p>Now go ahead and give this a try&#8230; don&#8217;t forget to let me know if it worked or failed for you&#8230; Good luck!</p>
<p>Cheers&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2009/08/jersey-and-websphere-6-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JATA &#8211; Java Application Terminal Alignment</title>
		<link>http://www.tmro.net/2009/06/jata-java-application-terminal-alignment/</link>
		<comments>http://www.tmro.net/2009/06/jata-java-application-terminal-alignment/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 03:03:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javame]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=107</guid>
		<description><![CDATA[The Sun JavaOne conference is now in progress and one of the interesting things that have been announced so far is the JATA. Together with France Telecom and Orange, Motorola, ]]></description>
			<content:encoded><![CDATA[<p><span><span style="font-size:11pt"><span style="font-family: verdana, sans-serif;">The Sun JavaOne conference is now in progress and one of the interesting things that have been announced so far is the JATA.</span></span></span></p>
<p><span><span style="font-family: verdana, sans-serif;"> </span><span style="font-family: verdana, sans-serif;"> </span> <span style="font-family: verdana, sans-serif;"><em>Together with France Telecom and Orange, Motorola, Nokia, Sony Ericsson and Vodafone, Sun announced the Java Application Terminal Alignment (JATA), which they promised would reduce the number of tests application developers would need to go through to ensure their applications run on different networks and handsets.</em></span></p>
<p><span style="font-family: verdana, sans-serif;"><em> </em></span></span></p>
<p><span><em> </em></span><span style="font-size:11pt"><span><span style="font-family: verdana, sans-serif;"><em>Also promised are a publisher ID digital certificate to authenticate a person and application, and R&amp;D signing for developers to test their applications.</em><br />
</span> </span><span><span style="font-family: verdana, sans-serif;"><br />
I am looking forward to learning more about it&#8230; in the mean time there is always j2mepolish <img src='http://www.tmro.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </span></span></span></p>
<div><span style="font-size: medium;"><span style="font-size: 15px;"><span style="font-family: verdana, sans-serif;"><br />
</span></span></span></div>
<div><span style="font-size: medium;"><span style="font-size: 15px;"><span style="font-family: verdana, sans-serif;">Cheers&#8230;</span></span></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2009/06/jata-java-application-terminal-alignment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jersey 1.0.2 JSON and JAXB</title>
		<link>http://www.tmro.net/2009/05/jersey-1-0-2-json-and-jaxb/</link>
		<comments>http://www.tmro.net/2009/05/jersey-1-0-2-json-and-jaxb/#comments</comments>
		<pubDate>Fri, 29 May 2009 04:10:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=106</guid>
		<description><![CDATA[In a previous post I explained how to unit test JAX-RS. Let&#8217;s now have a look at a more complex example: implementing RESTful webservices using Jersey 1.0.2. To get RESTful ]]></description>
			<content:encoded><![CDATA[<p>In a previous <a href="http://blog.tmro.net/2009/03/unit-test-jax-rs-using-java-6-and-junit.html">post</a> I explained how to unit test JAX-RS. Let&#8217;s now have a look at a more complex example: implementing RESTful webservices using Jersey 1.0.2.</p>
<div>To get RESTful web services (JAX-RS) that produce JSON output using Jersey you have to get the following libraries:</div>
<div>1. Jersey 1.0.2 (see the dependencies <a href="https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.2/jersey/dependencies.html">here</a> for a web application. Make sure you get: <span style="font-family: Times; font-size: 16px; "><a href="http://download.java.net/maven/2/com/sun/jersey/jersey-server/1.0.2/jersey-server-1.0.2.jar">jersey-server.jar</a>, <a href="http://download.java.net/maven/2/com/sun/jersey/jersey-core/1.0.2/jersey-core-1.0.2.jar">jersey-core.jar</a>, <a href="http://download.java.net/maven/2/javax/ws/rs/jsr311-api/1.0/jsr311-api-1.0.jar">jsr311-api.jar</a>, <a href="http://repo1.maven.org/maven2/asm/asm/3.1/asm-3.1.jar">asm.jar</a><span style="font-family: arial; font-size: 13px; ">) </span></span></div>
<div>2. JAXB 2.1 (<span style="font-family: Times; font-size: 16px; "><a href="http://download.java.net/maven/1/com.sun.xml.bind/jars/jaxb-impl-2.1.jar">jaxb-impl.jar</a>, <a href="http://download.java.net/maven/1/javax.xml.bind/jars/jaxb-api-2.1.jar">jaxb-api.jar</a>)<span style="font-family: arial; font-size: 13px; "> If you run into problems later just check that you are running jaxb 2.1.10. The <a href="http://download.java.net/maven/1/com.sun.xml.bind/jars/jaxb-impl-2.1.10.jar">2.1.10 jaxb-impl.jar</a> provides support for the natural jsonconfiguration. </span></span></div>
<div>3. JSON-lib 2.2.3 (<a href="http://sourceforge.net/project/downloading.php?group_id=171425&amp;filename=json-lib-2.2.3-jdk15.jar">json-lib-2.2.3-jdk15.jar</a>) You will use this later to construct a MessageBodyWriter Provider that outputs JSON content&#8230;</div>
<div>Let&#8217;s start setting up the whole lot.</div>
<div><strong>WEB.XML</strong></div>
<div>In your web application&#8217;s web.xml make sure you&#8217;ve hooked up Jersey:</div>
<div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Jersey Web Application<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.spi.container.servlet.ServletContainer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.config.property.resourceConfigClass<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.api.core.PackagesResourceConfig<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.config.property.packages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>net.tmro.demo.json;your.packages;separated.by.semicolons<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Jersey Web Application<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/webappjson/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</div>
<div>1. The PackagesResourceConfig param enables your to do automatic discovery of your relevant classes as long as you provide the packages location.</div>
<div>2. The url pattern is the endpoint where your resources will be made available.</div>
<div><strong>The RESTful resource</strong></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.tmro.demo.json</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ws.rs.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ws.rs.core.MediaType</span><span style="color: #339933;">;</span>
&nbsp;
@Path<span style="color: #009900;">&#40;</span>“<span style="color: #339933;">/</span>myresource”<span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyResource <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> MyResource<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@GET
	@Produces<span style="color: #009900;">&#40;</span>value<span style="color: #339933;">=</span>MediaType.<span style="color: #006633;">APPLICATION_JSON</span><span style="color: #009900;">&#41;</span>
	@Path<span style="color: #009900;">&#40;</span>“<span style="color: #339933;">/</span>getsomething”<span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">public</span> MyComplexObject getSomething<span style="color: #009900;">&#40;</span>@QueryParam<span style="color: #009900;">&#40;</span>“idOfSomething”<span style="color: #009900;">&#41;</span> <span style="color: #003399;">String</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//your complex object can expose primitive data types, objects as well as collections.</span>
		<span style="color: #666666; font-style: italic;">//you are not required to do anything fancy as long as you implement</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> MyComplexObject<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div>To get something your endpoint will now look like: http://yourserver:port/appcontext/<strong>webappjson</strong>/<strong>myresource</strong>/<strong>getsomething</strong>?<strong>ifOfSomething</strong>=id The parts in bold represent what you&#8217;ve defined so far.</div>
<div>The @Get annotation specifies what type of requests are handled by this method.</div>
<div>The @Path allows you to discriminate between several methods that you might have in this resource class.</div>
<div>If in your @Produces you were to specify a MediaType.APPLICATION_XML you&#8217;d get a neat xml response when pointing your browser at the endpoint above. But what we actually want is a JSON message. So let&#8217;s continue.</div>
<div><strong>JSON MessageBodyWriter</strong></div>
<div>The xml returned by our resource needs to be converted into JSON format. I used the json-lib that I mentioned above. Here&#8217;s the code for it:</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.tmro.demo.json</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.annotation.Annotation</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Type</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ws.rs.WebApplicationException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ws.rs.core.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.ws.rs.ext.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.jersey.spi.resource.Singleton</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">net.sf.json.JSONSerializer</span><span style="color: #339933;">;</span>
&nbsp;
@<span style="color: #003399;">Provider</span>
@Singleton
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyEntityProvider <span style="color: #000000; font-weight: bold;">implements</span> MessageBodyWriter<span style="color: #339933;">&lt;</span>object<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//the json serializer used to write out objects to the output stream</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> JSONSerializer serializer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONSerializer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">long</span> getSize<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> t, <span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;?&gt;</span> type, <span style="color: #000000; font-weight: bold;">final</span> Type genericType, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Annotation</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> annotations, <span style="color: #000000; font-weight: bold;">final</span> MediaType mediaType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isWriteable<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;?&gt;</span> type, <span style="color: #000000; font-weight: bold;">final</span> Type genericType, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Annotation</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> annotations, <span style="color: #000000; font-weight: bold;">final</span> MediaType mediaType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> mediaType.<span style="color: #006633;">isCompatible</span><span style="color: #009900;">&#40;</span>MediaType.<span style="color: #006633;">APPLICATION_JSON_TYPE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeTo<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> t, <span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;?&gt;</span> type, <span style="color: #000000; font-weight: bold;">final</span> Type genericType, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Annotation</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> annotations, <span style="color: #000000; font-weight: bold;">final</span> MediaType mediaType, <span style="color: #000000; font-weight: bold;">final</span> MultivaluedMap<span style="color: #339933;">&lt;</span>string, Object<span style="color: #339933;">&gt;</span> httpHeaders, <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">OutputStream</span> entityStream<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, WebApplicationException <span style="color: #009900;">&#123;</span>
		entityStream.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>serializer.<span style="color: #006633;">toJSON</span><span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div>Not much going on here: we implement the MessageBodyWriter interface and we only use this entity provider to handle JSON mime types.</div>
<div>Note that the class is annotated @Provider so make sure that you have specified this package in your web.xml deployment descriptor.</div>
<div><strong>Returned objects</strong></div>
<div>The only thing that is still missing is the actual object that is returned. Here is an example:</div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">net.tmro.demo.json</span><span style="color: #339933;">;</span>
&nbsp;
@XmlRootElement
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyComplexObject <span style="color: #000000; font-weight: bold;">extends</span> AnotherObject <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//fields: primitive data types, objects and collections. everything gets serialized unless</span>
	<span style="color: #666666; font-style: italic;">//marked as transient</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> MyComplexObject<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#91;</span>..<span style="color: #009900;">&#93;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//getters and setters</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<div>The only thing that I have done really is to annotate it with @XmlRootElement. If you have properties that you do not want to return simply annotate them with @XmlTransient.</div>
<div>Now build and deploy your application and keep an eye on the log. You should see:</div>
<div><em>- Scanning for root resource and provider classes in the packages: </em></div>
<div>and then a list of your packages defined in the web.xml</div>
<div>- <em>Root resource classes found:</em></div>
<div><em> </em>followed by your Resource class.</div>
<div>- <em>Provider classes found:</em></div>
<div><em> </em>followed by the entity provider that you have implemented.</div>
<div>To test just point your browser to the url I described above and your browser should prompt you to save some streamed data. Open it with a text viewer and you should be able to see your JSON response.</div>
<div>Cheers&#8230;</div>
<div>Before I conclude: if you&#8217;ve tried to get things going and ended up with something like this:</div>
<div>
<div><em><span style="color: #000099;">com.sun.jersey.spi.container.ContainerResponse write</span></em></div>
<div><em><span style="color: #000099;">SEVERE: A message body writer for Java type, class [..], and MIME media type, application/json, was not found</span></em></div>
<div><em><span style="color: #000099;">com.sun.jersey.server.impl.application.WebApplicationImpl onException</span></em></div>
<div><em><span style="color: #000099;">SEVERE: Internal server error</span></em></div>
<div><em><span style="color: #000099;">javax.ws.rs.WebApplicationException</span></em></div>
<div><span style="white-space:pre"><em><span style="color: #000099;"> </span></em></span><em><span style="color: #000099;">at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241)</span></em></div>
</div>
<div>you might want to check that your jaxb and json lib versions are OK and that the MessageBodyWriter implementation is picked up when you start your web app&#8230;</div>
<div>I would be interested to find out if you managed to find a way to NOT implement the MessageBodyWriter but still get JSON output.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2009/05/jersey-1-0-2-json-and-jaxb/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The Java Store &#8211; Project Vector</title>
		<link>http://www.tmro.net/2009/05/the-java-store-project-vector/</link>
		<comments>http://www.tmro.net/2009/05/the-java-store-project-vector/#comments</comments>
		<pubDate>Mon, 25 May 2009 03:41:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[The Wonderful Internet]]></category>
		<category><![CDATA[javame]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=104</guid>
		<description><![CDATA[So Jonathan Schwartz&#8217;s blog is alive again. This time we get to learn about the new Java Store.&#160; Here are the facts (extracted from the Jonathan&#8217;s&#160;blog): Project Vector:&#160; &#8220;[...]&#160;is a ]]></description>
			<content:encoded><![CDATA[<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">So Jonathan Schwartz&#8217;s blog is alive again. This time we get to learn about the new Java Store.&nbsp;</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Here are the facts (extracted from the Jonathan&#8217;s&nbsp;<a href="http://blogs.sun.com/jonathan/entry/will_java_be_the_world">blog</a>):</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Project Vector:&nbsp;</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">&#8220;[...]&nbsp;is a network service to connect companies of all sizes and types to the roughly one billion Java users all over the world. Vector (which we&#8217;ll likely rename the Java Store), has the potential to deliver the world&#8217;s largest audience to developers and businesses leveraging Java and JavaFX.&#8221;</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">How will it work:</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">&#8220;Candidate applications will be submitted via a simple web site, evaluated by Sun for safety and content, then presented under free or fee terms to the broad Java audience via our update mechanism. Over time, developers will bid for position on our storefront, and the relationships won&#8217;t be exclusive (as they have been for search). As with other app stores, Sun will charge for distribution &#8211; but unlike other app stores, whose audiences are <b>tiny</b>, measured in the millions or tens of millions, ours will have what we estimate to be approximately a billion users. That&#8217;s clearly a lot of traffic, and will position the Java App Store as having just about the world&#8217;s largest audience.&#8221;</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">More details:</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">&#8220;For details on how Vector will work, when it&#8217;ll be available, how to submit your content or application &#8211; alongside insights into Project Vector&#8217;s technology, roadmap, features and business model, come see us at&nbsp;<a href="http://java.sun.com/javaone/">JavaOne</a>&#8230;&#8221;</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">And here are my biased comments:</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">1. The Java Store will annoy developers: if the storefront is taken by the developers that <b>pay</b> the big bucks rather than the developers that write awesome apps then this Java Store will be one store I won&#8217;t develop for.</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">2. If deploying the apps will require Netbeans (why do I sense that it will?) then this will annoy even more developers. Unlike Microsoft or Apple&#8217;s environments (where you know form the beginning that you kind of have to use their tools since the whole environment is closed) the Java environment is supposed to be open. Forcing <b>Netbeans</b> down the throats of thousands of developers would be a mistake as it will alienate them&#8230;</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">3. <b>Windows only</b>: Jonathan is talking about an audience of billions. I wonder how many of those though sport a recent version of the java runtime. Just consider the countless computers which still run java 1.4, all the Macs and the *nix systems out there.&nbsp;</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">What do you think?</div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "></div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Cheers&#8230;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2009/05/the-java-store-project-vector/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unit Test JAX-RS using Java 6 and JUnit 4</title>
		<link>http://www.tmro.net/2009/03/unit-test-jax-rs-using-java-6-and-junit-4/</link>
		<comments>http://www.tmro.net/2009/03/unit-test-jax-rs-using-java-6-and-junit-4/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 01:34:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=93</guid>
		<description><![CDATA[Today I was amazed to discover that Unit testing JAX-RS resources with JUnit 4 and Java 6 is insanely easy. Have a look at the example below and then read ]]></description>
			<content:encoded><![CDATA[<p>Today I was amazed to discover that Unit testing JAX-RS resources with JUnit 4 and Java 6 is insanely easy.</p>
<p>Have a look at the example below and then read the description underneath if things are not clear enough already.</p>
<pre>import static org.junit.Assert.*;

import java.io.*;
import java.net.*;

import javax.ws.rs.*;

import org.junit.*;

import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.net.httpserver.HttpServer;

@Path("/hellotest")
public class MyResourceTest {

    private static final String LOCALHOST = "http://localhost:9998/";

    private static HttpServer server;

    @GET
    @Produces("text/plain")
    public String testSystem(){
        return "Hello. This is a test";
    }

    @BeforeClass
    public static void setUp() throws Exception{
        System.out.println("Creating server");
        server = HttpServerFactory.create(LOCALHOST);

        System.out.println("Starting server");
        server.start();

        System.out.println("HTTP server started");
        System.out.println("Running tests...");

        testResourceAtUrl(new URL(LOCALHOST + "hellotest"));
    }

    private static String testResourceAtUrl(URL url) throws Exception {

        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            connection.setRequestMethod("GET");
            connection.connect();

            InputStream inputStream = connection.getInputStream();

            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            String firstLineOfText = reader.readLine();//you can also read the whole thing and then test
            System.out.println("Read: " + firstLineOfText);

            System.out.println("System was initialized correctly. About to run actual tests...");

            connection.disconnect();

            return firstLineOfText;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (ProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        throw new Exception("could not establish connection to " + url.toExternalForm());
    }

    @Test
    public void testMyMethod() throws Exception {
        String activationText = testResourceAtUrl(new URL(LOCALHOST + "myresource"));

        //TODO test here

    }

    /**
    * Destroy the server
    */
    @AfterClass
    public static void tearDown() throws IOException{
        System.out.println("Stopping server");
        server.stop(0);
        System.out.println("Server stopped");
    }

}
</pre>
<p>So here&#8217;s what the code above means:<br />
1.&nbsp;<span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 13px; white-space: pre;">@Path(&#8220;/hellotest&#8221;)<span class="Apple-style-span" style="font-family: Times; font-size: 16px; white-space: normal;">&nbsp;The unit test itself is set up as a resource so when the tests are run we can check that the system is working by consuming the resource defined by&nbsp;<span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 13px; white-space: pre;">testSystem()</span></span></span><br />
2. Java 6 allows us to set up a HTTP server very easily using &nbsp;<span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 13px; white-space: pre;">HttpServerFactory.create(LOCALHOST)<span class="Apple-style-span" style="font-family: Times; font-size: 16px; white-space: normal;">&nbsp;This way we simply go ahead and send HTTP requests without having to worry about 3rd party libs and setting up mock HTTP servers.</span></span><br />
3.&nbsp;<span class="Apple-style-span" style="font-family: -webkit-monospace; font-size: 13px; white-space: pre;">testResourceAtUrl(new URL(LOCALHOST + &#8220;hellotest&#8221;))<span class="Apple-style-span" style="font-family: Times; font-size: 16px; white-space: normal;">&nbsp;does the hard work: it requests the resource from the location that we specify in the method call. &nbsp;</span></span><br />
4. put your actual test data in the placeholder <img src='http://www.tmro.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Of course this is a simplified test, and it is meant just to show you how easy it is to test your RESTful webservices. How would you make this better?</p>
<p>Cheers&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2009/03/unit-test-jax-rs-using-java-6-and-junit-4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Objective C &#8211; A translation from Java</title>
		<link>http://www.tmro.net/2008/09/objective-c-a-translation-from-java/</link>
		<comments>http://www.tmro.net/2008/09/objective-c-a-translation-from-java/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 00:31:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=85</guid>
		<description><![CDATA[Hello Objective C (objc) from a (mainly) Java developer. I&#8217;d love to welcome you into my portfolio of programming languages but hey, what&#8217;s with that slang, that weird terminology?! In ]]></description>
			<content:encoded><![CDATA[<p>Hello Objective C (objc) from a (mainly) Java developer. I&#8217;d love to welcome you into my portfolio of programming languages but hey, what&#8217;s with that slang, that weird terminology?!</p>
<p>In this blog post I will try to provide you with a translation, a dictionary or an index of terms that are used by objc programmers. If I have the time I will even keep it up to date&#8230;<br />I hope I am not breaking any NDAs by posting this, I am sure I will be told if I do&#8230;</p>
<p>Let&#8217;s not waste any time and jump straight in:</p>
<div>
<table class="" id="f8qa" border="1" bordercolor="#999999" cellpadding="3" cellspacing="0" width="100%">
<tbody>
<tr bgcolor="#cccccc">
<td valign="top" width="33%"><b>Java<br /></b></td>
<td valign="top" width="33%"><b>Objective C<br /></b></td>
<td valign="top" width="33%"><b>What the?!<br /></b></td>
</tr>
<tr>
<td valign="top" width="33%">-</td>
<td valign="top" width="33%">id</td>
<td valign="top" width="33%">Just remember: everything is an id. Any object, any &#8230; anything.</td>
</tr>
<tr>
<td valign="top" width="33%">Class (concept) (defined by a class)<br />.class<br />Files use .java extension.</td>
<td valign="top" width="33%">Class (concept) (defined by an interface and an implementation, see class structure below)<br />class method<br />Interface files use the .h extension, implementation files use the .m extension.</td>
<td valign="top" width="33%">Wanna know the class? do a [myObject class]</td>
</tr>
<tr>
<td valign="top" width="33%">Interface</td>
<td valign="top" width="33%">Protocol<br />Files use the .h extension.</td>
<td valign="top" width="33%">One adopts a protocol rather than implement an interface.</td>
</tr>
<tr>
<td valign="top" width="33%">this, super</td>
<td valign="top" width="33%">self, super</td>
<td valign="top" width="33%">Easy.</td>
</tr>
<tr>
<td valign="top" width="33%">null</td>
<td valign="top" width="33%">nil</td>
<td valign="top" width="33%">lol</td>
</tr>
<tr>
<td valign="top" width="33%">Field</td>
<td valign="top" width="33%">Property (and instance variable)</td>
<td valign="top" width="33%">One declares an instance variable (optional), then declares the @Property and finally specifies how it is implemented (@synthesize, @dynamic). Easy as.</td>
</tr>
<tr>
<td valign="top" width="33%">Call / Invoke<br />myObject.init()</td>
<td valign="top" width="33%">Send Message<br />[myObject init]<br />or<br />myObject.init() (quite unconventional though)</td>
<td valign="top" width="33%">That is how one uses a type&#8217;s methods. This gets more complicated, look up Selectors in the context of sending messages.</td>
</tr>
<tr>
<td valign="top" width="33%">Subclass<br />class A extends BaseClass</td>
<td valign="top" width="33%">Subclass, Category, Extension<br />@implementation A : BaseClass (CategoryOMG )</td>
<td valign="top" width="33%">You see, things are not as simply as you thought. A class can not only be extended but also <strike>mutilated</strike> modified via Categories and Extensions. An Extension is just an anonymous Category. Simple!</p>
<p>When defining a category you must import the class&#8217;s interface file.</td>
</tr>
<tr>
<td valign="top" width="33%">abstract</td>
<td valign="top" width="33%">-</td>
<td valign="top" width="33%">N/A</td>
</tr>
<tr>
<td valign="top" width="33%">public, protected, private</td>
<td valign="top" width="33%">same</td>
<td valign="top" width="33%">After specifying @public (or another) you can just list all the instance variables that have the same visibility. No need to do it for each variable. Cool eh?</p>
<p>One mention goes to package which cares about how many bits your platform has. google for this (search box available above)</td>
</tr>
<tr>
<td valign="top" width="33%">static method, non-static method<br />static void doSmth(){}<br />void printName(){}</td>
<td valign="top" width="33%">class method, instance method<br />+ (void) doSmth;<br />- (void) printName;</td>
<td valign="top" width="33%">That is just the method declaration in the objc column. The implementation uses brackets after the method name to group the method&#8217;s code, just like Java.</td>
</tr>
<tr>
<td valign="top" width="33%">public void setOrigin(int x, int y);</td>
<td valign="top" width="33%">- (void) setX:(int)x andY:(int)y;</p>
<p>Default return type is id.</td>
<td valign="top" width="33%">AndY is just a label for the second argument.<br />Note that the colons and the labels are part of the method name.</td>
</tr>
<tr>
<td valign="top" width="33%">Object</td>
<td valign="top" width="33%">NSObject</td>
<td valign="top" width="33%">This isn&#8217;t necessarily the Class that everything extends from. There is also NSProxy and you can also write your own. Feeling brave already?</td>
</tr>
<tr>
<td valign="top" width="33%">toString()</td>
<td valign="top" width="33%">description</td>
<td valign="top" width="33%">The NSObject implementation returns the name &amp; address of the object. Sounds familiar?</td>
</tr>
<tr>
<td valign="top" width="33%">import</td>
<td valign="top" width="33%">#import</td>
<td valign="top" width="33%">One can reference just the class not include the whole thing. See comment below. </td>
</tr>
<tr>
<td valign="top" width="33%">Class structure:<br />import java.lang.*;</p>
<p>class MyClass extends BaseClass implements Comma,Separated,List,OfInterfaces {<br />&nbsp; //fields and constants<br />&nbsp; private String name;</p>
<p>&nbsp; //method definitions<br />&nbsp; public String getName(){<br />&nbsp;&nbsp;&nbsp; return this.name;<br />&nbsp; }<br />}</td>
<td valign="top" width="33%">A class requires an Interface and an Implementation. </p>
<p>#import &#8220;BaseClass.h&#8221;<br />@Class AClassThatsBeingMentioned, AnotherClassLikeThat;</p>
<p>@interface MyClass : BaseClass &lt;Protocol1, Protocol2&gt;<br />{<br />&nbsp; //instance variables<br />&nbsp; NSNumber *number;<br />}</p>
<p>//method declarations<br />- (void) printThatNumber();<br />@end</p>
<p>//and then don&#8217;t forget the implementation</p>
<p>#import &#8220;MyClass.h&#8221;</p>
<p>@implementation MyClass<br />//method definitions<br />- (void) printThatNumber(){<br />&nbsp; //can you figure this one out?<br />}<br />@end</td>
<td valign="top" width="33%">Too much can be said and surely you will be asking me questions anyway.</p>
<p>Still: @Class is used when no instances are created / used in your implementation but rather parameter names are of that particular type. Is is simply a low-weight #import.</td>
</tr>
<tr>
<td valign="top" width="33%">Interface</p>
<p>interface A extends AnotherInterface, YetAnotherInterface{<br />&nbsp; void foo();<br />&nbsp; void foo2();<br />&nbsp; [...]<br />}</td>
<td valign="top" width="33%">Protocol<br />Specified using @Protocol</p>
<p>@Protocol A &lt;AnotherProtocol, YetAnotherProtocol&gt;</p>
<p>//required by default<br />- (void) fooBar;</p>
<p>@optional<br />- (void) foo;<br />- (void) foo2;<br />@required<br />- (void) bar;<br />- (void) bar2;</p>
<p>@end</td>
<td valign="top" width="33%">So much better&#8230;</p>
<p>Can incorporate another protocol just like Interfaces can extend other interfaces.</p>
<p>
Methods are @required (by default) or @optional. Use these to group the mandatory and the optional methods or your <strike>interface</strike> protocol. </p>
<p>You can declare objects that adopt a protocol:<br />id &lt;MyProtocol&gt; myObject;</p>
<p>And last, you can forward reference a protocol:<br />@protocol ForwardProtocol;<br />@protocol MyProtocol<br />- foo(id &lt;ForwardProtocol&gt; myObject);<br />@end<br />Confused? It&#8217;s okay, you&#8217;ll never use this anyway. (Unless you don&#8217;t have a Java shaped brain of course but an objc one.)</td>
</tr>
<tr>
<td valign="top" width="33%">MyClass myObject = new MyClass();</td>
<td valign="top" width="33%">MyClass *myObject = [[MyClass alloc] init];</p>
<p>or for non static typing:<br />id myObject = [[MyClass alloc] init];</td>
<td valign="top" width="33%">These are virtually equivalent. I suggest you use static typing if you want your compiler to be able to tell you if some method does not exist in the type that you are using, for example.</td>
</tr>
<tr>
<td valign="top" width="33%">object&#8217;s fields initialization<br />{<br />&nbsp;[...]<br />}</p>
<p>and for static fields<br />static {<br />}</p>
<p>/* Honestly, when did you last use this rather than a constructor with arguments? */</td>
<td valign="top" width="33%">- init<br />- initWithBlah<br />- init&#8230;</p>
<p>and for Class initialization</p>
<p>+ (void) initialize;</td>
<td valign="top" width="33%">NSObject&#8217;s init returns self. Therefore all classes should define an init method to initialize their instance variables.</p>
<p>The runtime will call initialize before using a class object. I am a little bit confused myself but I believe them.</td>
</tr>
<tr>
<td valign="top" width="33%">java.lang java.util etc</td>
<td valign="top" width="33%">NS, CG, CF</td>
<td valign="top" width="33%">NS = NextStep<br />CG = Core Graphics<br />CF = Core Foundation</p>
<p>unless I am wrong of course.</td>
</tr>
<tr>
<td valign="top" width="33%">instanceof</td>
<td valign="top" width="33%">Defined in NSObject:</p>
<p>isMemberOfClass &#8211; actual class<br />isKindOfClass &#8211; is or inherits from (instanceof)<br />respondsToSelector &#8211; implements method<br />conformsToProtocol &#8211; implements (&#8220;conforms&#8221; to protocol)</td>
<td valign="top" width="33%">Cool!</p>
<p>Responds to selector means that the method exists in the class passed as argument while conforms to protocol means that ALL the methods in the protocol. I suspect that a YES response is returned if the methods defined by the protocol exist in the type passed as argument even if the type does not conform to the protocol. </td>
</tr>
<tr>
<td valign="top" width="33%">synchronized</td>
<td valign="top" width="33%">@synchronized()</td>
<td valign="top" width="33%">No synchronized keyword for methods. A mutex is required. Self is a possible candidate, another good one can be _cmd as long as the method name is unique. Who is _cmd? Google in the search box above.</td>
</tr>
<tr>
<td valign="top" width="33%">Exception</td>
<td valign="top" width="33%">NSException</p>
<p>@try; @catch; @finally and @throw are the keywords.</td>
<td valign="top" width="33%">You can throw other objects, not necessarily part of the NSException inheritance tree.</p>
<p>Once an exception is caught it can be re-thrown by using @throw without having to specify the argument.</td>
</tr>
<tr>
<td valign="top" width="33%">!!!</p>
<p>Invoking non-existent methods. Say they have been deprecated and removed from the API. </td>
<td valign="top" width="33%">forwarding</p>
<p>- (void) forwardInvocation: (NSInvocation *) theInvocation {<br />&nbsp; if ([delegateObject respondsToSelector: [theInvocation selector]]){<br />&nbsp;&nbsp;&nbsp; [theInvocation invokeWithTarget:delegateObject];<br />&nbsp; } else {<br />&nbsp;&nbsp;&nbsp; [super forwardInvocation:theInvocation];<br />&nbsp; }<br />}</p>
<p>Here&#8217;s what just happened: a method that does not exist on our &#8220;self&#8221; was called and the runtime forwarded the call to the method I wrote above. It could&#8217;ve freaked out but it didn&#8217;t, it kept its calm and got my kudos. The original <strike>call</strike> message is obviously wrapped inside the NSInvocation. Brilliant!</p>
<p>Note: the NSObject&#8217;s forwardInvocation doesn&#8217;t do much. Soz.</td>
<td valign="top" width="33%">This is so cool, it should be a mandatory feature in all modern programming languages.</p>
<p>Can replace @deprecated, multiple inheritance (I can almost hear your cry), surrogate objects, proxies, delegates and more. It is up to you to confuse the crap out of all those that try to steal your job.</p>
<p>Piece of advice: consider overriding respondsToSelector, isKindOfClass, etc to make it look like your surrogate objects actually belong in the type hierarchy. That will simply make you irreplaceable.</td>
</tr>
<tr>
<td valign="top" width="33%">Remoting | RPC</td>
<td valign="top" width="33%">Remote Messaging</p>
<p>Type qualifiers:<br />- oneway &#8211; to specify that the call is asynchronous<br />- in &#8211; the relevant data is being passed in the message<br />- out &#8211; the argument is used to return info by reference<br />- inout &#8211; in and out together. duh! inout is the default too except for const arguments for which in is the default obviously.<br />- bycopy &#8211; return / pass a copy of the object rather than a pointer to an address. Must ensure that the receiver is aware of the type (in its address space).<br />- byref &#8211; !bycopy and is the sad default.</p>
<p>Example:<br />- (oneway void) goOutsideAndEnjoyTheSun;<br />- setStuff:(in struct things *) aThing;</p>
</td>
<td valign="top" width="33%">Normally all these qualifiers are to be used in the protocol that defines the remote messaging, not in the classes that you implement. They are implementation guidelines more than anything.</p>
<p>New to pointers? Then trust me: out and inout only make sense for pointers. </td>
</tr>
<tr>
<td width="33%">@deprecated</td>
<td width="33%">@interface SadClass<br />- sadmethod __attribute__((deprecated));<br />@end</td>
<td width="33%"></td>
</tr>
<tr>
<td valign="top" width="33%">Spring Framework, Log4j, Maven, Axis, Acegi</td>
<td valign="top" width="33%">LOL, ROFL, ZOMG</td>
<td valign="top" width="33%">I just thought it would be funny <img src='http://www.tmro.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  </td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;&nbsp; &nbsp;<br />My conclusion: objc is too powerful for its own good. God have mercy of all those who end up stuck in teams that have bad developers. Just stop and imagine someone abusing Categories and Extensions, what a disaster that project can become. Let me know when that happens though, I may have the right medicine <img src='http://www.tmro.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Do you want to study objc in depth? Well if you have an apple dev account then you already know where to find it. Otherwise try this <a title="Objective C in depth." target="_blank" href="http://en.wikibooks.org/wiki/Programming:Objective-C_in_depth" id="uecf">wikibook</a>.</p>
<p>Cheers&#8230;</p>
<p>p.s. special thanks go to my surgeon (who is truly awesome btw) who provided me with the time and the painkillers required to read the objc documentation </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2008/09/objective-c-a-translation-from-java/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Google Android confirmed for 4th Quarter</title>
		<link>http://www.tmro.net/2008/08/google-android-confirmed-for-4th-quarter/</link>
		<comments>http://www.tmro.net/2008/08/google-android-confirmed-for-4th-quarter/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 20:45:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Google]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[android]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=82</guid>
		<description><![CDATA[Google have announced today the availability of the 0.9 version of the Android SDK. This was done via the Google Android developer blog. Part of the announcement though was the ]]></description>
			<content:encoded><![CDATA[<div dir="ltr">
<div class="gmail_quote">Google have announced today the availability of the 0.9 version of the Android SDK. This was done via the Google Android developer <a href="http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html" target="_blank">blog</a>. Part of the announcement though was the confirmation of the android devices in the fourth quarter of 2008. This comes right after the FCC <a href="http://www.crn.com/retail/210101421" target="_blank">approved</a> the HTC Dream.</p>
<div dir="ltr">
Here is Google&#8217;s statement:<br />
<i>Since then, we&#8217;ve been working with our <a href="http://www.openhandsetalliance.com/" target="_blank">Open Handset Alliance</a> partners to incorporate much of that feedback, and finish the first devices. Since those devices are <b>shipping in the fourth quarter</b>, the platform is now converging on a final &#8220;Android 1.0&#8243; version.</i></p>
<p>The 0.9 SDK brings about a ton of new stuff:</p>
<ul>
<li>The new Home screen is included, along with a ton of UI changes for 1.0.</li>
<li>Some new applications are also included: an Alarm Clock, Calculator, Camera, Music player, Picture viewer, and Messaging (for SMS/MMS conversations.)</li>
<li>Several new development tools were added, such as a graphical preview for XML layouts for users of Eclipse, and a tool for constructing 9-patch images.</li>
<li>The source of the now-obsolete version from the M5 early-look SDK.
</li>
<li>A number of new APIs are fleshed out and improved, and others are now close to their final forms for 1.0.</li>
<li>Tons of bugs were fixed, of course.  (If you had problems with the MediaPlayer, try it now!)</li>
</ul>
<p>So Google are trying to win back the developers after the terrible SDK <a href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;articleId=9112800&amp;source=rss_news10" target="_blank">mishap</a>, when only the top 50 developers (Android Developer Challenge) were granted access to the &#8220;new&#8221; SDK while the rest of the community was left out in the dark. I wonder if it won&#8217;t be too late now that the iPhone is about to be <a href="http://blogs.zdnet.com/Apple/?p=2098" target="_blank">rolled out in 21 new countries</a> (22nd August).</p>
<p>
<span style="font-weight: bold;">UPDATE</span>: The new SDK unfortunately no longer includes a number of APIs such as GTalkService (for security reasons), and the Bluetooth API. Quote: <span style="font-style: italic;">Due to significant API changes in the upstream open-source project and due to the timeline of getting certain Bluetooth profile implementations certified, a comprehensive Bluetooth API will not be possible or present in Android 1.0</span></p>
<p>Cheers&#8230;</p>
</div></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2008/08/google-android-confirmed-for-4th-quarter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java ME on Windows Mobile</title>
		<link>http://www.tmro.net/2008/08/java-me-on-windows-mobile/</link>
		<comments>http://www.tmro.net/2008/08/java-me-on-windows-mobile/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 09:15:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=81</guid>
		<description><![CDATA[First of all, let me just say this: if one is using a Windows Mobile device, why would they need a J2ME / JavaME application? Unless maybe it&#8217;s a game&#8230; ]]></description>
			<content:encoded><![CDATA[<p>First of all, let me just say this: if one is using a Windows Mobile device, why would they need a J2ME / JavaME application? Unless maybe it&#8217;s a game&#8230;</p>
<p>Windows Mobile devices don&#8217;t always come with JVMs, which only makes it hard for both developers and users. The problem is that there are not too many options out there. Not free at least. Here are the implementations that I am aware of:</p>
<ul>
<li><a href="http://www.ibm.com/software/wireless/wme/">IBM Websphere Everyplace Micro Environment</a> (former J9)</li>
<li><a href="http://www.nsicom.com/Default.aspx?tabid=159">CrE-ME</a></li>
<li>Jeode (discontinued) in favour of the more expensive Jbed</li>
<li><a href="http://www.esmertec.com/">Jbed</a></li>
<li><a href="http://www.aplixcorp.com/en/index.html">JBlend</a></li>
<li><a href="http://www.access-company.com/products/mobile_solutions/java/java.html">JV-Lite2 Wireless Edition</a></li>
</ul>
<p>As a developer one can probably only hope to get IBM&#8217;s implementation or CrE-ME, as the other ones are mostly sold to device manufacturers. I know it hurts to pay money for a Java ME implementation but if you google long enough you&#8217;ll find some free versions on some forums. </p>
<p>The other problems that I&#8217;ve found with these implementations is that you can&#8217;t get too fancy with your applications. Sometimes the SSL certificates are not available to these JVMs, other times if the application is served as a stream from some server the JVM (AMS) won&#8217;t install it. Other JVMs will read the URL and name the application after whatever follows the last forward slash &#8220;/&#8221;. Problems everywhere.</p>
<p>So why does SUN not step up and provide an implementation to help the Java ME developers out there? There is no official JVM for the iPhone, no JVM for the Android platform&#8230; Is SUN giving up on the Java ME platform?</p>
<p>Windows Mobile (CE) and Java have been on the market for a long time, yet they have not worked together and other platforms have stepped up and conquered the developers&#8217; hearts. I really cannot see an iPhone developer switching to Java ME. I can imagine though lots of Java ME developers really looking forward to moving the Apple&#8217;s platform. And all this right before Google realease some final version of the hyped Android platform.</p>
<p>What do you think?</p>
<p>Cheers&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2008/08/java-me-on-windows-mobile/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PostgreSQL + Named Queries = Headache</title>
		<link>http://www.tmro.net/2008/07/postgresql-named-queries-headache/</link>
		<comments>http://www.tmro.net/2008/07/postgresql-named-queries-headache/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 03:52:00 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[DB]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.blog.tmro.net/?p=80</guid>
		<description><![CDATA[I am no DBA guy. No doubt about that. I would be even more frustrated if I were one. Today I stumbled upon another PostgreSQL issue but this time around ]]></description>
			<content:encoded><![CDATA[<p>I am no DBA guy. No doubt about that. I would be even more frustrated if I were one. Today I stumbled upon another PostgreSQL issue but this time around I decided to share my anger with you.</p>
<p><b>Problem: </b>Imagine that you need to write a query that returns the values that match a condition or null if nothing is matched. In other words you are trying to do a <a href="http://en.wikipedia.org/wiki/Null_%28SQL%29#COALESCE">coalesce</a>. So your query would be something like <i>Select * from EMPLOYEE where :empNoParameter IS NULL or :empNoParameter = EMP_NO</i>.<i> </i>Normally<i> </i>you&#8217;d rewrite this as: <i>Select * from EMPLOYEE where EMP_NO = COALESCE(:empNoParameter, EMP_NO</i>) because COALESCE will return the first non-null value that it finds <i>&#8230; </i>Now the problem is that in EJBQL or the new Java Persistence Query Language there is no Coalesce function. Damn. So you have to write in the first style. The problem is that, in PostgreSQL (8.3), you will get a <b>org.postgresql.util.PSQLException: ERROR: operator does not exist: character<br />
varying = bytea</b> or something similar to that.</p>
<p><b>Solution:</b> The query was <i>Select * from EMPLOYEE where :empNoParameter IS NULL or :empNoParameter = EMP_NO</i> and it failed; that happened because when the PostgreSQL JDBC driver first encountered the empNoParameter named parameter it had no clue what type it was because <i>empNoParameter IS NULL</i> does not really reveal the type. So the driver just assigned some default type to the param. Which would be okay if you didn&#8217;t need to do some other comparison later on with the same parameter. So when you come across :empNoParameter the second time around it will have the type it was given initially and will only work as intended if the EMP_NO is indeed of that type. Which in most cases will not be. So here is the solution: swap the tests around: <i>Select * from EMPLOYEE where </i><i>:empNoParameter = EMP_NO OR </i><i>:empNoParameter IS NULL.</i> Now<i> </i>the named query will work because the JDBC driver will be able to identify :empNoParameter&#8217;s type from the first test it has to make.</p>
<p><b>Rant:</b> Why don&#8217;t you do a look ahead you silly PostgreSQL driver? Eh? Why don&#8217;t you?</p>
<p><b>Note:</b> This is my guess as I have not studied the JDBC driver code. I know it worked in more than one scenario though so hopefully it will work for you too&#8230;</p>
<p>Cheers&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tmro.net/2008/07/postgresql-named-queries-headache/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
