June 5, 2009

June, 5th: Environmental Day

Sitting at home, reading about the recession in the papers, seeing it in the news, all this makes you angry and restless. But what if this is just a fraction of the real life?

Today is Environmental Day all over the world! What does this mean to me and to you? Well, I don't have the answer but this web site might give you an idea:

"We are living in exceptional times. Scientists tell us that we have 10 years to change the way we live, avert the depletion of natural resources and the catastrophic evolution of the Earth's climate.

The stakes are high for us and our children. Everyone should take part in the effort, and HOME has been conceived to take a message of mobilization out to every human being."

Go and visit HOME

May 17, 2009

Book Review: Business Process Driven SOA using BPMN and BPEL

One of my last projects was for the Public Services and it felt that these people tend to live for business processes by definition. But while we went on with the project requirements, a team mate showed the whole team what he did for a former project with similar requirements. It was a single diagram done with the BPMN notation and it covered a pretty thorough picture of the requirements and process dependencies.

BPMN is not just another modelling language for Business Process Modelling but the one orgininally build for this purpose. It is less technical then UML, includes support for timed execution of process steps and can help to run a simulation of the whole process in a tool.

The book by Matjaz B. Juric and Kapil Pant is a good starting point to learn BPMN for your project and get the right focus to it. While chapters 1 and 2 introduce you to the need of a proper modelling technique for SOAs, chapters 3 and 4 explain the BPMN language in more detail, present all available constructs as well as patterns and advanced techniques for better use of BPMN. Chapters 5 and 6 complete the book by showing how BPMN could and should be used in SOA / BPEL projects.

Compared to the UML books on my book-shelf, this one is a refreshingly small, easy to read and quickly to understand and apply. If you are a highly technical person, you might be quickly bored, but with a less technical more process oriented background you can get quickly up to speed with those tech guys. Likewise both types of readers can reach the same level of understanding with a fairly easy modelling language and can better work in a powerful team.

Book Details

Business Process Driven SOA using BPMN and BPEL, Matjaz B. Juric and Kapil Pant, 311 Pages, ISBN 978-1-84719-146-5, Packt Publishing, www.packtpub.com

Book Review: Processing XML documents with Oracle JDeveloper 11g

Although is very often not considered as the IDE of choice, JDeveloper is a wonderful and productive tool chest for everyone. When I found Deepak Vohra's book about XML processing with JDeveloper, I was instantly convinced as I know Deepak Vohra as an author on the Oracle Technology Network.

In its book he covers a broad range of XML document processing techniques within JDeveloper. In 14 chapters you will find almost everything that you might need for your XML processing. Very naturally it starts with XML document reading and writing. Once you finished that piece of work, requirements get more sophisticated and XML Schema definition and validation are needed for the documents of the same type. Voila, chapters 2 and 3 are there to read about it. And so it goes on, topics like XPath and XSLT transformations are followed by the JSTL XML Tag Library. DOM Level 3 Load and Save and Validation follow. A chapter on JAXB 2.0 concludes the first part of the book which introduces all basic techniques to work with XML.

The last five chapters show typical usage scenarios of these techniques. Chapter Comparing XML Documents is just the warm up phase for the next two chapters about XML Conversion to different output formats (chapter 11: PDF and chapter 12 for Excel). The last two chapters cover Storing XML in Oracle Berkeley DB XML while the last chapter gives you an appetizer for Oracle XML Publisher.

This book presents you a quick and easy learning path through the functionality offered by JDeveloper and the included Oracle XML Development Kit. You can start at every chapter you want. They are self-contained and do not require a cover to cover reading. Likewise the author does not bother to teach you XML, XSD, and XSLT from the ground up and in every detail. You just get enough information to set the scene and wet your appetite for more information.

