Great guide for people interested in Scala
July 17th, 2008
I just came across a great Scala presentation from JavaOne. If your not looking at learning Scala, then this presentation will give you a whole heap of reasons to get up and do something about it.
Download the article from here
How To Fix Generating XMPie API Java Stubs With Metro
June 6th, 2008
As a number of you are aware, I have spent quite a bit of time wrestling with XMPie uProduce SOAP API with the CXF service framework in Java. I finally (and with quite a lot of disappointment on my part) gave up trying to get that to work. CXF just does not want to play nice and I cant seem to make the XJB bindings work correctly with it and the mish-mash WSDL coming from uProduce
Anyway… with that rant over, I tried to be objective and switched to using Metro – ok, out of the box I still had a whole heap of problems, exactly as I did with CXF. However, I have managed to wangle it!
Step 1
You will need access to an XMPie server with the API’s installed and working. For the sake of this example i just wget’d the WSDL file so the generation code was not so bloated.
Step 2
You’ll need an XSD XJB binding file which looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.0">
<globalBindings>
<xjc:simple />
</globalBindings>
<bindings scd="~xsd:complexType">
<class name="ComplexTypeType"/>
</bindings>
<bindings scd="~xsd:simpleType">
<class name="SimpleTypeType"/>
</bindings>
<bindings scd="~xsd:group">
<class name="GroupType"/>
</bindings>
<bindings scd="~xsd:attributeGroup">
<class name="AttributeGroupType"/>
</bindings>
<bindings scd="~xsd:element">
<class name="ElementType"/>
</bindings>
<bindings scd="~xsd:attribute">
<class name="attributeType"/>
</bindings>
</bindings>
Save this as xsd.xjb (or whatever you like, just make sure the name is reflected in the command below)
Step 3
Actually generate the code! Your command might look different, but heres mine:
wsimport -b http://www.w3.org/2001/XMLSchema.xsd \
-b src/xjb/xsd.xjb \
-keep \
-s src/java \
-d target \
-p com.xmpie.wsapi.icp \
src/wsdl/InteractiveCampaign_SSP.wsdl
You should then see something like the following in your finder (or other OS file browser if not on mac):

