<?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>TechJava&#187; TechJava &#8211; Articles tagged by jee</title>
	<atom:link href="http://www.techjava.de/topics/tag/jee/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techjava.de</link>
	<description>Journal on Java Technology</description>
	<lastBuildDate>Thu, 17 Jun 2010 10:41:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JSF 2.0 Reality Check</title>
		<link>http://www.techjava.de/topics/2010/02/jsf-2-reality-check/</link>
		<comments>http://www.techjava.de/topics/2010/02/jsf-2-reality-check/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 21:50:42 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[enterprise systems]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[bean]]></category>
		<category><![CDATA[cdi]]></category>
		<category><![CDATA[di]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[jsf 2.0]]></category>
		<category><![CDATA[jsr 303]]></category>
		<category><![CDATA[jsr 330]]></category>
		<category><![CDATA[managed baen]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=632</guid>
		<description><![CDATA[
Abstract
The JavaServer Faces (JSF) 2.0 is the newest Java presentation technology that is covered in JSR-314 and was publicly released on July 01, 2009. It became a part of the JEE6 standard and can be comfortably used in conjunction with other JEE frameworks, with Spring or just on its own. This article reveals the possible [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: right; margin-left:5px;" title="check" src="http://www.techjava.de/wp-content/uploads/check-150x150.jpg" alt="" width="150" height="150" /></p>
<h2>Abstract</h2>
<p>The JavaServer Faces (JSF) 2.0 is the newest Java presentation technology that is covered in JSR-314 and was publicly released on July 01, 2009. It became a part of the JEE6 standard and can be comfortably used in conjunction with other JEE frameworks, with Spring or just on its own. This article reveals the possible scenarios and shows the required configuration for the usage of JSF 2.0 with EJB 3.1 and with Spring 3.0. It also discusses several auxilary technologies which can be used along with JSF 2.0. <span id="more-632"></span></p>
<h2>Management Summary</h2>
<p>There are many presentation frameworks available, so why JSF 2.0? The short answer is simple: it has an extensible component-oriented presentation layer and event-driven programming model, which both abstract from HTML/JS and leverage the developement. In more detail, the most important features are:</p>
<ul>
<li>Facelet Support</li>
<li>Validation &amp; Conversion Mechanisms</li>
<li>Resources Support</li>
<li>Templating</li>
<li>Expression Language</li>
<li>Annotation Support</li>
</ul>
<p>JSF 2.0 makes strong use of the SoC (Separation of Concerns) principle, promoting the MVC (Model View Controller) design pattern. Its declarative view is based on facelets: the view documents can be defined using XHTML. These documents build their own component tree from the core or third-party components. The use of special composition elements allows effective templating. The model or/and the controller are realized using so called backing beans / managed beans. A backing bean is an annotated POJO (Plain Old Java Object). The access from the view to the backing beans is possible using the expression language. The navigation can be influenced directly from the view or from the backing beans, by pointing to the logical names of the pages. JSF offers a flexible validation model, which suports Bean Validation (JSR 303) out of the box.</p>
<h2>Presentation with JSF 2.0</h2>
<p>This chapter discusses the model of the presentation used in JSF 2.0.</p>
<h3>Initial setup</h3>
<p>A JSF project is an ordinary Java Web project. The result of it runs inside of a web container, like Tomcat or Jetty. A characteristical descriptor has to contain the servlet definitions/mappings of the JSF servlet and third-party component servlets.  Here is an exammple for JSF 2.0 and Prime Faces, an open-source component library.</p>
<pre class="brush: xml;">
&lt;web-app xmlns=&quot;.../javaee&quot; xmlns:xsi=&quot;...&quot;
	xsi:schemaLocation=&quot;.../web-app_2_5.xsd&quot; version=&quot;2.5&quot;&gt;
...
	&lt;!-- Activating the Expression Language --&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;com.sun.faces.expressionFactory&lt;/param-name&gt;
		&lt;param-value&gt;com.sun.el.ExpressionFactoryImpl&lt;/param-value&gt;
	&lt;/context-param&gt;

	&lt;!-- Java Server Faces Servlet --&gt;
	&lt;servlet&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;!--  Prime Faces Resource loading --&gt;
	&lt;servlet&gt;
		&lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.primefaces.resource.ResourceServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;!-- Java Server Faces Servlet Mapping --&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
	&lt;!--  Prime Faces Resource loading --&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/primefaces_resource/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
...
&lt;/web&gt;
</pre>
<h3>The View</h3>
<p>The definition of a JSF presentation is relatevely simple. Just create a simple XHTML document and import the JSF namespaces in the header.</p>
<pre class="brush: xml;">
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
	xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
	xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
	xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
	xmlns:p=&quot;http://primefaces.prime.com.tr/ui&quot;&gt;
	 &lt;f:loadBundle var= &quot;msgs&quot; basename= &quot;ViewMessages&quot; /&gt;
	 &lt;h:head&gt;
		 &lt;title&gt;#{msgs.welcomeTitle}&lt;/title&gt;
		 &lt;h:outputStylesheet library=&quot;css&quot; name=&quot;default.css&quot; target=&quot;head&quot;/&gt;
	 &lt;/h:head&gt;
	 &lt;h:body&gt;
		 &lt;p:dataTable id= &quot;customers&quot; value=&quot;#{cusomterProvider.customer}&quot; var=&quot;customer&quot;&gt;
			 &lt;p:column&gt;
				 &lt;h:outputText id=&quot;customerName&quot; value=&quot;#{customer.name}&quot; /&gt;
			 &lt;/p:column&gt;
			...
		 &lt;/p:dataTable&gt;
	 &lt;/h:body&gt;
&lt;/html&gt;
</pre>
<p>Please note, that along with the JSF core components, the PrimeFaces component <code>dataTable</code> is used. At runtime the components will be transformed into the corresponding HTML elements.</p>
<h3>The Backing Bean</h3>
<p>In the previos example, special strings have been used <code>#{customerProvider.customers}</code> and <code>#{customer.name}</code>. Both of them are expressions specified in the Expression Language. This language allows to address elements known inside the application. The <code>customer.name</code> accesses the property <code>name</code> of the variable defined inside the iteration over the elements delivered from the <code>customerProvider.getCustomers()</code>. The <code>customerProvider</code> is a Java Object that delivers data to the view and is called Backing Bean. A Backing Bean is a serializeable POJO, that is attached to the view. It can be declared using JSF Annotation <code>javax.faces.ManagedBean</code>, using the <code>ManagedBean</code> element of the <strong>faces-config.xml</strong> or by other mechanisms compatible with the Expression Language resolvers.</p>
<pre class="brush: java;">
@ManagedBean
@SessionScope
public class CustomerProvider
{
	public List &lt;Customer &gt; getCustomers()
	{
		...
	}
}
</pre>
<h3>Internationalization</h3>
<p>Internationalization is an important requirement for the presentation layer. In the previous example, a special string has been used <code>#{msgs.welcomeTitle}</code> to provide a message. The <code>msgs</code> variable is bound to a resource file, containing the localized messages, so the <code>#{msgs.welcomeTitle}</code> is pointing to the key <code>welcomeTitle</code> inside the property file.</p>
<h3>Validation</h3>
<p>Input validation is another important requirement for web applications. Especially, the ability to validate parts of the input using technologies like AJAX has to be supported in order to deliver the state-of-the-art technology. JSF fosters numerous different validation approaches. For example:</p>
<pre class="brush: xml;">
...
 &lt;h:inputText id=&quot;customerName&quot; value=&quot;#{customerService.current.name}&quot; required= &quot;true&quot; /&gt;
	 &lt;f:validateLength minimum=&quot;7 &quot;/&gt;
 &lt;/h:inputText&gt;
 &lt;h:message for=&quot;customerName&quot;/&gt;
...
</pre>
<p>Please note, that in the example above, the input of the customer name is mandatory and the minimum length is seven.</p>
<p>Another validation approach is defined in the Bean Validation Standard (JSR 303) and is supported if the components are deployed and available. According to JSR 303, the data container can define format constraints which can be used for purposes of validation. There is a set of predefined constraints available, which can be extended by custom constraints. For example:</p>
<pre class="brush: java;">
public class Customer
{
	@Size(min=2, max=50, message= &quot;Customer name must be at least 2 and at most 50 characters long. &quot;)
	private String name;
	// getters and setters
	...
}
</pre>
<p>This example shows that the customer name has to be at least two and at most fifty characters long and defines a custom error message which is displayed on violation. Remember the previous section Internationalization? Yes, the validation error message can be localized too, by suppliying EL-expressions instead of the message description:</p>
<pre class="brush: java;">
public class Customer
{
	@Size(min=2, max=50, message= &quot;{customerNameError} &quot;)
	private String name;
	// getters and setters
	...
}
</pre>
<p>Thus, the value of <code>{customerNameError}</code> (without a #) is a key in the file which must be named <strong>ValidationMessages.properties</strong> and must be available on classpath.</p>
<h2>JSF 2.0 with other frameworks</h2>
<p>The use of JSF fosters comfort in implementing the presentation tier. The presentation-tier is usually built on top of the business logic layer. The latter can be implemented using different technolgies.</p>
<h3>JSF 2.0 and EJB 3.1</h3>
<p>Enterprise Java Beans is a standard way to implement business logic inside JEE applications. The current EJB 3.1 specification fosters the usage of Stateless and Statefull Session Beans for this purpose. Since JEE6-compliant servers support Context and Dependency Injection (CDI) and the EJB and Resource Injection, the session beans can be directly referenced from the backing beans. JSF 2.0 is also a part of the JEE 6, every JEE-compliant server will support JSF out-of-the-box, too.</p>
<pre class="brush: java;">
@ManagedBean
public class CustomerProvider
{
	@EJB
	private CustomerService service;
	...
}
</pre>
<h3>JSF 2.0 and Spring 3.0</h3>
<p>If you don&#8217;t want to run a full-blown JEE server, but a web-container only, you have to include some libraries into your application deployment.</p>
<ul>
<li>JSF 2.0 API and Implementation: e.g. Mojarra 2.0.2 (
<a  href="https://javaserverfaces.dev.java.net/files/documents/1866/146040/mojarra-2.0.2-FCS-binary.zip" onclick="javascript:pageTracker._trackPageview('/external/javaserverfaces.dev.java.net/files/documents/1866/146040/mojarra-2.0.2-FCS-binary.zip');" >mojarra-2.0.2-FCS-binary.zip</a>)</li>
<li>Expression Language 2.2 API and Implementation: 
<a  href="http://download.java.net/maven/glassfish/javax/el/el-api/2.2.0-SNAPSHOT/el-api-2.2.0-SNAPSHOT.jar" onclick="javascript:pageTracker._trackPageview('/external/download.java.net/maven/glassfish/javax/el/el-api/2.2.0-SNAPSHOT/el-api-2.2.0-SNAPSHOT.jar');" >el-api-2.2.jar</a>, 
<a  href="http://download.java.net/maven/glassfish/org/glassfish/web/el-impl/2.2.0-SNAPSHOT/el-impl-2.2.0-SNAPSHOT.jar" onclick="javascript:pageTracker._trackPageview('/external/download.java.net/maven/glassfish/org/glassfish/web/el-impl/2.2.0-SNAPSHOT/el-impl-2.2.0-SNAPSHOT.jar');" >el-impl-2.2.jar</a></li>
<li>Content and Dependency Injection (CDI, JSR 330) API and Implementation: 
<a  href="http://atinject.googlecode.com/files/javax.inject.zip" onclick="javascript:pageTracker._trackPageview('/external/atinject.googlecode.com/files/javax.inject.zip');" >javax.inject.zip</a></li>
<li>Bean Validation (JSR 303) API and Implementation: e.g. Hibernate Validator (
<a  href="http://sourceforge.net/projects/hibernate/files/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA-dist.zip/download" onclick="javascript:pageTracker._trackPageview('/external/sourceforge.net/projects/hibernate/files/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA-dist.zip/download');" >hibernate-validator-4.0.2.GA-dist.zip</a>)</li>
</ul>
<p>This list will be extended by libraries required to run the Spring framework. In order to activate Spring, the context listeners have to be activated. The application context parameter can be provided as a context parameter.</p>
<pre class="brush: xml;">
 &lt;!-- Spring Activation --&gt;
 &lt;listener&gt;
	 &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
 &lt;/listener&gt;
 &lt;listener&gt;
	 &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
 &lt;/listener&gt;
 &lt;context-param&gt;
	 &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
	 &lt;param-value&gt;/WEB-INF/spring-config.xml&lt;/param-value&gt;
 &lt;/context-param&gt;
</pre>
<p>In addition, the Expression Language variable resolvers of JSF should be replaced by those from Spring. This is configured in the <code>faces-config.xml</code></p>
<pre class="brush: xml;">
&lt;faces-config xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd&quot;
	version=&quot;2.0&quot;&gt;
	&lt;application&gt;
		&lt;el-resolver&gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&lt;/el-resolver&gt;
	&lt;/application&gt;
&lt;/faces-config&gt;
</pre>
<p>In order to enable the Spring&#8217;s IoC (Inversion of Control), we need to activate the component scan in the application-context configuration file:</p>
<pre class="brush: xml;">
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:xsi=&quot;...&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xsi:schemaLocation=&quot;...&quot;&gt;

	&lt;context:component-scan base-package=&quot;de.techjava&quot;&gt;
		&lt;context:include-filter type=&quot;annotation&quot;
			expression=&quot;org.springframework.stereotype.Service&quot; /&gt;
	&lt;/context:component-scan&gt;
&lt;/beans&gt;
</pre>
<p>Instead of using JSF for resolving the backing beans, the Spring framework can be used. The backing bean is annotated with the Spring annotation <code>Controller</code>. The controller is a special kind of Spring component, which is used in the presentation layer. The Spring&#8217;s way of implementing business logic is to provide Spring services. Spring service has to be annotated with <code>Service</code> annotation.</p>
<pre class="brush: java;">
@Controller
@Scope( &quot;session &quot;)
public class CustomerProvider implements Serializable
{
	@Inject
	private CustomerService customerService;
	...
}

@Service
@Scope( &quot;singleton &quot;)
public class CustomerServiceImpl implements CustomerService
{
	...
}
</pre>
<p>This is not as elegant as inside the JEE server, but it will work.</p>
<h3>References</h3>
<ul>
<li>
<a  href="http://jcp.org/en/jsr/detail?id=303" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/jcp.org/en/jsr/detail');" >JSR 303: Bean Validation</a></li>
<li>
<a  href="http://jcp.org/en/jsr/detail?id=330" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/jcp.org/en/jsr/detail');" >JSR 330: Dependency Injection for Java</a></li>
<li>
<a  href="http://blog.ralscha.ch/?p=652" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/blog.ralscha.ch/');" >JSR 330 with Spring (in German)</a></li>
<li>
<a  href="https://javaserverfaces.dev.java.net/" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/javaserverfaces.dev.java.net/');" >Mojarra Project</a></li>
<li>
<a  href="http://download.java.net/maven/glassfish/javax/el/el-api/2.2.0-SNAPSHOT/" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/download.java.net/maven/glassfish/javax/el/el-api/2.2.0-SNAPSHOT/');" >Expression Language API</a></li>
<li>
<a  href="http://download.java.net/maven/glassfish/org/glassfish/web/el-impl/2.2.0-SNAPSHOT/" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/download.java.net/maven/glassfish/org/glassfish/web/el-impl/2.2.0-SNAPSHOT/');" >Expression Language Implementation</a></li>
<li>
<a  href="https://www.hibernate.org/412.html" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/www.hibernate.org/412.html');" >Hibernate Validator (JSR 303 Implementation)</a></li>
<li>
<a  href="http://code.google.com/p/atinject/" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/code.google.com/p/atinject/');" >AtInject (JSR 330 Implementation)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2010/02/jsf-2-reality-check/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Real World Java EE Practices &#8211; Rethinking Best Practices by Adam Bien</title>
		<link>http://www.techjava.de/topics/2010/02/rethinking-best-practices/</link>
		<comments>http://www.techjava.de/topics/2010/02/rethinking-best-practices/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 23:21:43 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[enterprise systems]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[adam bien]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[enterprise]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=594</guid>
		<description><![CDATA[
I just returned from the furious event given by Adam Bien on 
Real World Java EE Practices. The presentation has been held in Lehmanns Bookstore in Hamburg in co-operation with the JUGHH. It was a full success with no space left in the bookstore. I think, I got the last seat and there were some [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.techjava.de/wp-content/uploads/adambien-225x300.jpg" alt="" title="adambien" width="225" height="300" style="float:right; margin:5px;" /><br />
I just returned from the furious event given by Adam Bien on 
<a  href="http://www.adam-bien.com/roller/abien/entry/free_jug_session_in_hamburg" onclick="javascript:pageTracker._trackPageview('/external/www.adam-bien.com/roller/abien/entry/free_jug_session_in_hamburg');" >Real World Java EE Practices</a>. The presentation has been held in Lehmanns Bookstore in Hamburg in co-operation with the JUGHH. It was a full success with no space left in the bookstore. I think, I got the last seat and there were some people standing. </p>
<p>Adam made it in an hour and presented many interesting topics. He started with new subjects introduces in JEE6, like optional local interfaces, cronjob-like Timer Service and other nice goodies. Then he covered new stuff from JEE like REST and CDI (Context and Dependency Injection). Finally, he moved to the best practices, patterns and anti-pattern. As usual, it was quick and precise &#8211; Adam answered many questions and gave a good overview of the technology.</p>
<p>After the presentation, JUGHH / Lehmanns offer a glass of sparkling wine for the smaller audience and Adam spoke about the possibility to speak about JavaFX next time. This time I left my camera at home and only had my phone with me, so sorry for the low-resolutioned picture&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2010/02/rethinking-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exposing Functionality using Web Services and JEE</title>
		<link>http://www.techjava.de/topics/2010/01/functionality-web-services-jee/</link>
		<comments>http://www.techjava.de/topics/2010/01/functionality-web-services-jee/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 11:11:22 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[enterprise systems]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[bean]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[ejb3]]></category>
		<category><![CDATA[java 5]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[web service]]></category>
		<category><![CDATA[wsdl]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=554</guid>
		<description><![CDATA[
Abstract
About two years ago, I published an 
article about Exposing the Functionality implemented in Stateless Session Beans (EJB 2.1) using Web Services. J2EE 1.4 times are over and the new version of the Java Enterprise framework, called Java Enterprise Edition 5 (JavaEE 5, or simply JEE) has emerged. In this article the same business scenario [...]]]></description>
			<content:encoded><![CDATA[<h2>
<a  href="http://www.techjava.de/wp-content/uploads/valve.jpg" onclick="javascript:pageTracker._trackPageview('/downloads/wp-content/uploads/valve.jpg');" ><img style="float: right; margin: 5px;" title="valve" src="http://www.techjava.de/wp-content/uploads/valve-150x150.jpg" alt="" width="150" height="150" /></a>Abstract</h2>
<p>About two years ago, I published an 
<a  href="http://www.techjava.de/topics/2008/02/ws4j2ee14/">article</a> about Exposing the Functionality implemented in Stateless Session Beans (EJB 2.1) using Web Services. J2EE 1.4 times are over and the new version of the Java Enterprise framework, called Java Enterprise Edition 5 (JavaEE 5, or simply JEE) has emerged. In this article the same business scenario is repeated in the new framework. </p>
<h2>Requirements</h2>
<p>Before we dive into code examples, some software is required. The good news about the software is, that it also evolved over time. Here is what we use:</p>
<ul>
<li>Sun&#8217;s Java 6 SDK</li>
<li>JBoss AS 5.1.0 GA for JDK6</li>
<li>Eclipse Galileo 3.5.1 for JEE development</li>
</ul>
<p><span id="more-554"></span><br />
Some words about the used software. It is important to get the JDK6-compiled version of the JBoss Application Server. There are some issues with running the version compiled with Java 5 on JDK6, since JDK6 has its own JAX-WS implementation which causes problems with JBoss (affected should be all versions of JBoss &lt; 5.2. Currently it seems like version 5.2 will be compiled with JDK6 by default.) If you launch JBoss from Eclipse, make sure to add the <code>-Djava.endorsed.dirs=PATH_TO_JBOSS/jboss-5.1.0.GA/lib/endorsed</code> as a VM argument, if launched from the command line, please add it as an option inside of the <code>run.conf.bat</code> file:</p>
<pre class="brush: bash;">
set &quot;JAVA_OPTS=%JAVA_OPTS% -Djava.endorsed.dirs=$JBOSS_HOME/lib/endorsed&quot;
</pre>
<p>Otherwise you will get the following exception:</p>
<pre class="brush: java;">java.lang.UnsupportedOperationException: setProperty must be overridden by all subclasses of SOAPMessage</pre>
<p>After installation (unpacking) of Eclipse, make sure to configure the JDK (under <strong>Preferences &gt; Java &gt; Installed JREs</strong>) and the JBoss instance (<strong>Preferences &gt; Server &gt; Runtime Environment</strong>).</p>
<h2>Use Case</h2>
<p>In order to demonstrate the technology by example, imagine the following use case. The system under construction is capable of providing measurements of some sensors. The sensors are identified by numbers and can be queried by the user by providing the timespan of measurements. As a result, the systems delivers the set of measurements for the given timespan with one measurement per minute but at most sixty measurements. Every measurement contains the id of sensor from which it has been recorded, the timestamp, the value as a byte array, the measurement unit and finally a flag whether the measurement exceeds the limits or specified alarm values.</p>
<h2>Implementation</h2>
<p>We start the implementation with the creation of a JEE Session Bean and then expose the functionality using a second Facade bean. In doing so we follow the EJB 3 specification.</p>
<h3>Eclipse for Java EE development</h3>
<p>The plugins in Eclipse for Java EE provide massive support and foster the development by deep integration withe JEE servers. Instead of a simple Java Project, start with an <strong>Enterprise Application Project</strong>. Then, create a new <strong>EJB Project</strong> and add it to the created Enterprise Application Project. In order to deploy the resulting application to the server, right-click on the enterprise project and select <strong>Run As &gt; Run on Server </strong>.</p>
<p>To check the deployment on the application server, use the JBoss Consoles. These can be accessed via 
<a  href="http://localhost:8080/" onclick="javascript:pageTracker._trackPageview('/external/localhost/');" >http://localhost:8080/</a> for the locally installed JBoss. An additional Web Service Console is accessible via 
<a  href="http://localhost:8080/jbossws/" onclick="javascript:pageTracker._trackPageview('/external/localhost/jbossws/');" >http://localhost:8080/jbossws/</a>.</p>
<h3>Implementing the Functionality</h3>
<p>In order to implement the functionality in a stateless session bean, we start with the creation of the business interface.</p>
<pre class="brush: java;">
/**
 * Defines the sensor manager functionality
 */
public interface SensorManager
{
	/**
	 * Retrieve sensor data
	 * @param sensorId id of the sensor
	 * @param timespan the measurement period
	 * @return a list of measurements in the given period
	 * @throws SensorManagerException on any kinds of errors
	 */
	public List&lt;Measurement&gt; getSensorData(SensorID sensorId, Timespan timespan) throws SensorManagerException;
}
</pre>
<p>The POJOs <code>Measurement</code>, <code>SensorID</code> and <code>Timespan</code> are used to show the usage of custom user types:</p>
<pre class="brush: java;">
public class Measurement
{
	private SensorID sensorID;
	private Date timestamp;
	private boolean critical;
	private byte[] value;
	private String unit;
...
// getters and setters
}
....
public class SensorID
{
	private long sensorId;
...
// getters and setters
}

public class Timespan
{
	private Date start;
	private Date end;
...
// getters and setters
}
</pre>
<p>After the creation of the business interface, let us create the actual Session Bean. The class is annotated with the <code>@javax.ejb.Stateless</code> annotation in order to indicate that the bean is a Stateless Session Bean. Since it implements the business interface (and only it), the container will be able to deduce that the given interface is the Local Business interface: this is just one of many examples of the Configurations by Exception in EJB 3. In order to be able to reference the bean from other beans, we annotate the binding of the local interface to a specific JNDI name using the vendor-specific annotation <code>org.jboss.ejb3.LocalBinding</code>.</p>
<pre class="brush: java;">
@Stateless
@LocalBinding(jndiBinding=&quot;de.techjava.sensor/SensorManager&quot;)
public class SensorManagerBean implements SensorManager
{
	/** Logging facility */
	protected static Logger LOG = Logger.getLogger(SensorManagerBean.class);
	/** Max number of returned values */
	private static final long MAX_DURATION = 60;

	/**
	 * Implementation of the business method
	 */
	public List&lt;Measurement&gt; getSensorData(SensorID sensorId, Timespan timespan) throws SensorManagerException
	{
		LOG.debug(&quot;Entering getSensorData()&quot;);
		if (sensorId == null || timespan == null || timespan.getStart() == null || timespan.getStart() == null)
		{
			throw new SensorManagerException(&quot;Missing a mandatory parameter, that was null (not set)&quot;);
		} else if (!timespan.getStart().before(timespan.getEnd()))
		{
			throw new SensorManagerException(&quot;The timespan is defined by the start that should be before end&quot;);
		}

		List&lt;Measurement&gt; measurements = new LinkedList&lt;Measurement&gt;();
		for (long i = 0; i &lt; getNumberOfElements(timespan); i++)
		{
			Date date = new Date();
			date.setTime(timespan.getStart().getTime() + i * 1000 * 60);
			if (date.after(timespan.getEnd()))
				break;
			Measurement measurement = createMeasurement(sensorId, date, i);
			measurements.add(measurement);
		}

		LOG.debug(&quot;Leaving getSensorData(). Returning &quot; + measurements.size() + &quot; values.&quot;);
		return measurements;
	}

	/**
	 * Retrieves the number of measurements in timespan
	 */
	private long getNumberOfElements(Timespan timespan) { ... }

	/**
	 * Creates a measurement instance, a dummy implementation
	 */
	private Measurement createMeasurement(SensorID sensorId, Date timestamp, long number) { ... }
}
</pre>
<h2>Web Service Definition</h2>
<p>The quality of the web service interface is an important design consideration. As described in 
<a  href="http://www.techjava.de/topics/2008/02/ws4j2ee14/">the previous post</a>, in many cases it is a good idea to create it by hand instead of generation by a tool. In this particular case, we create another annotated Stateless Session Bean, which is used as a Facade and contains all Web Service-specific settings. From this Bean we generate the WSDL and then tune it in order to show the capability of the customization. In doing so we try to match the WSDL from the previous example as close as possible.</p>
<p>Firstly, we create the business interface and the bean class, then annotate it and finally add the code delegating the Web Service request to the SensorManager.</p>
<pre class="brush: java;">
public interface MeasurementProviderFacade
{
	public List&lt;Measurement&gt; getSensorData(SensorID id, Timespan timespan) throws SensorDataOperationFault;
}

...

@Stateless
public class MeasurementProviderFacadeBean implements MeasurementProviderFacade
{
	public List&lt;Measurement&gt; getSensorData(SensorID id, Timespan timespan) throws SensorDataOperationFault
	{
	...
	// implementation code
	}
}
</pre>
<p>In order to have a Session Bean exposed as a Web Service, the JAX-WS specification defines a set of annotations. The most important two are <code>@javax.jws.WebMethod</code> and <code>@javax.jws.WebService</code>. The <code>@WebService</code> annotation is used to mark the class to be exposed e.G.</p>
<pre class="brush: java;">
@Stateless
@WebService(
	serviceName = &quot;MeasurementProviderService&quot;,
	name = &quot;MeasurementProviderPortType&quot;,
	portName = &quot;MeasurementProviderPort&quot;,
	targetNamespace = &quot;http://www.techjava.de/2010/ws4jee/measurement/&quot;
)
public class MeasurementProviderFacadeBean implements MeasurementProviderFacade
{
	@WebMethod(
		operationName=&quot;GetSensorDataOperation&quot;,
		action=&quot;http://www.techjava.de/2010/ws4jee/measurement/GetSensorDataOperation&quot;
	)
	public List&lt;Measurement&gt; getSensorData(SensorID id, Timespan timespan) throws SensorDataOperationFault { ... }
}
</pre>
<p>All the attributes of the annotation are optional and their values will be derived from the classname and the name of the business interface. The default target namespace for the service definition is derived from the package name, the annotated class is located in. By default, all public methods of the annotated class will be exposed as WSDL operations, with operation&#8217;s name derived from the method name. Using the <code>@WebMethod</code> annotation, the name of the WSDL operation and the SOAP action can be changed.</p>
<p>The careful reader might have observed that the <code>getSensorData</code>-method is throwing an exception. In order to map the exception to a SOAP-Fault, the <code>javax.xml.ws.WebFault</code> class-level annotation can be used. The <code>faultBean</code> attribute is used to provide the full-qulified class name of the exception.</p>
<pre class="brush: java;">
...
@WebFault(
	name=&quot;GetSensorDataFault&quot;,
	targetNamespace=&quot;http://www.techjava.de/2010/ws4jee/measurement/&quot;,
	faultBean=&quot;de.techjava.sensor.bean.SensorDataOperationFault&quot;)
public class MeasurementProviderFacadeBean implements MeasurementProviderFacade { ... }
</pre>
<p>In order to increase the quality of the WSDL further, the method parameters and return type can be annotated with <code>javax.jws.WebParam</code> and <code>javax.jws.WebResult</code> respectively, so the method signature becomes a little unreadable. In order not to copy the long string containing the taget namespace a String constant can be used.</p>
<pre class="brush: java;">
...
	public final static String TYPES = &quot;http://www.techjava.de/2010/ws4jee/measurement/types/&quot;;
...
	@WebResult(name=&quot;measurement&quot;, targetNamespace=TYPES)
	public List&lt;Measurement&gt; getSensorData(
		@WebParam(name=&quot;sensor-id&quot;, targetNamespace=TYPES) SensorID id,
		@WebParam(name=&quot;timespan&quot;, targetNamespace=TYPES) Timespan timespan) throws SensorDataOperationFault	{ ... }
</pre>
<p>Finally, in order to force the marshaller / unmarshaller to map the custom data types (<code>Measurement</code>, <code>SensorID</code> and <code>Timespan</code>) to belong to the same namespace, the JAX-B class-level annotation <code>javax.xml.bind.annotation.XmlType</code> has to be used. By default, the datatypes will be mapped to XML Schema types according to their package name and class name.</p>
<pre class="brush: java;">
@XmlType(namespace = &quot;http://www.techjava.de/2010/ws4jee/measurement/types/&quot;, name = &quot;TimeSpan&quot;, propOrder = { &quot;start&quot;, &quot;end&quot; })
public class Timespan
{
	private Date start;
	private Date end;
</pre>
<p>If deployed to the JBoss, the resulting WSDL looks as following:</p>
<pre class="brush: xml; collapse: true; light: false; toolbar: true;">
&lt;definitions name='MeasurementProviderService' targetNamespace='http://www.techjava.de/2010/ws4jee/measurement/' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:ns1='http://www.techjava.de/2010/ws4jee/measurement/types/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='http://www.techjava.de/2010/ws4jee/measurement/' xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;
 &lt;types&gt;
  &lt;xs:schema targetNamespace='http://www.techjava.de/2010/ws4jee/measurement/types/' version='1.0' xmlns:tns='http://www.techjava.de/2010/ws4jee/measurement/types/' xmlns:xs='http://www.w3.org/2001/XMLSchema'&gt;
   &lt;xs:element name='measurement' type='tns:Measurement'/&gt;
   &lt;xs:element name='sensor-id' type='tns:sensor-id'/&gt;
   &lt;xs:element name='timespan' type='tns:TimeSpan'/&gt;
   &lt;xs:complexType name='sensor-id'&gt;
    &lt;xs:sequence&gt;
     &lt;xs:element name='sensorId' type='xs:long'/&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
   &lt;xs:complexType name='TimeSpan'&gt;
    &lt;xs:sequence&gt;
     &lt;xs:element minOccurs='0' name='start' type='xs:dateTime'/&gt;
     &lt;xs:element minOccurs='0' name='end' type='xs:dateTime'/&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
   &lt;xs:complexType name='Measurement'&gt;
    &lt;xs:sequence&gt;
     &lt;xs:element name='critical' type='xs:boolean'/&gt;
     &lt;xs:element minOccurs='0' name='sensorID' type='tns:sensor-id'/&gt;
     &lt;xs:element minOccurs='0' name='timestamp' type='xs:dateTime'/&gt;
     &lt;xs:element minOccurs='0' name='unit' type='xs:string'/&gt;
     &lt;xs:element minOccurs='0' name='value' type='xs:base64Binary'/&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  &lt;xs:schema targetNamespace='http://www.techjava.de/2010/ws4jee/measurement/' version='1.0' xmlns:ns1='http://www.techjava.de/2010/ws4jee/measurement/types/' xmlns:tns='http://www.techjava.de/2010/ws4jee/measurement/' xmlns:xs='http://www.w3.org/2001/XMLSchema'&gt;
   &lt;xs:import namespace='http://www.techjava.de/2010/ws4jee/measurement/types/'/&gt;
   &lt;xs:element name='GetSensorDataOperation' type='tns:GetSensorDataOperation'/&gt;
   &lt;xs:element name='GetSensorDataOperationResponse' type='tns:GetSensorDataOperationResponse'/&gt;
   &lt;xs:element name='SensorDataOperationFault' type='tns:SensorDataOperationFault'/&gt;
   &lt;xs:complexType name='GetSensorDataOperation'&gt;
    &lt;xs:sequence&gt;
     &lt;xs:element minOccurs='0' ref='ns1:sensor-id'/&gt;
     &lt;xs:element minOccurs='0' ref='ns1:timespan'/&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
   &lt;xs:complexType name='GetSensorDataOperationResponse'&gt;
    &lt;xs:sequence&gt;
     &lt;xs:element maxOccurs='unbounded' minOccurs='0' ref='ns1:measurement'/&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
   &lt;xs:complexType name='SensorDataOperationFault'&gt;
    &lt;xs:sequence&gt;
     &lt;xs:element minOccurs='0' name='message' type='xs:string'/&gt;
    &lt;/xs:sequence&gt;
   &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
 &lt;/types&gt;
 &lt;message name='MeasurementProviderPortType_GetSensorDataOperation'&gt;
  &lt;part element='tns:GetSensorDataOperation' name='GetSensorDataOperation'&gt;&lt;/part&gt;
 &lt;/message&gt;
 &lt;message name='SensorDataOperationFault'&gt;
  &lt;part element='tns:SensorDataOperationFault' name='SensorDataOperationFault'&gt;&lt;/part&gt;
 &lt;/message&gt;
 &lt;message name='MeasurementProviderPortType_GetSensorDataOperationResponse'&gt;
  &lt;part element='tns:GetSensorDataOperationResponse' name='GetSensorDataOperationResponse'&gt;&lt;/part&gt;
 &lt;/message&gt;
 &lt;portType name='MeasurementProviderPortType'&gt;
  &lt;operation name='GetSensorDataOperation' parameterOrder='GetSensorDataOperation'&gt;
   &lt;input message='tns:MeasurementProviderPortType_GetSensorDataOperation' /&gt;
   &lt;output message='tns:MeasurementProviderPortType_GetSensorDataOperationResponse' /&gt;
   &lt;fault message='tns:SensorDataOperationFault' name='SensorDataOperationFault' /&gt;
  &lt;/operation&gt;
 &lt;/portType&gt;
 &lt;binding name='MeasurementProviderPortTypeBinding' type='tns:MeasurementProviderPortType'&gt;
  &lt;soap:binding style='document' transport='http://schemas.xmlsoap.org/soap/http'/&gt;
  &lt;operation name='GetSensorDataOperation'&gt;
   &lt;soap:operation soapAction='http://www.techjava.de/2010/ws4jee/measurement//GetSensorDataOperation'/&gt;
   &lt;input&gt;&lt;soap:body use='literal'/&gt;&lt;/input&gt;
   &lt;output&gt;&lt;soap:body use='literal'/&gt;&lt;/output&gt;
   &lt;fault name='SensorDataOperationFault'&gt;&lt;soap:fault name='SensorDataOperationFault' use='literal'/&gt;&lt;/fault&gt;
  &lt;/operation&gt;
 &lt;/binding&gt;
 &lt;service name='MeasurementProviderService'&gt;
  &lt;port binding='tns:MeasurementProviderPortTypeBinding' name='MeasurementProviderPort'&gt;
   &lt;soap:address location='http://127.0.0.1:8080/de.techjava.ws4ee-de.techjava.ws4ee.sensor/MeasurementProviderFacadeBean'/&gt;
  &lt;/port&gt;
 &lt;/service&gt;
&lt;/definitions&gt;
</pre>
<p>Please note, that the domain datatypes are mapped to the different namespace as the target namespace of the Web Service.</p>
<p>After some tuning the WSDL, like changing the cardinality of elements (minOccurs = 1, maxOccurs = 1) or adding comments we can let the container use the changed WSDL file instead of generating a new one. In order to do this, let us package the WSDL together with the source code. A good place for it is for example <code>/META-INF/wsdl/</code>, so we can provide a reference to it in an <code>wsdlLocation</code>attribute of the <code>@WebService</code> annotation:</p>
<pre class="brush: java;">
@WebService(
...
        wsdlLocation=&quot;META-INF/wsdl/MeasurementProviderService.wsdl&quot;
)
</pre>
<h2>Putting all together</h2>
<p>After the creation of the Facade Bean and its exposure as a Web Service, we need to delegate the call to the SensorManagerBean, providing the actual implementation. In order to do so, add a private member of type <code>SensorManager</code> inside of the facade bean and annotate it with the <code>javax.ejb.EJB</code> annotation. The container will intialize the member using Dependency Injection and provide a valid reference which can be simply used inside of the method.</p>
<pre class="brush: java; highlight: [4,5,20];">
...
public class MeasurementProviderFacadeBean implements MeasurementProviderFacade
{
	@EJB(mappedName=&quot;de.techjava.sensor/SensorManager&quot;)
	private SensorManager sensorManager;

	/**
	 * Simple delegate to the business method of the sensor manager
	 */
	@WebMethod(
			operationName=&quot;GetSensorDataOperation&quot;,
			action=TNS + &quot;/GetSensorDataOperation&quot;
	)
	public @WebResult(name=&quot;measurement&quot;, targetNamespace=TYPES) List&lt;Measurement&gt; getSensorData(
			@WebParam(name=&quot;sensor-id&quot;, targetNamespace=TYPES) SensorID id,
			@WebParam(name=&quot;timespan&quot;, targetNamespace=TYPES) Timespan timespan) throws SensorDataOperationFault
	{
		try
		{
			return sensorManager.getSensorData(id, timespan);
		} catch (SensorManagerException e)
		{
			throw new SensorDataOperationFault(&quot;Error accessing the Sensor Manager: &quot; + e.getMessage() + &quot;&quot;);
		}
	}
}
</pre>
<p>Here is the call in Web Service Explorer:<br />

<a  href="http://www.techjava.de/wp-content/uploads/ws-explorer.png" onclick="javascript:pageTracker._trackPageview('/downloads/wp-content/uploads/ws-explorer.png');" ><img style="margin: 5px;" title="WS Explorer" src="http://www.techjava.de/wp-content/uploads/ws-explorer.png" alt="image WS Explorer" /></a></p>
<h2>Outline</h2>
<p>In this article we showed how to expose the functionality implemented in an EJB 3 Session Bean using Web Service Technology. In fact, the creation of a FacadeBean was not required since one could annotate the <code>SensorManager</code>-Bean directly, but we separated the implementation Bean from the exposing Bean to make it easier to understand. Even if we didn&#8217;t match the WSDL from the J2EE 1.4 example exactly, we came very close. Merely some message-related datatypes have different names. In this example we used the Document/Literal/Wrapped style of Web Services in order to gain maximum interoperability. Even though the creation of the Web Service is a simple task using the annotations. The number of tools and dependencies has dramataically reduced since J2EE 1.4 and the development became less error-prone. Together with other EJB3 improvements it makes the JEE framework suitable for development in the context of enterprise distributed systems.</p>
<h2>References and Resources</h2>
<p>The example source code is available for download (
<a  href="http://www.techjava.de/download/examples/ws4jee.zip" onclick="javascript:pageTracker._trackPageview('/downloads/download/examples/ws4jee.zip');" >ws4jee.zip</a>). Just import the projects from the archive into Eclipse Worskspace. Make sure to set up the JRE and JBoss Server instance for the projecst to work.</p>
<ul>
<li>
<div>[2008,techreport] 
<a  href="#JAVAEE" class="toggle">bibtex</a>  
<a  href='http://java.sun.com/javaee/5/docs/tutorial/doc/' title='Go to document' onclick="javascript:pageTracker._trackPageview('/external/java.sun.com/javaee/5/docs/tutorial/doc/');" ><img src='http://www.techjava.de/wp-content/plugins/bib2html/external.png' width='10' height='10' alt='Go to document' /></a></div>
<div>E. Jendrock, J. Ball, D. Carson, I. Evans, S. Fordin, and K. Haase, &quot;The Java EE 5 Tutorial,&quot; 2008.</div>
<div class="bibtex" id="JAVAEE">
         <code>@techreport{JAVAEE, <br />
 &nbsp;&nbsp;author =	{Eric Jendrock and Jennifer Ball and Debbie Carson and Ian Evans and Scott Fordin and Kim Haase}, <br />
 &nbsp; title =	{The Java EE 5 Tutorial}, <br />
 &nbsp; url = {http://java.sun.com/javaee/5/docs/tutorial/doc/}, <br />
 &nbsp; month =	{Oct}, <br />
 &nbsp; year =	{2008}<br />
}</code>
    </div>
</li>
<li>
<div>[2007,book] 
<a  href="#IHNS_2003" class="toggle">bibtex</a>  
<a  href='Oliver Ihns, Dierk Harbeck, Stefan M. Heldt, Holger Koschek, Roman Schlömmer, Jo Ehm, Carsten Sahling' title='Go to document'><img src='http://www.techjava.de/wp-content/plugins/bib2html/external.png' width='10' height='10' alt='Go to document' /></a></div>
<div>O. Ihns, D. Harbeck, S. M. Heldt, H. Koschek, R. Schl&#5954405;r, J. Ehm, and C. Sahling, <em>EJB 3 professionell. Grundlagen- und Expertenwissen zu Enterprise JavaBeans 3 fr Einsteiger, Umsteiger und Fortgeschrittene , publisher	DPunkt Verlag</em>, , 2007.</div>
<div class="bibtex" id="IHNS_2003">
         <code>@Book{IHNS_2003, <br />
 &nbsp;&nbsp;author =	{Oliver Ihns and Dierk Harbeck and Stefan M. Heldt and Holger Koschek and Roman Schlömmer and Jo Ehm and Carsten Sahling}, <br />
 &nbsp; title =	{EJB 3 professionell. Grundlagen- und Expertenwissen zu Enterprise JavaBeans 3 für Einsteiger, Umsteiger und Fortgeschrittene }, <br />
 &nbsp; publisher	{DPunkt Verlag}, <br />
 &nbsp; year =	{2007}, <br />
 &nbsp; month =	{Jul}, <br />
 &nbsp; url = {Oliver Ihns, Dierk Harbeck, Stefan M. Heldt, Holger Koschek, Roman Schlömmer, Jo Ehm, Carsten Sahling}<br />
}</code>
    </div>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2010/01/functionality-web-services-jee/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Configuring JBoss Datasource for Firebird DB</title>
		<link>http://www.techjava.de/topics/2010/01/configuring-jboss-datasource-for-firebird-db/</link>
		<comments>http://www.techjava.de/topics/2010/01/configuring-jboss-datasource-for-firebird-db/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 00:33:17 +0000</pubDate>
		<dc:creator>shuron</dc:creator>
				<category><![CDATA[enterprise systems]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[Datasource]]></category>
		<category><![CDATA[firebird]]></category>
		<category><![CDATA[jaybird]]></category>
		<category><![CDATA[jca]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[rar]]></category>
		<category><![CDATA[server-side]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=537</guid>
		<description><![CDATA[
Accessing a relational database system from Java is a basic step required for many applications. The JEE architecture defines a standard for gaining this access, calls Java Connector Architecture (JCA). This article is a short HOWTO of configuring JCA-compliant datasource to a Firebird 2.x RDBMs using JBoss AS 5.1.0 as example. This tutorial is based [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 5px; float:right;" title="FirebirdPhoenix_Logo" src="http://www.techjava.de/wp-content/uploads/FirebirdPhoenix_Logo-150x150.gif" alt="FirebirdPhoenix_Logo" width="150" height="150" /><br />
Accessing a relational database system from Java is a basic step required for many applications. The JEE architecture defines a standard for gaining this access, calls Java Connector Architecture (JCA). This article is a short HOWTO of configuring JCA-compliant datasource to a Firebird 2.x RDBMs using JBoss AS 5.1.0 as example. This tutorial is based on a Windows installation, but can be easily ported to Linux, or other OS.</p>
<p>For the configuration of the datasource two steps are required:</p>
<ul>
<li>Deployment of the Firebird RAR resource adapter (<code>jaybird-*.rar</code>)</li>
<li>Creation of the <code>firebird-ds.xml</code> configuration</li>
</ul>
<p><span id="more-537"></span></p>
<h2>RAR Resource Adapter</h2>
<p>The RAR Resource Adapter is a version of RDBMs drivers packaged in a special way, defined by the JCA specifcation. The<br />

<a  href="http://www.ibphoenix.com/main.nfs?page=ibp_download_jaybird" target="_blank" onclick="javascript:pageTracker._trackPageview('/external/www.ibphoenix.com/main.nfs');" >latest versions of Type 4 JCA-JDBC Firebird Driver</a> (JayBird) can be downloaded from the IBPhoenix site. Inside of the downloaded archive you will find <code>jaybird-*.rar</code> (The version used during the creation of this tutorial was jaybird-2.1.6.rar). Since deployment in JBoss AS is performed by simple file copy, make sure to put the RAR-adapter-file into the deployment location of the application server. (e.G. ${JBOSS_ROOT}\server\default\deploy\).</p>
<p>After deployment, you can check the status of the resource adapter, by looking on the Administration Console of the JBoss (by default accessing the server URL http://localhost:8080/admin-console/ if run locally).</p>
<h2>Datasource Description</h2>
<p>After a successful deployment of the Resource RAR, the configuration of the datasource has to be created. The Firebird datasource configuration is supplied in a file, located in the default deployment location. JBoss AS auto-deplyoer will automatically look for the  <code>*-ds.xml</code> files, so we name it e.G. <code>firebird-ds.xml</code>.</p>
<p>The following datasource configuration defines a local transactional datasource. You just need to replace placeholders USERNAME, PASSWORD and path to your database-file (In the used installation the file was located in: <code>c:\databses\tesdb.fdb</code>)</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

  &lt;!-- ==================================================================== --&gt;
  &lt;!-- New ConnectionManager setup for firebird dbs using jca-jdbc xa driver--&gt;
  &lt;!-- Build jmx-api (build/build.sh all) and view for config documentation --&gt;
  &lt;!-- ==================================================================== --&gt;

&lt;connection-factories&gt;
	&lt;local-tx-datasource&gt;
		&lt;jndi-name&gt;DataSourceFirebirdDS&lt;/jndi-name&gt;
		&lt;connection-url&gt;jdbc:firebirdsql:localhost/3050:c:${/}databses${/}tesdb.fdb&lt;/connection-url&gt;
		&lt;driver-class&gt;org.firebirdsql.jdbc.FBDriver&lt;/driver-class&gt;
		&lt;transaction-isolation&gt;TRANSACTION_REPEATABLE_READ&lt;/transaction-isolation&gt;
		&lt;connection-property name=&quot;lc_ctype&quot; type=&quot;java.lang.String&quot;&gt;ISO8859_1&lt;/connection-property&gt;
		&lt;connection-property name=&quot;maxStatements&quot;&gt;10&lt;/connection-property&gt;
		&lt;user-name&gt;USERNAME&lt;/user-name&gt;
		&lt;password&gt;PASSWORD&lt;/password&gt;
		&lt;min-pool-size&gt;0&lt;/min-pool-size&gt;
		&lt;max-pool-size&gt;10&lt;/max-pool-size&gt;

		&lt;blocking-timeout-millis&gt;5000&lt;/blocking-timeout-millis&gt;

		&lt;idle-timeout-minutes&gt;15&lt;/idle-timeout-minutes&gt;
		&lt;check-valid-connection-sql&gt;SELECT CAST(1 as INTEGER) FROM rdb$database&lt;/check-valid-connection-sql&gt;
		&lt;track-statements&gt;false&lt;/track-statements&gt;
		&lt;prepared-statement-cache-size&gt;0&lt;/prepared-statement-cache-size&gt;
		&lt;metadata&gt;
			&lt;type-mapping&gt;Firebird&lt;/type-mapping&gt;
		&lt;/metadata&gt;
	&lt;/local-tx-datasource&gt;
&lt;/connection-factories&gt;
</pre>
<h2>Usage</h2>
<p>The datasource in the example above is registered in the <code>java</code> JNDI namespace and is called <code>DataSourceFirebirdDS</code>. In the source code, this resource should be accessible via <code>java:/DataSourceFirebirdDS</code>. Here is the example using Dependency Injection (DI):</p>
<pre class="brush: java;">
@Ressource(mappedName = &quot;java:/DataSourceFirebirdDS&quot;)
private DataSource firebirdDataSource;
</pre>
<p>In order to use the datasource in a JPA, the persistence unit has to be configured. For example, for using Hibernate, the following persistence unit can be configured.</p>
<pre class="brush: xml;">
...
&lt;persistence-unit name=&quot;testunit&quot;&gt;
	&lt;jta-data-source&gt;java:/DataSourceFirebirdDS&lt;/jta-data-source&gt;
	&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
	...
	&lt;properties&gt;
		&lt;property name=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.FirebirdDialect&quot;/&gt;
		&lt;property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot; /&gt;
		...
	&lt;/properties&gt;
&lt;/persistence-unit&gt;
...
</pre>
<p>Then in the DAO for manipulation of Persistent Entities, the Persistence Context can be injected by:</p>
<pre class="brush: java;">
@Stateless
public class TestDAOBean implements TestDAO {

	@PersistenceContext(unitName = &quot;testunit&quot;)
	private EntityManager manager;

	...
}
</pre>
<p>Have fun and please provide some feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2010/01/configuring-jboss-datasource-for-firebird-db/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Hacking, Progmatic, Productive</title>
		<link>http://www.techjava.de/topics/2008/09/hacking-progmatic-productive/</link>
		<comments>http://www.techjava.de/topics/2008/09/hacking-progmatic-productive/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 14:12:49 +0000</pubDate>
		<dc:creator>Simon Zambrovski</dc:creator>
				<category><![CDATA[enterprise systems]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[adam bien]]></category>
		<category><![CDATA[ejb]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[jughh]]></category>
		<category><![CDATA[lehmanns]]></category>

		<guid isPermaLink="false">http://www.techjava.de/?p=149</guid>
		<description><![CDATA[
Yesterday, 
the second 
Adam Bien event in 
Lehmanns Bookstore took place. Again, the event was a full success. I arrived half-an-hour earlier and got a seat only in the tenth row.
Adam spoke about new features of EJB 3.1 and Glassfish. He showed examples running on a developer build of Glassfish V3, promising that the features [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border: 1px solid black; margin: 5px;" title="AdamJUGHH" src="http://farm4.static.flickr.com/3275/2865301242_8935cb9ea7_m.jpg" alt="_MG_6980" width="120" height="180" /><img style="border: 1px solid black; margin: 5px;" src="http://farm4.static.flickr.com/3099/2865298698_0cb54c9bb2_m.jpg" alt="_MG_6978" width="120" height="180" /></p>
<p>Yesterday, 
<a  href="http://www.techjava.de/topics/2008/05/progmatic-java-ee-5-hacking/">the second</a> 
<a  href="http://www.techjava.de/topics/2008/09/productive-java-ee-6/">Adam Bien event</a> in 
<a  href="http://www.lob.de/cgi-bin/work/framesetneu?flag=new&amp;frame=yes&amp;id=48d1116c4905c" onclick="javascript:pageTracker._trackPageview('/external/www.lob.de/cgi-bin/work/framesetneu');" >Lehmanns Bookstore</a> took place. Again, the event was a full success. I arrived half-an-hour earlier and got a seat only in the tenth row.<br />
Adam spoke about new features of EJB 3.1 and Glassfish. He showed examples running on a developer build of Glassfish V3, promising that the features will work without exceptions&#8230;<br />
Here are some topics, I remember:</p>
<ul>
<li>Singleton Beans: usefull a s a central point of the application, e.G. central cache etc&#8230;</li>
<li>Async Methods: allows asynchronous execution of time-consuming methods. Especially, it is possible to abort the execution</li>
<li>Deploying Beans in WARs: could be helpful for small applications</li>
<li>Global JNDI-Namespace</li>
<li>No interface view: simplifies the access to beans, if needed</li>
<li>EJBCOntainer.getEJBContainer().getContext(): allows external initialization of bean context, which is nice for testing</li>
</ul>
<p>Later, 
<a  href="http://www.adam-bien.com/roller/abien/" onclick="javascript:pageTracker._trackPageview('/external/www.adam-bien.com/roller/abien/');" >Adam</a> discussed some 
<a  href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html" onclick="javascript:pageTracker._trackPageview('/external/java.sun.com/blueprints/corej2eepatterns/Patterns/index.html');" >Core J2EE patters</a>, that become absolete with EJB 3.1 and others which are still valid.</p>
<p>After the talk, I spoke with Adam about the 
<a  href="http://www.techjava.de/topics/2008/09/osgi-why-modularity-is-important/">OSGi</a> as a module architecture inside JEE application, which seems interesting to me.</p>
<p>The pictures are as usual available in my 
<a  href="http://flickr.com/photos/sza/sets/72157607337631878/" onclick="javascript:pageTracker._trackPageview('/external/flickr.com/photos/sza/sets/72157607337631878/');" >FlickR Gallery</a>.</p>
<p>Marco published a 
<a  href="http://www.loroma.com/loroma/movie.faces?movie=15503#Productive-Java-EE-6-1221891286879" onclick="javascript:pageTracker._trackPageview('/external/www.loroma.com/loroma/movie.faces');" >video on Loroma</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techjava.de/topics/2008/09/hacking-progmatic-productive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
