Enterprise Java

Getting started with SwitchYard 2.0.0.Alpha1 on WildFly 8.1.0.Final

I’ve been sticking my head into some hot RedHat technologies lately and among the many interesting parts I found SwitchYard. Without being disrespectful towards everybody wrapping their heads around SOA and service oriented architectures in the past, this has always been kind of weird to me as a Java EE developer.

switchyard_icon_256pxIn the past I’ve been building component oriented applications with what I had at hand. Mostly driven by the features available in the Java EE standard to be “portable” and easy to use. Looking back this has been a perfect fit for many customers and applications. With an increasing demand for highly integrated applications which use already available services and processes from all over the place (departmental, central or even cloud services) this approach starts to feel more and more outdated. And this feel does not come from a technology perspective but from all the requirements around it. Having this in mind this post is the starting point of a series of how-to’s and short tutorials which aim to showcase some more diverse ways of building (Java EE) applications that fit better into today’s requirements and landscapes.

What is SwitchYard?

It is a component-based development framework for integration applications using the design principles and best practices of Service Oriented Architecture. If you’re expecting kind of a full-blown fancy BPMN/SOA buzz-word suite you’re off by a bit. This is for developers and should make it comparably straight forward to use. It’s been around for a while now and starting with latest 2.0.0.Alpha1 it is compatible with WildFly 8. Reasons enough for me to get you excited about it.

Installing SwitchYard into latest WildFly 8.1.0.Final

Download both, the switchyard-2.0.0.Alpha1-wildfly bundle and WildFly 8.1.0.Final from the project websites. Install WildFly 8 by unzipping it into a folder of your choice (e.g. D:\wildfly-8.1.0.Final\). Now unzip the SwitchYard bundle into the WildFly folder. Depending on the zip utility in use, you may be prompted whether existing files should be replaced.  Answer yes/all for all files being unzipped.

It’s an alpha so you have to tweak the configuration a bit because of SWITCHYARD-2158. Open “JBOSS_HOME/standalone/configuration/standalone.xml” and search for “org.switchyard.component.camel.atom.deploy.CamelRSSComponent” and change the package from “atom” to “rss”. Now go ahead and start the server with “JBOSS_HOME/bin/standalone.sh/.bat”.

If everything worked correctly you should see a message like this:

09:18:25,857 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.1.0.Final "Kenny" started in 3712ms - Started 210 of 259 services (81 services are lazy, passive or on-demand)

Building and Deploying the Bean Service Quickstart

If you want to get your hands dirty you can easily start with the packaged applications in the “JBOSS_HOME/quickstarts/” directory of the distribution. A simple one is the bean-service example. It makes use of one of the core components of SwitchYard, the Bean Component. It allows Java classes (or beans) to provide and consume services. And therefore you can implement a service by simply annotating a Java class or consume one by injecting a reference directly into your Java class.

And because the Bean Component is a standard CDI Extension, there is no need to learn a new programming model to use it. It’s just a standard CDI Bean with a few more annotations.

For existing Java EE applications this means, that you can expose existing CDI-based beans in your application as services to the outside world or consume services within your bean by just adding some more annotations.

First things first. We need to tweak around a bit in the project pom.xml to make this work. Go to the build section and replace the “jboss-as-maven-plugin” with the latest version of the:

<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>

Now run “mvn package” to download all dependencies and execute the tests. It should just work fine and state:

Tests run: 6, Failures: 0, Errors: 0, Skipped: 0

Let’s deploy it to our WildFly instance by issuing “mvn -Pdeploy install”. The WildFly console finally lets you know about the successful execution:

10:19:44,636 INFO  [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "switchyard-bean-service.jar" (runtime-name : "switchyard-bean-service.jar")

Quick Test For The Application

A very quick test is to execute mvn exec:java which will execute the BeanClient class and fire a SOAP request towards the deployed service. The output should be:

SOAP Reply:
<soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><env:header xmlns:env="http://www.w3.org/2003/05/soap-envelope"></env:header><soap:body><ord ers:submitorderresponse="" xmlns:orders="urn:switchyard-quickstart:bean-service:1.0
"><orderack><orderid>PO-19838-XYZ</orderid><accepted>true</accepted><status>Orde
r Accepted [intercepted]</status></orderack></ord></soap:body></soap:envelope>

That is it for today. The next parts will examine the sample application in a bit more detail and install the tooling and introduce you to various other components. If you can’t wait, check out:

Markus Eisele

Markus is a Developer Advocate at Red Hat and focuses on JBoss Middleware. He is working with Java EE servers from different vendors since more than 14 years and talks about his favorite topics around Java EE on conferences all over the world. He has been a principle consultant and worked with different customers on all kinds of Java EE related applications and solutions. Beside that he has always been a prolific blogger, writer and tech editor for different Java EE related books. He is an active member of the German DOAG e.V. and it's representative on the iJUG e.V. As a Java Champion and former ACE Director he is well known in the community. Follow him on Twitter @myfear.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button