Friday Dec 11, 2009

Enterprise Tech Tip: DataSource Resource Definition in Java EE 6

Java EE 6 has a wide variety of new features that makes enterprise and web application development a lot easier. I covered many of these features in the article Introducing the Java EE 6 Platform. However, one of the areas of improvement in Java EE 6 that I didn't cover in that article is datasource resource definition.

If you've accessed relational databases through the JDBC API, you know all about DataSource objects. For those of you who aren't familiar with DataSource objects, they're Java objects that identify and describe real-world data sources such as relational databases. To access a datasource, you need to define a DataSource object and register it with the Java Naming and Directory Interface (JNDI) naming service. An application can then use the JNDI API to access that DataSource object, which can then be used to connect to the datasource it represents.

Prior to Java EE 6, you could create a DataSource object only through vendor-specific mechanisms, such as commands. However, Java EE 6 makes datasource definition more flexible. It introduces a new datasource definition resource that you can declare portably for database connectivity across any Java EE 6-compatible application server. You can declare datasource definitions either through annotations or through the use of deployment descriptors.

Jagadish Ramu, an engineer in the GlassFish Application Server team, has written a very nice Tech Tip that describes this new capability in more detail and shows code examples that demonstrate datasource definition using annotations and deployment descriptors. The tip also includes a sample application that demonstrates the use of these features. See the tip DataSource Resource Definition in Java EE 6.

Monday Nov 30, 2009

Enterprise Tech Tip: Asynchronous Support in Servlet 3.0

The next release of the Servlet API, Servlet 3.0, which is part of the Java EE 6 Platform, adds support for asynchronous processing. That good news for developers who are working on applications that require long-lived client connections with a servlet. A good example of that kind of application is a chat application.

You can learn about some of the key features of this support such as new annotation attributes — yes, Servlet 3.0 now supports the use of annotations as an alternative to deployment descriptors — new classes, such as the AsyncContext class that provides the execution context for an asynchronous operation, and new servlet request methods, such as startAsync() for submitting an asynchronous request.

You can learn more about this support in Rajiv Mordani's Tech Tip Asynchronous Support in Servlet 3.0. Rajiv is the specification lead for Servlet 3.0.

Monday Nov 16, 2009

Enterprise Tech Tip: POST-REDIRECT-GET and JSF 2.0

JavaServer Faces co-spec lead, Ed Burns, is in the process of writing a follow up to his popular book JavaServer Faces: The Complete Reference. The new book,co-written with Neil Griffin, is titled JavaServer Faces 2.0, The Complete Reference. It's chock full of excellent tutorials about the latest version of JavaServer Faces (JSF) technology, JSF 2.0.

You can get a sneak peek into one of these tutorials, a tutorial that focuses on support in JSF 2.0 that makes it much easier to implement the POST-REDIRECT-GET pattern, or PRG for short. If you're not familiar with the PRG pattern, in short, it's a pattern described by Michael Jouravlev, in an August 2004 TheServerSide.com article titled Redirect After Post. In the article, Jouravlev described a problem that many web applications present, as follows:

All interactive programs provide two basic functions: obtaining user input and displaying the results. Web applications implement this behavior using two HTTP methods: POST and GET respectively. This simple protocol gets broken when an application returns a web page in response to a POST request. Peculiarities of the POST method combined with idiosyncrasies of different browsers often lead to an unpleasant user experience and may produce an incorrect state of the server application.

To address the problem, Jouravlev described a technique that he called POST-REDIRECT-GET, or the PRG pattern for short. The rules of the pattern are as follows:

  • Never show pages in response to POST.
  • Always load pages using GET.
  • Navigate from POST to GET using REDIRECT.

Burns says that previous versions of JSF technology violated the first of these rules by using POST for every page navigation. In navigating from one page to another in a JSF-enabled application, the JSF framework forwarded a POST request through the Servlet API's RequestDispatcher.forward( ) method. This caused a new Faces page to be rendered and returned to the browser in response to the postback request. However, thanks to a JSF contribution from the Seam team at JBoss, it is now much easier to do PRG with JSF 2.0.

If you want to learn more about this topic, read Burns's Tech Tip POST-REDIRECT-GET and JSF 2.0 The content of the tip is an adaptation of a section on PRG and JSF 2.0 in Burns's upcoming book.

Friday Oct 30, 2009

Enterprise Tech Tip: Using CDI and Dependency Injection for Java in a JSF 2.0 Application

