A Home Made Eclipse CXF Plugin

I’d been looking around for web service stacks to use in a recent web service implementation I had. I read about both Apache Axis2 and CXF, but for various reasons I felt drawn to CXF.

Unfortunately, I realised that there was no web service runtime plugin for CXF as there is for Axis2. If you are just like me in this predicament, don’t give up just yet. I recently came across a way to get what I wanted, though not in as beautiful a solution as I’d have wanted. And the solution? Use, Eclipse’s External Tool Configurations. Here’s how you could also solve the problem.

  1. Create a new Java project named cxfclient.

  2. Copy the wsdl file to the src folder of the project.

  3. In the Eclipse menu, select Run → External Tools → External Tools Configuration.

  4. Click the “New launch Configuration” icon at the top of the left column. A “New_configuration” configuration is created.

  5. In the name field, provide the word “wsdl2java” as the name of the configuration.

  6. In the “Main” tab, provided the following values in the respective fields

    1. Location – Click “Browse File System” and navigate to the location where your cxf download is extracted to.

    2. Working directory – Click “Browse Workspace” which should show the list of projects in your Eclipse workspace. Select the “src” folder of your project, since the generated classes will be put there, and your wsdl file is also located there.

    3. Arguments – The only argument that we will provide in this process is the name of the WSDL file, in this case Calculator.wsdl. However, this is where any extra parameters can be passed to wsdl2java to tweak its behaviour. For example, to generate a consumer of the Calculator service, specify “-client” before the name of the wsdl file.

  7. Click the “Refresh” tab and check the “Refresh resources upon completion”.

  8. Click “Apply” to make all these changes permanent.

  9. Click “Run” to see your generated implementations of the Calculator service. Your configuration should look like this.

You can apply this trick to add any tool that is not yet integrated into Eclipse but has command line tools to work with. Enjoy tweaking.

Advertisements

Using Eclipse Dali with Hibernate as Persistence Provider

Eclipse Ganymede comes with in built support for the EclipseLink JPA implementation. However, we’ll want to explore how to use Hibernate’s JPA implementation with Eclipse Dali for JPA operations

To begin with, please make sure you have the following

  1. Eclipse Ganymede for JavaEE

  2. Hibernate EntityManager

  3. Hibernate Tools

  4. MySQL connector (or a jdbc connector of your choice if you are not using MySQL)

You will need to install Hibernate Tools as an Eclipse plugin. Next, you’ll have to add MySQL to your list of driver definitions. This you do by going to the “Window” → “Preferences”. On the left tree, navigate to “Data Management” → “Connectivity” → “Driver Definitions”. Click on the “Add” button. You now have a “New Driver Definition” window with three tabs – Name/Type, Jar List and Properties.


In the Name/Type tab, select MySQL. A list of choices now appears of “MySQL JDBC Driver”. Select System Version 5.0, click on the “Jar List” tab and delete the default MySQL driver file specified there. Click on “Add Jar/Zip” and add your MySQL connector. Please ensure that there are no spaces in the path to your MySQL connector, or you may have trouble later on. Click “Ok” to finish the driver definition.

Next is to add the Hibernate EntityManager libraries as your JPA implementation. First, extract the Hibernate EntityManager zip that you downloaded into a location without spaces in the path. Still in the “Preferences” window, click on “JPA” on the left tree. In the “Default JPA Implementation Library”, click the “Configure user libraries” link. Click on the “New” button and give this a good name e.g. HibernateJPA. Click on “Add JARs” and add the “hibernate-entitymanager.jar” that is available in your extracted Hibernate EntityManager folder. Next, add all the jars in the lib folder of the extracted folder. These should be

  • slf4j-api.jar
  • dom4j.jar
  • ejb3-persistence.jar
  • hibernate-annotations.jar
  • hibernate-commons-annotations.jar
  • hibernate-core.jar
  • javassist.jar
  • jta.jar


Click on “Ok” to complete adding the JPA implementation.

Now, create a Java Project called “jpaproject”. In the project explorer view, right-click the project and select “JPA Tools” → “Convert To JPA Project”. Click on “Next” on the “Project Facets” screen that shows up. On the “Configure JPA Settings” window, select “Hibernate” as your platform. You will now add your connection to the database by clicking on “Add connection” link. In the “Connection Profile” window, type MySQL in the filter. Select MySQL and enter the name “jpaprojectDB” in the “Name” field. Click “Next”, and specify your database connection details. Click “Test connection” to be sure, and then “Finish” when completed.

You should now have something like below


Remember to uncheck the “Create orm.xml” option. Its useless overhead we don’t need now. You now have a project that supports JPA, with a META-INF/persistence.xml file generated in your src folder. Funny enough, after all this information provided, Dali still refuses to populate your persistence.xml file with these details. You will have to do them yourself (talk about DRY).

