Syndicate This Blog
Saturday, January 19. 2008
Welcome to the last entry of this blog. No I am not quitting, I am just moving. I just installed a new blog software framework. I was starting to dislike the way to interact and I wanted something that contained more out of the box. I am in the middle of moving to wordpress software. There is a very good reason to do this. I had found a great tool on the mac called MarsEdit. And again this could not be used with serendipity. I hope I did make a good choice. Since there is a lot of information in the old blog, I did not take this blog offline. It will stay to exist, but I will not make changes there anymore.
I hope to see you at the new version of the blog (check the page at http://www.gridshore.nl). You can attach you feedreader to the following url: feed://www.gridshore.nl/feed/
Sunday, January 6. 2008
Spring Experience 2008
It feels like a year ago, actually it was last year, that I went to Miami, Florida, USA together with two colleques. There we were able to follow a lot of presentations about the springframework. These presentations were given by the contributors of all different springframework modules. For us three it was a three day learning experience. In this article I want to give you an impression of these days.
I started of my presentations with a presentation about “Full Stack Web Frameworks”. What is a Full Stack Web Framework? To be honest, I did not really care about that question, but it was a nice presentation about the current status of Spring web projects and the future. The separation between Spring webmvc and Spring webflow is going to disappear. It is going to be one fully integrated web project. I think this is a good think, it will became easier to use webflow when you need it and not make the choice to do webmvc or webflow. Some important things in the presentation were:
- Using REST like url’s for web resources.
- Support rendering of different views (xml, html, json) by state of the request (REST as well)
- Convention over configuration resulting in easier spring config files (or annotations)
￼The next presentation was about the new features in Springframework 2.0/2.5 by Jürgen Höller. There are three big groups of changes:
Platforms : There is now support for Java 6 and Java EE 5, better support for JCA and JPA. The most important platform improvement is out of the box support for OSGi modules. Every springframework module is now an OSGi module. This does result in some name changes, so beware when upgrading. Another thing I like a lot is that there is finally officially support for spingframework on websphere. So finally you can do threading and transactions on websphere with support from IBM. The catch? You need websphere 18.104.22.168+ or 6.1.9+.
Annotation Configuration : more and more xml type of configurations can now be replaced by annotation driven configuration. These annotations can be market standard annotations like @PersistenceUnit or @TransactionAttribute or special spring framework annotations like @Controller and @Autowired. The Test framework is also completely annotation driven. You can switch between junit 3.8, 4.x and TestNG without really making code changes.
AspectJ support : There is still a lot of proxy based aspects, there is however a new kid on the block. It is called load time weaving. The good part, you can use aspectJ without a change to the jdk your server is running on. There are some buts, have a look at the reference documentation to find out the specifics.
￼After this tough Jürgen presentation I had a presentation about “Ajax integration guide for 2008”. Nice but not a lot of new things. I did learn about an ajax framework called jQuery. A very nice and lightweight ajax framework. I will an article about jQuery in the future. I did use it for a demo application, more on that later. You can also check the web page of course. ￼Another presentation about ajax was actually about JSF or Java Server Faces. If you like the idea of Java Server Faces, then this framework is a must see. The framework is called icefaces and there is a very good integration between icefaces and springframework. It’s all looking very sharp and there is a nice petshop implementation with icefaces available.
￼Back to more springframework, well actually it can become more springframework. The next presentation was about “Useful Spring Extensions”. This presentation is about the spring-modules project, sorry it is renamed to spring extensions. This project has some extensions to the springframework that sometimes become part of the springframework. It has a lot of different modules. There are three modules I want to bring to attention right now:
Caching - Should be as non intrusive as possible, do not think about caching when creating your business logic. The caching solution as provided by spring extensions is an abstraction of multiple caching solutions. So it is not a caching provider, it integrates with EHCache, JBoss cache, JCS, Gigasoaces and OCache.
DB40 - This is an object database that makes extensive use of the data layer as defined by the springframework. So very good integration with spring. There is a Template and a support class available just like for jdbc, jpa, jms, spring-batch, etc. A very nice way to start experimenting with an object database.
Validation - Nice integration with validation frameworks like: Commons validator, Valang and Bean Validation. The bean validation is now enhanced with some nice annotations to specify which beans to validate and with what rules.
Another presentation is about “Grails for spring developers”, I am not going to talk about￼ this very long. If you are interested in stuff like ruby on rails, check this out. Without any prior knowledge Allard, Roel and me were able to create a complete application in a few minutes while waiting for the plane. Maybe I will write something about this as well, but the available documentation is already pretty good.
In the past I have done a lot with acegi security, now called Spring-security. Therefore I was curious to find out about the direction of the 2.0 release. So I went to “What’s new in Spring Security 2.0”. ￼It was a nice presentation. The morale can be described in one sentence. More convention, less configuration (if you want). The amount of necessary configuration lines decreased from around 120 to around 20. Not bad is it? Due to the name change all the package names have changed as well. There is the possibility (for backwards compatibillity) to keep using your old configuration, you do need to do a find replace on package names.
Another presentation I attended is “RESTful web services”. One thing I can tell, this is going to be big according to the springframework people.
The last presentation I would like to mention is the “Spring Dynamic Modules”. Some of you will think, what no OSGi? Well, they had to change the name of spring-osgi into “Spring Dynamic Modules for OSGi(tm) Service Platforms”. To be honest, this was the main reason why Allard and me wanted to go to miami. Not the nice weather, not the everglades, not the florida keys. We wanted to learn about the next release of spring dynamic modules. Along the way we got Roel in there as well. Why? Well, OSGi is all about SOA. Yes, so there is a very nice bridge between cool custom development and commercial architectures. When talking about OSGi, you are talking about services. These services come with a certain version, dependencies and visibility. Using a light weight BPM framework (available using the Spring-extension project I mentioned) you can create a very light weight Service Oriented Architecture using components instead of web services. The fact that each component in itself CAN be a web service is not important anymore. This is all very hot and cool technology. Hope to be blogging about this in the future as well.
Concluding, it was a great event, very good talks, good atmosphere. Hope to be there again next year.
Wednesday, November 21. 2007
Some time ago I started working with intellij, recently I bought a mac, and now I want to start programming. But where to start? There are some mandatory things, or not? Well let’s just start and try to make it as flexible as possible so we can use other frameworks for some layers. For now I will focus on the following technologies:
When creating the sample I started of programming in Intellij. Even with the excellent integration of JPA and Hibernate I still had a lot op problems creating the sample. Damn this is not easy. So what do you do when you are stuck? You start reading, I already had some books that could help me out. Still I like the “Java Persistence with Hibernate” book the best. The similarities between hibernate and JPA enabled me to quicker learn the basics. So I started reading, I came to the conclusion I had or wanted to start using annotations. It struck me how well Intellij was helping me again.
Just a few tips when developing with intellij, maven, jpa, spring, etc.
Create a new project based on an external model, click next and choose maven. Click next again and browse to the folter containing the master pom file. Click next and you have the option to select the project. The finish will create your new project with all modules present.
By default the spring and jpa facets are not present. You need to add them to the modules. Open the module settings (right mouse click and select menu item) and add the plus sign for adding a facet. The following screen shows the result of adding the spring facet and creating a new File Set. Another cool thing is that you can create a datasource to a database and connect this to a persistent unit. Columns and tables are then checked when creating your annotations.
I like the intellij way of creating new projects, but still I am a maven adept, so I wanted to have it all running with maven. You can find the sample online again. Beware, it is work in progress. I am adding a front end and more logic the coming weeks. Check:
If you want to start with jpa, spring and maven I can recommend the following archetype:
I did not try it out myself, but it looks very good. It is create by Chris Maki (http://www.jroller.com/cmaki/category/JPA+101)
In the reference manual of the springframework I found a sentence that for new applications they prefer not to use the JpaDaoSuppor class. There is another way based on the special bean PersistenceAnnotationBeanPostProcessor. Using this bean you can use annotations like : @Entity, @PersistenceContext from within the spring container.
Back to my problem, for some reason my tests using the AbstractJpaTests did not work with the separate jars for domain and data access (dao). I started by combining them in one module. But I was not satisfied. So I went back to my friend Google. I typed in a query for information about using modules with jpa and springframework. To my surprise I got back a lot of articles about the debate between using DAO’s or not. Yes we are back to the discussion about DDD or Domain Driven Design. After reading a lot of posts I guess the following sentence found on a blog item from Craig Wickesser but written by Adam Bien:
“I would say: it depends. It depends how complex your application really is. ”
Now back to the original problem, how to design a application using JPA?
Some of the choices you have to make:
In the end I did manage to get back to my so well known structure of a DAO layer and domain objects. What I had to do? We will check the persistence.xml file later on. I had to add the specific classes in this file.
Every problem needs a sample
Let me first explain a bit about the example that I am going to use. For a technology evening at my company I had some books that I could give away to the people present. Since it was an evening about the Google Web Toolkit I created a nice front end application using a file as storage to a Raffle application. Check the following application if you want to see it:
I decided this file thing was not really optimal, so I wanted to create a database backed application. What to use? Well let’s try it out JPA, hibernate started to get boring and I wanted to move on. So what is in the raffle applications domain model
We begin with the project setup using maven:
First the dependencies that you need in your pom:
spring-aop, spring-dao, spring-jpa, spring-hibernate3, hibernate-entitymanager, c3p0, mysql-connector-java, concurrent, spring-mock
That’s about it, put that in the pom.xml, create the structure and do a mvn clean install, or ...
Fire up intelij, create a new project based on this pom.xml and you can do the same things as I showed before.
We’ll begin with the domain objects:
Next step is to create a DAO interface that does not have anything to do with JPA, I use the interface like this:
For now I will not focus on the implementation, I am not a JPA expert yet . One thing I want to mention is the EntityManager. Using a special annotation we make sure the EntityManager is injected by the container, the spring container in our case.
Next step is to configure the spring beans:
Finally we need to configure the the entity manager, this is done with a special file named persistence.xml which is displayed beneath.
That is enough to start using the application. However, there is one thing I forget. What about testing this application. Spring comes with a special class for testing called AbstractJpaTests. This is class had familiar functionality, auto dependency injection and rolling back a transaction after the test.
Using this test you still need a database. For the data access tests I am using a combination of dbunit, springframework and hsqldb. Most important part of the test class is the injection of the dao:
The following beans are in the special test spring config file together with the datasource for the test database.
That is about it, again, check the source code, everything is runnable by maven2 and tested on tomcat 5.5. If you want to read more, I used the following resources while creating learning about jpa and the other topics.
Friday, November 16. 2007
finally a new technical item. It is a short item, but I have been struggling to get this to work. Therefore I want to share this so other can use it to configure there properties in a flexible way.
Properties like database url's, userid's and pasword's are different in your test environment and your production environment. There are other items you might want to configure.
You can make complicated deployment scripts that get the right property files for the right environment. But you need to create different packages for different environments. I think a more elegant solution is to use the JNDI parameters to load the specific environmental values. If there are a lot a good way might be to store them in a database and only configure the database access parameters using JNDI.
The following solution is based on two posts in different forums:
http://forum.java.sun.com/thread.jspa?threadID=647327&messageID=3810991 - gives details about the configuration of tomcat.
http://forum.springframework.org/showthread.php?t=30991 - gives details about the spring configuration
Now the code, we start with the tomcat configuration. The server.xml file contains all the actual values connected to the exposed JNDI parameter names.
We need to tell the application the names of the parameters that are available. We must add the following items to the web configuration file.
Of course you need to do this for all four parameters. Then the tricky part. This is the one I missed while getting this to work. You need to add a tomcat specific deployment configuration with the following lines
Thats is all we need to do to make these values available to the spring beans. So the last part is the spring configuration. We are going to create a PropertyPlaceHolderConfigurer. That way you can access the properties just like properties from a file.
This made my deployment life a lot easier, hope you will find some good use of it. Thanks again to contributers on the forum for making the different parts clear to me.
Till next time, which is going to be a piece about JPA.
greetz Jettro Coenradie
Monday, November 5. 2007
Wow, I have finally made the decision, I bought a Mac. Now I am the proud owner of a MacBook pro. So the next blog entries will be written on my new Mac. I think I will loose time at first, new key board, new mouse, new platform. But IntelliJ is running already. I have my mail setup, importing i-tunes now. To bad it is time to go to bed. I understood, I need to read the following website http://www.macmiep.nl, if you have better options, please let me know.
Now I say, goodnight, I am off with a very big smile.
Sunday, October 14. 2007
The last month(s) I have been working on multiple Google Web Toolkit implementations. I must admit that the implementations are not very big. They are mostly small applications I needed for some reason. One of them is a Raffle system, there is one with a large amount of data on a screen that should be editable as well. In this blog item I will share some experiences I have gained using the Google Web Toolkit with maven2, JetBrains IntelliJ. The applications can interact with a standard GWT servlet, or with the springframework and security via spring security (acegi). I also experimented with a nice GUI framework called gwt-ext. Finally, I also used the Google Web Toolkit in a sample we created for spring osgi. So please continue reading, most sources can be found in in my code repository at google.
In this blog item I will mostly look at IntelliJ, I will create new blog items about using eclipse and maven as well.
Step 1 - Creating a project skeleton
Step 2 - Adding the module and entry point
Raffle.gwt.xml - the configuration file for the module with a reference to the entry point.
Raffle.java - in the client package, this is the entry point for the gwt application.
Raffle.css - stylesheet referenced by the html file that is also in the public folder.
Step 3 - Test the setup we have created
Step 4 - Adding stuff to the screen.
Step 4.1 - Add the menu
The total screen will consist of two panels, one containing the menu, the other is the content panel in which all menu actions take place.
The code shows how to create the MenuBar and how to add an item. This is not a very thorough example and as you can see I did not implement the method createListNames. Before I do this I need to explain remoting which I will do next. The sample up till now does show how to add an a menu and how to add items to the menu. Look at the way to create a command when the menu item is clicked. By using the method setWidget on the content panel we can change the content on the page when clicking a menu item.
Step 4.2 - Doing some remoting
In the client package
RaffleRemoteService - Interface containing a static internal class App with a utility method getInstance to get a RaffleRemoteServiceAsync. Check the code later on.
RaffleRemoteServiceAsync - Interface that has the same methods as the RaffleRemoteService with one extra parameter of type AsyncCallback.
In the server package
RaffleRemoteServiceImpl that implements RaffleRemoteService and is a subclass of RemoteServiceServlet, a google web toolkit provided servlet. This servlet is also automatically configured in the module configuration file 'Raffle.gwt.xml'. The following lines are added.
Want to see some intellij magic? Let's add a method to the RaffleRemoteService for obtaining a list of names.
As you can see on the image there is an error. Intellij asks you if you want to synchronise the remote service with the asynchronous service. Click ant + enter and the interfaces are in sync again. There is more in the image. Check the return argument ArrayList. This is not a java 5 collection, gwt cannot handle that. But we do need to tell what kind of objects are in the ArrayList. This is why we need the annotation @gwt.typeArgs
Step 4.3 - Doing some styling
You can add styling via the style sheet. Almost every widget has it's own styling and of course you can add a style name to every widget you create. Some of the basic styles are:
That is about it for now, hope this helps, you can extract the important information if you want to use eclipse. Next time I will write something about using maven2 and a special toolkit called gwt-ext. You can find the complete source code online: http://gridshore.googlecode.com/svn/trunk/Raffle/
Monday, August 20. 2007
There are many blog entries and articles out there about web service versioning. So why write another? In my day-to-day work, I am often asked about how to solve web service versioning issues. The articles on the web provide different ways to do it, but do not take the impact on the codebase, deployment and testing into consideration. Now that's exactly what I'll be trying to do in this article.
First, I'll briefly describe what I mean with Web Service versioning. Then, I'll shed some light on different possible solutions. Finally, I'll compare all of these solutions in terms of complexity, codebase, deployment and testing.
Web service versioning, real or just a myth?
Many, maybe even all, projects that involve web services will encounter a problem they call "web service versioning". But what is it? And does it really exist?
Why versioning web services is an issue
Web Service versioning doesn't exist. So why is it an issue? Because developers (myself included) want to be able to reuse existing classes for new versions of a service. So, in our Version Control System (VCS, e.g. Subversion or CVS) repository weÂ?ll want to create a branch for the old version, and continue development in our main branch. We'd want to deploy our application with our old JAR and the new one and provide some mechanism for selecting either the old classes or the new ones.
Solutions for service versioning
The web is full of solutions for versioning. I'll mention each solution briefly, and explain how it is set up. At the end of this blog entry, I will compare these solutions in terms of codebase, deployment and testing.
Comparing the solutions
Now that I have mentioned each solution briefly, it is time to put them in the ring to compete against each other. Here we go:
Monday, July 16. 2007
Hai, today I have a short blog item. This is just because I am having fun with java generics. Check out the following piece of code. Will it compile? If you think it will compile, what will it print? If you think it won't compile, why not?
Use the comment option at the end of each blog item to give me your answer.
After a few weeks I'll give the answer
Wednesday, July 4. 2007
My previous post was about creating a client with the spring-ws project. This dis take me some time to grasp. But without a published webservice a client is of no much use. Therefore I also had a look at the server side. To my surprise this was even easier than expected. I did have some requirements for the sample:
That does not sound to bad does it? Well try to do it with axis and you'll be surprised. If you know a little bid about spring-webmvc and the use of the dispatcher, you know you need one configuration file for spring. For the webservice I had to provide the spring config file and one class, yes really, just one class. I used maven to generate the jaxb stuff and this is wat I did:
The spring-ws framework provides a special servlet that receives the requests. No the really hard part, the spring configuration for the endpoint:
First check the endpoint mapping, this class SimpleMethodEndpointMapping is found by the dispatcher to map all incoming requests to endpoints. In our case we map to our only endpoint called the congressRegistrationEndpoint. This class has a special super class that needs a marshaller and unmarshaller. Other than that it needs nothing. By convention the name of the Request is used by the super class to know which method to call. In our case we have a CongressRegistrationRequest. Therefore we need to implement to method handleCongressRegistrationRequest as you can see in the following coded block.
In this code the argument and the return value are JAXB objects. I created the most easy method, do nothing with the request and always return the same response. Bu as you can see the code itself is very clean. I do not need to do a lot of conding. I think this is probably one of the easiest implementations I have seen that works in java 1.4 as well.
That is it for one of the requirements. Now I also wanted a solution for generating the wsdl. In the end this is only some springframework configuration. You also need an xsd, but you have already used this to generate the jaxb classes with maven. So we can reuse it. Check the following configuration
So you need the location of the xsd, the name of the bean is used to find the wsdl. The locationUri locates the endpoint and the targetNamespace is the namespace used in the xsd. By entering the following url you can find the wsdl.
You can check the code at the google code project.
I know it is pretty short, but with the code you should be able to understand it.
Saturday, June 30. 2007
Last week I attended the SpringOne Congress in Antwerp. Just one or two days before the congress I wanted to create a proof of concept for a client connecting to a webservice. I have been using the proxy way (spring-remote), but I did not really like the way this works. Therefore I was looking for something else. I stumbled upon the Spring Webservices project. I did try this out before, but not for clients. I started working and it did not look very complicated. I must admit I needed the help from Arjen Poutsma himself to make it work, but now I have a very light weight solution. I like the approach very much, therefore I will briefly describe the solution I have created. You can of course find the sources online as well. Check the google code subversion repo for gridshore.
Overview of application
Maven 2 for buildingThis time not much details about the maven2 part. There are some things interesting though. Most important part is the creation of the jaxb generated classes using the maven2 jaxb2 plugin.
Using spring-webmv for web projectI do not think it is really interesting to talk a long time about this. There can be found a lot (better) resources online. I used the spring webmvc project to make the client i18n compatible, used the form controllers from spring to help with the error messages and validation stuff. For the webservices part the most interesting thing starts in the file service-applicationcontext.xml. This spring configurtion file contains the webservice client, the converters for jaxb (using generics to abstract the technique marshalling technique).
Webservice client created using spring-wsLet's start by having a look at the configuration:
This configured class is the class that knows how to connect to the webservice. It uses a few values and classes to do it's work. The defaultUri is used to find the endpoint to connect to (we obtain it from a property file). Since we use JAXB2 to marshall and unmarshall the request we need the marshaller and unmarshaller. These (un)marshallers are provided by spring-ws as well. Actually they are provided by spring-oxm. The interface for the marshaller is the same as for the unmarshaller. The only thing you need to provide is the package where the jaxb files are generatd in. The other two references are converters used to convert the application specific components to JAXB2 components. More on this later as well. So the most important class is the Gateway class. Let's have a look at that now.
This is it, really. I show you the complete class, but in the end the most important works takes place in one line. That's the one in bold. Here we use the special webServiceTemplate class and ask it to marshall our request object and send it as a soap message to the configured endpoint. Ofcourse you can do a lot more, but for most situations this is all it takes. Do not forget to extend the WebServiceGatewaySupport class.
Mapping between objects and xml using jaxb2 and spring-oxmNot much to tell here as well. I keep saying this, but that's because it is true. We have configured the marshaller and the unmarshaller which are provided by spring-oxm. We also call the right method from the template adapter called marshalSendAndReceive. I did create an interface and some implementations that enable the gateway to be ignorand to the type of marshalling and unmarshalling we use. This is my first try to do something with generics. There can be a better way, if you know one, please let me know as well . Let's start with the generic interface.
So we have an interface specifying we have a object as a parameter and an object as a return type. Then there is a method called convert that uses these generic types. At the moment I have two concrete implementations for creating the JAXB request and handling the JAXB Response. One of them is presented below.
As you can see we now have a concrete implementation for the generic interface. The returned object is a String and the parameter is a JAXB object called CongressRegistrationResponse. Now look back at the gateway code, check that there is no jaxb reference in that code.
Again check out the code at google code subversion repo for gridshore. You can already find the code for a server implementation there as well. The next blog will deal with the server. I am also working on a sample about the Rule engine called Drools. so stay tuned.
(Page 1 of 8, totaling 71 entries) » next page