The next release of the enterprise Java platform, Java EE 6 includes a number of powerful new technologies and well as significant enhancements to existing technologies. Two of the new technologies are JSR 299: Contexts and Dependency Injection (CDI) (referred to in earlier times as Web Beans) and JSR 330: Dependency Injection For Java. One of the significantly enhanced technologies is JSR 314: JavaServer Faces 2.0.

CDI defines a set of services for the Java EE environment that makes applications much easier to develop. Perhaps most significantly, CDI unifies and simplifies the Enterprise JavaBeans (EJB) and JavaServer Faces (JSF) programming models. It allows enterprise beans to act as managed beans in a JSF application.

Until now there has not been a standard approach for annotation-based dependency injection. Dependency Injection For Java changes that by introducing a standard set of annotations that can be used for dependency injection.

If you're involved with creating user interfaces (UIs) for web applications, you're probably familiar with JavaServer Faces. It's a technology that provides a server-side component framework that is designed to simplify the development of UIs for Java EE applications. The latest release of the technology, JSR 314: JavaServer Faces 2.0, makes UI development for Java EE applications even easier through support for annotations and the addition of new features such as Facelets and composite components.

You can get a good idea of how these technologies simplify web application development by reading the Tech Tip Using CDI and Dependency Injection for Java in a JSF 2.0 Application, written by Roger Kitain, the JavaServer Faces co-specification lead. Roger presents a JSF 2.0 application and shows in the source code where CDI components and Dependency Injection for Java annotations play a role.

Tuesday Sep 29, 2009

Enterprise Tech Tip: Locking and Concurrency in Java Persistence 2.0

One of the real success stories behind Java EE 5 is the Java Persistence API, know informally as JPA. The technology has been widely adopted and is recognized as the enterprise standard for Object/Relational (O/R) persistence.

However, one of the shortcomings of JPA 1.0 is that the only type of locking it supports is optimistic locking. Recall that locking is a technique for handling database transaction concurrency. When two or more database transactions concurrently access the same data, locking is used to ensure that only one transaction at a time can change the data.

There are generally two locking approaches: optimistic and pessimistic. Optimistic locking assumes that there will be infrequent conflicts between concurrent transactions, that is, they won't often try to read and change the same data at the same time. In optimistic locking, the objective is to give concurrent transactions a lot of freedom to process simultaneously, but to detect and prevent collisions. Two transactions can access the same data simultaneously. However, to prevent collisions, a check is made to detect any changes made to the data since the data was last read.

Pessimistic locking assumes that transactions will frequently collide. In pessimistic locking, a transaction that reads the data locks it. Another transaction cannot change the data until the first transaction commits the read.

The next release of JPA, JPA 2.0, which will be offered as part of Java EE 6, adds support for pessimistic locking. Using JPA 2.0, you can lock an entity either optimistically or pessimistically, depending on how often you think transactions will collide.

To learn about the new locking support in JPA 2.0, see the Tech Tip Locking and Concurrency in Java Persistence 2.0 by Carol McDonald.

Friday Jun 26, 2009

Enterprise Tech Tip: A Sampling of EJB 3.1

Enterprise JavaBeans (EJB) technology has taken a number of knocks in the past. When it was first introduced some, perhaps many, cried that it was too complicated, with a lot of programming overhead that made the technology needlessly difficult to use.

Over time things have improved dramatically. Features such as annotations in EJB 3.0 made the technology much, much easier to use. Those ease-of-use advancements continue with the upcoming release of EJB 3.1, which will be included in Java Platform, Enterprise Edition (Java EE) 6. A preview version of Java EE 6 is currently available for download. The preview version includes a nearly complete implementation of EJB 3.1

If you want to learn about some of the new, cool features in EJB 3.1, see the Tech Tip, A Sampling of EJB 3.1, written by Ken Saks, the EJB 3.1 Specifical Lead.

Wednesday Apr 15, 2009

Enterprise Tech Tip: Jersey and Spring

There have been a number of interesting Enteprise Tech Tips about JAX-RS and Jersey. These include Implementing RESTful Web Services in Java, Configuring JSON for RESTful Web Services in Jersey 1.0, and Consuming RESTful Web Services With the Jersey Client API. Recently, another interesting Tech Tip on Jersey made an appearance. This one covers Jersey's support for the Spring Framework.

Spring is a very popular enterprise Java framework, and if you're a Spring user who is also interested in JAX-RS, check out this tip.

Monday Apr 13, 2009

Two new Tech Tips

