<?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>Misterdom's World &#187; Java</title>
	<atom:link href="http://www.guinard.org/~misterdom/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guinard.org/~misterdom</link>
	<description>My Computing Logbook</description>
	<lastBuildDate>Sat, 24 Dec 2011 09:31:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Embedding Databases in a WAR File</title>
		<link>http://www.guinard.org/~misterdom/2010/10/22/embedding-db-war-file/</link>
		<comments>http://www.guinard.org/~misterdom/2010/10/22/embedding-db-war-file/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 22:38:58 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[derby]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=180</guid>
		<description><![CDATA[Lately I needed a Java Web Application to have its own small database. I know the common/good practice is to have Web apps connect to a DB through a database pool but this requires some user configuration (at least copying the DB driver to the lib folder of the app server) when deploying the app. [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I needed a Java Web Application to have its own small database. I know the common/good practice is to have Web apps connect to a DB through a database pool but this requires some user configuration (at least copying the DB driver to the lib folder of the app server) when deploying the app. Since the Web app was supposed to be deploy-and-play this was not an option.</p>
<p>Thus, we decided to embed a SQLite database in the app. This worked fine as long as I was locally testing the application. However, when deploying to a production Tomcat instance I started getting these exceptions:</p>
<blockquote><p>
<code>java.sql.SQLException: opening db: 'restfulepcis.db': Permission denied<br />
	at org.sqlite.Conn. init(Conn.java:117)<br />
	at org.sqlite.Conn. init(Conn.java:49)<br />
	at org.sqlite.JDBC.connect(JDBC.java:86)</code>
</p></blockquote>
<p>The reason is pretty clear, on the production server I did not have permission to write to the Tomcat working directory.</p>
<p>I was left with two solutions:<br />
1) have the directory where the database has to be created as a config parameter<br />
2) find a directory that&#8217;s universally accessible from an app in an app server.<br />
Since 1) involved user-configuration it was not an option.</p>
<p>There is actually a folder to which any Web app can write, the folder where the app is deployed (or at least my knowledge). The location of this folder can be found by calling:</p>
<blockquote><p><code><br />
ServletContext context = servletContext.getRealPath("/")<br />
</code>
</p></blockquote>
<p>from a servlet. Since my app is a JAX-RS (RESTful) application I can obtain it by CDI (Contexts and Dependency Injection):</p>
<blockquote><p><code>    @Context<br />
    ServletContext servletContext;</p>
<p>    /**<br />
     * Returns a representation of the EPCIS REST Adapter home resource according to the requested mime type<br />
     *<br />
     * @param context<br />
     * @return an instance of javax.ws.rs.core.Resource<br />
     */<br />
    @GET<br />
    public Resource getRESTfulEPCIS(@Context UriInfo context) {<br />
        System.setProperty("sqlite.system.home", servletContext.getRealPath("/"));<br />
        RESTfulEPCISBusinessLogic logic = new RESTfulEPCISBusinessLogic();<br />
        return logic.getRESTfulEPCIS(context);<br />
    }<br />
</code></p></blockquote>
<p>I then load the sqlite.system.home from my database manager class (which is not a Servlet) and use it as path in my database connection URI:</p>
<blockquote><p>
<code><br />
...<br />
     String sqliteHome = System.getProperty("sqlite.system.home");<br />
