Friday, September 10, 2010

ModeShape integration with Java EE

This is one of my old posts from here http://community.jboss.org/wiki/DNAintegrationwithJavaEE

ModeShape (formerly "JBoss DNA") integration with enterprise services or one of possible answers to the Ultimate Question of Life, the Universe, and Everything

Well, while the answer is not that simple like 42 but considering that JBoss DNA will utilize other JBoss technologies and frameworks it is not that complex either - the integration picture might look like following:

dna-jee.PNG

Why Seam?

Basically it explained in short here http://seamframework.org/Home/WhySeam

Many people think that JBoss Seam is just another JSF integration framework. No, it’s not just. J

It’s all about integration infrastructure, conversation management, various services support, and bijection. One might call it “universal glue for services” – at least in Java world.

Some advantages of using Seam as the core of web service layer infrastructure (from DNA prospective):

View & presentation layer:

- built-in support for JSF (generic);

- built-in support for RichFaces and Facelets (Rich JSF implementation – AJAX+XHTML)

- Seam Remoting

- integration with alternative view layers: GWT, Hessian, Wicket, and Flex

- flexible page flow: - stateless navigation model(Using JSF or Seam navigation rules) and stateful navigation model (JBPM)

- support for reporting services: iText PDF, MS Excel, e-mail,

Services layer:

- built-in support for business processes and decisions: JBoss Rules (Drools) and JBoss JBPM;

- advanced security model based on JAAS.

- Spring framework integration;

- Web services;

- RSS support;

- Flexible packaging model;

View & presentation layer

I respectfully disagree with romney (DNA user interface discussion) and not convinced that “FLEX would be the preferred choice because it would support a dynamic user interface which will support a very expressive type of user interface. I[romney] believe html/Ajax have some limitation in this area especially when dealing with large amount of data/information.

I’m not against it as one of possible implementations but Flex may have as many limitations as any other RIA framework – everything depends on a design - for example, loading millions of records at a time (instead of paging) might “kill” any even native application. Also in order to integrate with Flex some intermediate framework(s)/service(s) needs to be deployed/configured onto application server – like Granite Data Services which adds an extra level of complexity.

On the other hand there are other ways to implement rich UI while still having it simple, maintainable and thin.

Java Server Faces technology allows abstracting particular presentation format from middle tier UI controller layer and follows MVC pattern - it separates model (UIComponent) from RenderKits which in turn allows using different render kits while still having same POJO Web controller layer.

JSF has flexible functionality to substitute not only different rendering kits on the fly or by configuration but also it allows plugging in JSF phase listeners to do custom work – e.g. invoke business rules to decide, load or create view page on the fly, etc. Other frameworks like JBoss Seam are going much further than that.

Different free rendering kits exists on JSF market – such as JBoss RichFaces (XHTML, JS, AJAX), Facelets (JSF templates + declarative composition of UI components using XHTML), XulFaces (JSF + XUL), project Woodstock, ICESoft ICEfaces, Mobile JSF (WML, XHTML-MP), and many more.

JBoss RichFaces (JSF+AJAX) is very powerful, feature rich, lightweight and simple to use AJAX framework that implements Java Server Faces spec and supports dynamic interface based on JS + XHTML – de-facto standards for dynamic web applications:

- 100+ components and UI controls (including but not limiting to calendar, inplace input and select, tree, toolbar, menu, tabbed panels, etc);

