<?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>info.michael-simons.eu &#187; J2EE</title>
	<atom:link href="http://info.michael-simons.eu/tag/j2ee/feed/" rel="self" type="application/rss+xml" />
	<link>http://info.michael-simons.eu</link>
	<description>Just another nerd blog</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:26:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Some random Grails thoughts and tipps</title>
		<link>http://info.michael-simons.eu/2008/12/04/some-random-grails-thoughts-and-tipps/</link>
		<comments>http://info.michael-simons.eu/2008/12/04/some-random-grails-thoughts-and-tipps/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 10:46:33 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[English posts]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=236</guid>
		<description><![CDATA[Lately i&#8217;ve been rambling and ranting a lot on twitter about the Grails framework. To my surprise, many other developers actually read this tweets and helped me out on some problems. Thanks a lot gals and guys, i really appreciate that. Me rambling isn&#8217;t meant to be personal at any time, i guess you know [...]]]></description>
			<content:encoded><![CDATA[<p>Lately i&#8217;ve been rambling and ranting a lot on twitter about the <a href="http://grails.org/">Grails</a> framework.</p>
<p>To my surprise, many other developers actually read this tweets and helped me out on some problems. Thanks a lot gals and guys, i really appreciate that. Me rambling isn&#8217;t meant to be personal at any time, i guess you know how easily one gets frustrated with too less time and too much stuff to do.</p>
<p>Anyway, here are some shortcuts that could eventually be helpful. I&#8217;m gonna add more to this list the next days:</p>
<h3>Enabling hibernate filters in the grails session</h3>
<p>Took me a little digging through the source code, but i came up with the following idea:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">org.springframework.transaction.support.TransactionSynchronizationManager</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> SecurityFilters <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">def</span> sessionFactory
  <span style="color: #000000; font-weight: bold;">def</span> filters <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span>
    login<span style="color: #66cc66;">&#40;</span>controller:<span style="color: #ff0000;">'*'</span>, action:<span style="color: #ff0000;">'*'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      before <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// get your user id somewhere</span>
        <span style="color: #000000; font-weight: bold;">def</span> whatsoeveruserId <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>
        <span style="color: #000000; font-weight: bold;">def</span> sessionHolder <span style="color: #66cc66;">=</span>  TransactionSynchronizationManager.<span style="color: #006600;">getResource</span><span style="color: #66cc66;">&#40;</span>sessionFactory<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>     
        sessionHolder.<span style="color: #006600;">getSession</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">enableFilter</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;filterByOwner&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">setParameter</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;currentUserId&quot;</span>, whatsoeveruserId<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>I want to have some kind of rowlevel security through a Hibernate filter. Through dependency injection i get hold of the sessionFactory and through the TA Manager, i get the current session on which i can enable my filter.</p>
<p>Doing this in a Grails filter, i can combine this with some kinda login mechanism and i&#8217;m good to go.</p>
<h3>Whitelisting attributes through bindData</h3>
<p>To me it&#8217;s a bad idea using blacklisting on data binding as i can and will forget attributes that must not be updated through a webform.</p>
<p>With <a href="http://www.anyware.co.uk/2005/">Marc</a> i found the following solution:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">bindData<span style="color: #66cc66;">&#40;</span>entity, params, entity.<span style="color: #006600;">properties</span>.<span style="color: #663399;">collect</span><span style="color: #66cc66;">&#123;</span>it.<span style="color: #006600;">key</span><span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">-</span> <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'foo'</span>, <span style="color: #ff0000;">'bar'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>That way only attributes foo and bar gets updated.</p>
<p>Anyway, with Grails 1.1 this won&#8217;t be necessary anymore as Graeme <a href="http://graemerocher.blogspot.com/2008/10/new-gorm-features-coming-in-11.html">anonced</a>.</p>
<p><ins datetime="2008-12-04T12:55:33+00:00">Graeme was so kind to comment on this: This feature is already in 1.0.x, i just didn&#8217;t find it, have a look at the docu at <a href="http://grails.org/doc/1.1/guide/6.%20The%20Web%20Layer.html#6.1.6%20Data%20Binding">The Web Layer</a>.</ins></p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">bindData<span style="color: #66cc66;">&#40;</span>entity, params,  <span style="color: #66cc66;">&#91;</span>include:<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'foo'</span>, <span style="color: #ff0000;">'bar'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p><ins datetime="2008-12-09T12:31:41+00:00">Updates on 2008/12/9</ins></p>
<h3>Adding custom errors to a domain class</h3>
<p>The grails reference has a handy example for adding custom errors to domain classes, have a look <a href="http://grails.org/doc/1.0.x/ref/Domain%20Classes/errors.html">here</a>. This works quite well except that all other errors from databinding are mysteriously gone. </p>
<p>For me, the following steps worked to update a user (change some persistent attributes and the transient attributes password and passwordConfirmation):</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">bindData<span style="color: #66cc66;">&#40;</span>anwender, params, <span style="color: #66cc66;">&#91;</span>include:<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'name'</span>, <span style="color: #ff0000;">'vorname'</span>, <span style="color: #ff0000;">'password'</span>, <span style="color: #ff0000;">'passwordConfirmation'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>params.<span style="color: #006600;">password</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">&amp;&amp;</span> params.<span style="color: #006600;">password</span> <span style="color: #66cc66;">==</span> params.<span style="color: #006600;">passwordConfirmation</span><span style="color: #66cc66;">&#41;</span>
  anwender.<span style="color: #006600;">hashPassword</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// As alway, never ever store plaintext passwords ;)</span>
<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>params.<span style="color: #006600;">password</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  anwender.<span style="color: #006600;">validate</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// IMPORTANT without that step, possible other errors from bindData vanished</span>
  anwender.<span style="color: #006600;">errors</span>.<span style="color: #006600;">rejectValue</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'password'</span>, <span style="color: #ff0000;">'user.anwender.passwords_doesnotmatch'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Afterwords, hasErrors() show all errors, i.a. non nullable fields and the like.</p>
<h3>More thoughts</h3>
<p>I somewhat used to hibernate and come along very well with it, even though i&#8217;m actually a SQL fan. I guess if my inside into the Spring Framework would be a little bit deeper, some areas wouldn&#8217;t be hard to understand.</p>
<p>On the other hand i think that Grails does a great job for J2EE based development and it should do so even more. As always, there is the <a href="http://info.michael-simons.eu/2006/04/22/the-law-of-leaky-abstractions/">law of leaky abstractions</a>, but the whole butload of stuff that is the J2EE stack should be abstracted away.</p>
<p><ins datetime="2009-02-06T09:00:00+00:00">Updates on 2009/2/6</ins></p>
<h3>Grails 1.1-beta3</h3>
<p>I use hibernate validator in my domain classes (that i created outside of rails as hibernate annotated classes) and i got</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">NoSuchMethodError</span><span style="color: #339933;">:</span> org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">event</span>.<span style="color: #006633;">PreInsertEvent</span>.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>Lorg<span style="color: #339933;">/</span>hibernate<span style="color: #339933;">/</span>engine<span style="color: #339933;">/</span>SessionImplementor</pre></div></div>

<p>on every insert and update. Hibernate validator 3.0.0.GA is incompatible with the Hibernate version in Grails 1.1-beta3. Problem was gone after upgrading validator to 3.1.0.GA.</p>
<p>Some other stuff:</p>
<ul>
<li>
Installed plugins are obviously gone. i.e yui plugin is still in the application folder, it needs to be reinstalled after upgrade (<i>grails install-plugin yui</i>)</p>
<p>Ok, i see  this was done on purpose: &#8220;Plugins are now stored in your USER_HOME directory. You will need to re-install your plugins or run&#8221; (from the beta2 release note). Not a good decision making this a default imho. I like having my apps pinned to specific plugins.
</li>
<li>The message method for doing I18n in controllers used to be available in filters. This method seems to be gone. No solution for that so far.</li>
<li><del>Values not bound in a form are not null anymore but 0 in case of numeric values. Bummer!</del> Actually my bad.</li>
<li><a href="http://info.michael-simons.eu/2009/02/12/grails-hibernate-current-session-context/">Some problems solved.</li>
</ul>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=236&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_236" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2008/12/04/some-random-grails-thoughts-and-tipps/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Tired of all the powerpoint presentations&#8230;</title>
		<link>http://info.michael-simons.eu/2008/04/23/tired-of-all-the-powerpoint-presentations/</link>
		<comments>http://info.michael-simons.eu/2008/04/23/tired-of-all-the-powerpoint-presentations/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 13:20:47 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[English posts]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[JAX]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Powerpoint]]></category>
		<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/?p=163</guid>
		<description><![CDATA[Right now i&#8217;m in Wiesbaden, attending the JAX 2008 conference. The mood is somewhat different compared to the DOAG i used to visit the last years. The people are more open minded, partially much younger and generally try to be much cooler. And for the sake of it, some are even more interesting and after [...]]]></description>
			<content:encoded><![CDATA[<p>Right now i&#8217;m in Wiesbaden, attending the <a href="http://www.jax.de">JAX 2008</a> conference.</p>
<p>The mood is somewhat different compared to the <a href="http://www.doag.org">DOAG</a> i used to visit the last years. The people are more open minded, partially much younger and generally try to be much cooler. And for the sake of it, some are even more interesting and after all, there isn&#8217;t that ongoing whining about Oracle not engaging in Forms 6i Client Server any more (although, i must admit, i somewhat like <a href="/tag/oracle-forms/">Oracle Forms</a> 6i, maybe it&#8217;s a love/hate relationship, trust me, i know both worlds, Java and Forms).</p>
<p>The sessions suffer from one big problem: Many of them just seem to play <em>powerpoint karaoke</em>: Throw in a bunch of crappy slides with a handfull code snippets and sing-a-long to that stuff which means basically: Hind behind the slides.</p>
<p>Let me tell you: This is so boring and pointless. In the past i tried to be polite and always stayed to the end of a session but the last 2 or 3 conferences i can&#8217;t stand it any more. I can read myself, thanks. If you haven&#8217;t got anything additionally to say, just pass me the slide and i&#8217;m fine.</p>
<p>The 3 most interesting sessions where the sessions spoken freely with the slides just illustrating the speech. I especially liked <a href="http://liferay.com/web/bchan/home">Brian Chans</a> presentation of <em>Liferay Portal</em>, <a href="http://blog.springsource.com/main/author/rodj/">Rod Johnsons</a> keynote on the future of J2EE and the most witty one, <a href="http://blogs.tedneward.com/">Ted Newards</a> talk about the renaissance of languages. It was funny, included the audience, was well prepared and freely hold, not to forget the topic: It wasn&#8217;t about the nth framework around the corner but about the nearly philosophy topic about the &#8220;perfect programming language&#8221;.</p>
<p>I really wish that i&#8217;d be creative and intelligent enough to design a language that is not predestined to die an early death, but i ain&#8217;t. But i can distinguish a sharp tool from a spoon if i see one and i can adopt to it very easily. And in that sense i share Teds opinion that a discussion about abstracting things and about the tool itself is of much more value than implementing some arbitrary pattern (i.e. one be the GOF) in just another framework. For example, many implementations of some patterns in frameworks have been rendered obsolete by more powerful and more expressive languages and i&#8217;d like to see this trend go on.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=163&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_163" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2008/04/23/tired-of-all-the-powerpoint-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails and Grails revisited</title>
		<link>http://info.michael-simons.eu/2007/06/25/rails-and-grails-revisited/</link>
		<comments>http://info.michael-simons.eu/2007/06/25/rails-and-grails-revisited/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 17:54:30 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[J2EE]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/2007/06/25/rails-and-grails-revisited/</guid>
		<description><![CDATA[I&#8217;ve never thought that my little little post would made such an impact. While writing that post i was frustrated explaining the Spring configuration to my colleaques again, i was frustrated over the url mappings and so the post was a little harsh. I don&#8217;t think that Hibernate is inferior to Active Record, regarding Spring [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never thought that my little <a href="http://info.michael-simons.eu/2007/06/21/ruby-on-rails-the-java-way-grails/">little post</a> would made such an impact.</p>
<p>While writing that post i was frustrated explaining the Spring configuration to my colleaques again, i was frustrated over the url mappings and so the post was a little harsh.</p>
<p>I don&#8217;t think that Hibernate is inferior to Active Record, regarding Spring and ActionController, i cannot tell, i like ActionController just better.</p>
<p>Anyhow, bring all three parts, model, view and controller, together&#8230; And see where Rails shines: In ease of use and working right out of the box. No wonder they came up with this whole screencasting things (at least, i never saw this before), it&#8217;s just impressing.</p>
<p>Instead of pushing out framework after framework, view technology after view technology (Faces, ADF, etc.), they bundled working things together and i think that&#8217;s what people like about RoR.</p>
<p>And i guess there&#8217;s a need for such think on the Java side of life as well&#8230; If not, why is the <a href="http://grails.org">Grailsteam</a> working on Grails? To paraphrase my last post positive: They bring good things in a nice package together.</p>
<p>For getting me into groovy i must thank the people behind Grails, this stuff is really cool.</p>
<p>For further reading i recommend the following posts:</p>
<ul>
<li><a href="http://graemerocher.blogspot.com/2007/06/grails-vs-rails-myth-1-grails-has.html">Grails vs Rails Myth #1: Grails has a fraction of what Rails has to offer</a></li>
<li><a href="http://weblog.masukomi.org/2007/6/22/grails-functionality-vs-rails-functionality">Grails functionality Vs Rails functionality</a></li>
<li><a href="http://www.stonemind.net/blog/2007/06/25/weighing-in-on-rails-vs-grails/">Weighing in on Rails vs. Grails.</a></li>
</ul>
<p>Apart from this, can please anyone assure me, that some of the questions on the SCJP exam are a little weird and not really from this world? <img src='http://info.michael-simons.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=98&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_98" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2007/06/25/rails-and-grails-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kaputte UTF-8 Daten im Servlet</title>
		<link>http://info.michael-simons.eu/2006/10/05/kaputte-utf-8-daten-im-servlet/</link>
		<comments>http://info.michael-simons.eu/2006/10/05/kaputte-utf-8-daten-im-servlet/#comments</comments>
		<pubDate>Thu, 05 Oct 2006 09:31:09 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/2006/10/05/kaputte-utf-8-daten-im-servlet/</guid>
		<description><![CDATA[Beruflich habe ich gerade mit einer Webanwendung zu tun, die mit Spring realisiert ist. Spring macht ähnlich viel Spaß wie Ruby und ist bis jetzt das erste J2EE Framework, dass mir von Anfang zusagte und es auch schaffte, mich zu begeistern. Die Webanwendung ist komplett UTF-8 basiert. Soweit so gut. Leider mußte ich feststellen, dass [...]]]></description>
			<content:encoded><![CDATA[<p>Beruflich habe ich gerade mit einer Webanwendung zu tun, die mit <a href="http://springframework.org/">Spring</a> realisiert ist. Spring macht ähnlich viel Spaß wie Ruby und ist bis jetzt das erste J2EE Framework, dass mir von Anfang zusagte und es auch schaffte, mich zu begeistern.</p>
<p>Die Webanwendung ist komplett UTF-8 basiert. Soweit so gut. Leider mußte ich feststellen, dass Eingaben per form nicht so ankamen, wie ich mir das vorgestellt hatte, irgendwo ging das Characterset verloren.</p>
<p>Ich nutze zur Zeit Java 1.5.0.8, Apache Tomcat 5.5.17, Spring 1.2.8 sowie Hibernate 3.1.x. Irgendwo im Zusammenspiel der ersten drei Komponenten trat der Fehler auf, obwohl ich in allen beteiligten JSP Dateien den Content Type angegeben habe. Ich habe mir jetzt mit folgenden Filter beholfen, der dafür sorgt, dass UTF-8 auch als solches ankommt:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">filter</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Filter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.FilterChain</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.FilterConfig</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CharsetFilter <span style="color: #000000; font-weight: bold;">implements</span> Filter <span style="color: #009900;">&#123;</span>
	FilterConfig config<span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> encoding <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * @see javax.servlet.Filter#destroy()
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> destroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Sets the character encoding on the request
	 * @see javax.servlet.Filter#doFilter(javax.servlet.Servle tRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */</span>
	<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 request, ServletResponse response,
			FilterChain chain<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>
		request.<span style="color: #006633;">setCharacterEncoding</span><span style="color: #009900;">&#40;</span>encoding<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		chain.<span style="color: #006633;">doFilter</span><span style="color: #009900;">&#40;</span>request, response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConf ig)
	 */</span>
	<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 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: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">config</span> <span style="color: #339933;">=</span> config<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">encoding</span> <span style="color: #339933;">=</span> config.<span style="color: #006633;">getInitParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;requestEncoding&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Der Filter kann im web.xml einfach konfiguriert werden:</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;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		charsetFilter
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		filter.CharsetFilter
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>requestEncoding<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UTF-8<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>charsetFilter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-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-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/app/html/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p class="akst_link"><a href="http://info.michael-simons.eu/?p=39&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_39" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2006/10/05/kaputte-utf-8-daten-im-servlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring und JNDI Datasources</title>
		<link>http://info.michael-simons.eu/2006/09/21/spring-und-jndi-datasources/</link>
		<comments>http://info.michael-simons.eu/2006/09/21/spring-und-jndi-datasources/#comments</comments>
		<pubDate>Thu, 21 Sep 2006 07:44:12 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Webdevelopment]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Tipps]]></category>

		<guid isPermaLink="false">http://info.michael-simons.eu/2006/09/21/spring-und-jndi-datasources/</guid>
		<description><![CDATA[Ich nutze gerade das J2EE Framework Spring zusammen mit Hibernate und Oracle für eine Webanwendung. Die Hibernate DataSource kann entweder über eine DriverManagerDataSource und Angabe der Verbindungsparameter innerhalb der Webanwendung gesteuert werden, oder es kann eine JNDI Datasource des Application Containers (in dem Fall Tomcat) genutzt werden: &#60;bean id=&#34;serverDataSource&#34; class=&#34;org.springframework.jndi.JndiObjectFactoryBean&#34;&#62; &#60;property name=&#34;jndiName&#34; value=&#34;java:comp/env/jdbc/blah&#34;/&#62; &#60;/bean&#62; Der [...]]]></description>
			<content:encoded><![CDATA[<p>Ich nutze gerade das J2EE Framework Spring zusammen mit Hibernate und Oracle für eine Webanwendung. </p>
<p>Die Hibernate DataSource kann entweder über eine DriverManagerDataSource und Angabe der Verbindungsparameter innerhalb der Webanwendung gesteuert werden, oder es kann eine JNDI Datasource des Application Containers (in dem Fall Tomcat) genutzt werden:</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;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;serverDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jndiName&quot;</span>  <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;java:comp/env/jdbc/blah&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Der Trick dabei ist, den vollständigen Namen der DataSource anzugeben, also &#8220;java:comp/env/jdbc/blah&#8221; statt &#8220;jdbc/blah&#8221;, ansonsten bekommt nur &#8220;javax.naming.NameNotFoundException: Name jdbc is not bound in this Context&#8221; um die Ohren geschlagen, auch wenn man die DataSource im Tomcat konfiguriert hat.</p>
<p>Bah, das sowas immer soviel Zeit kosten muss&#8230;.</p>
<p class="akst_link"><a href="http://info.michael-simons.eu/?p=37&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_37" class="akst_share_link " rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://info.michael-simons.eu/2006/09/21/spring-und-jndi-datasources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.761 seconds -->

