<?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>JAVA DevBlog</title>
	<atom:link href="http://www.i-net-design.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.i-net-design.com</link>
	<description>Java, Spring, Maven, Hibernate and GWT development</description>
	<lastBuildDate>Fri, 07 Oct 2011 08:50:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Convert milliseconds to formatted String with Java</title>
		<link>http://www.i-net-design.com/2011/10/07/convert-milliseconds-to-formatted-string-with-java/</link>
		<comments>http://www.i-net-design.com/2011/10/07/convert-milliseconds-to-formatted-string-with-java/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 08:50:37 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[Milliseconds]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=122</guid>
		<description><![CDATA[Since 1.5 there is the java.util.concurrent.TimeUnit class, use it like this: String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)) );]]></description>
			<content:encoded><![CDATA[<p>Since 1.5 there is the java.util.concurrent.TimeUnit class, use it like this:</p>
<pre class='brush:java'>String.format("%d min, %d sec",
    TimeUnit.MILLISECONDS.toMinutes(millis),
    TimeUnit.MILLISECONDS.toSeconds(millis) -
    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
);</pre>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/10/07/convert-milliseconds-to-formatted-string-with-java/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/10/07/convert-milliseconds-to-formatted-string-with-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitoring Tomcat 7 with JMX</title>
		<link>http://www.i-net-design.com/2011/07/15/monitoring-tomcat-7-with-jmc/</link>
		<comments>http://www.i-net-design.com/2011/07/15/monitoring-tomcat-7-with-jmc/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 09:38:37 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JMX]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=109</guid>
		<description><![CDATA[Enabling JMX on Tomcat Enabling JMX without Authentication JMX is enabled by setting some Java properties in the command used to start an application. You will need to set the CATALINA_OPTS environment variable so the correct properties get set for to Tomcat when it starts. Furthermore, the properties you set will determine if application can [...]]]></description>
			<content:encoded><![CDATA[<h1>Enabling JMX on Tomcat</h1>
<h2><a name="MonitoringTomcatwithJMX-EnablingJMXwithoutAuthentication"></a>Enabling JMX without Authentication</h2>
<p>JMX is enabled by setting some Java properties in the command used to  start an application. You will need to set the CATALINA_OPTS  environment variable so the correct properties get set for to Tomcat  when it starts. Furthermore, the properties you set will determine if  application can access the JMX interface remotely and if they need to  authenticate. This section describes how to setup JMX so that  applications can access the interface remotely without authenticating. <strong>Authentication should be used in production environments, this configuration should only be used for testing.</strong> The following commands show how to set the CATALINA_OPTS environment variable so that clients can connect to TCP port <strong>8999</strong> of the host <strong>localhost</strong> without any authentication:</p>
<div>
<p><strong>For Windows:</strong></p>
<pre class="brush:java">
.
set CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=localhost";
.</pre>
<p><strong>For Linux:</strong></p>
<pre class="brush:java">
.
$ CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=localhost";
$ export CATALINA_OPTS;
.</pre>
</div>
<p>The values in bold should be set to values appropriate for your system. The property <tt>com.sun.management.jmxremote</tt> indicates that JMX should be activated. The property <tt>com.sun.management.jmxremote.port</tt> indicates that remote access is allowed and it should occur on the given port (in the example 8999). The next two properties, <tt>com.sun.management.jmxremote.ssl=false</tt> and <tt>com.sun.management.jmxremote.authenticate=false</tt> disable SSL and authentication respectively. The final property <tt>java.rmi.server.hostname</tt> indicates the name of the host on which tomcat is running (<em>NOTE:  The JMX documentation did not say this was required but I found that  attempting remote access returned &#8216;Connection failed&#8217; when this property  was not set</em>). After setting CATALINA_OPTS you need to restart Tomcat:</p>
<div>
<div>
<p>$ CATALINA_HOME/bin/shutdown.sh<br />
$ CATALINA_HOME/bin/startup.sh</p>
</div>
</div>
<p>After the restart JMX is running and you may test it by following the instructions in the section titled <a href="https://wiki.internet2.edu/confluence/display/CPD/Monitoring+Tomcat+with+JMX#MonitoringTomcatwithJMX-jconsole">Using JConsole to Monitor Tomcat</a>.</p>
<h2><a name="MonitoringTomcatwithJMX-EnablingJMXwithPasswordAuthentication"></a>Enabling JMX with Password Authentication</h2>
<p>You should enable some type of authentication if you are going to run  JMX on Tomcat in a non-testing environment. Simple password  authentication is probably the easiest to setup. You may want to setup  client SSL authentication instead but instructions for that are left to  the Sun documentation. The first thing you need to do is create a  password file with the user accounts that can access the monitoring  information. I created a file called <strong>$CATALINA_HOME/conf/jmxremote.password</strong> but it can be located anywhere on the filesystem. The file takes the  form of a username and a password separated by a space on each line. An  example is below:</p>
<div>
<div>
<p>user passwd<br />
admin password</p>
</div>
</div>
<p>The file above create two users, oscars and admin. The  &#8220;oscars&#8221; account has a password &#8220;oscars&#8221; and the admin account has the  password &#8220;password&#8221;. The next step is to assign permissions to each  account. This is done in another text file that I named <strong>$CATALINA_HOME/conf/jmxremote.access</strong>. An example of that file is below:</p>
<div>
<div>
<p>user readonly<br />
admin readwrite</p>
</div>
</div>
<p>See the <a rel="nofollow" href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html">Sun documentation</a> for more information on what the readonly and readwrite permissions  means. After creating these two file you need to set the file  permissions such that only the owner can read them. An example of the  commands to do this are as follows:</p>
<div>
<div>
<p>$ chmod 600 $CATALINA_HOME/conf/jmxremote.password<br />
$ chmod 600 $CATALINA_HOME/conf/jmxremote.access</p>
</div>
</div>
<p>The final step is to add properties to CATALINA_OPTS that  initialize JMX and point to the given files. An example of the commands  needed to do this are as follows:</p>
<div><strong>For Windows:</strong></p>
<pre class="brush:java">
.
set CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access";
.</pre>
<p><strong>For Linux:</strong></p>
<pre class="brush:java">
.
$ CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access";
$ export CATALINA_OPTS;
.</pre>
</div>
<p>The values in bold should be set to values appropriate for your system. The property <tt>com.sun.management.jmxremote</tt> indicates that JMX should be activated. The property <tt>com.sun.management.jmxremote.port</tt> indicates that remote access is allowed and it should occur on the given port (in the example 8999). The next two properties, <tt>com.sun.management.jmxremote.ssl=false</tt> and <tt>com.sun.management.jmxremote.authenticate=false</tt> disable SSL and enable authentication respectively. The next property <tt>java.rmi.server.hostname</tt> indicates the name of the host on which tomcat is running (<em>NOTE:  The JMX documentation did not say this was required but I found that  attempting remote access returned &#8216;Connection failed&#8217; when this property  was not set</em>). The last two parameters, <tt>com.sun.management.jmxremote.password.file</tt> and <tt>com.sun.management.jmxremote.password.access</tt>,  point to your password and access files, respectively. After setting  CATALINA_OPTS restart Tomcat and you are ready to test JMX. See the  section <a href="https://wiki.internet2.edu/confluence/display/CPD/Monitoring+Tomcat+with+JMX#MonitoringTomcatwithJMX-jconsole">Using JConsole to Monitor Tomcat</a> for information on how to test.</p>
<p><a name="MonitoringTomcatwithJMX-jconsole"></a></p>
<h1><a name="MonitoringTomcatwithJMX-UsingJConsoletoMonitorTomcat"></a>Using JConsole to Monitor Tomcat</h1>
<p>JConsole is a GUI application designed for monitoring Java  applications. It acts as a client to the JMX interface and can monitory  statistics locally or remotely. JConsole comes preinstalled on many  systems that have Java (i.e. Mac OS X). If you don&#8217;t have it then you  can get it from the latest JDK download <a rel="nofollow" href="http://java.sun.com/javase/downloads/index.jsp">here</a>. Basic instructions for running JConsole are below:</p>
<p><strong>1.</strong> Open a command-line window (on Mac OS X go to /Applications/Utilities/Terminal).</p>
<p><strong>2.</strong> Enter the command <tt>jconsole</tt></p>
<table border="0" cellspacing="0" cellpadding="5" width="100%">
<tbody>
<tr>
<td width="70%" valign="top"><strong>3.</strong> A window  will load. What the window displays will depend on whether you are  running jconsole on the same machine as you are running Tomcat. If you  are running it on the same machine as Tomcat you should see an option to  select the Tomcat server in the local tab and should <strong>proceed to step 4a</strong>.  If this is the case your window will look similar to the following:</td>
<td width="30%" valign="top"><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/1-jc-local-login.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/1-jc-local-login.jpg" alt="" /></a></td>
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="5" width="100%">
<tbody>
<tr>
<td width="70%" valign="top">If you are running Tomcat on a remote machine then you will see a blank box and should <strong>proceed to step 4b</strong>. If this is the case your window will look similar to the following:</td>
<td width="30%" valign="top"><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/1-jc-login.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/1-jc-login.jpg" alt="" /></a></td>
</tr>
</tbody>
</table>
<p><strong>4a.</strong> You should be at this step if you want to connect to a  Tomcat server running on the same machine as jconsole. To connect to the  server select the item listed and click &#8220;Connect&#8221;.</p>
<table border="0" cellspacing="0" cellpadding="5" width="100%">
<tbody>
<tr>
<td width="70%" valign="top"><strong>4b.</strong> You should be at this step if Tomcat is running on a machine remote from jconsole. Click on the <em>Remote</em> tab. Enter the hostname to which you&#8217;d like to connct and the port on  which JMX is listening (these were both specified when configuring  Tomcat to use JMX with the <tt>java.rmi.server.hostname</tt> and <tt>com.sun.management.jmxremote.port</tt> properties). If authentication is enabled for JMX enter a username and  password, otherwise leave those fields blank. When the fields are  filled-in click &#8220;Connect&#8221;.</td>
<td width="30%" valign="top"><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/2-jc-remote-login.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/2-jc-remote-login.jpg" alt="" /></a></td>
</tr>
</tbody>
</table>
<p><strong>5.</strong> You should connect to the server and see some summary  statistics. Navigate the tabs to view the set of information offered.  Some screenshots are shown below:</p>
<div>
<div>
<table>
<tbody>
<tr>
<td><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/3-summary.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/3-summary.jpg" alt="" /></a></td>
<td><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/3-memory.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/3-memory.jpg" alt="" /></a></td>
<td><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/3-threads.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/3-threads.jpg" alt="" /></a></td>
</tr>
<tr>
<td><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/3-classes.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/3-classes.jpg" alt="" /></a></td>
<td><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/3-mbeans.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/3-mbeans.jpg" alt="" /></a></td>
<td><a href="https://wiki.internet2.edu/confluence/download/attachments/23025/3-vm.jpg"><img src="https://wiki.internet2.edu/confluence/download/thumbnails/23025/3-vm.jpg" alt="" /></a></td>
</tr>
</tbody>
</table>
</div>
</div>
<p>Original post from: <a href="https://wiki.internet2.edu/confluence/display/CPD/Monitoring+Tomcat+with+JMX" target="_blank">https://wiki.internet2.edu/confluence/display/CPD/Monitoring+Tomcat+with+JMX</a></p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/07/15/monitoring-tomcat-7-with-jmc/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/07/15/monitoring-tomcat-7-with-jmc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Socket creation problem with Java on Linux</title>
		<link>http://www.i-net-design.com/2011/07/04/socket-creation-problem-with-java-on-linux/</link>
		<comments>http://www.i-net-design.com/2011/07/04/socket-creation-problem-with-java-on-linux/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 07:06:38 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Socket]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=104</guid>
		<description><![CDATA[Sometimes a problem occurs while trying to open a socket connection with Java on a Linux system. Mostly this is a problem with server settings. It happens if you&#8217;ve enables IPv4 and IPv6 on the system. To make shure Java uses only IPv4 every time a connection is created, just put a new entry in [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes a problem occurs while trying to open a socket connection with Java on a Linux system.<br />
Mostly this is a problem with server settings. It happens if you&#8217;ve enables IPv4 and IPv6 on the system.</p>
<p>To make shure Java uses only IPv4 every time a connection is created, just put a new entry in your JAVA_OPTS.</p>
<pre class='brush:java'>
export JAVA_OPTS=$JAVA_OPTS;-Djava.net.preferIPv4Stack=true
</pre>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/07/04/socket-creation-problem-with-java-on-linux/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/07/04/socket-creation-problem-with-java-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using classes from external jars in GWT project</title>
		<link>http://www.i-net-design.com/2011/04/27/using-classes-from-external-jars-in-gwt-project/</link>
		<comments>http://www.i-net-design.com/2011/04/27/using-classes-from-external-jars-in-gwt-project/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 10:03:34 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[External class]]></category>
		<category><![CDATA[JAR]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=83</guid>
		<description><![CDATA[For an introduction in GWT please see GWT tutorial. The following describes how to use external jars or Java projects within your GWT project. The standard approach in Java is to have separated projects for separate purposes. For example the domain model of the application is usually defined in its own project. One way of making these [...]]]></description>
			<content:encoded><![CDATA[<p>For an introduction in <a href="http://www.vogella.de/articles/GWT/article.html" target="_top">GWT</a> please see <a href="http://www.vogella.de/articles/GWT/article.html" target="_top">GWT tutorial</a>. The following describes how to use external jars or Java projects within your GWT project.</p>
<p>The standard approach in Java is to have separated projects for separate purposes. For example the domain model of the application is usually defined in its own project. One way of making these classes available to GWT is to copy them into the package &#8220;client&#8221; in your GWT project. This is bad practice as it leads to code duplication (which is inherently evil). This chapter describes how you can make these projects available to the GWT compiler as modules.</p>
<p>GWT need to have access to the source files to compile them into Javascript code. If you add the project or the jar file to your GWT classpath then the Java compiler will not complain if you use the classes from the included project / jar but the GWT compiler will not be able to compile them.</p>
<p>To make the Java files available to the GWT compiler you need to</p>
<ul type="disc">
<li>Create a gwt.xml file in the Java project / jar file which you want to use &#8211; This will instruct the GWT compiler to use the listed classes.</li>
<li>Use the included library via the inherit definition</li>
<li>If you are using a jar file you also need to include the source files in the jar</li>
</ul>
<p>Here&#8217;s a short example *.gwt.xml file:</p>
<pre class="brush:java"><module>
  <inherits name='com.google.gwt.user.User'/>
  <source path="model"></source>
</module></pre>
<p>To make the classes available for GWT use the inherti tag in your *.gwt.xml file:</p>
<pre class='brush:java'><inherits name='com.your.company.moduleName'/></pre>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/04/27/using-classes-from-external-jars-in-gwt-project/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/04/27/using-classes-from-external-jars-in-gwt-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Persist detached entity</title>
		<link>http://www.i-net-design.com/2011/03/03/persist-detached-entity/</link>
		<comments>http://www.i-net-design.com/2011/03/03/persist-detached-entity/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 14:45:25 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[entity]]></category>
		<category><![CDATA[persist]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=75</guid>
		<description><![CDATA[Sometimes you have to store an object in a database. I run into the problem that I got this error: org.hibernate.PersistentObjectException: detached entity passed to persist It&#8217;s realy easy to solve this problem, just ensure to create the object to be saved after beginning the transaction. In my case I just created a constructor like [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you have to store an object in a database. I run into the problem that I got this error:</p>
<p>org.hibernate.PersistentObjectException: detached entity passed to persist</p>
<p>It&#8217;s realy easy to solve this problem, just ensure to create the object to be saved after beginning the transaction.<br />
In my case I just created a constructor like this one:</p>
<pre class="brush:java">
public MyBean(MyBean entity){
setProp1(entity.getProp1);
setPop2(......
}</pre>
<p>Then I created a new Onject to be saved just before the create statement to persist the object.</p>
<pre class="brush:java">
MyBean myBean = new MyBean(entity);
myDao.create(myBean);
</pre>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/03/03/persist-detached-entity/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/03/03/persist-detached-entity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problem including dispatcher servlet with spring security</title>
		<link>http://www.i-net-design.com/2011/02/18/problem-including-dispatcher-servlet-with-spring-security/</link>
		<comments>http://www.i-net-design.com/2011/02/18/problem-including-dispatcher-servlet-with-spring-security/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 11:56:40 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Security]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=59</guid>
		<description><![CDATA[First of all here&#8217;s my way to integrate the dispatcher servlet: 1. Create a controller class to handle the RCP requests: public class GWTController extends RemoteServiceServlet implements Controller, ServletContextAware { /** The Constant serialVersionUID. */ private static final long serialVersionUID = -6044751640456464234L; // Instance fields /** The remote service. */ private RemoteService remoteService; /** The [...]]]></description>
			<content:encoded><![CDATA[<p>First of all here&#8217;s my way to integrate the dispatcher servlet:</p>
<p>1. Create a controller class to handle the RCP requests:<br />
<span id="more-59"></span></p>
<pre class="brush:java">

public class GWTController extends RemoteServiceServlet implements Controller, ServletContextAware {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = -6044751640456464234L;
    // Instance fields
    /** The remote service. */
    private RemoteService remoteService;

    /** The remote service class. */
    private Class<!--? extends RemoteService--> remoteServiceClass;

    /** The servlet context. */
    private transient ServletContext servletContext;

    // Public methods
    /**
     * Call GWT's RemoteService doPost() method and return null.
     *
     * @param request
     *            The current HTTP request
     * @param response
     *            The current HTTP response
     * @return A ModelAndView to render, or null if handled directly
     * @throws Exception
     *             In case of errors
     */
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        doPost(request, response);
        return null; // response handled by GWT RPC over XmlHttpRequest
    }

    /**
     * Process the RPC request encoded into the payload string and return a string that encodes either the method return
     * or an exception thrown by it.
     *
     * @param payload
     *            The RPC payload
     * @return the string
     * @throws SerializationException
     *             the serialization exception
     */
    @Override
    public String processCall(String payload) throws SerializationException {
        try {
            if (remoteService instanceof DependencyInjectionRemoteServiceServlet) {
                try {
                    DependencyInjectionRemoteServiceServlet d = (DependencyInjectionRemoteServiceServlet) remoteService;
                    d.setServletContext(getServletContext());
                    d.init();
                } catch (ServletException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass);

            // delegate work to the spring injected service
            return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters());
        } catch (IncompatibleRemoteServiceException e) {
            return RPC.encodeResponseForFailure(null, e);
        }
    }

    /**
     * Setter for Spring injection of the GWT RemoteService object.
     *
     * @param remoteService
     *            the new remote service
     */
    public void setRemoteService(RemoteService remoteService) {
        this.remoteService = remoteService;
        this.remoteServiceClass = this.remoteService.getClass();
    }

    @Override
    public ServletContext getServletContext() {
        return servletContext;
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }
}
</pre>
<p>This class includes the remoteServlet as property which is injected by Springs property injection.<br />
Property injection is used because there are much services available which are handles by the<br />
controller class and the used service has to be injected.</p>
<p>In this class I set the ServletContext and call the init method of DependencyInjectionRemoteServiceServlet.<br />
I do this to handle the problems I described above.</p>
<p>2. Change the web.xml to use the dispatcher servlet instead of the documentServlet:</p>
<pre class="brush:java">
		dispatcher
		org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:spring/dispatcher-servlet.xml

		1

		dispatcher
		/gwtspring/documentService</pre>
<p>3. This is the dispatcher-servlet.xml file:</p>
<pre class="brush:java">

	<!-- == SPRING DISPATCH HANDLER == -->

				/gwtspring/documentService=documentGWTService</pre>
<p>4. Include a message property in the ServiceSecurityException and create a custumFildSerializer for the<br />
ServiceSecurityException to handle the serialisation of the message.</p>
<p>ServiceSecurityException.java:</p>
<pre class="brush:java">@SuppressWarnings("serial")
public class ServiceSecurityException extends Exception {

    private String message;

    /**
     * @return the message
     */
    @Override
    public String getMessage() {
        return message;
    }

    /**
     * @param message
     *            the message to set
     */
    public void setMessage(String message) {
        this.message = message;
    }

}</pre>
<p>ServiceSecurityException_CustomFieldSerializer.java:</p>
<pre class="brush:java">public final class ServiceSecurityException_CustomFieldSerializer {

    /**
     * Instantiates a new object name dto_ custom field serializer.
     */
    private ServiceSecurityException_CustomFieldSerializer() {

    }

    /**
     * Initiate.
     *
     * @param reader
     *            the reader
     * @return the object name dto
     * @throws SerializationException
     *             the serialization exception
     */
    public static ServiceSecurityException initiate(SerializationStreamReader reader) throws SerializationException {

        return new ServiceSecurityException();

    }

    /**
     * Serialize.
     *
     * @param writer
     *            the writer
     * @param instance
     *            the instance
     * @throws SerializationException
     *             the serialization exception
     */
    public static void serialize(SerializationStreamWriter writer, ServiceSecurityException instance)
            throws SerializationException {
        if (instance == null) {
            throw new NullPointerException("ServiceSecurityException object is null");
        } else {
            writer.writeString(instance.getMessage());
        }
    }

    /**
     * Deserialize.
     *
     * @param reader
     *            the reader
     * @param instance
     *            the instance
     * @throws SerializationException
     *             the serialization exception
     */
    public static void deserialize(SerializationStreamReader reader, ServiceSecurityException instance)
            throws SerializationException {
        instance.setMessage(reader.readString());
    }
}</pre>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/02/18/problem-including-dispatcher-servlet-with-spring-security/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/02/18/problem-including-dispatcher-servlet-with-spring-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perform release with Maven</title>
		<link>http://www.i-net-design.com/2011/02/17/perform-release-with-maven/</link>
		<comments>http://www.i-net-design.com/2011/02/17/perform-release-with-maven/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 12:36:40 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=50</guid>
		<description><![CDATA[1. Remove Snapshot dependencies in pom.xml files 2. Change version numbers of dependencies if necessary 3. Build artifakts: mvn clean install 4. Change actionscriptProperties and remove Snaphot dependencies too 5. Check if all dependencies are set correctly: mvn release:prepare -DdryRun=true -DautoVersionSubmodules=true -DtagBase=***SVN repository URL*** Attention: Check for right folder, the release has to put in [...]]]></description>
			<content:encoded><![CDATA[<p>1. Remove Snapshot dependencies in pom.xml files<br />
2. Change version numbers of dependencies if necessary<br />
<span id="more-50"></span><br />
3. Build artifakts:</p>
<pre class="brush:java">
mvn clean install
</pre>
<p>4. Change actionscriptProperties and remove Snaphot dependencies too<br />
5. Check if all dependencies are set correctly:</p>
<pre class="brush:java">
mvn release:prepare -DdryRun=true -DautoVersionSubmodules=true -DtagBase=***SVN repository URL***
</pre>
<p><strong>Attention:</strong> Check for right folder, the release has to put in the <strong>tags</strong> folder!<br />
If errors occurs, run clean install again<br />
6. Reset automatic changes on pom.xml files:</p>
<pre class="brush:java">
mvn release:clean
</pre>
<p>7. Prepare release:</p>
<pre class="brush:java">
mvn release:prepare -DautoVersionSubmodules=true -DtagBase=***SVN repository URL***
</pre>
<p><strong>Attention:</strong> Check for right folder, the release has to put in the <strong>tags</strong> folder!<br />
8. Perform release:</p>
<pre class="brush:java">
mvn release:perform
</pre>
<p><strong>If deployment fails, check out from svn and build locally:</strong></p>
<pre class="brush:java">
mvn clean install
mvn clean deploy
</pre>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/02/17/perform-release-with-maven/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/02/17/perform-release-with-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven options</title>
		<link>http://www.i-net-design.com/2011/02/17/maven-options/</link>
		<comments>http://www.i-net-design.com/2011/02/17/maven-options/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 12:31:44 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[options]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=48</guid>
		<description><![CDATA[-C,&#8211;strict-checksums Fail the build if checksums don&#8217;t match -c,&#8211;lax-checksums Warn if checksums don&#8217;t match -P,&#8211;activate-profiles Comma-delimited list of profiles to activate -ff,&#8211;fail-fast Stop at first failure in reactorized builds -fae,&#8211;fail-at-end Only fail the build afterwards; allow all non-impacted builds to continue -B,&#8211;batch-mode Run in non-interactive (batch) mode -fn,&#8211;fail-never NEVER fail the build, regardless of project [...]]]></description>
			<content:encoded><![CDATA[<p>-C,&#8211;strict-checksums         Fail the build if checksums don&#8217;t match<br />
-c,&#8211;lax-checksums            Warn if checksums don&#8217;t match<br />
-P,&#8211;activate-profiles        Comma-delimited list of profiles to activate<br />
<span id="more-48"></span><br />
-ff,&#8211;fail-fast               Stop at first failure in reactorized builds<br />
-fae,&#8211;fail-at-end            Only fail the build afterwards; allow all non-impacted builds to continue<br />
-B,&#8211;batch-mode               Run in non-interactive (batch) mode<br />
-fn,&#8211;fail-never              NEVER fail the build, regardless of project result<br />
-up,&#8211;update-plugins          Synonym for cpu<br />
-N,&#8211;non-recursive            Do not recurse into sub-projects<br />
-npr,&#8211;no-plugin-registry     Don&#8217;t use ~/.m2/plugin-registry.xml for plugin versions<br />
-U,&#8211;update-snapshots         Update all snapshots regardless of repository policies<br />
-cpu,&#8211;check-plugin-updates   Force upToDate check for any relevant registered plugins<br />
-npu,&#8211;no-plugin-updates      Suppress upToDate check for any relevant registered plugins<br />
-D,&#8211;define                   Define a system property<br />
-X,&#8211;debug                    Produce execution debug output<br />
-e,&#8211;errors                   Produce execution error messages<br />
-f,&#8211;file                     Force the use of an alternate POM file.<br />
-h,&#8211;help                     Display help information<br />
-o,&#8211;offline                  Work offline<br />
-r,&#8211;reactor                  Execute goals for project found in the reactor<br />
-s,&#8211;settings                 Alternate path for the user settings file<br />
-v,&#8211;version                  Display version information,&#8211;version </p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/02/17/maven-options/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/02/17/maven-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Branch with Maven</title>
		<link>http://www.i-net-design.com/2011/02/17/create-branch-with-maven/</link>
		<comments>http://www.i-net-design.com/2011/02/17/create-branch-with-maven/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 12:30:46 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[create branch]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=46</guid>
		<description><![CDATA[Creating a branch involves the following release phases: Check that there are no uncommitted changes in the sources Change the version in the POMs if you want to change it in the branch (you will be prompted for the versions to use) Transform the SCM information in the POM to include the final destination of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Creating a branch involves the following release phases:</strong><br />
Check that there are no uncommitted changes in the sources Change the version in the POMs if you want to change it in the branch (you will be prompted for the versions to use) <span id="more-46"></span>Transform the SCM information in the POM to include the final destination of the tag Commit the modified POMs Tag the code in the SCM as a new branch with a version name (this will be prompted for) Bump the version in the POMs if you want to change it to a new value y-SNAPSHOT (these values will also be prompted for) Commit the modified POMs To create a branch execute this command:</p>
<pre class="brush:java">
mvn release:branch -DbranchName=my-branch
</pre>
<p>By default, the POM in the new branch keeps the same version as the local working copy, and the local POM is incremented to the next revision. If you want to update versions in the new branch and not in the working copy, run:</p>
<pre class="brush:java">
mvn release:branch -DbranchName=my-branch -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false
</pre>
<p>Note: This can be useful if you want to create a branch from a tag</p>
<p><strong>Specify versions on the command line</strong><br />
You may want to specify the versions to use on the command line. This can be useful for example if you are running the release in non-interactive mode. The branch goal can use the same properties used by the prepare goal for specifying the versions to be used.</p>
<pre class="brush:java">
mvn --batch-mode release:branch -DbranchName=my-branch-1.2 -Dproject.rel.org.myCompany:projectA=1.2 \
     -Dproject.dev.org.myCompany:projectA=2.0-SNAPSHOT
</pre>
<p>In this example, the POM in the new branch will be set to the version 1.2-SNAPSHOT, and the local POM will be set to the version 2.0-SNAPSHOT.</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/02/17/create-branch-with-maven/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/02/17/create-branch-with-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create database scripts with maven profile</title>
		<link>http://www.i-net-design.com/2011/02/17/create-database-scripts-with-maven-profile/</link>
		<comments>http://www.i-net-design.com/2011/02/17/create-database-scripts-with-maven-profile/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 12:28:08 +0000</pubDate>
		<dc:creator>StephanBeutel</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[create database scripts]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.i-net-design.com/?p=44</guid>
		<description><![CDATA[If you want to create the database scripts automatically, this can be easily done with a maven profile. The profile has to look like this: hsqldb test.dbms hsql org.codehaus.mojo hibernate3-maven-plugin 2.1 hbm2ddl jpaconfiguration mypu ${basedir}/src/test/resources/META-INF/database/hsql.properties ${basedir}/src/test/resources/META-INF/database/datasets.hbm.xml ${project.artifactId}-${project.version}_HSQL_CREATE.sql true false false hsqldb hsqldb 1.8.0.10 test maven-surefire-plugin my.test.dbms hsqlMemory hsqldb hsqldb 1.8.0.10 test Here&#8217;s an example for [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to create the database scripts automatically, this can be easily done with a maven profile.<br />
<span id="more-44"></span><br />
The profile has to look like this:</p>
<pre class="brush:java">
<profile>
	<id>hsqldb</id>
	<activation>
<property>
			<name>test.dbms</name>
			<value>hsql</value>
		</property>
	</activation>
	<build>
<plugins>
<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>hibernate3-maven-plugin</artifactId>
				<version>2.1</version>
				<configuration>
					<components>
						<component>
							<name>hbm2ddl</name>
							<implementation>jpaconfiguration</implementation>
						</component>
					</components>
					<componentProperties>
<persistenceunit>mypu</persistenceunit>
<propertyfile>${basedir}/src/test/resources/META-INF/database/hsql.properties
						</propertyfile>
						<configurationfile>${basedir}/src/test/resources/META-INF/database/datasets.hbm.xml
						</configurationfile>
						<outputfilename>${project.artifactId}-${project.version}_HSQL_CREATE.sql
						</outputfilename>
						<create>true</create>
						<drop>false</drop>
						<export>false</export>
					</componentProperties>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>hsqldb</groupId>
						<artifactId>hsqldb</artifactId>
						<version>1.8.0.10</version>
						<scope>test</scope>
					</dependency>
				</dependencies>
			</plugin>
			<!-- Test Execution Configuration -->
<plugin>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<systemProperties>
<property>
							<name>my.test.dbms</name>
							<value>hsqlMemory</value>
						</property>
					</systemProperties>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>hsqldb</groupId>
			<artifactId>hsqldb</artifactId>
			<version>1.8.0.10</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
</profile>
</pre>
<p>Here&#8217;s an example for the properties file for the database connection:</p>
<pre class="brush:java">
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:hsql://localhost:9112/my
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.dialect=org.hibernate.dialect.HSQLDialect

dbunit.datatypeFactory=org.dbunit.ext.hsqldb.HsqldbDataTypeFactory
project.ddlDirectory=my_db_dictionary/hsql
</pre>
<p>Here&#8217;s the file to declare the mapping files to create the statements from:</p>
<pre class="brush:java">
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

	<!-- a SessionFactory instance listed as /jndi/name -->
	<session-factory name="java:hibernate/SessionFactory">

		<!-- mapping files -->
<mapping resource="META-INF/hibernate/Class1.hbm.xml" />
<mapping resource="META-INF/hibernate/Class2.hbm.xml" />

		<!-- Enter all mapping files in that way -->

	</session-factory>

</hibernate-configuration>
</pre>
<p>In the maven profile you have to use &#8220;jpaconfiguration&#8221;, if you use &#8220;configuration&#8221; no sql file is created and you have to copy the sql commands from the command line and create a file by yourself.</p>
<div class="al2fb_like_button"><div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=214448445260922&amp;xfbml=1" type="text/javascript"></script><fb:like href="http://www.i-net-design.com/2011/02/17/create-database-scripts-with-maven-profile/" send="true" layout="standard" show_faces="false" width="450" action="like" font="arial" colorscheme="light" ref="AL2FB"></fb:like></div>]]></content:encoded>
			<wfw:commentRss>http://www.i-net-design.com/2011/02/17/create-database-scripts-with-maven-profile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

