<?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>Len &#187; java</title>
	<atom:link href="http://www.len.ro/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.len.ro</link>
	<description>Len&#039;s personal site: work, cooking, cycling, experiences</description>
	<lastBuildDate>Mon, 26 Jul 2010 20:24:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Tomcat query parameters and encodings</title>
		<link>http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/</link>
		<comments>http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 08:26:42 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=4808</guid>
		<description><![CDATA[Did you ever wondered which from which encoding the query parameters are parsed by default in java (servlet) and the response in rendered? Say UTF-8. Wrong. Try ISO-8859-1. There are 3 cases to consider: 1. Query parameters as GET 2. Query parameters as POST 3. Response encoding. In order to solve 1 and 2 one [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/12/jboss-and-ldap/' rel='bookmark' title='Permanent Link: JBoss and LDAP'>JBoss and LDAP</a> <small>Target: create a test environment for JBoss JAAS authentication using...</small></li>
<li><a href='http://www.len.ro/2009/11/changing-dates-in-thunderbird/' rel='bookmark' title='Permanent Link: Changing dates format in Thunderbird'>Changing dates format in Thunderbird</a> <small>Since my migration to thunderbird I did not had many...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Did you ever wondered which from which encoding the query parameters are parsed by default in java (servlet) and the response in rendered? Say UTF-8. Wrong. Try ISO-8859-1. There are 3 cases to consider:</p>
<p>1. Query parameters as GET</p>
<p>2. Query parameters as POST</p>
<p>3. Response encoding.<span id="more-4808"></span></p>
<p>In order to solve 1 and 2 one solution is just to convert the parameters to UTF-8:</p>
<pre>String param = request.getParameter("test");
if(param != null)
    param = new String(param.getBytes("8859_1"),"UTF8");</pre>
<p>This is not a solution if you need to change in a lot of places.</p>
<p>You can fix this if using tomcat by setting the URIEncoding=&#8221;UTF-8&#8243; in the connector definition in server.xml (jboss location: ./deploy/jboss-web.deployer/server.xml)</p>
<pre>&lt;Connector port="8080" address="${jboss.bind.address}"    
 maxThreads="250" maxHttpHeaderSize="8192"
 emptySessionPath="true" protocol="HTTP/1.1"
 enableLookups="false" redirectPort="8443" acceptCount="100"
 connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/&gt;</pre>
<p>It will only fix the problem for GET query parameters. For POST a more complicated solution has to be done which involves writing a servlet filter. There is an example which can be found with tomcat examples. Just search for: SetCharacterEncodingFilter.java and the corresponding configuration in web.xml. This filter will set the request characterEncoding to the value provided as parameter.</p>
<p>The third case implies just setting the response encoding to UTF-8. It can be done as such:</p>
<pre>public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
...
 response.setCharacterEncoding("UTF8");
 PrintWriter out = response.getWriter();
 //response.setCharacterEncoding("UTF8"); seetting the encoding here has no effect
... write things to out
</pre>
<p>Note: the character encoding must be set <em>before</em> getting the writer otherwise it will not work.</p>
<p>Another idea is to modify the SetCharacterEncodingFilter.java to set the response encoding as well.</p>
<pre>public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

 // Conditionally select and set the character encoding to be used
 if (ignore || (request.getCharacterEncoding() == null)) {
 String encoding = selectEncoding(request);
 if (encoding != null){
 request.setCharacterEncoding(encoding);
 }
 }
 <em>response.setCharacterEncoding(encoding);</em>
 // Pass control on to the next filter
 chain.doFilter(request, response);
 }
</pre>
<p>Tested with Tomcat 5 as bundled with Jboss 4.2.2-GA.</p>
<h2>Addendum</h2>
<p>If as in my case the params ended eventually in an oracle database via hibernate the funny thing was that the query param (interpreted as iso-8859-1) was converted to utf-8 via jdbc conversion and stored into a nvarchar2 column. How to fix the database content? The following sql might come in handy:</p>
<pre>update my_table set value = to_nchar(convert(to_char(value), 'WE8ISO8859P1', 'UTF8'));
</pre>
<p>As always with encoding problems, good luck, you will need it.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/12/jboss-and-ldap/' rel='bookmark' title='Permanent Link: JBoss and LDAP'>JBoss and LDAP</a> <small>Target: create a test environment for JBoss JAAS authentication using...</small></li>
<li><a href='http://www.len.ro/2009/11/changing-dates-in-thunderbird/' rel='bookmark' title='Permanent Link: Changing dates format in Thunderbird'>Changing dates format in Thunderbird</a> <small>Since my migration to thunderbird I did not had many...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JBoss migration 4.2.2-GA to 5.1.0-GA</title>
		<link>http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/</link>
		<comments>http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 10:19:15 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[tinker]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=4695</guid>
		<description><![CDATA[In my stupidity innocence I just hoped that deploying the application on the new JBoss (from 4.2.2-GA to 5.1.0-GA) should be just a simple matter of changing paths in ant. Here are some problems I encountered and was able to fix. application.xml The format of this file has changed from: &#60;?xml version="1.0" encoding="UTF-8"?&#62; &#60;application xmlns="http://java.sun.com/xml/ns/j2ee" [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/12/jboss-and-ldap/' rel='bookmark' title='Permanent Link: JBoss and LDAP'>JBoss and LDAP</a> <small>Target: create a test environment for JBoss JAAS authentication using...</small></li>
<li><a href='http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/' rel='bookmark' title='Permanent Link: Tomcat query parameters and encodings'>Tomcat query parameters and encodings</a> <small>Did you ever wondered which from which encoding the query...</small></li>
<li><a href='http://www.len.ro/2009/10/evolution-to-thunderbird-migration/' rel='bookmark' title='Permanent Link: Evolution to Thunderbird migration'>Evolution to Thunderbird migration</a> <small>I have been using Evolution since more than 7 years...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In my <span style="text-decoration: line-through;">stupidity</span> innocence I just hoped that deploying the application on the new JBoss (from 4.2.2-GA to 5.1.0-GA) should be just a simple matter of changing paths in ant. Here are some problems I encountered and was able to fix.<span id="more-4695"></span></p>
<h2>application.xml</h2>
<p>The format of this file has changed from:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"&gt;
 &lt;display-name&gt;My application&lt;/display-name&gt;
 &lt;description&gt;My server interface&lt;/description&gt;
...
</pre>
<p>to</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;application xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"
 version="5"&gt;
 &lt;display-name&gt;My application&lt;/display-name&gt;
</pre>
<p>The description field is now no longer required and schema has changed. A minor change in itself but as you will see further there are a lot of minor changes of this type.</p>
<h2>Unified classloader</h2>
<p>In JBoss 4 in order to unify tomcat and jboss classloaders one had to change</p>
<pre>&lt;attribute name="UseJBossWebLoader"&gt;true&lt;/attribute&gt;</pre>
<p>in <strong>jboss/server/default/deploy/jboss-web.deployer/META-INF/jboss-service.xml</strong> . It is no longer the case in JBoss 5, instead the following has to be commented:</p>
<pre>&lt;!-- Allow for war local class loaders: in testing --&gt;
 &lt;!--
 &lt;bean name="WarClassLoaderDeployer"&gt;
 &lt;property name="relativeOrder"&gt;-1&lt;/property&gt;
 &lt;property name="filteredPackages"&gt;javax.servlet,org.apache.commons.logging&lt;/property&gt;      
 &lt;/bean&gt;
 --&gt;
</pre>
<p>in <strong>jboss-5.1.0.GA/server/default/deployers/jbossweb.deployer/META-INF/war-deployers-jboss-beans.xml</strong>.</p>
<h2>Hibernate har&#8217;s</h2>
<p>This is by far one of the change I found stupid. The hibernate-service.xml is now named service-hibernate.xml and it&#8217;s content has changed using the following rules:</p>
<ul>
<li>attribute elements are now called property</li>
<li>the name attribute was starting with an uppercase and now it&#8217;s lowercase</li>
</ul>
<p>Example before:</p>
<pre>&lt;server&gt;
 &lt;mbean code="org.jboss.hibernate.jmx.Hibernate" name="com.mccsoft:name=MyOracleSessionFactory"&gt;
 &lt;attribute name="DatasourceName"&gt;java:/DiapasonOracleDS&lt;/attribute&gt;
 &lt;attribute name="Dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/attribute&gt;
</pre>
<p>and after:</p>
<pre>&lt;hibernate-configuration xmlns="urn:jboss:hibernate-deployer:1.0"&gt;
 &lt;session-factory name="java:/hibernate/MyOracleSessionFactory"
 bean="jboss.test.har:service=Hibernate,testcase=TimersUnitTestCase"&gt;
 &lt;property name="datasourceName"&gt;java:/DiapasonOracleDS&lt;/property&gt;
 &lt;property name="dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt;
</pre>
<h2>TreeCache</h2>
<p>Also jbossCache configuration has changed from:</p>
<pre>&lt;attribute name="CacheProviderClass"&gt;org.hibernate.cache.TreeCacheProvider&lt;/attribute&gt;</pre>
<p>to:</p>
<pre>&lt;property name="cacheRegionFactoryClass"&gt;org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory&lt;/property&gt;
</pre>
<p>I am not quite sure yet how the cache parameters have changed, still searching for more documentation.</p>
<h2>ActiveMQ</h2>
<p>Since the application was using activemq a strange error occured when deploying:</p>
<pre>Specification violation [EJB3 JPA 6.2.1.2] activemq</pre>
<p>Actually it seems this is related to the format of the persistence.xml file which is unfortunately bundled in the activemq jar. I was simple however to upgrade from 5.2.0 to 5.3.0 which solved the problem.</p>
<h2>Ear service dependency</h2>
<p>One of the problems which causes the most head bumping was related to the ear service dependency. In short a service was depending on the deployment of an ear using the following syntax:</p>
<p>&lt;depends&gt;jboss.j2ee:service=EARDeployment,url=&#8217;my.ear&#8217;&lt;/depends&gt;</p>
<p>The EARDeployment does not exist in JBoss 5 and I could not find it&#8217;s proper replacement. After some trial and error I switched the dependency on a war inside the ear using the following syntax:</p>
<pre>&lt;depends&gt;jboss.web.deployment:war=/my&lt;/depends&gt;</pre>
<p>as an alternative a service provided by the ear could be used:</p>
<pre>&lt;depends&gt;com.len.queue:service=Listener&lt;/depends&gt;</pre>
<p>In all I lost a bunch of time which could have been better spend otherwise. Here are some links which helped:</p>
<ul>
<li><a href="http://community.jboss.org/wiki/useJBossWebClassLoaderinJBoss5">http://community.jboss.org/wiki/useJBossWebClassLoaderinJBoss5</a></li>
<li><a href="http://community.jboss.org/wiki/JBossHibernate3">http://community.jboss.org/wiki/JBossHibernate3</a></li>
</ul>
<p>One of the more sad results is that starting time jumped from &lt; 1m to &gt; 2m in the base config so there is surely still a lot of config to change.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/12/jboss-and-ldap/' rel='bookmark' title='Permanent Link: JBoss and LDAP'>JBoss and LDAP</a> <small>Target: create a test environment for JBoss JAAS authentication using...</small></li>
<li><a href='http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/' rel='bookmark' title='Permanent Link: Tomcat query parameters and encodings'>Tomcat query parameters and encodings</a> <small>Did you ever wondered which from which encoding the query...</small></li>
<li><a href='http://www.len.ro/2009/10/evolution-to-thunderbird-migration/' rel='bookmark' title='Permanent Link: Evolution to Thunderbird migration'>Evolution to Thunderbird migration</a> <small>I have been using Evolution since more than 7 years...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JBoss and LDAP</title>
		<link>http://www.len.ro/2009/12/jboss-and-ldap/</link>
		<comments>http://www.len.ro/2009/12/jboss-and-ldap/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 10:50:23 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=4432</guid>
		<description><![CDATA[Target: create a test environment for JBoss JAAS authentication using LDAP. Platform: Linux Ubuntu 9.10, JBoss 4.2.2.GA, java 1.6.0_15 Install and configure openldap Installing ldap proved to be the most complicated part as apparently Karmic stripped all ldap configuration from the install so all tutorials found on ubuntu site are useless. Finally I&#8217;ve found a [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/11/karmic-various-tricks/' rel='bookmark' title='Permanent Link: Karmic various tricks'>Karmic various tricks</a> <small>Logout messages If you are opening a terminal to a...</small></li>
<li><a href='http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/' rel='bookmark' title='Permanent Link: Tomcat query parameters and encodings'>Tomcat query parameters and encodings</a> <small>Did you ever wondered which from which encoding the query...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Target: create a test environment for JBoss JAAS authentication using LDAP.</p>
<p>Platform: Linux Ubuntu 9.10, JBoss 4.2.2.GA, java 1.6.0_15</p>
<h2>Install and configure openldap</h2>
<p>Installing ldap proved to be the most complicated part as apparently Karmic stripped all ldap configuration from the install so all tutorials found on ubuntu site are useless. Finally I&#8217;ve found <a href="http://ubuntuforums.org/showthread.php?t=1313472">a thread</a> which described the process. Here are the steps I followed:<span id="more-4432"></span></p>
<pre>apt-get remove --purge slapd ldap-utils #remove all my tests
apt-get install slapd ldap-utils #install fresh
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif</pre>
<p>I&#8217;ve created a db.ldif similar to the one described and applied it, the only difference is than I changed the database to match dc=example,dc=com and the cn=admin,dc=example,dc=com password to be secret:</p>
<pre>ldapadd -Y EXTERNAL -H ldapi:/// -f /tmp/db.ldif</pre>
<p>I&#8217;ve then created a app.ldif containing an admin user with password secret</p>
<pre>dn: dc=example,dc=com
objectclass: top
objectclass: dcObject
objectclass: organization
dc: example
o: MCC

dn: ou=People,dc=example,dc=com
objectclass: top
objectclass: organizationalUnit
ou: People

dn: uid=admin,ou=People,dc=example,dc=com
objectclass: top
objectclass: uidObject
objectclass: person
uid: admin
cn: Admin
sn: Admin
userPassword: simple

dn: ou=Roles,dc=example,dc=com
objectclass: top
objectclass: organizationalUnit
ou: Roles

dn: cn=Admin,ou=Roles,dc=example,dc=com
objectClass: top
objectClass: groupOfNames
cn: Admin
description: the DiapasonAdmin group
member: uid=admin,ou=People,dc=example,dc=com</pre>
<p>which I then imported:</p>
<pre>ldapadd -x -D cn=admin,dc=example,dc=com -W -f /tmp/app.ldif</pre>
<div class="wp-caption alignnone" style="width: 329px"><img class="  " title="Openldap structure" src="http://www.len.ro/photo/daily/work/openldap.png" alt="Openldap structure" width="319" height="367" /><p class="wp-caption-text">Openldap structure</p></div>
<h2>JBoss configuration</h2>
<p>Following informations from <a href="http://www.jboss.org/community/wiki/LdapExtLoginModule">this page</a> I then configured an authentication policy in $<em>JBOSS_HOME/server/defautl/conf/login-config.xml</em> as follows:</p>
<pre>&lt;application-policy name="example"&gt;
 &lt;authentication&gt;
 &lt;login-module code="org.jboss.security.auth.spi.LdapExtLoginModule" flag="required" &gt;
 &lt;module-option name="java.naming.factory.initial"&gt;com.sun.jndi.ldap.LdapCtxFactory&lt;/module-option&gt;
 &lt;module-option name="java.naming.provider.url"&gt;ldap://localhost:389&lt;/module-option&gt;
 &lt;module-option name="java.naming.security.authentication"&gt;simple&lt;/module-option&gt;
 &lt;module-option name="bindDN"&gt;cn=admin,dc=example,dc=com&lt;/module-option&gt;
 &lt;module-option name="bindCredential"&gt;secret&lt;/module-option&gt;
 &lt;module-option name="baseCtxDN"&gt;ou=People,dc=example,dc=com&lt;/module-option&gt;
 &lt;module-option name="baseFilter"&gt;(uid={0})&lt;/module-option&gt;

 &lt;module-option name="rolesCtxDN"&gt;ou=Roles,dc=example,dc=com&lt;/module-option&gt;
 &lt;module-option name="roleFilter"&gt;(member={1})&lt;/module-option&gt;
 &lt;module-option name="roleAttributeID"&gt;cn&lt;/module-option&gt;
 &lt;module-option name="searchScope"&gt;ONELEVEL_SCOPE&lt;/module-option&gt;
 &lt;module-option name="allowEmptyPasswords"&gt;true&lt;/module-option&gt;
 &lt;/login-module&gt;
&lt;/authentication&gt;</pre>
<p>which works in authenticating my user.</p>
<h2>JAAS Code</h2>
<p>Here is a piece of example code which can use this authentication policy to perform user authentication:</p>
<pre>protected void doLogin(String user, String pass) {
 try {
 CallbackHandler handler = new UserPassHandler(user, pass);
 LoginContext lc = new LoginContext("example", handler);
 lc.login();
 } catch (Exception e) {
 log.info("Login failed", e);
 }
 return null;
 }

 class UserPassHandler implements CallbackHandler {
 private String user, pass;

 private UserPassHandler(String user, String pass) {
 super();
 this.user = user;
 this.pass = pass;
 }

 public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
 for (int i = 0; i &lt; callbacks.length; i++) {
 if (callbacks[i] instanceof NameCallback) {
 NameCallback nc = (NameCallback) callbacks[i];
 nc.setName(user);
 } else if (callbacks[i] instanceof PasswordCallback) {
 PasswordCallback pc = (PasswordCallback) callbacks[i];
 pc.setPassword(pass.toCharArray());
 } else {
 throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
 }
 }
 }
 }</pre>
<h2>Apache Directory Studio</h2>
<p>In the process of searching information about openldap I&#8217;ve found a link to an <a href="http://directory.apache.org/studio/">eclipse based ldap environment</a> which I&#8217;ve tested (read this if <a href="http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/">eclipse crashes in ubuntu</a>). It&#8217;s bundled with Apache Directory. I&#8217;ve tested it and imported the same app.ldif and I only needed to change a few lines in the application-policy file to make it work:</p>
<div class="wp-caption alignnone" style="width: 343px"><img title="ApacheDS" src="http://www.len.ro/photo/daily/work/apacheds.png" alt="ApacheDS" width="333" height="405" /><p class="wp-caption-text">ApacheDS</p></div>
<pre>&lt;application-policy name="example"&gt;
 &lt;authentication&gt;
 &lt;login-module code="org.jboss.security.auth.spi.LdapExtLoginModule" flag="required" &gt;
 &lt;module-option name="java.naming.factory.initial"&gt;com.sun.jndi.ldap.LdapCtxFactory&lt;/module-option&gt;
 &lt;module-option name="java.naming.provider.url"&gt;ldap://localhost:10389&lt;/module-option&gt;
 &lt;module-option name="java.naming.security.authentication"&gt;simple&lt;/module-option&gt;
 &lt;module-option name="bindDN"&gt;uid=admin,ou=system&lt;/module-option&gt;
 &lt;module-option name="bindCredential"&gt;secret&lt;/module-option&gt;
 &lt;module-option name="baseCtxDN"&gt;ou=People,dc=example,dc=com&lt;/module-option&gt;
 &lt;module-option name="baseFilter"&gt;(uid={0})&lt;/module-option&gt;

 &lt;module-option name="rolesCtxDN"&gt;ou=Roles,dc=example,dc=com&lt;/module-option&gt;
 &lt;module-option name="roleFilter"&gt;(member={1})&lt;/module-option&gt;
 &lt;module-option name="roleAttributeID"&gt;cn&lt;/module-option&gt;
 &lt;module-option name="searchScope"&gt;ONELEVEL_SCOPE&lt;/module-option&gt;
 &lt;module-option name="allowEmptyPasswords"&gt;true&lt;/module-option&gt;
 &lt;/login-module&gt;
 &lt;/authentication&gt;
&lt;/application-policy&gt;</pre>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/11/karmic-various-tricks/' rel='bookmark' title='Permanent Link: Karmic various tricks'>Karmic various tricks</a> <small>Logout messages If you are opening a terminal to a...</small></li>
<li><a href='http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/' rel='bookmark' title='Permanent Link: Tomcat query parameters and encodings'>Tomcat query parameters and encodings</a> <small>Did you ever wondered which from which encoding the query...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2009/12/jboss-and-ldap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eclipse crashes in Ubuntu Karmic</title>
		<link>http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/</link>
		<comments>http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 13:48:22 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=4436</guid>
		<description><![CDATA[Trying to run Apache Directory Studio I&#8217;ve found that eclupse crashes in ubuntu karmic 9.10 with the following error: # # An unexpected error has been detected by HotSpot Virtual Machine: # #  SIGSEGV (0xb) at pc=0x00d64856, pid=8870, tid=3077867296 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_11-b03 mixed mode) # Problematic frame: # C  [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/10/ubuntu-9-10-karmic-koala/' rel='bookmark' title='Permanent Link: Ubuntu 9.10 Karmic Koala'>Ubuntu 9.10 Karmic Koala</a> <small>This ubuntu installation was the bit of fun expected after...</small></li>
<li><a href='http://www.len.ro/2009/11/ubuntu-9-10-karmic-koala-netbook/' rel='bookmark' title='Permanent Link: Ubuntu 9.10 Karmic Koala netbook'>Ubuntu 9.10 Karmic Koala netbook</a> <small>I&#8217;ve also migrated my Acer Aspire One to the new...</small></li>
<li><a href='http://www.len.ro/2009/09/sending-a-fax-in-ubuntu/' rel='bookmark' title='Permanent Link: Sending a fax in ubuntu'>Sending a fax in ubuntu</a> <small>Conexant fax-modem configuration In the process of sending a fax...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Trying to run Apache Directory Studio I&#8217;ve found that eclupse crashes in ubuntu karmic 9.10 with the following error:</p>
<pre>#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  SIGSEGV (0xb) at pc=0x00d64856, pid=8870, tid=3077867296
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_11-b03 mixed mode)
# Problematic frame:
# C  [libpango-1.0.so.0+0x23856]  pango_layout_new+0x36
#</pre>
<p>I&#8217;ve tried running it with different java version and with the GDK_NATIVE_WINDOWS=1 with no luck and found the problem unanswered on lot of sites. Finally <a href="https://bugs.launchpad.net/ubuntu/+source/eclipse/+bug/460104">the solution</a> required to disable the Assistive Technologies (System -&gt; Preferences -&gt; Assistive Technologies). After that everything works ok.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/10/ubuntu-9-10-karmic-koala/' rel='bookmark' title='Permanent Link: Ubuntu 9.10 Karmic Koala'>Ubuntu 9.10 Karmic Koala</a> <small>This ubuntu installation was the bit of fun expected after...</small></li>
<li><a href='http://www.len.ro/2009/11/ubuntu-9-10-karmic-koala-netbook/' rel='bookmark' title='Permanent Link: Ubuntu 9.10 Karmic Koala netbook'>Ubuntu 9.10 Karmic Koala netbook</a> <small>I&#8217;ve also migrated my Acer Aspire One to the new...</small></li>
<li><a href='http://www.len.ro/2009/09/sending-a-fax-in-ubuntu/' rel='bookmark' title='Permanent Link: Sending a fax in ubuntu'>Sending a fax in ubuntu</a> <small>Conexant fax-modem configuration In the process of sending a fax...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hibernate localized data</title>
		<link>http://www.len.ro/2009/06/hibernate-localized-data/</link>
		<comments>http://www.len.ro/2009/06/hibernate-localized-data/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 15:00:40 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=3845</guid>
		<description><![CDATA[Here are some reflections and solutions on how to localize strings in hibernate objects. The model I am assuming the localized strings will be stored in the database in a structure similar to: Table MY_OBJECT: &#8230; LOCALIZED_FIELD &#8230; Table LOCALIZED_DATA: CATEGORY (object type) LOCALE LOCALIZED_FK (stores the id of the localized object but without foreign [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/' rel='bookmark' title='Permanent Link: Tomcat query parameters and encodings'>Tomcat query parameters and encodings</a> <small>Did you ever wondered which from which encoding the query...</small></li>
<li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Here are some reflections and solutions on how to localize strings in hibernate objects.</p>
<h2>The model</h2>
<p>I am assuming the localized strings will be stored in the database in a structure similar to:</p>
<p>Table MY_OBJECT:</p>
<ul>
<li>&#8230;</li>
<li>LOCALIZED_FIELD</li>
<li>&#8230;</li>
</ul>
<p>Table LOCALIZED_DATA:</p>
<ul>
<li>CATEGORY (object type)</li>
<li>LOCALE</li>
<li>LOCALIZED_FK (stores the id of the localized object but without foreign key restrictions)</li>
<li>FIELD (field of the object)</li>
<li>DATA (the actual localization)</li>
</ul>
<p><span id="more-3845"></span></p>
<h2>First ideea (bad)</h2>
<p>Create a <strong>bag of composite elements with the actual localizations</strong>:</p>
<pre>&lt;bag name="localizedData" table="LOCALIZED_DATA" where="CATEGORY='myObject'"&gt;
 &lt;key column="LOCALIZED_FK" /&gt;
 &lt;composite-element&gt;
 &lt;property name="category" column="CATEGORY" type="java.lang.String"/&gt;
 &lt;property name="locale" column="LOCALE" type="java.lang.String"/&gt;
 &lt;property name="name" column="DATA" type="java.lang.String"/&gt;
 &lt;/composite-element&gt;
&lt;/bag&gt;</pre>
<p>There are several cons against this method and the biggest one is that this will generate a large number of extra requests to the database. When loading an object hibernate will generate an extra request to load the localizedData and since there is no primary key (id) for a composite element there is also no way of caching these objects. All the localized strings will be loaded each time instead of finding just the right one. It will also require a bag for each localized property in the object.</p>
<h2>Second ideea</h2>
<p>The second ideea is based on <a title="Hibernate localized data" href="http://www.theserverside.com/tt/blogs/showblog.tss?id=HibernateInternational">the example found here</a> which implies the creation of a special data type which will handle the localization. However this example has the limitation that if you wish for you application to handle multiple locales at the same time (based on the http request for instance) then you have to find a way to pass the locale information to the LabelUserType object and I found no way of doing so.</p>
<h2>Third ideea (complete)</h2>
<p>This last ideea uses bits of the previous ideea and is based on interceptors for localization.Using interceptors has the advantage that the interceptor can be configured per session thus allowing to handle multiple locales in the same application and pass the locale information to the locale loading process instead of depending on a singletone like access to the current locale.</p>
<p>I am also using a custom type but this only derives from StringType and it&#8217;s purpose is just to mark the field which are localized.</p>
<pre>public class LocalizationInterceptor extends EmptyInterceptor{
...
 @Override
 public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
 if(entity instanceof Localized){
 Localized lEntity = (Localized)entity;
 for (int i = 0; i &lt; types.length; i++) {
 //identifies the field which is localized
 if(types[i] instanceof LocalizedStringType){
 //translate here
 state[i] = getLocalizedString(lEntity.getCategory(), (Long)id, propertyNames[i], (String)state[i]);
 }
 }
 }
 return false;
 }</pre>
<p>The ideea is to identify the objects which contain localized data by forcing them to implement the Localized interface and then to identify the fields which are localized as they are of type LocalizedStringType which is an empty subclass of StringType used for this purpose alone.</p>
<p>This interceptor can be then initialized per session:</p>
<pre>LocalizationInterceptor localizationInterceptor = new LocalizationInterceptor();
hsession = factory.openSession(localizationInterceptor);
localizationInterceptor.init(hsession, locale.toString());</pre>
<h2>The caching part</h2>
<p>My first approach was to add an id field to the LocalizedData object and to use a search of the form:</p>
<pre>from l in class LocalizedData where
l.category = ... and l.locale = ... and l.code = and l.localizedFk = ...</pre>
<p>but I realized that this approach could not be cached by hibernate because it would first require all possible queries to be made <a href="http://www.len.ro/2009/03/a-bit-about-hibernate-cache/">due to the way the query cache and the object cache work in hibernate</a>.</p>
<p>So I chosed the following mapping:</p>
<pre>&lt;hibernate-mapping package="com.mccsoft.diapason.data"&gt;
 &lt;class name="LocalizedData" table="LOCALIZED_DATA"&gt;
 &lt;cache usage="transactional"/&gt;
 &lt;composite-id name="id"&gt;
 &lt;key-property name="category" type="java.lang.String" column="CATEGORY"/&gt;
 &lt;key-property name="locale" type="java.lang.String" column="LOCALE"/&gt;
 &lt;key-property name="localizedFk" type="java.lang.Long" column="LOCALIZED_FK"/&gt;
 &lt;key-property name="code" type="java.lang.String" column="CODE"/&gt;
 &lt;/composite-id&gt;
 &lt;property name="data" type="java.lang.String"&gt;
 &lt;column name="DATA" not-null="true" /&gt;
 &lt;/property&gt;
 &lt;/class&gt;
&lt;/hibernate-mapping&gt;</pre>
<p>By using a composite id with the same properties as the query I could be sure that a cache per these parameters will be created. Thus the getLocalizedString function:</p>
<pre>public String getLocalizedString(String category, Long id, String code, String defaultValue){
 log.info("Getting " + locale + " data for: " + category + "/" + id + "." + code);
 LocalizedDataId lId = new LocalizedDataId(locale, category, id, code);
 LocalizedData lData = (LocalizedData)currentSession.get(LocalizedData.class, lId);
 if(lData == null){
 return defaultValue;
 }else{
 return lData.getData();
 }
 }</pre>
<p>and the cache initialization for a locale:</p>
<pre>public static void initLocalizedCache(Session session, String locale){
 Query query = session.createQuery("from l in class com.mccsoft.diapason.data.LocalizedData where l.id.locale = :locale");
 query.setParameter("locale", locale);
 query.list();
 }</pre>
<p>The only disadvantage I can find until now is that for missing locale values a query will be still made but this can be solved by storing a &#8220;null&#8221; value for these locales to enable the hibernate cache to store these locales also.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2010/04/tomcat-query-parameters-and-encodings/' rel='bookmark' title='Permanent Link: Tomcat query parameters and encodings'>Tomcat query parameters and encodings</a> <small>Did you ever wondered which from which encoding the query...</small></li>
<li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2009/06/hibernate-localized-data/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Tapestry, hibernate application (no.5)</title>
		<link>http://www.len.ro/2009/06/tapestry-hibernate-application-no5/</link>
		<comments>http://www.len.ro/2009/06/tapestry-hibernate-application-no5/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 17:45:41 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tapestry]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=3828</guid>
		<description><![CDATA[A few years ago I was writting some simple tutorials about using hibernate with tapestry to build a simple application. I&#8217;ve used Tapestry 3, 4 and I found it reliable to build applications which are still in production. I could consider myself a Tapestry fan and as such I am disappointed a bit to write [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/08/integrating-lightbox-into-tapestry-5/' rel='bookmark' title='Permanent Link: Integrating Lightbox into Tapestry 5'>Integrating Lightbox into Tapestry 5</a> <small>This show a basic way of using Lightbox 2.03 (wiki)...</small></li>
<li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/' rel='bookmark' title='Permanent Link: Eclipse crashes in Ubuntu Karmic'>Eclipse crashes in Ubuntu Karmic</a> <small>Trying to run Apache Directory Studio I&#8217;ve found that eclupse...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A few years ago I was writting some simple tutorials about <a href="http://www.len.ro/2006/11/tapestry-hibernate-app/">using hibernate with tapestry</a> to build a simple application. I&#8217;ve used Tapestry 3, 4 and I found it reliable to build applications which are still in production. I could consider myself a Tapestry fan and as such I am disappointed a bit to write this article since I was expecting to find no need for it. My goal was to build a simple example of Tapestry &#8211; Hibernate application using Tapestry 5.<span id="more-3828"></span></p>
<p>1. First try: the maven method recomended on the site:</p>
<pre>$ ./mvn archetype:create -DarchetypeGroupId=org.apache.tapestry  -DarchetypeArtifactId=quickstart -DgroupId=org.apache.tapestry -DartifactId=tutorial1 -DpackageName=org.apache.tapestry5.tutorial
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Setting property: classpath.resource.loader.class =&gt; 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on =&gt; 'false'.
[INFO] Setting property: resource.loader =&gt; 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound =&gt; 'false'.
[INFO] [archetype:create]
[WARNING] This goal is deprecated. Please use mvn archetype:generate instead
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating OldArchetype: quickstart:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.apache.tapestry
[INFO] Parameter: packageName, Value: org.apache.tapestry5.tutorial
[INFO] Parameter: package, Value: org.apache.tapestry5.tutorial
[INFO] Parameter: artifactId, Value: tutorial1
[INFO] Parameter: basedir, Value: /phantom/java/kits/apache-maven-2.1.0/bin
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] <span style="color: #ff0000;">Error creating from archetype

Embedded error: The META-INF/maven/archetype.xml descriptor cannot be found.</span>
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds</pre>
<p>I&#8217;ve found the track in jira for this but the fix is in the next release.</p>
<p>2. Well I don&#8217;t like maven anyways but I am sure I will be able to find some examples. And I found some indeed:</p>
<ul>
<li><a href="http://www.infoq.com/articles/tapestry5-intro">http://www.infoq.com/articles/tapestry5-intro</a></li>
<li><a href="http://code.google.com/p/shams/wiki/Setup">http://code.google.com/p/shams/wiki/Setup</a></li>
</ul>
<p>They work ok with the 5.0.* version of Tapestry but since current version is 5.1.0.5 I thought stupid to use an old version and not the latest so I just replaced the jars:</p>
<ul>
<li><tt>tapestry-core.jar</tt></li>
<li><tt>tapestry-ioc.jar</tt></li>
<li><tt>commons-codec.jar</tt></li>
<li><tt>tapestry-annotation.jar</tt></li>
<li><tt>javassist.jar</tt></li>
<li><tt>slf4j-api.jar</tt></li>
<li><tt>slf4j-log4j12.jar</tt></li>
</ul>
<p>with their newer version. At this time nothing worked and I got a very &#8220;suggestive&#8221; error:</p>
<pre>SEVERE: Error filterStart
Jun 14, 2009 8:37:56 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/test] startup failed due to previous errors</pre>
<p>A google search revealed nothing so I was left over with the task of just finding which jar was required from the list of jars coming with Tapestry archive. Finally I was left with this list:</p>
<ul>
<li><tt>antlr-runtime.jar</tt></li>
<li><tt>tapestry-core.jar</tt></li>
<li><tt>tapestry-ioc.jar</tt></li>
<li><tt>commons-codec.jar</tt></li>
<li><tt>tapestry-annotation.jar</tt></li>
<li><tt>stax2-api.jar</tt></li>
<li><tt>woodstox-core-asl.jar</tt></li>
<li><tt>javassist.jar</tt></li>
<li><tt>slf4j-api.jar</tt></li>
<li><tt>slf4j-log4j12.jar</tt></li>
</ul>
<p>This restored the applications.</p>
<p>3. I thought making tapestry work with hibernate would also be a simple task but again jar dependencies generated strange errors from the filterStart error to other strange ones. After some more time of jar finding here is the final list to make a simple hibernate example also work:</p>
<ul>
<li><tt>antlr-2.7.6.jar</tt></li>
<li><tt>antlr-runtime-3.1.1.jar</tt></li>
<li><tt>commons-codec-1.3.jar</tt></li>
<li><tt>commons-collections-3.1.jar</tt></li>
<li><tt>dom4j-1.6.1.jar</tt></li>
<li><tt>ejb3-persistence.jar</tt></li>
<li><tt>hibernate3.jar</tt></li>
<li><tt>hibernate-annotations.jar</tt></li>
<li><tt>hibernate-commons-annotations.jar</tt></li>
<li><tt>javassist-3.9.0.GA.jar</tt></li>
<li><tt>jta-1.1.jar</tt></li>
<li><tt>log4j-1.2.14.jar</tt></li>
<li><tt>postgresql-8.3-604.jdbc3.jar</tt></li>
<li><tt>slf4j-api-1.5.2.jar</tt></li>
<li><tt>slf4j-log4j12-1.5.2.jar</tt></li>
<li><tt>stax2-api-3.0.1.jar</tt></li>
<li><tt>stax-api-1.0.1.jar</tt></li>
<li><tt>tapestry5-annotations-5.1.0.5.jar</tt></li>
<li><tt>tapestry-core-5.1.0.5.jar</tt></li>
<li><tt>tapestry-hibernate-5.1.0.5.jar</tt></li>
<li><tt>tapestry-hibernate-core-5.1.0.5.jar</tt></li>
<li><tt>tapestry-ioc-5.1.0.5.jar</tt></li>
<li><tt>woodstox-core-asl-4.0.3.jar</tt></li>
</ul>
<p>At the end I lost a lot of time making this work but even so I liked what I found, too bad it was not very easy to get here and in all some stupid list of dependencies would have made all the difference.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/08/integrating-lightbox-into-tapestry-5/' rel='bookmark' title='Permanent Link: Integrating Lightbox into Tapestry 5'>Integrating Lightbox into Tapestry 5</a> <small>This show a basic way of using Lightbox 2.03 (wiki)...</small></li>
<li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/' rel='bookmark' title='Permanent Link: Eclipse crashes in Ubuntu Karmic'>Eclipse crashes in Ubuntu Karmic</a> <small>Trying to run Apache Directory Studio I&#8217;ve found that eclupse...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2009/06/tapestry-hibernate-application-no5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A bit of hibernate optimization</title>
		<link>http://www.len.ro/2009/02/a-bit-of-hibernate-optimization/</link>
		<comments>http://www.len.ro/2009/02/a-bit-of-hibernate-optimization/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 12:46:47 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=3619</guid>
		<description><![CDATA[The context Assume you are dealing with a hibernate operation which requires to copy a lot of objects in the database. For instance you are having 2 objects as described in the diagram bellow: budget and entries and you want to duplicate the budget and all it&#8217;s entries for some operation. There are several way [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<h3>The context</h3>
<p>Assume you are dealing with a hibernate operation which requires to copy a lot of objects in the database. For instance you are having 2 objects as described in the diagram bellow: budget and entries and you want to duplicate the budget and all it&#8217;s entries for some operation. There are several way to do this.</p>
<div class="wp-caption alignnone" style="width: 356px"><img title="Budget - entries" src="http://www.len.ro/photo/daily/work/budget_entries.png" alt="Budget - entries" width="346" height="134" /><p class="wp-caption-text">Budget - entries</p></div>
<h3>First approach</h3>
<p>In hibernate usual approach this is done most of the time as something similar to:<span id="more-3619"></span></p>
<pre>//duplicate the oldBudgetVersion
//load the old entries
query = session.createQuery("from BudgetEntry as e where e.version.id = :budgetVersionId");
query.setParameter("budgetVersionId", budgetVersion.getId());
List entries = query.list();
for (Iterator i = entries.iterator(); i.hasNext();) {
        BudgetEntry entry = (BudgetEntry) i.next();
	BudgetEntry newEntry = new BudgetEntry();
	newEntry.setAmount(entry.getAmount());
	//set all the other valies
	session.save(newEntry);
}
session.flush();</pre>
<p>This is probably ok for a small number of entries but it will become not so efficient for more entries. Consider the number of sql&#8217;s:</p>
<ul>
<li>load the old budgetVersion (1)</li>
<li>save the new budgetVersion (1)</li>
<li>load the old entries (1) and the associated objects which might need referencing (n*?)</li>
<li>save the new entries (n)</li>
</ul>
<p>It can sum up to 400 sql&#8217;s for around 200 entries.</p>
<h3>Second approach</h3>
<p>Even if there are not many examples hibernate supports <a href="http://www.hibernate.org/hib_docs/v3/reference/en-US/html_single/#batch-direct">DML style syntax</a>. For our case it can be implemented as:</p>
<pre>query = session.createQuery("insert into BudgetEntry(version, structure, amount, ....) select " +
			"v, e.structure, e.amount, ... from BudgetEntry e, BudgetVersion v where e.version.id = :origBudgetVersionId and v.id = :newBudgetVersionId");
query.setParameter("newBudgetVersionId", newBudgetVersion.getId());
query.setParameter("origBudgetVersionId", budgetVersion.getId());
query.executeUpdate();
session.flush();</pre>
<p>which sums up to only 1 sql. Note that there a <strong>bit of a trick in the join</strong> to actually make the new objects link to the proper parent but it&#8217;s worth every effort.</p>
<h3>Conclusion</h3>
<p>In my simple test with around 800 entries the first approach took a bit <strong>over 5 minutes</strong> while the second a bit <strong>under 5 seconds</strong>.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
<li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2009/02/a-bit-of-hibernate-optimization/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The conflicting ssleay32 and libeay32</title>
		<link>http://www.len.ro/2009/02/the-conflicting-ssleay32-and-libeay32/</link>
		<comments>http://www.len.ro/2009/02/the-conflicting-ssleay32-and-libeay32/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 17:50:02 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[windoze]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=3596</guid>
		<description><![CDATA[Since everybody seemed to be stuck with using the library on windows and yet on linux it worked from the start I&#8217;ve decided to dive into the wonderful world of windoze. The problem: while trying to use a java, jni-based library the error was unavoidable: java.lang.UnsatisfiedLinkError: C:\sw_api\sw_api\windows\sw_api.dll: The operating system cannot run %1                         at [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
<li><a href='http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/' rel='bookmark' title='Permanent Link: Eclipse crashes in Ubuntu Karmic'>Eclipse crashes in Ubuntu Karmic</a> <small>Trying to run Apache Directory Studio I&#8217;ve found that eclupse...</small></li>
<li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Since everybody seemed to be stuck with using the library on windows and yet on linux it worked from the start I&#8217;ve decided to dive into the wonderful world of windoze.<span id="more-3596"></span></p>
<p><strong>The problem</strong>: while trying to use a java, jni-based library the error was unavoidable:</p>
<pre>java.lang.UnsatisfiedLinkError: C:\sw_api\sw_api\windows\sw_api.dll: The operating system cannot run %1
                        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
                        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
                        at java.lang.ClassLoader.loadLibrary(Unknown Source)
                        at java.lang.Runtime.loadLibrary0(Unknown Source)
                        at java.lang.System.loadLibrary(Unknown Source)</pre>
<p>As such I decided to wrote this simple program:</p>
<pre>public class Test
{
    static
    {
            System.loadLibrary( "sw_api" );
            System.loadLibrary( "SWAPILink" );
        }
        catch( UnsatisfiedLinkError e ) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void main(String argv[]){
        System.out.println("success");
    }
}</pre>
<p>which of course gave the same problem. This was obviously not a PATH problem which would have caused a more general error such as:</p>
<pre>java.lang.UnsatisfiedLinkError: no sw_api in java.library.path
                        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
                        at java.lang.Runtime.loadLibrary0(Runtime.java:823)
                        at java.lang.System.loadLibrary(System.java:1030)
                        at Test.&lt;clinit&gt;(Test.java:10)</pre>
<p>As such the sw_api.dll was probably found but during load some error occured. And what happens during load? It loads some other dll&#8217;s. By taking a look in the path where the sw_api.dll was located I found a lot of sw_*.dll but also ssleay32.dll and libeay32.dll. The ssl versions are known to cause problems even on linux and by doing a search for the ssleay32.dll I found at least 5 instances of 3 different versions.</p>
<div class="wp-caption alignnone" style="width: 604px"><img title="Multiple versions" src="http://www.len.ro/photo/daily/work/win-2.png" alt="Multiple versions" width="594" height="220" /><p class="wp-caption-text">Multiple versions</p></div>
<p>So <strong>cause of the problem</strong> was that my sw_api.dll was trying to load the symbols for a function probably not present. In order to confirm this idea I modified my test code as such:</p>
<pre>System.load( "C:\\sw_api\\sw_api\\windows\\libeay32.dll");
System.load( "C:\\sw_api\\sw_api\\windows\\ssleay32.dll");
System.loadLibrary( "sw_api" );</pre>
<p>and yes, it worked. Sounds ok but this is no solution to hardcode some dll&#8217;s. Wondering who of is using this dll? Well even the intel driver for the wireless card is using it:</p>
<div class="wp-caption alignnone" style="width: 605px"><img title="Who?" src="http://www.len.ro/photo/daily/work/win-1.png" alt="Who?" width="595" height="540" /><p class="wp-caption-text">Who?</p></div>
<p><strong>First try</strong>: put the DLL path before %PATH%</p>
<pre>set PATH=C:\sw_api\sw_api\windows;%PATH%</pre>
<p>not working.</p>
<p><strong>Second try</strong>: I found this link where the dynamic library search order is <a href="http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx">described</a>. The solution was in fact to run the application from the DLL directory and as such impose these to be loaded first.</p>
<p><strong>The elegant solution</strong>: would be to rename the problem dll&#8217;s as: sw-libeay32.dll and sw-ssleay32.dll and modify the sw-api.dll to use them. Of course this is not possible since it would require recompilation of this dll file.</p>
<p>Am I not entitled to miss the <a href="http://en.wikipedia.org/wiki/DLL_injection">LD_PRELOAD</a> ?</p>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
<li><a href='http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/' rel='bookmark' title='Permanent Link: Eclipse crashes in Ubuntu Karmic'>Eclipse crashes in Ubuntu Karmic</a> <small>Trying to run Apache Directory Studio I&#8217;ve found that eclupse...</small></li>
<li><a href='http://www.len.ro/2010/02/jboss-migration-4-2-2-ga-to-5-1-0-ga/' rel='bookmark' title='Permanent Link: JBoss migration 4.2.2-GA to 5.1.0-GA'>JBoss migration 4.2.2-GA to 5.1.0-GA</a> <small>In my stupidity innocence I just hoped that deploying the...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2009/02/the-conflicting-ssleay32-and-libeay32/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote java debug</title>
		<link>http://www.len.ro/2009/01/remote-java-debug/</link>
		<comments>http://www.len.ro/2009/01/remote-java-debug/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 18:20:12 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.len.ro/?p=3422</guid>
		<description><![CDATA[This is something which should be know be every java developer: how to enable remote debugging of your java application. The solution is remarcable simple: export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n" and the start your application normally. You can use your IDE of choice for the debugging. Here is a screenshot of the eclipse configuration: Related posts:JBoss and [...]

<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/12/jboss-and-ldap/' rel='bookmark' title='Permanent Link: JBoss and LDAP'>JBoss and LDAP</a> <small>Target: create a test environment for JBoss JAAS authentication using...</small></li>
<li><a href='http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/' rel='bookmark' title='Permanent Link: Eclipse crashes in Ubuntu Karmic'>Eclipse crashes in Ubuntu Karmic</a> <small>Trying to run Apache Directory Studio I&#8217;ve found that eclupse...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This is something which should be know be every java developer: how to enable remote debugging of your java application. The solution is remarcable simple:</p>
<pre>export JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"</pre>
<p>and the start your application normally. You can use your IDE of choice for the debugging. Here is a screenshot of the eclipse configuration:</p>
<div class="wp-caption alignnone" style="width: 522px"><img title="Remote java debug" src="http://www.len.ro/photo/daily/work/slides/remote-java-debug.jpg" alt="Remote java debug" width="512" height="369" /><p class="wp-caption-text">Remote java debug</p></div>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/12/jboss-and-ldap/' rel='bookmark' title='Permanent Link: JBoss and LDAP'>JBoss and LDAP</a> <small>Target: create a test environment for JBoss JAAS authentication using...</small></li>
<li><a href='http://www.len.ro/2009/11/eclipse-in-ubuntu-karmic/' rel='bookmark' title='Permanent Link: Eclipse crashes in Ubuntu Karmic'>Eclipse crashes in Ubuntu Karmic</a> <small>Trying to run Apache Directory Studio I&#8217;ve found that eclupse...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2009/01/remote-java-debug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Locale files</title>
		<link>http://www.len.ro/2008/05/locale-files/</link>
		<comments>http://www.len.ro/2008/05/locale-files/#comments</comments>
		<pubDate>Tue, 13 May 2008 14:55:19 +0000</pubDate>
		<dc:creator>len</dc:creator>
				<category><![CDATA[work]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://ng.len.ro/2008/05/locale-files/</guid>
		<description><![CDATA[Locale, flex vs java


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/08/radio-button-renderer-in-a-datagrid/' rel='bookmark' title='Permanent Link: Radio button renderer in a datagrid'>Radio button renderer in a datagrid</a> <small>Using a radio button as a data grid cell renderer...</small></li>
<li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
<li><a href='http://www.len.ro/2009/11/changing-dates-in-thunderbird/' rel='bookmark' title='Permanent Link: Changing dates format in Thunderbird'>Changing dates format in Thunderbird</a> <small>Since my migration to thunderbird I did not had many...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When using flex and java in parallel the localization mechanism might be clear. One aspect which is not clear is the encoding of the properties files:</p>
<ul>
<li>Flex locale files encoding: UTF-8</li>
<li>Java locale files encoding: ISO-8859-1</li>
</ul>
<p>Convertor script:</p>
<pre>..$ cat fixUTF.sh #!/bin/bash

TMP=iconv.tmp

if [ "!$2" == "!rev" ]; then	iconv -t ISO_8859-1 -f UTF-8 -o $TMP $1else	iconv -f ISO_8859-1 -t UTF-8 -o $TMP $1fimv $TMP $1</pre>


<h3>Related posts:</h3><ol><li><a href='http://www.len.ro/2009/08/radio-button-renderer-in-a-datagrid/' rel='bookmark' title='Permanent Link: Radio button renderer in a datagrid'>Radio button renderer in a datagrid</a> <small>Using a radio button as a data grid cell renderer...</small></li>
<li><a href='http://www.len.ro/2009/09/flex-applications-size-optimization/' rel='bookmark' title='Permanent Link: Flex applications size optimization'>Flex applications size optimization</a> <small>After quite some time of development we realised that our...</small></li>
<li><a href='http://www.len.ro/2009/11/changing-dates-in-thunderbird/' rel='bookmark' title='Permanent Link: Changing dates format in Thunderbird'>Changing dates format in Thunderbird</a> <small>Since my migration to thunderbird I did not had many...</small></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://www.len.ro/2008/05/locale-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
