<?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/category/loogbook/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>Switching Java Versions in Ubuntu</title>
		<link>http://www.guinard.org/~misterdom/2010/09/08/switching-java-versions-in-ubuntu/</link>
		<comments>http://www.guinard.org/~misterdom/2010/09/08/switching-java-versions-in-ubuntu/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 14:00:13 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=171</guid>
		<description><![CDATA[Use this command to switch between the versions of Java (e.g. Sun, Oracle, Openjdk, etc.)
sudo update-alternatives --config java
]]></description>
			<content:encoded><![CDATA[<p>Use this command to switch between the versions of Java (e.g. Sun, Oracle, Openjdk, etc.)</p>
<blockquote><p><code>sudo update-alternatives --config java</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2010/09/08/switching-java-versions-in-ubuntu/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>Packaging a Property File in a Maven Project</title>
		<link>http://www.guinard.org/~misterdom/2010/06/25/property-file-maven-project/</link>
		<comments>http://www.guinard.org/~misterdom/2010/06/25/property-file-maven-project/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 14:12:52 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=154</guid>
		<description><![CDATA[When working with a Maven project, property (e.g. config.properties) files are not copied to the build as a default. The easiest way to have them appear in the final jar is to put them in ${basedir}/src/main/resources.
As a result your property file will be copied at the root of your packaged jar.
]]></description>
			<content:encoded><![CDATA[<p>When working with a Maven project, property (e.g. config.properties) files are not copied to the build as a default. The easiest way to have them appear in the final jar is to put them in <code>${basedir}/src/main/resources</code>.</p>
<p>As a result your property file will be copied at the root of your packaged jar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2010/06/25/property-file-maven-project/feed/</wfw:commentRss>
		<slash:comments>0</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>Changing the Default Java Vendor (or Version) in Ubuntu</title>
		<link>http://www.guinard.org/~misterdom/2010/04/20/changing-the-default-java-vendor-or-version-in-ubuntu/</link>
		<comments>http://www.guinard.org/~misterdom/2010/04/20/changing-the-default-java-vendor-or-version-in-ubuntu/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 08:34:13 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=135</guid>
		<description><![CDATA[Run sudo update-java-alternatives -l to see the current configuration and possibilities.
Run sudo update-java-alternatives -s XXXX to set the XXX java version as default.
For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun
Run java -version to ensure that the correct version is being called. 
Source: https://help.ubuntu.com/community/Java
]]></description>
			<content:encoded><![CDATA[<p><code>Run sudo update-java-alternatives -l to see the current configuration and possibilities.</code></p>
<p><code>Run sudo update-java-alternatives -s XXXX to set the XXX java version as default.<br />
For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun</code></p>
<p>Run <code>java -version</code> to ensure that the correct version is being called. </p>
<p>Source: <a href="https://help.ubuntu.com/community/Java">https://help.ubuntu.com/community/Java</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2010/04/20/changing-the-default-java-vendor-or-version-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Browse to URI (or URL) in the Default Browser Directly From Java</title>
		<link>http://www.guinard.org/~misterdom/2009/10/03/browse-url-java/</link>
		<comments>http://www.guinard.org/~misterdom/2009/10/03/browse-url-java/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 10:52:57 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=114</guid>
		<description><![CDATA[
if (Desktop.isDesktopSupported()) {
                        Desktop dt = Desktop.getDesktop();
                        if (dt.isSupported(Desktop.Action.BROWSE)) [...]]]></description>
			<content:encoded><![CDATA[<p><code><br />
if (Desktop.isDesktopSupported()) {<br />
                        Desktop dt = Desktop.getDesktop();<br />
                        if (dt.isSupported(Desktop.Action.BROWSE)) {<br />
                            dt.browse(new URI("http://localhost:8182/EnergieVisible"));<br />
                        }<br />
                    }<br />
</code></p>
<p>From Java 1.6.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2009/10/03/browse-url-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doing PUT DELETE and Other Niceties with GWT</title>
		<link>http://www.guinard.org/~misterdom/2009/10/01/doing-put-with-gwt/</link>
		<comments>http://www.guinard.org/~misterdom/2009/10/01/doing-put-with-gwt/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 15:33:35 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[Google Web Toolkit (GWT)]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[PUT]]></category>
		<category><![CDATA[verbs]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=112</guid>
		<description><![CDATA[You probably are REST lovers like I personally am.
Thus you were probably quite frustrated when seeing that a GWT (Google Web Toolkit) client cannot send other requests than POST or GET.
Well here is the solution:
public class RequestBuilderForAnyHTTPMethodTypeExample extends RequestBuilder {
  /**
   * Constructor that allows a developer to override the HTTP method
 [...]]]></description>
			<content:encoded><![CDATA[<p>You probably are REST lovers like I <a href="http://www.webofthings.com/tag/rest/">personally am</a>.</p>
<p>Thus you were probably quite frustrated when seeing that a GWT (Google Web Toolkit) client cannot send other requests than POST or GET.<br />
Well here is the solution:</p>
<p><code>public class RequestBuilderForAnyHTTPMethodTypeExample extends RequestBuilder {</p>
<p>  /**<br />
   * Constructor that allows a developer to override the HTTP method<br />
   * restrictions imposed by the RequestBuilder class.  Note if you override the<br />
   * RequestBuilder's HTTP method restrictions in this manner, your application<br />
   * may not work correctly on Safari browsers.<br />
   *<br />
   * @param httpMethod any non-null, non-empty string is considered valid<br />
   * @param url any non-null, non-empty string is considered valid<br />
   *<br />
   * @throws IllegalArgumentException if httpMethod or url are empty<br />
   * @throws NullPointerException if httpMethod or url are null<br />
   */<br />
  public RequestBuilderForAnyHTTPMethodTypeExample(String httpMethod, String url) {<br />
    super(httpMethod, url);<br />
  }<br />
</code></p>
<p>i.e. simply subclass the <code>RequestBuilder</code></p>
<p>Source: <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/http/client/package-summary.html"> (see the bottom of the page).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2009/10/01/doing-put-with-gwt/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>
	</channel>
</rss>