...<br />
    private Connection getConnection() {<br />
        Connection connection = null;<br />
        try {<br />
            Class.forName(DRIVER);<br />
            connection = DriverManager.getConnection("jdbc:sqlite:" + sqliteHome + DB_NAME + ".db");<br />
...<br />
</code>
</p></blockquote>
<p>Note that for Apache Derby, you can make it even easier by simply setting the <code>derby.system.home</code> in the servlet class. Then, you do not need to read it manually from your database manager class as it is read automatically when loading the driver:</p>
<blockquote><p><code> System.setProperty("derby.system.home", servletContext.getRealPath("/"));</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2010/10/22/embedding-db-war-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting SOAP XML out of KSOAP2 Requests</title>
		<link>http://www.guinard.org/~misterdom/2010/10/20/soap-xml-out-of-ksoap2/</link>
		<comments>http://www.guinard.org/~misterdom/2010/10/20/soap-xml-out-of-ksoap2/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 22:59:37 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ksoap]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[webservices]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=177</guid>
		<description><![CDATA[Use the debug mode of the HttpTransport with:

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;

and get a hold on the raw response from the service using:
String result = androidHttpTransport.responseDump;
]]></description>
			<content:encoded><![CDATA[<p>Use the debug mode of the <code>HttpTransport</code> with:</p>
<blockquote><p><code><br />
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);<br />
androidHttpTransport.debug = true;<br />
</code></p></blockquote>
<p>and get a hold on the raw response from the service using:</p>
<blockquote><p><code>String result = androidHttpTransport.responseDump;</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2010/10/20/soap-xml-out-of-ksoap2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>java.lang.IllegalArgumentException: No enum const class Pachube.Exposure.</title>
		<link>http://www.guinard.org/~misterdom/2010/08/27/jpachube-bug/</link>
		<comments>http://www.guinard.org/~misterdom/2010/08/27/jpachube-bug/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 19:40:46 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[pachube]]></category>
		<category><![CDATA[patch]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=166</guid>
		<description><![CDATA[Trying to push some data to Pachube using JPachube I faced this error: java.lang.IllegalArgumentException: No enum const class Pachube.Exposure which is reported as an issue on the JPachube forge but was not fixed yet. However, a nice fox actually located the bug and uploaded the solution. Since the it requires you to recompile the JPachube [...]]]></description>
			<content:encoded><![CDATA[<p>Trying to push some data to <a href="http://www.pachube.com">Pachube</a> using <a href="http://code.google.com/p/jpachube">JPachube</a> I faced this error: java.lang.IllegalArgumentException: No enum const class Pachube.Exposure which is reported as an issue on the <a href="http://code.google.com/p/jpachube/issues/detail?id=2">JPachube</a> forge but was not fixed yet. However, a nice fox actually located the bug and uploaded the solution. Since the it requires you to recompile the JPachube library I&#8217;ve done the job for you and <a href="http://www.guinard.org/misc/JPachube_patched.jar">uploaded it to here, until a patched version is officially released&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2010/08/27/jpachube-bug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Manually Add a Jar to a Maven Repository</title>
		<link>http://www.guinard.org/~misterdom/2010/06/21/manually-add-a-jar-to-a-maven-repository/</link>
		<comments>http://www.guinard.org/~misterdom/2010/06/21/manually-add-a-jar-to-a-maven-repository/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 16:42:15 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=148</guid>
		<description><![CDATA[Use this command to manually add a Jar to a Maven Repository
mvn install:install-file -DgroupId=javax.comm -DartifactId=comm -Dversion=3.0 -Dpackaging=jar -Dfile=/home/misterdom/Documents/3_Software_Projects/WebPlogg/commapi/comm.jar
]]></description>
			<content:encoded><![CDATA[<p>Use this command to manually add a Jar to a Maven Repository<br />
<code>mvn install:install-file -DgroupId=javax.comm -DartifactId=comm -Dversion=3.0 -Dpackaging=jar -Dfile=/home/misterdom/Documents/3_Software_Projects/WebPlogg/commapi/comm.jar</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2010/06/21/manually-add-a-jar-to-a-maven-repository/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSON and the Quoted Strings</title>
		<link>http://www.guinard.org/~misterdom/2009/09/16/json-and-the-quoted-strings/</link>
		<comments>http://www.guinard.org/~misterdom/2009/09/16/json-and-the-quoted-strings/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 16:50:38 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Dev Logbook]]></category>
		<category><![CDATA[Google Web Toolkit (GWT)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=103</guid>
		<description><![CDATA[&#8220;Bug&#8221; number two for today is a little more tricky.
I was retrieving a JSON object in the GWT (Google Web Toolkit) and putting its Java representation in a HashMap. The only problem is that I could never find it again by referring to its key which I also extracted from JSON object. Here is why:

currentCons.get("URI").isString().toString()

Is [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;Bug&#8221; number two for today is a little more tricky.</p>
<p>I was retrieving a JSON object in the <a href="../../../../category/loogbook/google-web-toolkit-gwt/">GWT (Google Web Toolkit)</a> and putting its Java representation in a <code>HashMap</code>. The only problem is that I could never find it again by referring to its key which I also extracted from JSON object. Here is why:</p>
<blockquote><p>
<code>currentCons.get("URI").isString().toString()</code>
</p></blockquote>
<p>Is actually not returning the String representation of a JSONString object but the quoted representation of that String: e.g. &#8220;key&#8221; and not key. It was in the API but it took me a while to figure it out&#8230;</p>
<p>The solution is:</p>
<blockquote><p>
<code>currentCons.get("URI").isString().stringValue();</code>
</p></blockquote>
<p>Which gets what I wanted, i.e. the String representation without the quotes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2009/09/16/json-and-the-quoted-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Iterators and Deadlocks: How Not to Use Iterators!</title>
		<link>http://www.guinard.org/~misterdom/2009/09/16/iterators-and-deadlocks-how-not-to-use-iterators/</link>
		<comments>http://www.guinard.org/~misterdom/2009/09/16/iterators-and-deadlocks-how-not-to-use-iterators/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 16:34:59 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Dev Logbook]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[iterators]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=99</guid>
		<description><![CDATA[Two nice little bugs today which sums up most of my day  
How not to use iterators:


        while(views.iterator().hasNext()) {
            View currentView = (View) views.iterator.next();
            currentView.update();
 [...]]]></description>
			<content:encoded><![CDATA[<p>Two nice little bugs today which sums up most of my day <img src='http://www.guinard.org/~misterdom/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>How not to use iterators:</p>
<blockquote><p>
<code><br />
        while(views.iterator().hasNext()) {<br />
            View currentView = (View) views.iterator.next();<br />
            currentView.update();<br />
        }<br />
</code>
</p></blockquote>
<p>Bing that basically crashed my Firefox (this is part of a GWT app) when running it as well as my Netbeans / GWT debugger. Notice that Firefox was so good to tell me that apparently the script I was running in a weird manner.</p>
<p>And it was indeed in an endless loop as you can guess: invoking the <code>iterator()</code> method returns a new <code>Iterator</code> object every time (which it is supposed to do, I&#8217;m the dumb one in that story). Thus, I was basically getting the same &#8220;<code>next()</code>&#8221; object every time and <code>hasNext()</code> was thus always true <img src='http://www.guinard.org/~misterdom/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Anyway that fixes it:</p>
<blockquote><p>
<code><br />
        Iterator viewsIt = views.iterator();<br />
        while(viewsIt.hasNext()) {<br />
            View currentView = (View) viewsIt.next();<br />
            currentView.update();<br />
        }<br />
</code>
</p></blockquote>
<p>Ok that was a trivial one, but actually so trivial that I just felt like shaming me a little more and publishing it here <img src='http://www.guinard.org/~misterdom/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2009/09/16/iterators-and-deadlocks-how-not-to-use-iterators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbeans and the GWT: GWT4NB module</title>
		<link>http://www.guinard.org/~misterdom/2008/11/03/netbeans-and-the-gwt-gwt4nb-module/</link>
		<comments>http://www.guinard.org/~misterdom/2008/11/03/netbeans-and-the-gwt-gwt4nb-module/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 17:08:02 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Dev Logbook]]></category>
		<category><![CDATA[Google Web Toolkit (GWT)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[gwt]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=35</guid>
		<description><![CDATA[A few days ago I started experimenting with the Google Web Toolkit module for the Netbeans IDE  a rather nice module that lets you develop GWT code directly in your (at least mine!) very favorite IDE. The biggest benefit is free code completion and tagets for building and debugging your application.
A few remarks thought, [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I started experimenting with the <a href="https://gwt4nb.dev.java.net/">Google Web Toolkit module for the Netbeans IDE </a> a rather nice module that lets you develop GWT code directly in your (at least mine!) very favorite IDE. The biggest benefit is free code completion and tagets for building and debugging your application.</p>
<p>A few remarks thought, when trying to integrate the awesome <a href="http://code.google.com/p/ofcgwt/">OFCGWT chart library</a> in my application I had to face two problems.</p>
<p>First of all the <a href="http://www.netbeans.org/kb/60/web/quickstart-webapps-gwt.html">GWT4NB tutorial </a>on Netbeans.org says you should use the 1.4 java compiler because the GWT does not support Java EE 1.5. Well I&#8217;m pretty sure the GWT does not offer support for EJBs and the like (because it has nothing to do with the backend, it&#8217;s a UI toolkit!) but it does support Java SE 6 constructs. Thus, if you do select Java EE 1.4 when first creating your project be sure to then change the source/binary version to 1.6 in the project properties.</p>
<p>As an example I could not compile the OFCGWT example without it.</p>
<p>The next thing to be aware of is that the GWT4NB module does not fully comply with the URL assigned to your application by the GWT, when a typical application URL would look like (in GWT):</p>
<p><a rel="nofollow" href="http://localhost:8080/UWTest/org.test.Main" target="_blank">http://localhost:8080/UWTest/org.test.Main</a></p>
<p>Netbeans with the GWT4NB plugin exposes it as:</p>
<p><a rel="nofollow" href="http://localhost:8080/UWTest/" target="_blank">http://localhost:8080/UWTest/</a></p>
<p>That basically means the entry point .html file is not located in org.test.Main in the GWT4NB version but rather directly at the root context of your app.</p>
<p>A consequence of this is that GWT modules assuming that the compiled javascript will be loaded by a page at org.test.Main will look for files in the wrong place. Namely, in the case of OFCGWT, the .js references .swf files which it expects to be located in the same folder as where it has been loaded from.</p>
<p>Anyway, I found two workarounds for that matter:</p>
<p>1:</p>
<p>We need to override the post-compile target in our build.xml which is guaranteed<br />
never to be re-generated by the IDE:<br />
<code><br />
&lt;target name="-post-compile"&gt;<br />
&lt;property name="gwt.compiler.output.style" value="OBFUSCATED"/&gt;<br />
&lt;property name="gwt.compiler.logLevel" value="WARN"/&gt;<br />
&lt;java classpath="${javac.classpath}:${src.dir}"<br />
failonerror="true"<br />
classname="com.google.gwt.dev.GWTCompiler" fork="true"<br />
maxmemory="512m"&gt;<br />
&lt;arg value="-out"/&gt;<br />
&lt;arg path="${build.web.dir}/"/&gt;<br />
&lt;arg value="-style"/&gt;<br />
&lt;arg value="${gwt.compiler.output.style}"/&gt;<br />
&lt;arg value="-logLevel"/&gt;<br />
&lt;arg value="${gwt.compiler.logLevel}"/&gt;<br />
&lt;arg value="${gwt.module}"/&gt;<br />
&lt;/java&gt;<br />
&lt;property name="gwt.output.dir" value="${gwt.module}"/&gt;<br />
&lt;move todir="${build.web.dir}/${gwt.output.dir}"&gt;<br />
&lt;fileset dir="${build.web.dir}/${gwt.module}"/&gt;<br />
&lt;fileset dir="${build.web.dir}"&gt;<br />
&lt;include name="**/*.html"/&gt;<br />
&lt;include name="**/*.css"/&gt;<br />
&lt;/fileset&gt;<br />
&lt;/move&gt;<br />
&lt;/target&gt;</code></p>
<p>This will actually move all the .css and .html files of your web folder to the correct output dir. You then need to be sure that the correct .js file is loaded in your welcomeGWT.html file. That is: you need to remove the org.test.Main/ part.</p>
<p>When deploying Apache might not really be happy anymore since there is no html file at the root of your application anymore however, you just need to call it explicitely like:<br />
<a rel="nofollow" href="http://localhost:8080/UWTest/org.test.Main/welcomeGWT.html" target="_blank">http://localhost:8080/UWTest/org.test.Main/welcomeGWT.html</a> and that<br />
should do the trick! BUT &#8211;&gt;</p>
<p>2:</p>
<p>BUT, that said, there is a much simpler way of getting rid of that problem: In gwt.properties change the line gwt.output.dir to gwt.output.dir=/<br />
This will deploy the GWT files (all of them, including the .html and the ofcgwt .swf files) at the root <a rel="nofollow" href="http://localhost:8080/UWTest/" target="_blank">http://localhost:8080/UWTest/</a> which then means that the .js, .swf and .html files are all located in the same folder and thus all on the same path.</p>
<p>This will actually move all the .css and .html files of your web folder to the correct output dir. You then need to be sure that the correct .js file is loaded in your welcomeGWT.html file. That is: you need to remove the org.test.Main/ part.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2008/11/03/netbeans-and-the-gwt-gwt4nb-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