The downside of the book are the code samples. Almost every code sample is just there to demonstrate how things work, but should not be considered as a blueprint for your product. I saw resource leaks, hardly maintainable code due to ignoring DRY style (Don't Repeat Yourself) or different type usage conventions (import vs fully qualified class names). Proper code formatting with indentation, usage of blanks or curly braces, or common sense of factoring for repeated code parts would have made the book superb.

Having said that, it is quite a good book in nearly every aspect. It leads you quickly to the point of the topic and does not waste your time with chapter-long introductions. You can start quickly and improve your knowledge as you go.

Book Details

Processing XML documents with Oracle JDeveloper 11g, Deepak Vohra, 370 pages, ISBN 978-1-847196-66-8, Packt Publishing, www.packtpub.com

April 29, 2009

Java Performance: The Return of the Usual Suspects (Updated)

After some years of Java development, one should expect that all lessons are learned and good code is the norm. Yes, really, but this isn't the case. As I work in different projects and reading many books, I am still surprised how often you will find the same ways for doing things wrong.

Create Unnecessary Objects

One of the easiest errors you can do, is to create unnecessary objects. Yes, honestly. There is one famous class in the whole Java environment that can only have two real values. These values are provided as constant values and the only reasonable ones everybody should use as objects of this class. I am talking of the Boolean class. True and false are the only instance and are provided as constant values Boolean.TRUE and Boolean.FALSE. Unfortunately, this class also has a public constructor Boolean(boolean value). This constructor leads to really unnecessary code new Boolean(true) or new Boolean(false). If you see this in your code, it is time to speak with the author and introduce some code inspection tools like FindBugs or PMD.

Use of StringBuffer

In JDK 1.0 times, StringBuffer was a reasonable approach to boost performance for String concatenation. It still is an alternative, but StringBuilder is a better one. The worst thing you can do is to concatenate string literals (aka constant strings) with StringBuffer.append(). Because you are working with literals use the + operator. It gives the compiler the chance to optimize the concatenation during compile time and not to leverage the effect to the runtime.

Method Calls in Loop Conditions

It is really tempting to use the "size" methods of the collection classes (anything like size(), length(), rowCount(), etc.). But before you use them in a loop condition like for(int i = 0; i < array.size(); ++i), take a step back and think about it again. Do you just iterate over it to find something? Or do you modify it in the loop? If the content of the collection will not be modified you should use a construct like for(int i = 0, size = array.size(); i < size; ++i). This is much faster, especially when the method is synchronized.

Repeated Access of the Same Object Through a Method

Very often, in a loop you find code to access the same object through the same method more then once. This makes your code hard to read, less maintainable, and slower. Imagine this method call is synchronized, what an avoidable bottleneck. Of course, you check the method before writing the code, but this does not help for ever. The next version of the API might use a synchronized method. Anyway, to improve the readability, maintainability and performance of the loop, you can introduce a temporary variable, call the method and use the variable throughout the loop. Here is some code:

// Bad
for (int i = 0, size = array.size(); i < size; ++i) {
   doSomething(array.get(i));
   doSomethingElse(array.get(i));
}

// Better
for (int i = 0, size = array.size(); i < size; ++i) {
   Object obj = array.get(i);
   doSomething(obj);
   doSomethingElse(obj);
}

Sure, these two line loop isn't really challenging, but image loops with more lines and line lengths with more then 80 characters...

JDBC DriverManager vs DataSource

Another classic. Use of JDBC in a server environment is much different than in a simple demo environment. You should avoid the DriverManager API (for example, not allowed in Java EE) as this does not allow you to provide connection pools as with a DataSource and very often the wrong class loader is used.

Closing JDBC Resources

Although some JDBC drivers support implicit closing of JDBC resources it is still a recommended practice to close the JDBC resources in the right order at the right place in your code and explicitly. The right order is ResultSet, PreparedStatement, Statement, and Connection. The right place for issuing this code is the finally clause of your try-catch-finally block. Do not reinvent the wheel for this, use the Apache Commons DbUtils library.

Use the Correct ClassLoader

The usage of the ClassLoader in Java is very often the only way to get resources loaded. Using the correct ClassLoader is essential for a perfect running application. The best way to use the correct ClassLoader is by using the Context ClassLoader. You can access it through Thread.currentThread.getContextClassLoader()

Don't Repeat Yourself - DRY

You can write the worst code in every programming language. If you write your code, always ask yourself, whether you have seen this code before, if so, try to refactor both pieces to common code and find ways to put custom code in it. Repetition is boring and introduces errors and problems.

Common Wisdom

This is just the tip of the iceberg. You can get much more interesting points to check your code against from very good references:

April 6, 2009

Upgrading your WebLogic to ADF 11.1.1.0.2

One of the first questions that come up with the JDev /ADF 11.1.1.0.2 release is how to upgrade your WebLogic 10.3 to it. Here is my solution:

  1. Open the Uninstaller of your WebLogic installation
  2. Select JDeveloper 11g (11.1.1.0.x) Studio Edition 11.1.1.0
  3. Uncheck everything under WebLogic Server
  4. Click Next to finish the deinstallation. If you're interested you can click on the Details button to see what has be uninstalled.
  5. Now open the JDev 11.1.1.0.2 Installer
  6. Select the WebLogic home where to install the new ADF version
  7. Now deselect everything and select the Application Development Framework Runtime only. Note: This will also select the JDeveloper and ADF folder again.
  8. To avoid class loading issues, rebuild all your EAR files.

Enjoy.

Note: You will find the Uninstaller either as $WLSHOME/wlserver_10.3/uninstall/uninstall.sh or %WLSHOME%\wlserver_10.3\uninstall\uninstall.cmd. On a headless server (like a Linux or Unix-based system) you may need to set the DISPLAY variable to an X Server like VNC or Xming. (Assuming that $WLSHOME or %WLSHOME% is your home directory for the WebLogic Server 10.3. installation.)

JDeveloper 11.1.1.0.2 Released!

Over the weekend the latest bug fix release of JDeveloper 11g (11.1.1.0.2 or Build 5205) was released on OTN. Go and get it while it's hot.

January 8, 2009

Who to Blame for the Crisis?

If you are lucky to live and work in the industry for some decades, you will notice that every crisis follows a similar pattern:

  1. Total Surprise, Total Shock - Oh my god, how could this happen? Everybody was working like hell in a "rock solid" company with a "rock solid foundation".
  2. That was expected - There is always someone, who expected it, and always someone who is able to blame someone.
  3. Blame Someone Else - Finally, after the first shocks and blames are gone, someone starts to blame things or ideas or technologies, just to become the World's Next Hero.

Today's Victim

Today's victim is ... (drum roll) ... SOA. I don't advocate for any opinion, just read these few links to make up your mind. The truth is somewhere in the middle.

Morale

The step from Hero to Zero is small. The gap between both is huge and not everybody is able to realize or accept these dangers. If you decide to be World's Next Hero, be prepared and good luck. There is always room enough for more then one hero.

What about me?

Well, no changes. I'm still following my own mantra, live to have fun and don't stop to be curious about the inner workings of the ideas that keep the world spinning...

November 3, 2008

ADF in Action (11g): Prepare Yourself for the UI

A Simple Test Application

Before we start to develop the UI, we test the deployment of a simple Hello World ADF Faces application. This helps to find possible errors and problems very early. OK, here we go.

  1. To make things easy we start with a new application. In your JDeveloper 11g Application Navigator go to the list of applications and select the New Application ... entry from the drop down.
  2. In the Create Generic Application wizard, set the Application Name to ADFHelloWorld. Select the Application Template: Generic Application and click on Next.
  3. Now enter HelloWorld for the Project Name and click on Finish.
  4. Select the HelloWorld project and open the Context Menu, and chose New...
  5. In the All Technologies tab scroll down until you find JSF, select it, select JSF Page from the Items area, and click OK.
  6. In the Create JSF Page window, set the File Name to helloworld.jspx, for Use Page Template select /oracle/templates/threeColumnTemplate.jspx, check Create as XML Document (*.jspx), and click on OK.
  7. Open the Component Palette and select ADF Faces from the drop down box.
  8. In the Common Components accordion find the Output Text component and drag it to the center area in the helloworld.jspx.
  9. Find the Output Text Property Inspector and set the Value to Hello World! Expand Style and set the Size to xx-large.
  10. To see the results in a browser, select the helloworld.jspx, open the Context Menu and select Run

Deploy to WebLogic 10.3

During development we use the integrated WebLogic server and everything works fine. But will the same be true for a standalone WebLogic 10.3 server? Not necessarly. We have to do some steps before we can successfully deploy to the WebLogic server.

During installation of JDeveloper 11g you might have noticed that you can select an existing WebLogic server installation directory. This is necessary to install the ADF runtime to the WebLogic server in question.

  1. Start the JDeveloper 11g Installation Wizzard.
  2. In Choose Middleware Home Directory select Use an existing Middleware Home and select the home directory of your WebLogic server.
  3. In Choose Products and Components uncheck everything but Application Development Framework Runtime
  4. The wizard will install all the necessary libraries in a jdeveloper directory underneath your Middleware Home
  5. With the WebLogic Domain Wizard create a new domain or update an existing domain with the Application Development Framework included.

Are we ready? No, unfortunately not. We have to do create a Deployment Profile to be able to deploy it and also need to setup an Application Server connection.

The Deployment Profile

Creating an Deployment Profile has not changed. But we mention all the steps again.

  1. Select the HelloWorld project, open the Context Menu and select the New entry.
  2. In the New Gallery scroll up to the General group and find the Deployment Profiles sub group.
  3. From Items select the WAR File entry and click OK
  4. Use helloworld as Deployment Profile Name
  5. In the Edit WAR Deployment Profile Properties window select Specify Java EE Webb Context Root and set it to helloworld. Click OK.

The Weblogic Deployment Descriptor

It is necessary to enable the JSF and JSTL libraries with a WebLogic-specific deployment descriptor. For this case we use the deployment descriptor for the web application:

  1. Select the HelloWorld project, open the Context Menu and select the New entry.
  2. In the New Gallery scroll to the General group and find the Deployment Descriptors sub group.
  3. From Items select WebLogic Deployment Descriptor, click OK, select weblogic.xml and click OK
  4. Open the weblogic.xml and make sure it looks like this:
<?xml version="1.0" ?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app.xsd"
xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
  <library-ref>
    <library-name>jstl</library-name>
  </library-ref>
  <library-ref>
    <library-name>jsf</library-name>
  </library-ref>
</weblogic-web-app>

The Application Server Connection

As mentioned in previous posts, JDev 11g offers us two options to specify Connections to various server types. Unfortunately, the application-specific option for Application Server Connections is not available. These are only available as IDE Connections.

  1. Open the Resource Palette and expand the IDE Connections accordion.
  2. Click on the Folder with Star icon and select New Connection > Application Server
  3. Follow the wizard to specify all the information requested. Do not forget to Test the connection.

Deploy the Sample

Great, we are now ready to deploy the sample application.

  1. Select the HelloWorld project, open the Context Menu, select Deploy, select helloworld, select to and find the application server connection you have just created.
  2. You can now run the application by pointing your browser to the URL http://hostname:7001/helloworld/faces/helloworld.jspx

Caveat

Sometimes the deployment does not work as expected. I have encountered these:

  1. Remote WLS servers - You have to create a WAR or an EAR file, copy it to the remote server and deploy it through the WLS Console (http://hostname:7001/console)
  2. WLS on Windows - Sometimes the deployment on a standalone WLS 10.3 on Windows XP doesn't work correctly. I am investigating this and will post a solution.

October 31, 2008

JDev 11g: Packaging Libraries at EAR Level

Many users have problems to use their libraries in their applications. But sometimes a working solution is too obvious to be noticed.

To include all the libraries you need for your project in an EAR file:

  1. Create a package project called common-libs and put all the libraries in a directory included in the Project Source Path. Don't use the src directory but lib at the same hierarchy level. Add this new directory to the Project Source Paths.
  2. Open the Application Properties
  3. Create a deployment profile for the EAR file.
  4. To include the libraries within the EAR file we have two options to include the libraries are available: either put into APP-INF/lib or a directory of your choice (eg. lib). In the Deployment Profile select Application Assembly, tick the check box of every JAR file you need and enter the directory name (APP-INF/lib or lib) in the Path in EAR text field at the bottom. This must be done for every JAR file!
  5. If you do not want to use APP_INF/lib you need to create an application.xml for the application. Open the Application Resources accordion and expand Descriptors and META-INF to see which Deployment Descriptors are available. On Descriptors, chose New JEE Deployment Descriptor... from the Context Menu and select application.xml. In the newly created application.xml insert the tag <library-directory>lib</library-directory>.
  6. From the Application Menu select Deploy to EAR File to check the contents before deploying it to the server.


Nice JDev 11g Feature: EAR Packaging

While working on the samples for JDeveloper hands-on workshops and on the ADF in Action series, I stumbled into this nice feature...

EAR Packaging with JDeveloper 11g

In previous releases of JDeveloper a number of different strategies have been used to ensure a proper EAR file packaging. Very common is the usage of Ant or Maven scripts, because these are useful for daily builds.

Background

The JDeveloper IDE has the concept of Applications and Projects, if we translate Application to Enterprise Application and Project to Module, we are right in the Java EE nomenclature and can easily understand how to create an Enterprise Application Archive (EAR) with modules like Web Application (WAR), Enterprise JavaBeans (EJB JAR) and so on. With this background information we are able to locate the necessary deployment profiles for each part of the final application.

Each project has its own deployment profile, eg WAR file for a web application or JAR file for a library project. But if you want to put everything together, where do find it?

The Application Deployment Profile

Exactly, the application itself will hold the deployment profile for the EAR file. To find it we need to go to the Application Properties. Application Properties? Where are they? They are located at the Application Level:

  1. Open the Application Navigator
  2. The topmost element is a drop down box with the names of the applications in your IDE. Right next to the drop down box you find the application menu. Click on it and open the Menu. There, at the end of the menu you will find the entry Application Properties! Select it and you will open the Application Properties window.
  3. Select the Deployment entry to go to the Deployment Profiles overview. On the first time it is empty.
  4. To create a deployment profile, you must click on the New... button. The Create Deployment Profile window appears and you can select the Archive Type. On this level only the type EAR File is avaiblable and useful.
  5. Give the profile a Name and click OK.
  6. Once created you are able to edit the EAR Profile Properties.

Edit the Appliction Deployment Profile

The Edit EAR Deployment Profile Properties window allows you to edit the Application Assembly, ie. which modules, er project results, are part of your EAR file, or the Filter Groups.

Bonus: Locate and Edit the Application Deployment Descriptors

To locate and edit the Application Deployment Descriptors you have to expand the Application Resources accordion in the Application Navigator. The Descriptors group contains all the deployment descriptors used at the EAR level. If you want to add a Java EE or product specific deployment descriptor click on META-INF and open the Context Menu. It will contain the three entries New JEE Deployment Descriptor, New Oracle Deployment Descriptor and New Weblogic Deployment Descriptor. All three open a window to select the specific deployment descriptors from.

Enjoy.