If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Tuesday, October 12, 2010

example of connection url for oracle 10g (loadbalanced)

Just in case I ever need to connect to oracle again.. below an example how to configure a readable property spread out over multiple lines where the values for server1 to 4 and servicename are depending on the use case.

Saturday, October 9, 2010

creating higher order functions in javascript

For the ones who haven't noticed yet... I tend to lean more and more towards functional programming because it allows you to create higher-order functions and get more done with less code.

Below a first draft version of a javascript Collection API which shows the immediate usage of higher-order functions.

Building webservices with Spring-WS (part 9)

Part 9 (final part) will explain how we can create the client for our movie webservice.

The interface acts as a facade and hides any webservice related details from the end user.

The implementation uses Springs webservicetemplate to (un)marshall the request and response objects and do a bidirectional send and receive.

The application-context.xml below will show you how easy it is to configure your client. For demo purpose I hardcoded the defaultUri.

And finally a little unit test which can be executed succesfully if you start the movieService application.

I left out the pom.xml but the dependencies are mostly the same as for the movieService project itself.

All source files for this demo webservice can be downloaded:

One remark:
You will need to install the default-value plugin in your local maven repository which is used by the movieDomain project and you should use following groupId 'org.jvnet.jaxb2-commons' and artifactId 'defaultvalueplugin' since I configured the plugin like that.

Kind regards,

Building webservices with Spring-WS (part 8)

In part 8 we are going to take a quick look at some unit tests of our webservice.

Please take a good look at the generic return type of the findByTitle method on both the movieDao and movieService. They are not the same!!

Since our mock MovieDao only had 2 movies both tests should lightup green.

Part 9 will explain how we can quickly write an easy client (using a little facade) based on the movieDomain project from part 1.

Building webservices with Spring-WS (part 7)

A big part of our applicationContext was already configured in demo-ws-servlet.xml mentioned in part 3.


The bean 'movieWSDL' takes care of autogenerating our WSDL which will be available at http://[servername]:[port]/webservicedemo/services/movieWSDL.wsdl and it's completely based on our xml schema which we defined as our first step. As you can remember I proposed to create a separate project 'movieDomain'. Hence i reference the schema with value="classpath:webservicedemo.xsd".


As you can see I used the mocked MovieDao implementation so we can do run some unit tests quickly.

Building webservices with Spring-WS (part 6)

Part 6 will take a closer look at the movieService interface/implementation and the endpoint.

Since all our service offers is finding movies by title the interface is very basic.

The implementation uses the DAO layer to fetch the collection of movies by title provided. We only have to take care of adapting our Movie to MovieWS classes.

I created a generic Adapter interface:

And a Abstract class DomainAdapterImpl which implements 1 method.

The adapters are easy 1 on 1 mappers from our application domain objects onto our webservice domain objects.

Part 7 will take a look at our applicationContext.

Building webservices with Spring-WS (part 5)

Since for our use case we only need to retrieve data from the database I only added following methods to our generic DAO interface:

A real implementation could look like the one below.

But in order to quickly test our application I wrote a little mock implementation for the MovieDao interface.

Part 6 will take a closer look at our MovieService interface/implementation and the endpoint and I will shortly explain why I had to use domain object adapters.

Building webservices with Spring-WS (part 4)

Part 4 of this series will take a look at the domain model used by our application.
I think it's good practice to always start out your domain model with a basic interface and abstract implementation. Not only offers this the opportunity to add some generic methods/properties but it will also allow you to code in a generic way.

Part 5 will take a look at our DAO layer.

Building webservices with Spring-WS (part 3)

Let us first take a look at our pom.xml since we will have declare quite a few dependencies to do the heavy lifting.

Important to notice is we have declared a dependency on the project 'movieDomain' we created in part 1.

My web.xml:

One thing important to remember is that your main application context file has to end with '-ws-servlet.xml' and in my case it's mapped to WEB-INF/demo-ws-servlet.xml. If you rename it you will find out the hard way your project will run into some exceptions.

I decided to have all webservice related requests mapped onto the url-pattern '/services/*', but that's upto you.

In part 4 of this serie we'll take a look at some other files.

Building webservices with Spring-WS (part 2)

Now it's time to create the actual webservice and below are 2 screenshots of the completed version.

The project has been setup under the assumption the webservice will be using a database so I created a DAO layer which will be used by our MovieService implementation.

In the next article we will take a deeper look into the files listed above.

Building webservices with Spring-WS (part 1)

The next series of articles describe my experiences and my personal believe about some best practives using Spring-WS to build a webservice and a corresponding client.

The Spring documentation itself promotes using a Contract-First approach. This means you first think about your Request - Response objects and the corresponding service objects used to interchange information.

For this hands-on tutorial I wrote a webservice which allows you to find movies based on their title.

Below the xml schema used for this demo 'webservicedemo.xsd'.

It's important to know that your request and response messsages HAVE to end with respectively uppercase 'Request' and 'Response' like in my case QueryByTitleRequest and QueryByTitleResponse.

To start we'll create a separate project which contains nothing more then the generated JAXB classes. The reason why I advise this approach is that you only have to generate the stubs once for both the webservice itself as well as the client and add this project as a dependency.

Create a new source folder src/main/resources and copy webservicedemo.xsd to this folder. Also create a bindings.xjb with the content below.

As you can see I created a SimpleTypeConverter which contains some methods to convert to and from java.util.Date to the XML String representation of a Date.

The pom.xml for this project is show below:

Now we can generate our jaxb stubs using the command below:

If we also run mvn eclipse:eclipse again the folder src/main/generated will be added as a source folder.

In part 2 I will start with explaining step-by-step how to create the webservice itself.