Double-click on your persistence.xml. On the “General” tab, specify “org.hibernate.ejb.HibernatePersistence” as your Persistence Provider. In the “Connection” tab, choose “Resource Local” from the Transaction Type drop down list. Under “Hibernate” tab, select “MySQL” as Database dialect, “com.mysql.jdbc.Driver” as Driver class, “jdbc:mysql://localhost:3306/jaccra” as your connection URL, and then provided the username and password fields for the database connection. Click on “Source” and you should something close to the ff.


<?xml
version=“1.0”
encoding=“UTF-8”?>

<persistence version=“1.0” xmlns=http://java.sun.com/xml/ns/persistence&#8221;
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&#8221;
>

<persistence-unit name=“jpaproject” transaction-type=“RESOURCE_LOCAL”>

<provider>org.hibernate.ejb.HibernatePersistence</provider>

<properties>

<property name=“hibernate.dialect” value=“org.hibernate.dialect.MySQLDialect”/>

<property name=“hibernate.connection.driver_class” value=“com.mysql.jdbc.Driver”/>

<property name=“hibernate.connection.url” value=“jdbc:mysql://localhost:3306/jaccra”/>

<property name=“hibernate.connection.username” value=“edem”/>

<property name=“hibernate.connection.password” value=“edem”/>

</properties>

</persistence-unit>

</persistence>

Now you are all set up for your JPA machinations. One last and very important thing to do is to add the MySQL connect jar to your build path. Now when you right-click on your project in the project explorer, you should see an option “JPA Tools”, under which there are a couple of other options. Explore them and see what you get.

Book Release : JBoss Tools 3 Developers Guide

JBoss Tools is an impressive set of open source Eclipse plugins that allow rapid development of enterprise and SOA based applications. It is developed by the JBoss group under the leadership of Max Rhydal Anderson.

It include support for rapid Hibernate, Seam, JSF and Richfaces, jBPM, JBoss ESB development and a lot more.There is no doubt that with such a compelling toolset, JBoss Tools stands out as the best set of tools for Ajax based JavaEE development that you can get for free and compares very well with those for pay.

To quickly point out how to harness the power of JBoss Tools for rapid application development, Packt Publishing has just announced their book JBoss Tools 3 Developers Guide by Anghel Leonard, scheduled to be released in April 2009. I believe this is the first book on JBoss Tools, and it has come at the right time for us developers.

Taking a hands on step by step approach to the 11 Chapters detailing each of the plugins at the time of writing, a developer is immediately delved into productive use of JBoss Tools in their project through a small project developed per chapter.

Of course, you will not expect to learn everything about Seam, Hibernate, Richfaces, JBoss-WS etc from the book simply because that is not the aim of it. However pointers are given to the right resources that will get you up to speed on them.

It has been fun being a technical reviewer of this book and I have to congratulate Leonard and the staff at Packt Publishing (Sarah and Leena) for their hardwork. I eagerly look forward to the release in April.

Don’t say I didn’t tell you how good it is, because this post is evidence that I have.

JBoss Tools, Seam and XML Editing

I’d never been a fun of xml files. Never. I like to put my money where my mouth is, and that is not in xml files. Then came EJB3. And just when I was getting settled down with the new craze (Annotations), along came Seam. Now I could happily run away from my EJB 2.1 days of verbose xml and never go
down the trail of “xml hell” again, editing xml just when i
really, really need to. Alas, twas just a dream. When you are faced
with an application that needs to be flexible and extensible,
sometimes the best (and probably only) way is through xml. And that
is exactly what I was faced with recently. However, JBoss reminded me
of one of the reasons why Seam is a compelling choice of framework –
tools support through JBoss Tools. Now I’ve fallen in love with xml
editing – simply because I don’t have to do any.

Here’s the scenario. Let’s say I were
developing an application for playing games, allowing users to play
different games which obey a consistent API. This means a separation
into interfaces and implementations. Here is how I tried to create
that separation.

  • Plugnplay-api – consistent
    interfaces that are to be coded to.

  • Plugnplay-impl – implementations
    of the above api. Contains Seam components (i.e. Entities, Actions,
    UI components etc).

  • Plugnplay-web – the basic Seam
    application (here’s where the facelets as well as the aforementioned
    components finally end up).

