February 21st, 2010

Embed Glassfish in an existing OSGi environment

OSGi is something that is very fashionable in the industry these days. Every big software company makes sure that its products are running inside OSGi environment. Besides the ‘cloud’, OSGi is one of the most used buzzwords today.

Glassfish is the reference implementation application sever of the Java EE specification. It is itself built of modules that are run and managed by an OSGi environment. So the question that the author of the article answers is whether it can be bundled in another OSGi framework. Equinox is used for that purpose.

The author has developed a simple bundle activator. As Glassfish is itself modularized, the task of the bundle is to walk through the modules directory, register the modules that it finds there with the OSGi runtime, find Glassfish’s main bundle and to start it.

Very interesting post for those of you, who have some experience in the OSGi bundle business.

Rich Java web applications with Apache Wind and AJAX

After last week we read an article about one of Apache’s JAX-WS libraries (Apache CXF), now IBM developers works give us ASF’s proposal for the other web services standard – JAX-RS. Apache Wink is still an incubator project, but nevertheless you can see that it works great. It provides support for both the server side part for developing the web services as well as for the client part for consuming them.

The author explains in the beginning the benefits of JAX-RS: it is easier to use and understand than JAX-WS and the format (or the payload) of the documents that are transmitted between the communicating parties, is not always XML.

The last thing is actually elaborated in more details – in the example application the data is transmitted via JSON. It is less verbose than XML and there are plenty of libraries that convert a JSON file to an object and vice versa.

The second part of the article is for developing the client side of the application. As it is a web application, you can imagine that the author builds some web pages. One of the most popular technologies here is AJAX. Through AJAX, you can execute server request from within java script code of your page without the need reload the whole page. The combination of java script code and quick response time makes the AJAX-ified web applications look and behave nearly like desktop ones.

By reading the article you will not only get hands-on experience in building REST-ful web services, but you will learn how to combine it with the JSON format and how to call the web services from AJAX.

Short introduction to XML schemas

Continuing with the web services in this blog, I present you a short introduction to one very important aspect of the JAX-WS world: the XML schemas.

These are documents that describe the order and type of the XML elements in a document. XML schema documents are very useful for both validating the XML content and also for generating objects from XML. It is a successor of the document type definition (DTD) format, which most of you should know and maybe worked with. By applying XML namespaces, you can have an XML document, which uses and conforms to several XML schemata.

If you need a quick intro and do not have the time to go through the detailed w3c schools tutorials, then this is the article for you. You can also browse Inform IT’s Java guide section for another topic that might be interesting.

Version Control Tools

Another article by Martin Fowler. Virtually all the world developers work with version control tools. You use them everywhere, even for the open source projects that you develop by yourself. If you are not using one for your project, then you should consider choosing. As the author points version control tools are used for both tracking the different versions of the code you develop and also for collaboration.

There are a lot of tools that help us in that. The author reviews three of them, but before that he mentions which are the tools, the he would never use. He classifies the good tools in two groups – with centralized repository and with distributed repository.

If you want to understand more about the differences between Subversion, Mercurial and Git, then go and read the short article.

February 14th, 2010

This is the week of the web services (both kinds) articles. And some hard skills for dessert.

Comparing JAX-RS and Spring MVC

Before going into details about the above article, I would give you a short introduction in the abbreviations you see. JAX-RS stands for Java API for RESTful Web Services. This API provides standard interfaces (or rather annotations) that turns your POJO class into a RESTful application. This REST abbreviation stands for REpresantational State Transfer. As opposed to the standard web services, which are more thought as providing some remote functions to be called, the REST services build on the paradigm of providing resources, that have a path in the form of a URI (or URL), they have a type (the HTTP mime types – XML, text, HTML, PDF, etc.). As REST is carried by the HTTP protocol, the web service’s functions are annotated and correspond to the four HTTP request types – get, put, post, delete. So, the web service that you develop live in a container that supports the REST protocol (Jersey is the reference implementation and is part of Glassfish v3). The web service annotates its methods with one of the annotations representing HTTP request type and also indicates to which URL it responds. Usually, the latter is a relative path following the hosting server address. When the server receives a request for a path, it dispatches it to the corresponding web service method. For more information, you can search for the various resources in Internet.

Spring MVC is Springsource’s Model-View-Controller technology. Its main job is provide easy to use way for our web applications to handle incoming requests, invoke the appropriate business logic and based on that build the response. In Spring 3.0 this is easier more than ever. It is achieved with minimal configurations, most of which is part of the class definitions in the form of annotations. Another thing in the latest version is that Spring controllers are REST-oriented: each of them maps to a specific path in the URL, each if its methods correspond to a specific request type and sub-path of the original type.

If you were not familiar with these technologies, then it would be great to read something about them, as especially JAX-RS and REST are getting momentum right now. If you already know the basics, then the article is for you. The author does not actually try to compare them and judge which is the better one. He rather shows how a technology like Spring MVC, that was initially designed for web application development, can be used as a JAX-RS container. It supports most of the specification’s common features. Very interesting article by the fellow Bulgarian blogger, who BTW works for Springsource ;-).

Introducing CXF

Apache CXF is a web services framework built by the Apache Software Foundation. It supports both types of web services – JAX-WS (including most of the standards under its umbrella) and JAX-RS. It can both create java classes from WSDL files and vice versa.