- Ajax-ed files upload to server (an example - http://livedemo.exadel.com/richfaces-demo/richfaces/fileUpload.jsf?c=fileUpload&tab=usage)

- Plug-n-skin

- Standard JSF controls extended to support AJAX;

- drag and drop support.

- JQuery support (see example with Fisheye effect - http://livedemo.exadel.com/richfaces-demo/richfaces/jQuery.jsf?c=jQuery&tab=usage );

- JS effects;


It is very easy to develop rich UI while still having thin client (without any necessity to download any plug-ins or virtual machines). See more examples here - http://livedemo.exadel.com/richfaces-demo/richfaces/support.jsf

On the other hand, same company that gave us RichFaces and Ajax4Jsf – also gave another alternative - Exadel Flamingo – an integration of Flex and JavaFX with JBoss Seam, and Exadel Fiji that extends JSF by allowing the use of Flex with JSF components and within a jsf page. See examples here - http://exadel.com/web/portal/flamingo/demo and here - http://livedemo.exadel.com/fiji-demo/

Another alternative would be to use XULFaces – an integration of Java Server Faces and XUL – powerful XML User Interface Language that relies on multiple existing web standards and technologies, including CSS, JavaScript, and DOM and integrates with native UI. For example, XulRunner might be very serious alternative to other approaches, and already used to some degree in famous IDEs like Eclipse and NetBeans as embedded Internet browser widget.

I believe that putting all eggs into single UI basket might be disastrous to any project with UI functionality – a number of new RIA frameworks are emerging as we speak. Who knows, the Java FX might be the next killer RIA in the nearest future – based on declarative language + extremely mature MVC UI framework Swing + newest enhancements in deployment model, Swing and applet in JRE 6u10 might completely change the picture of RIA and desktop.

I don’t want to start another thread about which platform/framework is better - that’s not the point that I’m trying to make. My point is simple: I believe in “AND” (integration) - in contrast with “OR” or “VS” (segregation). J

Proper infrastructure for middle layer that rely on standards is the key to success for an enterprise application - that will enable and simplify access to an application from different existing and new clients and let community to do any other way.

Services layer

Java Content Repository API (a.k.a. JSR-170 and JSR-283)

No questions here – it simple and powerful way to access hierarchical and flat content from Java applications using loose coupling like following:

// Get the Repository object

InitialContext ctx = ... Repository repository = (Repository)ctx.lookup("myrepo");

// Get a Credentials object

Credentials credentials = new SimpleCredentials("MyName", "MyPassword".toCharArray());

// Get a Session

Session mySession = repository.login(credentials, "MyWorkspace");

// get root node

Node root = mySession.getRootNode();

// get child node

Node node = root.getNode(“/a/b/c”);

Apache JackRabbit s a fully conforming implementation of the Content Repository for Java Technology API (JCR) and supports different deployment modes including embedded JCR container mode. However, it has some performance limitations (in the current design) http://wiki.apache.org/jackrabbit/Performance

One of other possible implementations might use JBoss Cache in its core – together with graph API. Sounds strange? From bird's-eye view prospective – perhaps. But closer look shows similarity in architecture: transactional tree structure of nodes with caching, clustering and persistence support (JDBCCacheLoader, FileCacheLoader, Amazon S3 CacheLoader, ETC) out of box – it might be an excellent choice for lightweight implementation of JCR API.

Typical JBoss usage example:

// Let's get a hold of the root node.
Node rootNode = cache.getRoot();
 
// Remember, JBoss Cache stores data in a tree structure.
// All nodes in the tree structure are identified by Fqn objects.
Fqn peterGriffinFqn = Fqn.fromString("/griffin/peter");
 
// Create a new Node
Node peterGriffin = rootNode.addChild(peterGriffinFqn);
 
// let's store some data in the node
peterGriffin.put("isCartoonCharacter", Boolean.TRUE);
peterGriffin.put("favoriteDrink", new Beer());

It looks very similar to JCR access code example above, isn’t it?

What about applications that built using technologies other than Java? The answer is also simple –it is essential to support widely deployed open standard’s and de-facto implementations - see below.

WebDAV

Despite on critique and its limitations this standard is not dead yet and might be useful by allowing external clients such as Microsoft Windows and Apple OS X to connect to, read and edit the content from JCR compliant repository. However, it has some issues in Windows Vista, only the WebDAV redirector is present by default; the original "Web folders" client has been removed. The "Web folders" client is only present if the Microsoft Update for Web Folders is installed.

For example, Apache JackRabbit has WebDAV module in the form of Servlet packaged in WAR application – specifically JCRWebdavServerServlet.

Common Internet File System (CIFS) support

Another possible extension for JBoss DNA is to support CIFS. CIFS is the standard file sharing protocol on the Microsoft Windows platform (e.g. Map Network Drive ...).

JCIFS is a client library that implements the CIFS/SMB networking protocol in 100% Java.

Alfresco JLAN uses a virtual file system interface that allows plugging in custom file system implementation with the core server handling all of the network protocol exchange between the client and server. JLAN is Java implementation of Window's CIFS (Common Internet File System), in addition to supporting NFS and FTP.

Apache commons VFS provides access to the files on a CIFS server.

Service auto discovery (zero configuration networking)

Federated repository works with multiple resources that require some sort of configuration and automatic discovery of services on IP networks. While it is might be difficult to enable zeroconf for some external resources without prior deploying some agents – it worth to at least enable auto-discovery of JBoss DNA Federated repository – it might be very important for JBoss DNA clients and for JBoss DNA itself in a scenario where DNA repository might sit on top of hierarchy of other DNA repositories. It is very likely scenario for global companies that have distributed, independently managed offices but still want to benefit from federated repository features.

Bonjour, formerly Rendezvous, is Apple Inc.'s trade name for its implementation of Zeroconf, a service discovery protocol. Bonjour locates devices such as printers, as well as other computers, and the services that those devices offer on a local network using multicast Domain Name System service records. This feature used in iTunes to advertise playlist.

Bonjour for Windows includes a plug-in for Internet Explorer, so you can set up a Bonjour-enabled device without knowing its IP address.

JmDNS as a pure Java implementation of mDNS/DNS-SD might help with implementing discovery of other instances of JBoss DNA repository. It is used by Apache ActiveMQ which implements Discovery Agent to detect remote services such as remote JMS brokers.

Atom based publishing service

JCR + Atom Publishing Protocol – seams to be a winning combination based on REST principles.

It is especially important for those who don’t want to use JCR or Java APIs directly.

JAX-RS (a.k.a JSR-311 The JavaTM API for RESTful Web Services) and its implementations like JBoss RestEasy, Jersey plus Apache Abdera (high performance implementation of Atom Syndication Format (RFC 4287) and Atom Publishing Protocol (RFC 5023) specifications) and Rome (RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, and Atom 1.0), will make an implementation as simple as possible.

Not to mention that RestEasy now implements Atom (thanks to Randall for pointing that out) and supports various marshallers like JAXB, JAXB +JSON.

Content Management Interoperability Services API (a.k.a CMIS)

An emerging standard is a nice addition to JCR and APP way to access content repositories of any sort based on Web Services. It is already been supported by open source community – Alfresco CMIS – is an example). Basically, it completes the picture of the repository API - JCR, Atom Publishing Protocol, and WebDAV may work together to satisfy any customer needs.

Open Search

It is difficult to imagine having any sort of repository without ability to search. It is not surprising that JCR API specification has at least ¼ of entire spec space allocated for search capability. But again, what about applications that built using technologies other than Java?

The Open Search might be the answer together with Lucene Web Service implementation – which is a REST-compliant Java servlet capable of searching and managing multiple Lucene indices via the web. It is built upon the Atom Publishing Protocol and conforms to the OpenSearch 1.1 standard. It sounds very promising.

JBoss DNA packaging and deployment

JBoss DNA consist of lots of modules and services – so it is very important to define proper packaging that suits most of use cases and deployment models while still having small number of artifacts.

IMO, RESTful service (any other WS planned?) as well as web UI application components as well as other DNA services might be deployed in any particular combination – part of standard enterprise archive (EAR ) as two independent WAR modules + DNA JCR implementationas JBoss service archive SAR and/or as JEE standard JCA Connector + DNA other services (EJB3 artefacts likeSLSB/SFSB, MDB, TB, etc) .

For example, Apache JackRabbit has JCA Resource Adapter and various deployment scenarios.

Additionally, having standard packaging artefacts like above actually will enable JBoss DNA deployment onto JEE servers different from JBoss AS (for instance, if a client will require).

Maven has support for standard and non standard JBoss packaging artefacts – thanks to guys from Codehouse.org and Maven plugins comunity.

References

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/ JBoss Seam 2.1.0.SP1, Builtin support for JSF and Richfaces

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/concepts.html#d0e3491 Context Management

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/webservices.html Webservices, REST (RestEasy integration)

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/remoting.html Remoting/AJAX

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/events.html#d0e5013 URL rewriting / bookmarkable pages

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/events.html#events.pageaction.navigation Flexible Navigation

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/jbpm.html Support for JBPM

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/drools.html Support for Drools

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/spring.html Spring Framework integration

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/groovy.html Groovy integration

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/wicket.html Wicket integration

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/gwt.html Google Web Toolkit integration

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/security.html JAAS Security

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/itext.html iText/PDF integration

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/rss.html RSS support

http://docs.jboss.com/seam/2.1.0.SP1/reference/en-US/html/configuration.html Flexible packaging in JEE5 / JSE

http://java.dzone.com/articles/flex-j2ee-developers-case-gran Flex for J2EE Developers (using Seam)

http://www.seamframework.org/Community/FlexAndSeamIntegration Flex and Seam Integration

http://livedemo.exadel.com/richfaces-demo/richfaces/support.jsf RichFaces Demo

http://exadel.com/web/portal/flamingo With Exadel Flamingo, Flex or JavaFX can be easily glued to Seam or Spring. And, in the future, Flamingo will be extended to provide glue for other RIA technologies.

http://www.infoq.com/news/2008/06/flamingo-flex-and-java-dev Introductory article

http://www.jamesward.com/wordpress/2008/09/05/integrating-flex-and-jsf-with-exadel-fiji/ Another article

http://exadel.com/web/portal/flamingo/demo Exadel Flamingo demo

http://demo.flamingo.exadel.com/booking/

http://livedemo.exadel.com/fiji-demo/ Exadel Fiji extends JSF by allowing the use of Flex with JSF components and within a jsf page.