<?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>dominikdorn.com</title>
	<atom:link href="http://dominikdorn.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dominikdorn.com</link>
	<description>shit happens ;)</description>
	<lastBuildDate>Tue, 27 Jul 2010 14:58:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>StarCraft 2 (DVD) with Linux + Wine</title>
		<link>http://dominikdorn.com/2010/07/starcraft-2-dvd-with-linux-wine/</link>
		<comments>http://dominikdorn.com/2010/07/starcraft-2-dvd-with-linux-wine/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 13:13:25 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=318</guid>
		<description><![CDATA[Describes installing of StarCraft 2 from DVD on a Linux System (Ubuntu) with Wine and how to cope with the problems involved. ]]></description>
			<content:encoded><![CDATA[<p>I just got my StarCraft 2 Collectors Edition. </p>
<p>Right after unpacking it, I inserted the DVD and was wondering &#8220;They ship a whole DVD with just 2 Files, not more than 3 MB of size?&#8221; </p>
<p>The thing is: The DVD has a file system called UDF which supports hidden files and directories. Unlike with normal filesystems in linux, even a ls -lah does not show these files. </p>
<p><strong>1. Unmount the DVD</strong><br/><br />
Make sure to unmount the DVD first.<br />
Close every filemanager and console that has the DVD folder open.<br />
In my Ubuntu installation, the DVD is mounted to /media/cdrom0</p>
<p>Do the following in a console</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>cdrom0</pre></div></div>

<p>If it does not work, look which processes still have a lock on the directory using</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> lsof <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>cdrom0</pre></div></div>

<p>and kill those.</p>
<p><strong>2. Mount the DVD correctly</strong><br />
First, get your own user Id. Most of the times its just 1000.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">domdorn ~ $ <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>domdorn<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">1000</span><span style="color: #000000; font-weight: bold;">&lt;/</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>domdorn<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">groups</span></span>=<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>adm<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">20</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>dialout<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">24</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>cdrom<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">46</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>plugdev<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">103</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>fuse<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">104</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>lpadmin<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">114</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>admin<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">118</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>sambashare<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>domdorn<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Note the values of uid=&#8230; and gid=&#8230;. (here both are 1000)</p>
<p>Next, mount the DVD the following way:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>cdrom <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>cdrom0 <span style="color: #660033;">-o</span> <span style="color: #007800;">uid</span>=<span style="color: #000000;">1000</span>,<span style="color: #007800;">gid</span>=<span style="color: #000000;">1000</span>,unhide,<span style="color: #007800;"><span style="color: #7a0874; font-weight: bold;">umask</span></span>=0000</pre></div></div>

<p>unhide makes linux show the hidden files on the dvd, uid/gid makes sure you&#8217;re allowed to read the files.</p>
<p><strong>3. Start the Installer</strong><br />
Now try to start the installer: Open a console, change to /media/cdrom0 and start it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>cdrom0
wine Installer.exe</pre></div></div>

<p><strong>If you&#8217;re lucky, it now works out of the box and you are finished. </strong></p>
<p>If not (like me), it simply does nothing and we have to do the following. </p>
<p><strong>4. Copy the DVD</strong><br />
If the Installer does not work out of the box, create a folder on your filesystem, e.g.<br />
~/.wine/drive_c/sc2install<br />
and copy the whole DVDs contents to this directory. After this is finished, try to start the Installer from there. </p>
<p><del><br />
Log into your Battle.net Account.</p>
<p>http://www.battle.net</p>
<p>and Add your CD-Key to your Account. If you don&#8217;t have an Battle.net Account yet, create one, you&#8217;ll need it anyway.</p>
<p>After you&#8217;ve added the Game to your account, download the Windows Installer.<br />
Start up the downloaded installer and select a folder in your wines Drive C. Let it  download a few bytes and then quit the installer.<br />
Now copy the files</p>
<pre>
Installer Tome 1.MPQE.part
Installer UI 1.MPQ.part
Installer UI 2.MPQE.part
</pre>
<p>from /media/cdrom0 to the created folder. In my case its ~/.wine/drive_c/sc2download/SC2-WingsOfLiberty-enGB-Installer</p>
<p>Now startup the downloaded installer again.<br />
It should start checking the downloaded files (you might not see a difference in the progress bar, but the CPU goes up, watch with &#8220;top&#8221;).<br />
After the file check is finished, the installer should start.<br />
</del></p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/07/starcraft-2-dvd-with-linux-wine/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>JPA2 Abstract DAO,  Criteria Query &amp; the &#8220;like&#8221; Operator</title>
		<link>http://dominikdorn.com/2010/06/jpa2-abstract-dao-criteria-query-like-operator/</link>
		<comments>http://dominikdorn.com/2010/06/jpa2-abstract-dao-criteria-query-like-operator/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 13:48:17 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[Abstract DAO]]></category>
		<category><![CDATA[DAO]]></category>
		<category><![CDATA[EclipseLink]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JPA2]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=312</guid>
		<description><![CDATA[Shows an Abstract DAO realized with JPA2. Also includes a method findByAttributes which leverages JPA2s CriteriaQuerys and the like Operator. ]]></description>
			<content:encoded><![CDATA[<p>For a project at the university, I had to implement an abstract search in an abstract JPA Dao. </p>
<p>Maybe this class comes handy for some of you</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.dominikdorn.rest.dao</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.EntityManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.PersistenceContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.PersistenceException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.TypedQuery</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.criteria.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.ParameterizedType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author Dominik Dorn
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractJpaDao<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    @PersistenceContext
    <span style="color: #000000; font-weight: bold;">protected</span> EntityManager em<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">Class</span> entityClass<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">Class</span> getEntityClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> entityClass<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setEntityClass<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> entityClass<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">entityClass</span> <span style="color: #339933;">=</span> entityClass<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AbstractJpaDao<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ParameterizedType genericSuperclass <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ParameterizedType<span style="color: #009900;">&#41;</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getGenericSuperclass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">entityClass</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> genericSuperclass.<span style="color: #006633;">getActualTypeArguments</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AbstractJpaDao<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> clazz<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">entityClass</span> <span style="color: #339933;">=</span> clazz<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> EntityManager getEm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> em<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> AbstractJpaDao setEm<span style="color: #009900;">&#40;</span>EntityManager em<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">em</span> <span style="color: #339933;">=</span> em<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> TYPE persist<span style="color: #009900;">&#40;</span>TYPE item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>item <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> PersistenceException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Item may not be null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        em.<span style="color: #006633;">persist</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> item<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> TYPE update<span style="color: #009900;">&#40;</span>TYPE item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>item <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> PersistenceException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Item may not be null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        em.<span style="color: #006633;">merge</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> item<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span> getAll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        CriteriaQuery cq <span style="color: #339933;">=</span> em.<span style="color: #006633;">getCriteriaBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cq.<span style="color: #006633;">select</span><span style="color: #009900;">&#40;</span>cq.<span style="color: #006633;">from</span><span style="color: #009900;">&#40;</span>entityClass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> em.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>cq<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResultList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> TYPE getById<span style="color: #009900;">&#40;</span><span style="color: #003399;">Long</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>id <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> id <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> PersistenceException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Id may not be null or negative&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>TYPE<span style="color: #009900;">&#41;</span> em.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>entityClass, id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> delete<span style="color: #009900;">&#40;</span>TYPE item<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>item <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> PersistenceException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Item may not be null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        em.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>em.<span style="color: #006633;">merge</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span> findByAttributes<span style="color: #009900;">&#40;</span>Map<span style="color: #339933;">&lt;</span>String, String<span style="color: #339933;">&gt;</span> attributes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        List<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span> results<span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">//set up the Criteria query</span>
        CriteriaBuilder cb <span style="color: #339933;">=</span> em.<span style="color: #006633;">getCriteriaBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CriteriaQuery<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span> cq <span style="color: #339933;">=</span> cb.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>getEntityClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Root<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span> foo <span style="color: #339933;">=</span> cq.<span style="color: #006633;">from</span><span style="color: #009900;">&#40;</span>getEntityClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        List<span style="color: #339933;">&lt;</span>Predicate<span style="color: #339933;">&gt;</span> predicates <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Predicate<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s <span style="color: #339933;">:</span> attributes.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>foo.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                predicates.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>cb.<span style="color: #006633;">like</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Expression<span style="color: #009900;">&#41;</span> foo.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;%&quot;</span> <span style="color: #339933;">+</span> attributes.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;%&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        cq.<span style="color: #006633;">where</span><span style="color: #009900;">&#40;</span>predicates.<span style="color: #006633;">toArray</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Predicate<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        TypedQuery<span style="color: #339933;">&lt;</span>TYPE<span style="color: #339933;">&gt;</span> q <span style="color: #339933;">=</span> em.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>cq<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        results <span style="color: #339933;">=</span> q.<span style="color: #006633;">getResultList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> results<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>To instantiate this for an Entity, e.g. &#8220;Item&#8221;, simply do this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">// get an entityManager somewhere here </span>
  AbstractJpaDao<span style="color: #339933;">&lt;</span>Item<span style="color: #339933;">&gt;</span> dao <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AbstractJpaDao<span style="color: #339933;">&lt;</span>Item<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
dao.<span style="color: #006633;">setEm</span><span style="color: #009900;">&#40;</span>em<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>now you can use this Data Access Object for your persistence stuff. </p>
<p>To now <strong>search for entities</strong> in your DB, you can use the method <strong>findByAttributes</strong> which takes a map&lt;String,String&gt; and searches for appropriate items.<br />
If your Entity looks like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">@<span style="color: #003399;">Entity</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Item <span style="color: #009900;">&#123;</span>
&nbsp;
    @Id
    @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span>, generator <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ITEM_GEN&quot;</span><span style="color: #009900;">&#41;</span>
    @SequenceGenerator<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;ITEM_GEN&quot;</span>, allocationSize<span style="color: #339933;">=</span><span style="color: #cc66cc;">25</span>, sequenceName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;item_seq&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> id<span style="color: #339933;">;</span>
&nbsp;
    @Basic
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> name<span style="color: #339933;">;</span>
&nbsp;
    @Basic
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> description<span style="color: #339933;">;</span>
&nbsp;
    @Basic
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> size<span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// constructors, getters, setters</span></pre></td></tr></table></div>

<p>you could search for an item which names contain &#8220;test&#8221; like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">&nbsp;
Map<span style="color: #339933;">&lt;</span>String,String<span style="color: #339933;">&gt;</span> attr <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hashmap<span style="color: #339933;">&lt;</span>String,String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
attr.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>, <span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
List<span style="color: #339933;">&lt;</span>Item<span style="color: #339933;">&gt;</span> results <span style="color: #339933;">=</span> dao.<span style="color: #006633;">findByAttributes</span><span style="color: #009900;">&#40;</span>attr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>which comes quite handy in my opinion. Also note, that <strong>you don&#8217;t have to pre-generate your JPA2 Model classes</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/06/jpa2-abstract-dao-criteria-query-like-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Essential Glassfish Performance Tuning Blogs</title>
		<link>http://dominikdorn.com/2010/06/essential-glassfish-performance-tuning-blogs/</link>
		<comments>http://dominikdorn.com/2010/06/essential-glassfish-performance-tuning-blogs/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 14:42:53 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=308</guid>
		<description><![CDATA[This post tries to collect a list of important links for everyone wanting to optimize his/her Glassfish v3 Server for production use.]]></description>
			<content:encoded><![CDATA[<p>In my time on the Glassfish users mailinglist, I came across some important links for everyone setting up a Glassfish server for production.</p>
<p>This is my personal bookmarks list, that may also serve its purpose to others.  </p>
<ol>
<li><a href="http://jfarcand.wordpress.com/2009/11/27/putting-glassfish-v3-in-production-essential-surviving-guide/">Putting Glassfish v3 in Production &#8211; Essential surviving Guide</a>: This post describes basic performance enhancements you can get with changing settings in your domain.xml configuration and adjusting jvm settings</li>
<li><a href="http://blogs.sun.com/binublog/entry/monitoring_in_glassfish">Monitoring in Glassfish</a>: This post shows how to further enhance the thread pool settings for your Glassfish domain and how to determine the correct settings for your system</li>
<li><a href="http://dominikdorn.com/2010/04/tomcat-glassfish-jetty-port-80-iptables-nat/">Tomcat/Glassfish/Jetty on Port 80 with IPTables + NAT</a>: This post describes, how you can run your Glassfish hosted webapps on Port 80 without running a Apache or other web server in front of it, thus you are able to fully utilize every aspect of Glassfishs new asynchronous architecture without always have to think of that old Indian making problems (Comet etc.)</li>
<li><a href="http://forums.java.net/jive/thread.jspa?messageID=474193">Blog Post on Java.net</a>: This post by user &quot;radix_zero&quot; also suggests a few other tricks, like creating multiple connection pools to the same data source or running multiple real-domains, each in a own JVM.</li>
<li><a href="http://forums.java.net/jive/thread.jspa?messageID=475828">Another Post on Java.net</a>: The thread points out that one should use distinct thread pools for each http-listener to prevent locking between the listeners</li>
</ol>
<p>This post will be updated with new additional &#038; helpful links, as soon as I get aware of them. </p>
<p><strong>Do you have interesting links? Post them in the comments!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/06/essential-glassfish-performance-tuning-blogs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access Quercus PHP-Session from Java Servlets/Filters/Beans &#8211; Part 1</title>
		<link>http://dominikdorn.com/2010/06/access-quercus-php-session-from-java-servlets-filters-beans/</link>
		<comments>http://dominikdorn.com/2010/06/access-quercus-php-session-from-java-servlets-filters-beans/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 16:06:15 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Quercus]]></category>
		<category><![CDATA[Filter]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[Session]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=302</guid>
		<description><![CDATA[This article shows how to access a PHP-Session from Java when running under Quercus - an implementation of PHP in Java which runs in any decent Servlet-Container. ]]></description>
			<content:encoded><![CDATA[<p>If you are integrating a PHP Application in your Java Environment, you&#8217;ll probably came across <a href="http://quercus.caucho.com">Quercus</a>, a <a href="http://quercus.caucho.com">Java Implementation of PHP</a> provided by <a href="http://www.caucho.com">Caucho Technologies</a>. </p>
<p>As you are moving more and more into the Servlet world, you&#8217;ll probably will be using Servlet-Filters and normal Servlets todo some tasks. </p>
<p>If you then want to access Variables in a PHP Session, here&#8217;s how to do it:</p>
<p>The Quercus PHP-Session is not stored the same way as the normal Servlet HTTP-Session is stored. Quercus uses an own Session Manager that is capable of doing all this stuff that you know from PHP, like e.g. migrating Session-IDs (to prevent session-hijacking etc.). </p>
<p>To access this Session Manager, you first have to get a hand on the <strong>QuercusContext</strong>. In the current release (4.0.7) there is no easy way to get a hand on it if you are not inside a <strong>PHPModule</strong> or a PHP-Page. Thus I simply copied <strong>com.caucho.quercus.servlet.QuercusServlet</strong> to <strong>com.caucho.quercus.servlet.DCQuercusServlet</strong> and added this line to the end of the method:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> initImpl<span style="color: #009900;">&#40;</span>ServletConfig config<span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">throws</span> ServletException
  <span style="color: #009900;">&#123;</span>
....
      <span style="color: #006633;">config</span>.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;quercusContext&quot;</span>, quercus<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>which <strong>exposes the QuercusContext as an Attribute in the ServletContext</strong>.</p>
<p>(Note: If you are running multiple <strong>QuercusServlet</strong>s in your WebApp &#8211; which you probably shouldn&#8217;t &#8211; this might will be a problem)<br />
(Note2: The package name com.caucho.quercus.servlet must be used, or else you will not have access to some package scoped properties used in the QuercusServlet)<br />
Ok, so now we have access to the <strong>QuercusContext</strong> from every <strong>Servlet</strong>, <strong>Filter</strong> or <strong>JSF-Bean</strong>, horray <img src='http://dominikdorn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>But how to use it? </p>
<p>Lets take a look at the following filter and its methods helping me to work with the PHP-Session:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoginOutFilter <span style="color: #000000; font-weight: bold;">implements</span> Filter <span style="color: #009900;">&#123;</span>
&nbsp;
    QuercusContext context<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// we store the reference to the quercusContext in the filter</span>
    FilterConfig config<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the reference to the config </span>
&nbsp;
... 
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span>FilterConfig filterConfig<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException <span style="color: #009900;">&#123;</span>
        config <span style="color: #339933;">=</span> filterConfig<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// looks up the QuercusContext the first time it is accessed</span>
    <span style="color: #666666; font-style: italic;">// Beware: will return null if no PHP page has been rendered yet and the quercusContext is not already set. </span>
    <span style="color: #000000; font-weight: bold;">private</span> QuercusContext getQuercusContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>context <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            context <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>QuercusContext<span style="color: #009900;">&#41;</span> config.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;quercusContext&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> context<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// find the PHP-Session Cookie in the array of Cookies provided by the browser</span>
    <span style="color: #000000; font-weight: bold;">public</span> Cookie findPHPSessionCookie<span style="color: #009900;">&#40;</span>Cookie<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> cookies<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Cookie c <span style="color: #339933;">:</span> cookies<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PHPSESSID&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">return</span> c<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doFilter<span style="color: #009900;">&#40;</span>ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, ServletException <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>someCondition<span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// clear a PHP-Session, e.g. when logging out a user</span>
                Cookie c <span style="color: #339933;">=</span> findPHPSessionCookie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletRequest<span style="color: #009900;">&#41;</span> servletRequest<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCookies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    QuercusSessionManager mng <span style="color: #339933;">=</span> getQuercusContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getQuercusSessionManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #003399;">String</span> phpSessionId <span style="color: #339933;">=</span> c.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    mng.<span style="color: #006633;">removeSession</span><span style="color: #009900;">&#40;</span>phpSessionId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>someOtherCondition<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        QuercusSessionManager mng <span style="color: #339933;">=</span> getQuercusContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getQuercusSessionManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        SessionArrayValue val<span style="color: #339933;">;</span>
                        Cookie c <span style="color: #339933;">=</span> findPHPSessionCookie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletRequest<span style="color: #009900;">&#41;</span> servletRequest<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCookies</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #003399;">String</span> phpSessionId<span style="color: #339933;">;</span>
                        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// we found a session cookie</span>
                            phpSessionId <span style="color: #339933;">=</span> c.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            val <span style="color: #339933;">=</span> mng.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, phpSessionId, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>val <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
                            <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// but the session does not exist on the server, so create it</span>
                                val <span style="color: #339933;">=</span> mng.<span style="color: #006633;">createSession</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, phpSessionId, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #009900;">&#125;</span>
&nbsp;
                        <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span>
                        <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">// we haven't found a php-session cookie, so create a new session</span>
                            val <span style="color: #339933;">=</span> mng.<span style="color: #006633;">createSession</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>,<span style="color: #000066; font-weight: bold;">null</span>,<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            phpSessionId <span style="color: #339933;">=</span> val.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #666666; font-style: italic;">// and store the appropriate cookie</span>
                            Cookie newCookie <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Cookie<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PHPSESSID&quot;</span>, phpSessionId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletResponse<span style="color: #009900;">&#41;</span>servletResponse<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addCookie</span><span style="color: #009900;">&#40;</span>newCookie<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
     <span style="color: #666666; font-style: italic;">// storing data in the session</span>
                      <span style="color: #003399;">String</span> username <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;myUsername&quot;</span><span style="color: #339933;">;</span>
                        val.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ludata_suserid&quot;</span>, username<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        val.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ludata_nusernr&quot;</span>, someService.<span style="color: #006633;">getUserId</span><span style="color: #009900;">&#40;</span>username<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        val.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ludata_nstatusnr&quot;</span>, someService.<span style="color: #006633;">getUserStatus</span><span style="color: #009900;">&#40;</span>username<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        val.<span style="color: #006633;">addUse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This is required for saving, else an IllegalStateException will be thrown</span>
                        mng.<span style="color: #006633;">saveSession</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The above code shows how to <strong>erase a session</strong> and how to <strong>add values to a session</strong>. To <strong>get values from a session</strong>, simply use val.get(..). </p>
<p><strong>Attention: This currently only works if the page after the filter is not a Quercus Page itself (e.g. a Servlet or a JSF Page). I&#8217;m working on a solution for this</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/06/access-quercus-php-session-from-java-servlets-filters-beans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven + JUnit + ClassFormatError: Absent Code attribute in method that is not native or abstract in class file</title>
		<link>http://dominikdorn.com/2010/05/maven-junit-classformaterror-absent-code-attribute/</link>
		<comments>http://dominikdorn.com/2010/05/maven-junit-classformaterror-absent-code-attribute/#comments</comments>
		<pubDate>Tue, 11 May 2010 19:39:29 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[servlet]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=294</guid>
		<description><![CDATA[Solutions to the Absent Code attribute problem often encountered when trying to do unit testing with Maven&#038;/JUnit.]]></description>
			<content:encoded><![CDATA[<p>Once in a while one stumbles upon an error message like this</p>
<pre>
java.lang.<strong>ClassFormatError</strong>: <strong>Absent Code attribute</strong> in method that is not native or abstract in class file javax/mail/Session
</pre>
<p>This happens if your code compiles against incomplete classes, like the JavaEE6 Api and your Unit tests try to access code thats not there. JUnit will simply fail and mark the test as error, printing something like this</p>
<pre>
Tests in error:
  initializationError(com.dominikdorn.dc.passwordReset.SimplePasswordResetServiceTest)
</pre>
<p>and the corresponding surefire text file starts like this:</p>
<pre>
-------------------------------------------------------------------------------
Test set: com.dominikdorn.dc.passwordReset.SimplePasswordResetServiceTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.022 sec <<< FAILURE!
initializationError(com.dominikdorn.dc.passwordReset.SimplePasswordResetServiceTest)  Time elapsed: 0.005 sec  <<< ERROR!
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Session
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
....
</pre>
<p><strong>The Solution</strong><br />
You have to compile against real-implementations of the classes. You do that by adding those dependencies before the most generic dependency in your pom.xml</p>
<p>As example, we add javax.mail BEFORE javaee6-api like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> ...<span style="color: #000000; font-weight: bold;">&gt;</span></span>
...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provided<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javaee-api<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>6.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provided<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>If you are deploying your App on an Appserver like Glassfish or JBoss AS, leave the scope of javax.mail:mail as provided to prevent the inclusion of the jar in the final webapp. </p>
<p>I now list required dependencies for various Absent Code Errors I've encountered and still encountering. This post will be updated every time I solve another of these problems.</p>
<p><strong>JavaMail</strong>: <strong>javax/mail/Session</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> ...<span style="color: #000000; font-weight: bold;">&gt;</span></span>
...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mail<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provided<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><strong>Servlet 3.0</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> ...<span style="color: #000000; font-weight: bold;">&gt;</span></span>
...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.glassfish<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.servlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provided<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
....   
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #808080; font-style: italic;">&lt;!-- Required until the Servlet 3.0 API can be resolved in Central --&gt;</span>     
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Glassfish<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Glassfish Maven2 Repository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://download.java.net/maven/glassfish/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><strong>JPA2</strong>: <strong>javax/persistence/PersistenceException</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>...
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.eclipse.persistence<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.persistence<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>provided<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
..
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>eclipse<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Eclipse Maven Repository<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://www.eclipse.org/downloads/download.php?r=1<span style="color: #ddbb00;">&amp;amp;</span>nf=1<span style="color: #ddbb00;">&amp;amp;</span>file=/rt/eclipselink/maven.repo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repository<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/repositories<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>more to come soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/05/maven-junit-classformaterror-absent-code-attribute/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XHTML strict &amp; OL start=&#8221;xx&#8221;</title>
		<link>http://dominikdorn.com/2010/04/xhtml-strict-ol-start/</link>
		<comments>http://dominikdorn.com/2010/04/xhtml-strict-ol-start/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 11:53:19 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[strict]]></category>
		<category><![CDATA[valid]]></category>
		<category><![CDATA[Validator]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=287</guid>
		<description><![CDATA[This little post shows how to replace the start attribute of the ol tag in XHTML STRICT pages to validate again!]]></description>
			<content:encoded><![CDATA[<p>In XHTML strict, the ol-tag does not have the attribute start. </p>
<p>To get this working again, simply create a css-class</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.counterList</span> li <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.counterList</span> li<span style="color: #3333ff;">:before </span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> counter<span style="color: #00AA00;">&#40;</span>start<span style="color: #00AA00;">&#41;</span> <span style="color: #ff0000;">&quot;. &quot;</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">counter-increment</span><span style="color: #00AA00;">:</span> start<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>and surround your list with a tag like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class='counterList&gt;
&lt;ol style=&quot;counter-reset: start 4&quot;&gt;
&lt;li&gt;this will be item 5&lt;/li&gt;
&lt;li&gt;this will be item 6&lt;/li&gt;
...
&lt;/ol&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>I got this idea from http://www.timrivera.com/tests/ol-start.html </p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/04/xhtml-strict-ol-start/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CDI/Weld manual lookup</title>
		<link>http://dominikdorn.com/2010/04/cdi-weld-manual-bean-lookup/</link>
		<comments>http://dominikdorn.com/2010/04/cdi-weld-manual-bean-lookup/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 18:04:28 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF2]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=279</guid>
		<description><![CDATA[This post describes how to manually lookup beans in a CDI / Weld managed environment when you are somewhere where a simple @Inject does not work because the object itself is not managed by CDI / Weld. ]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;re ended up in a situation, where you are somewhere (e.g. a javax.faces.Converter) where you are <strong>unable to simple @Inject SomeClass</strong> ? </p>
<p>I had the problem, that I had a FacesConverter like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.ManagedBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.enterprise.context.RequestScoped</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.component.UIComponent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.context.FacesContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.convert.Converter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.convert.FacesConverter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
@FacesConverter<span style="color: #009900;">&#40;</span>forClass <span style="color: #339933;">=</span> AvailableCountry.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
@ManagedBean <span style="color: #666666; font-style: italic;">// does not help :(</span>
@RequestScoped <span style="color: #666666; font-style: italic;">// does not help :(</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AvailableCountryConverter <span style="color: #000000; font-weight: bold;">implements</span> Converter
<span style="color: #009900;">&#123;</span>
	@Inject
	AvailableCountryDao dao<span style="color: #339933;">;</span>
&nbsp;
	@PostConstruct
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> postConstruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;calling postConstruct&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> getAsObject<span style="color: #009900;">&#40;</span>FacesContext facesContext, UIComponent
			component, <span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> value.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> dao.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>getKey<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003399;">Long</span> getKey<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Long</span> key<span style="color: #339933;">;</span>
		key <span style="color: #339933;">=</span> <span style="color: #003399;">Long</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> key<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003399;">String</span> getStringKey<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">StringBuffer</span> sb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getAsString<span style="color: #009900;">&#40;</span>FacesContext facesContext, UIComponent
			component, <span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #000000; font-weight: bold;">instanceof</span> AvailableCountry<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			AvailableCountry o <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AvailableCountry<span style="color: #009900;">&#41;</span> object<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> getStringKey<span style="color: #009900;">&#40;</span>o.<span style="color: #006633;">getCountry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;object &quot;</span> <span style="color: #339933;">+</span> object <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;
					is of type &quot;</span> <span style="color: #339933;">+</span> object.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; expected type: &quot;</span> <span style="color: #339933;">+</span>
					AvailableCountry.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>But my <strong>DAO was <u>not</u> injected</strong>, nor was the postConstruct method triggered by CDI.</p>
<p>Why?<br />
<strong>Because the bean is not managed by CDI</strong>, not even when annotating it with @ManagedBean because it gets created by the JSF-Lifecycle and not by CDI. </p>
<p>Well.. but <strong>how to manually lookup a Bean with CDI / Weld? </strong></p>
<p>First, you need to get the <strong>BeanManager</strong>. When you have a <strong>FacesContext</strong> (like in the converter above), you can get it like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> BeanManager getBeanManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>BeanManager<span style="color: #009900;">&#41;</span> 
              <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ServletContext<span style="color: #009900;">&#41;</span> facesContext.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                   .<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.enterprise.inject.spi.BeanManager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you don&#8217;t have access to a FacesContext, ServletContext or similar, you can<strong> lookup the BeanManager through JNDI</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> BeanManager getBeanManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">InitialContext</span> initialContext <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InitialContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>BeanManager<span style="color: #009900;">&#41;</span> initialContext.<span style="color: #006633;">lookup</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java:comp/BeanManager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NamingException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Couldn't get BeanManager through JNDI&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>After you&#8217;ve got your <strong>BeanManager</strong>, simply <strong>lookup</strong> your Bean like this:<br />
(In my case, I wanted to lookup a bean with the type AvailableCountryDao)<br />
<strong>Type-based CDI manual lookup</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> AvailableCountryDao getFacade<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        BeanManager bm <span style="color: #339933;">=</span> getBeanManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Bean<span style="color: #339933;">&lt;</span>AvailableCountryDao<span style="color: #339933;">&gt;</span> bean <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Bean<span style="color: #339933;">&lt;</span>AvailableCountryDao<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> bm.<span style="color: #006633;">getBeans</span><span style="color: #009900;">&#40;</span>AvailableCountryDao.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CreationalContext<span style="color: #339933;">&lt;</span>AvailableCountryDao<span style="color: #339933;">&gt;</span> ctx <span style="color: #339933;">=</span> bm.<span style="color: #006633;">createCreationalContext</span><span style="color: #009900;">&#40;</span>bean<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        AvailableCountryDao dao <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AvailableCountryDao<span style="color: #009900;">&#41;</span> bm.<span style="color: #006633;">getReference</span><span style="color: #009900;">&#40;</span>bean, AvailableCountryDao.<span style="color: #000000; font-weight: bold;">class</span>, ctx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this could be inlined, but intentionally left this way</span>
        <span style="color: #000000; font-weight: bold;">return</span> dao<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Thanks to my friend <a href="http://ocpsoft.com/">Lincoln Baxter, III</a> for the snipped. </p>
<p><strong>Name-based CDI manual lookup</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> getBeanByName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// eg. name=availableCountryDao</span>
    <span style="color: #009900;">&#123;</span>
        BeanManager bm <span style="color: #339933;">=</span> getBeanManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Bean bean <span style="color: #339933;">=</span> bm.<span style="color: #006633;">getBeans</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CreationalContext ctx <span style="color: #339933;">=</span> bm.<span style="color: #006633;">createCreationalContext</span><span style="color: #009900;">&#40;</span>bean<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// could be inlined below</span>
        <span style="color: #003399;">Object</span> o <span style="color: #339933;">=</span> bm.<span style="color: #006633;">getReference</span><span style="color: #009900;">&#40;</span>bean, bean.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, ctx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// could be inlined with return</span>
        <span style="color: #000000; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So, now you&#8217;re able to manually lookup beans with CDI.<br />
In case you have the same problem (with Converters/Validators) like I had above, checkout <a href="http://seamframework.org/Seam3/FacesModule">Seam Faces</a>, where this <strong>problem already is fixed</strong>,<br />
meaning your <strong>@ManagedBean annotated Converter/Validator is working as expected with @Inject, @PostConstruct &#038; @PreDestroy</strong> <img src='http://dominikdorn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/04/cdi-weld-manual-bean-lookup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tomcat/Glassfish/Jetty on Port 80 with IPTables</title>
		<link>http://dominikdorn.com/2010/04/tomcat-glassfish-jetty-port-80-iptables-nat/</link>
		<comments>http://dominikdorn.com/2010/04/tomcat-glassfish-jetty-port-80-iptables-nat/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 20:24:19 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[jboss as]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=260</guid>
		<description><![CDATA[If you &#8211; like me &#8211; have the problem, that you need to run Tomcat or Glassfish or any other Java Webserver on Port 80, this might come handy for you: The problem: Tomcat, Jetty, Glassfish, JBoss AS etc. .. they all run on unprivileged ports &#62; 1024, defaulting to 8080. If you want to [...]]]></description>
			<content:encoded><![CDATA[<p>If you &#8211; like me &#8211; have the problem, that you need to run Tomcat or Glassfish or any other Java Webserver on Port 80, this might come handy for you:</p>
<p>The problem:<br />
Tomcat, Jetty, Glassfish, JBoss AS etc. .. they all run on unprivileged ports &gt; 1024, defaulting to 8080.</p>
<p>If you want to run them on port 80, you have several choices:<br />
- front them with Apache<br />
- front them with Squid<br />
- use some tools like authbind, etc.<br />
- use IPTables magic (which we will describe here)</p>
<p>Primitive IPTables solution:<br />
This solution comes from the blog entry &#8221; <a href="http://rifers.org/wiki/display/RIFE/Installing+Tomcat+on+port+80+with+iptables">Installing Tomcat on port 80 with iptables</a> &#8221;<br />
You have to compile NAT support into your kernel and use an iptables rule like this one</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-I</span> PREROUTING <span style="color: #660033;">--src</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--dst</span> <span style="color: #007800;">$yourip</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> REDIRECT <span style="color: #660033;">--to-ports</span> <span style="color: #000000;">8080</span></pre></div></div>

<p>which redirects all incoming traffic on port 80 on $yourip (e.g. 74.125.39.99) to port 8080 on the local machine.<br />
If your webserver listens only to 127.0.0.1 this is all you need to be save.</p>
<p>However, I have a bit a different setup:</p>
<p>- Two networks with different providers (4mbit e.g. 74.125.39.99, 12mbit e.g. 98.137.149.56 )<br />
- Two servers, one of them quite small powered (pentium4 on the 4mbit line), the other quite strong (dual quad core 2ghz on the 12mbit line)<br />
- Glassfish on the strong server<br />
- DNS load balancing for the domain<br />
- both servers should map to the same glassfish instance.<br />
- the servers are connected through a direct link with private IP-addresses (10.x.x.x range)<br />
- Glassfish binds only to the private IP-Address of the strong server, meaning 10.0.100.10:8080<br />
- both 74.125.39.99:80 and 98.137.149.56:80 should redirect the traffic to 10.0.100.10:8080</p>
<p>Here&#8217;s how I&#8217;ve done it (I got some inspiration from this <a href="http://www.linuxquestions.org/questions/linux-security-4/iptables-nat-port-forwarding-rule-set-492758/">linux questions forum entry</a>):</p>
<p>On the &#8220;strong&#8221; server</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#this forwards traffic to the internal ip</span>
iptables <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-d</span> 74.125.39.99<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> DNAT <span style="color: #660033;">--to</span> 10.0.100.10:<span style="color: #000000;">8080</span>
<span style="color: #666666; font-style: italic;">#this allows traffic on the external interface on port 80</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-d</span> 74.125.39.99<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #666666; font-style: italic;">#this allows traffic on the internal ip on port 8080</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-d</span> 10.0.100.10<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">8080</span> <span style="color: #660033;">-j</span> ACCEPT</pre></div></div>

<p>nearly the same on the &#8220;weaker&#8221; server</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#this forwards traffic to the internal ip</span>
iptables <span style="color: #660033;">-A</span> PREROUTING <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-d</span> 74.125.39.99<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> DNAT <span style="color: #660033;">--to</span> 10.0.100.10:<span style="color: #000000;">8080</span>
<span style="color: #666666; font-style: italic;">#this allows traffic on the external interface on port 80</span>
iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-d</span> 98.137.149.56<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-m</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-j</span> ACCEPT</pre></div></div>

<p>That&#8217;s it!</p>
<p>Perfectly save, perfectly scalable glassfish v3 (no apache bottleneck in your comet apps!)</p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/04/tomcat-glassfish-jetty-port-80-iptables-nat/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>File Templates for web.xml &amp; web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)</title>
		<link>http://dominikdorn.com/2010/03/web-xml-web-fragment-xml-2-3-2-4-2-5-3-0/</link>
		<comments>http://dominikdorn.com/2010/03/web-xml-web-fragment-xml-2-3-2-4-2-5-3-0/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 12:20:55 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=254</guid>
		<description><![CDATA[Here you'll find the web.xml headers for servlet 2.3, 2.4, 2.5 and 3.0 + web-fragment.xml for servlet 3.0]]></description>
			<content:encoded><![CDATA[<p>As I sometimes need these, I have compiled a list of the valid headers of the web.xml and web-fragment.xml file for servlet version 2.3 until 3.0.<br />
Maybe you find them as handy as I do.</p>
<p>web.xml v2.3</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;ISO-8859-1&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>web.xml v2.4</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;WebApp_9&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.4&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>web.xml v2.5</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>web.xml v3.0</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span></span>
<span style="color: #009900;">        <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;3.0&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>web-fragment.xml:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-fragment</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;</span>
<span style="color: #009900;">        http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;3.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-fragment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/03/web-xml-web-fragment-xml-2-3-2-4-2-5-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using complex urls &amp; regular expressions with PrettyFaces</title>
		<link>http://dominikdorn.com/2010/03/complex-urls-regular-expressions-validators-prettyfaces/</link>
		<comments>http://dominikdorn.com/2010/03/complex-urls-regular-expressions-validators-prettyfaces/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 20:15:24 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF2]]></category>
		<category><![CDATA[PrettyFaces]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Validator]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=249</guid>
		<description><![CDATA[In this post you will learn how to match complex urls with regular expressions and PrettyFaces in JSF2 Web Applications.]]></description>
			<content:encoded><![CDATA[<p>If you like to construct complex &#038; pretty urls with JSF2 &#038; PrettyFaces, you might be interested in the following few lines of code.</p>
<p>In our example, we want to match a URL like this one</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">http://www.studyguru.eu/at/tuwien/184.153--Entwurfsmethoden-fuer-verteilte-Systeme</pre></td></tr></table></div>

<p>Previously I tried to match it with a PrettyFaces Pattern/Regex like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/([a-z]{2})/([a-z0-9\-_]*)/([a-z0-9\-_\.]*)\-\-.*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>But thankfully, PrettyFaces >2.0.4 supports directly populating the RequestParams! </p>
<p>Configure your pretty-config like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pretty-config</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces/2.0.4&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces/2.0.4</span>
<span style="color: #009900;">                http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-2.0.4.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
....
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;coursePage&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/#{countryCode}/#{uniShortName}/#{courseId}--.*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/path/to/coursePage.xhtml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
....</pre></td></tr></table></div>

<p>and use JSF2&#8242;s viewParams like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE html</span>
<span style="color: #00bbdd;">        PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">        &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #000066;">xml:lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:h</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/html&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:f</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/core&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:pretty</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/facelets&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:p</span>=<span style="color: #ff0000;">&quot;http://primefaces.prime.com.tr/ui&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:metadata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:viewParam</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;countryCodeId&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">requiredMessage</span>=<span style="color: #ff0000;">&quot;Kein Land spezifiziert&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;countryCode&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.countryCode}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:validateRegex</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;([a-z]{2})&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:viewParam<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:viewParam</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;universityCodeId&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">requiredMessage</span>=<span style="color: #ff0000;">&quot;Keine Hochschule spezifiziert&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;uniShortName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.universityCode}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:validateRegex</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;([a-z0-9\-_]*)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:viewParam<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:viewParam</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;courseIdId&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">requiredMessage</span>=<span style="color: #ff0000;">&quot;Keine KursId spezifiziert&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;courseId&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.courseId}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:validateRegex</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;([a-z0-9\-_\.]*)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:viewParam<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:event</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;preRenderView&quot;</span> <span style="color: #000066;">listener</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.populate}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:metadata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>coursePage<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
countryCode #{ coursePageBean.countryCode} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
courseId #{coursePageBean.courseId}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
universityCode #{coursePageBean.universityCode}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Voila! You now can match complex urls with PrettyFaces and apply all your custom validators<br />
to your Pretty URL <img src='http://dominikdorn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/03/complex-urls-regular-expressions-validators-prettyfaces/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