The IBM developer works article is third in a series presenting web service frameworks. The author compares Apache CXF to Axis2 (again from Apache) and to Metro (from Sun). He shows later on how you can create a simple web service (the server and the client side) for searching a book library. This very same sample was built in the previous two installments of the series with the other two web service stacks.

Introduction to JAX-RS with Jersey

This article is for those of you who have a vague understanding of what RESTful web services are, but have no experience with implementing those in Java. The author does not really go into details about how REST works, what do the different annotations mean, etc. He puts more emphasis on how to pack and access your POJOs in a server that used Jersey (the reference implementation for JAX-RS).

Glassfish v3 is chosen as an app server, though it is not obligatory. When you install it, you get Jersey for free. By reading the article, you will find in great detail how to configure the web.xml, how to deploy the war file, and then how to access it. It is also accompanied with fistful of screenshots.

Are you a software architect?

The role of the software architect is assumed to be taken by the most experienced developers in the team. However, is that the only thing that the architect should possess – experience?

According to the author, the architecture process can be broken into two phases: architecture definition and architecture delivery. These two phases are additionally broken down into five elements each. All these elements are discussed in details. Read on and answer the question: Are you a software architect?

February 7th, 2010

by Ivan St. Ivanov

JavaScript frameworks compared

The JavaScript language is very heavily used in many web sites. It has the features of both the dynamic and object orientated languages and makes the static HTML pages look shinier. With the advent of AJAX and the rich internet applications, the importance of JavaScript has become even greater. Of course some of the rich sites use other technologies like Flash, Wicket, GWT (which eventually translates to JavaScript), Java Applets, Silverlight, etc. But JavaScript is still ubiquitous.

One of the problems of JavaScript is that it is incompatible across the different browsers (Internet Explorer, Firefox, Safari, Chrome, etc.). It also does not come by default with all the GUI components that are usually used in a page. Well, it is not a component framework after all.

However, there are some JavaScript libraries that help us in those directions. They provide standard objects and functions which do all the standardization and boilerplate for us. The author of the above article discusses several aspects of a typical JavaScript program (DOM tree manipulation, utility functions, event handling and AJAX) and explains how the most popular JavaScript frameworks support them – what are their built in objects and functions that do the job for us.

At the end there is a comparison between all these frameworks and the features which they support. I was surprised that Dojo was not in the list of the compared libraries, but only in the ‘Others’ section, but anyway. Even without it the article looks interesting enough.

Google App Engine, JSF and Weld – part 1

In this article you can see how you can easily create and host a web site using some of the hottest Java technologies and solutions in the industry. So let’s start one by one…

The hosting solution is provided by Google app engine (GAE). It started about an year ago and initially could host applications written in python. But in a little while it provided the same service (with very small limitations like disabled multi-threading for example) for Java apps. And the best thing is that if you don’t go over the free quotas, then you don’t have to pay for the hosting service. As you can see from the above linked figures, this is a perfect proposal for a site with not so many users and not so high traffic. Google also provides an SDK, which can help you run your application locally, as well as a plugin for integration with Eclipse.

The author of the article starts exactly with that – how you can create a Google App Engine account and then how to create your project. The next step is setting up the presentation layer using the JSF technology. As it is a simple Hello world application, there is not so much of the JSF itself, rather than the author spends most of the time in explaining in detail how to configure it so that it can be used in the GAE environment. You can see very well explained all the bits and pieces of the web.xml configuration.

Next comes the technology that backs JSF. It is the Java Contexts and Dependency Injection represented by its reference implementation – Weld. Using this you can create a plain old java object, which methods can be called in the JSF pages.

Finally, after you have built the application, you can run it on a local web server provided by the GAE SDK. And if you are satisfied, then you can deploy it via the Eclipse plugin to the Google App Engine on the internet.

Debugging and testing Swing code

I suppose most of the readers of this blog have the experience of doing GUI programming. In the Java world the most common way to do this is to by using the Swing technology. Of course Java FX is emerging these days, but all the legacy Java standalone applications use Swing.

The author of the article points that sometimes if you need to understand and later on support such an applications is a very challenging task. Swing is so flexible and feature-full that you can express a very simple program window in more than one way. In addition to that different events can cause hiding of some of the controls and the components and showing up of others. This makes understanding the structure and testing the GUI even harder.

In this very interesting article you can find out how a couple of libraries can help us find out which are the components that build up the application interface, how are they structured, which are the exact Java classes that are used to visualize those components and display the components’ properties etc. You can also run some behavioral tests using a special Java domain specific language in order to find out whether clicking some buttons, menus, etc. produce the expected behavior. It is achieved not by simply using screen coordinates and generating some mouse clicks or keyboard strokes, but is goes on another level – the components are distinguished by their names and the user events are more sophisticated.

You can read the article for more details.

Soft skills article of the week

And now for something completely different. Martin Fowler (the author of the terms inversion of control and dependency injection) speculates on what is the correct way of task definition in the agile processes. Most of the people think that developers should not care about defining the user stories as it is the responsibility of the product owners (or system analysts). However, according to the author the defining (or actually the refining) task is a mutual responsibility of both parties.