These are the class files created for the InteractiveCampaign WSDL – all 128 of them!
Anyway, I have run out of time for today, but will try and get another blog up soon about how to use this in a client application from a java CLI.
Its been in the wings for some time now but the announcement has finally been made public. This is great news as it means that when were coding in Scala the classes in your web container will automatically be updated without the need to restart the container and redeploy the WAR.
For more on this check out the announcement
Using Embedded Resin as a Development Container
May 19th, 2008
I recently read this article and realised that I had never blogged about the resin plugin that works perfectly with lift for development and deployment.
Heres what you need to add to your pom.xml
<build>
...
<finalName>${project.name}</finalName>
...
<!-- resin plugin -->
<plugin>
<groupId>com.caucho</groupId>
<artifactId>resin-maven-plugin</artifactId>
<version>3.1.6</version>
<configuration>
<contextPath>/</contextPath>
</configuration>
</plugin>
...
</build>
<pluginRepositories>
...
<pluginRepository>
<id>caucho</id>
<name>Caucho</name>
<url>http://caucho.com/m2</url>
</pluginRepository>
...
</pluginRepositories>
Note, the final name var is important, as thats what resin uses to point at. Dont worry tho, as lift already has a name element so provided you haven’t deleted it, your laughing.
Next, to boot the server, just do:
mvn resin:run
That should be it! Enjoy!
Right, as you know, I use the lift framework a lot these days. I also use Resin as my choice container. So, i recently got to thinking, wouldn’t it be cool if i could just bosh together a simple way to expose controllers in lift via the groovy protocols made available by Resin – well, I have here an example of just such a thing.
Lift Side
Ok, before anyone has a poke at this code… it was a very quick and dirty example, so its not ideal, and obviously your code would be a whole lot more complex, but this article is just about proving concept.
I set up the object that I want to expose via remoting. Critically, there would be nothing stopping me using the persistance built into lift, or anything else available to java or scala for that matter. The key is the traits… as they are like java interfaces (broadly speaking), they let resin know what methods it can call.
package com.timperrett.resin.example.controller
trait HelloTrait {
def hello: String
}
class HelloWorld extends Object with HelloTrait {
def hello = "Hello from lift"
}
Resin Configuration
Next, we add a bit of config to resin so that it knows how/where to expose the service. Critically, we could have used Hessian, Burlap or CXF (for SOAP) and all by being pushed out of the container with zero extra effort.
<web-app id="/lift-remoting-example"
root-directory="webapps/lift-remoting-example">
<servlet-mapping
url-pattern="/api/hello-world"
servlet-class="com.timperrett.resin.example.controller.HelloWorld">
<protocol uri="hessian:"/>
</servlet-mapping>
</web-app>
Client Side (in another language!)
To proove the point, I thought I would just make a simple client in another language (namely ruby):
require 'rubygems'
require 'hessian'
url = http://127.0.0.1:8080/lift-remoting-example/api/hello-world
client = Hessian::HessianClient.new(url)
puts client.hello
Again, a very simple example, but one that proves the point. You should then see “Hello from lift” output in the terminal window.
Project Files
You can download my example from here
If you found this article interesting, or have played with this yourself also, then by all means leave a comment or get in touch.
Geek Honors: Joins Scala Lift Core Team
April 24th, 2008
My appologies; I hardly ever blow my own trumpet on this blog, but I just cant let this one pass without a good old toot of the proverbial horn.
Today I joined the lift committers. That might not sound much, but when you think that lift will be the next Ruby on Rails size phenomenon to hit the development community, thats pretty dang awesome.
I shall toot no more – respect to David and the rest of the other guys on lift core… you freaking rock!
Apache CXF Graduates From The Incubator
April 16th, 2008
Today was the day that Apache CXF graduated out of the incubator and will now become a full bonafied apache project. This is such brilliant news as it means that CXF should replace Apache Axis and Xfire as the defaco Java services framework.
Congratulations to Dan Kulp and the rest of the CXF team – all the sterling work has paid off after about 20+ months of rocking development.
I wish them all the best for the future – CXF will be a big hit!
Tutorial: Getting Started with Apache CXF
April 12th, 2008
If you are looking to lean CXF, then you should really read this:
http://www.jroller.com/gmazza/entry/using_strikeiron_s_super_data
It was one of the best written tutorials I managed to find and covers both Maven and Ant compilation.
Kudos Glen!
Java Is Not A Dirty Word...
April 11th, 2008
Strong title I know… It feels like thats how Java is regarded these days – Ruby and Python are becoming the golden boys of programming choice and poor ol’ java is being left out in the cold because people only remember it as having crap costing/license models where you [the developer] needed to pay for everything.
Well, I have good news for you my friends, Java should no longer be a dirty word! The inertia that Ruby on Rails had in the Java community did cause quite a lot of controversy its true, but its almost like after the initial xenophobia had worn off they sat up and thought “you know what, these guys might actually be onto something here”. I recently got into using Maven 2, and god, my good god, its a million times better than Ant, which just sucked so badly I cant explain! For anyone who is familiar with Rake, Maven is like Rake, but with all the package management stuff built right in – it does still have a certain level of entry required, but it just simplifies the process of created projects and managing dependencies in a very streamlined way.
The language itself has evolved quite a lot too – the new annotations are used heavily be JEE apps and frameworks – take CXF as an example; it will eventually replace XFire and Axis2 as the premier SOAP/WebService framework for Java, its a very very powerful tool and pretty easy to use (relatively speaking)
Anyway, I digress… my point is that if, like me, you left Java because the last time you worked with it you were slogging it out with 1.4 and Ant hell, then perhaps its time you took another look? Java has had significant investment as a platform, and there is a hell of a lot of good code out there for doing pretty much anything you can think of. In all honesty, one of the main reasons I have come back to JEE and the JVM in general is deployment – the JVM is very robust, and the containers built of top of it like Resin and Glassfish are being used in very high-concurrency environments and the deployment method via JAR or WAR is just so much more robust than on a platform like Ruby – and thats coming from having spent nearly the past 3 years solidly coding Ruby and doing all manner of deployments!
Dont write Java off – its an amazing platform, so what if its not as easy to get started as with other languages; think long-term, its a language that will grow with you rather than one you might someday reach the ceiling of – or just find incredibly annoying when the application dispatchers crash for a past time ;-)
Over and out
One Click Installer for Apache Maven 2.0.8 on Mac OSX
April 10th, 2008
I have put together an all-in-one installer for Apache Maven 2.0.8 and Scala 2.7.0-final! Just download the installer, be it on 10.5 or 10.4, just download the right distro for your operating system and then follow the installation procedure.
The installer will then automatically append all the right shell variables to your $PATH so they will be freshly available from the terminal – splendid.
You can find the all in one maven installer for OSX here
Any problems feel free to get in touch.