This meant that I’d have to use the
components.xml file to specify the names (instead of @Name) as well
as other properties of my Seam entities and actions. No hustle. I
immediately realized how big such a file will get. Thankfully Seam
allows you to define one components.xml file for each component like
Hibernate (not my idea of fun) or one components.xml file per
package. I chose the second option and decided to put JBoss Tools to
work. The result was pleasing. Let’s look at mapping different
implementations of the Game interface – DominoGameImpl and
MonopolyGameImpl.

  1. Select File -> New -> Other.

  2. Scroll to XML subcontent and
    select XML.

  3. Enter the name “components.xml”
    as file name and click Next.

  1. In the “Create XML File From”
    screen, choose “Create an XML file from an XML schema file”.
    This forces our xml file to conform to a schema, in this case the
    components-2.0.xsd from Seam. Click Next.

  2. At XML Schema File, select “Select
    XML Catalog entry”. This should show a list of all schema files
    currently registered in your Eclipse installation.

  3. Scroll through the XML Catalog and
    find the key “http://jboss.com/products/seam/components-2.0.xsd”.
    Click Next.

  4. At the Root Element dialog box,
    change the default Root element of “action” to “components”.
    This is the root element in all components.xml files, and allow
    other child elements such as pdf, mail etc. You may leave the other
    checkboxes as their default. Click Finish to end the wizard.

Finally our components.xml file is
created and displayed in the Seam Components Editor. At this top
level we can add components, define factories, events and imports.
Without much ado we’ll add our Game components. This is the part I
love the most.

  1. Click “Add” to add a seam
    component.

  2. Enter the name of the Seam
    component.

  3. To add the particular class, click
    Browse. You have a window with 3 tabs – “Search”, “Browse”
    and “Recent”.

  4. In “Search” begin typing the
    name “DominoImpl” as our Seam component. A dynamic list of
    matching classes are displayed as you type to select the particular
    one you want.

  1. Select the appropriate class and
    click “OK”.

  2. In the Seam Components Editor, you
    may now specify the scope as well as other properties. I’ll choose
    CONVERSATION from the Scope drop down list. Press Ctrl+S to save.

  3. Repeat these steps to add the
    MonopolyGameImpl as a Seam component.

Now that we have our games, we want to
associate them with a particular user. Our User API defines a list of
Games as a field. We repeat the above process in the “admin”
package, selecting UserImpl as with the component name “user”.
Set the scope of the component as you wish.

To add properties to the “user”
component do the following.

  1. Click on it in Component Editor.
    In the Properties sub-section, click on Add… . You immediate get
    three options to select from; “Add Simple Property”, “Add List
    property” and “Add Map property”.

  2. Choose the 2nd option.
    In the dialog box that appears give our list the name “games”,
    mapping to the getGames and setGames of the UserImpl. We can now add
    values to the games list. Add the name “monopoly”.

  3. Repeat the steps above to add
    “domino” as another game to the “games” list.

  4. Your Editor should look like this
    now.

This XML support in JBoss Tools allows me to easily wire my components together (like Spring, though Spring IDE can’t compare) and still get all the ooze of Seam. So why wouldn’t I fall in love with XML editing with JBoss Tools. And note, JBoss Tools 3.0-alpha is out with experimental pages.xml editor, visual view of navigations, portlet and a host of other stuff that you are better of finding out for yourself. And I’ll definitely be blogging about my experiences with it very soon.

Technorati Tags: , ,

GenKey Africa Is here

o by God’s grace I was confronted with the choice of learning for an MSc in Networks and Distributed Systems and doing networks and distributed systems real hand with stuff like SOA, ESBs, Web Services, SVN etc. Well, I give it a very long thought (about 5 minutes) and decided to go for the latter. So here I am in East Legon, Accra with Diabeney Agyiri-Tetteh and Wesley Kirinya from Kenya.

GenKey Africa has started and the first week has been challenging enough already. As if that is not enough, there’s a lot of pessimism about whether we can achieve what the American, Indian and Irish software developers can achieve. Suffice it to say that with my boss Hajo Birthelmer guiding us, and even more importantly with God on our side, we’ll beat everyone’s expectations.

So I now have to get comfortable with something called Spring (why does that give me the chills). Being a proponent for standards in enterprise Java, I thought Seam and Google Guice’s Web Beans JSR gave me enough motivation to stick with Seam as my preferred dependency injection-based framework.

Then to make it worse I also have to get comfortable with Eclipse. I’ve always had a bias against it and it SWT leanings, but because Spring support in Eclipse is quite advanced, i guess there’s no other choice. I might as well enjoy learnig and using them as I go along.

I’m already missing the folks on campus I used to teach and discuss Java and Linux technologies. Hope to spend sometime with some of them when they are on vacation. Like to say a few thanks though to Frank Appiah, Edwin Amoakwah, Appiah-Kubi, Nana Sawyer, Julius Kudjoe, Annan Sowah, Boamah Steven and Tolu Erinle. Keep up the hard work.

To my Seam friends, don’t worry we still have a long way to go yet. Keep your eyes on the ball.

To all the folks that turned up for my seminar on Seam, thanks for coming and I hope you enjoyed the session. Hope to do another seminar sometime soon and you’re definitely on my list.