I'd like to highlight two interesting Enterprise Tech Tips that were added over the last few months to the Enterprise Tech Tips blog. The first, Converged Enterprise Applications, by Prasad Subramanian, is a follow up to an earlier tip on Session Initiation Protocol (SIP) servlets and their use in voice-related applications. The earlier tip introduced the concept of a converged enterprise application -- an enterprise application that has a SIP servlet application bundled within it. The follow-up tip goes into more detail about this concept and provides a working example. Prasad Subramanian is the project lead for the Sailfin project, an open source implementation of a SIP servlet container using the GlassFish application server.

The second tip covers Jersey's support for Spring. The tip is written by Paul Sandoz, co-spec lead and implementation lead for JSR-311, the Java API for RESTful Web Services (JAX-RS). Jersey is an open-source, production-ready reference implementation of JAX-RS. Spring is a popular framework for building and running enterprise Java applications. Jersey has integrated support for Spring. This tip shows you how to take advantage of that support. It shows you how to configure Spring with Jersey and use Jersey's Spring-related features.

And by the way, if your a quiz aficianado, try the Tech Tips quiz.

Friday Oct 31, 2008

Enterprise Tech Tip: Configuring JSON for RESTful Web Services in Jersey 1.0

There's a lot of interest in the developer community in RESTful web services. That's because the Representational State Transfer (REST) approach presents a relatively simple and flexible way of building and communicating with web services. Message exchanges with a RESTful web service can be conducted in any format, including JavaScript Object Notation (JSON). Because of its simple text format, JSON provides a good alternative to other message interchange formats such as XML and is particularly attractive as a meassage interchange format for RESTful web services.

This tip shows you how to build a Jersey-based web application that returns information in JSON format. Jersey is an open-source, production-ready reference implementation of JAX-RS, the Java API for RESTful Web Services (JSR-311).

See the tip Configuring JSON for RESTful Web Services in Jersey 1.0.

Tuesday Oct 21, 2008

Enterprise Tech Tip: Using WS-Trust Support in Metro to Secure Web Services

This is another in a series of Tech Tips related to Metro, the high performance, extensible, easy-to-use web services stack that is implemented in the GlassFish application server. This one, written by Jiandong Guo, a senior member of the Application Server Web Services Security GroupWeb Services Security, focuses on the support in Metro for WS-Trust. You will learn the basics of WS-Trust and its Security Token Service (STS) framework. You'll also learn about the support in Metro for WS-Trust and STS. And you'll see how easy it is to take advantage of this support to secure a web service using Metro and the NetBeans IDE.

See the tip Using WS-Trust Support in Metro to Secure Web Services.

Monday Sep 15, 2008

Enterprise Tech Tip: Composite UI Components in JSF 2.0 -- Part 2

As I mentioned in my previous post, this two-part Tech Tip introduces a powerful new feature in JavaServer Faces (JSF) 2.0 technology: composite user interface (UI) components. Part 1 of the tip shows you how create a composite UI component and use it in a web application.

Part 2 is now available. It shows you how to add functionality (through attached validators, converters, action listeners, and value change listeners) to the composite component you created.

See Composite UI Components in JSF 2.0 -- Part 1 and Composite UI Components in JSF 2.0 -- Part 2.

Tuesday Sep 02, 2008

Enterprise Tech Tip: Composite UI Components in JSF 2.0 -- Part 1

This Tech Tip introduces a powerful new feature in JavaServer Faces (JSF) 2.0 technology: composite user interface (UI) components. This feature allows you to turn any collection of page markup into a JSF UI component -- with attached validators, converters, action listeners, and value change listeners -- for use by page authors.

This tip is presented in two parts. In the first part, you'll learn you how create a composite UI component and use it in a web application. In the second part, which will be published in the next issue of the Enterprise Tech Tips, you'll learn how to add functionality to the composite component.

See Composite UI Components in JSF 2.0 -- Part 1.

Tuesday Jul 15, 2008

Enterprise Tech Tip: Using P6Spy and the GlassFish Connection Pool to Trace Database Operations

Detecting performance bottlenecks is an important task in optimizing database operations in an application. One way to do that is to trace the database operations of the application. This information can help you fine tune the database calls that the application makes and in this way improve the application's performance. In this Tech Tip, Sun engineer Jagadish Ramu demonstrates how to use a tool called P6Spy to trace the database requests issued by an application running with the GlassFish v2 application server. Specifically, you'll learn how to trace SQL statements from an application that uses GlassFish's JDBC Connection Pool. It's all covered in the tip Using P6Spy and the GlassFish Connection Pool to Trace Database Operations.
About

edort

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today