Jump start camel projects with the new yeoman-based project generator

Jump start camel projects with the new yeoman-based project generator

The Red Hat Fuse Tooling team recently broadened its focus from a cross-platform, single-IDE (Eclipse) approach to a cross-platform, cross-IDE approach (Eclipse, VS Code, Che), starting several concerted efforts to provide tools that work across platforms and development environments. Supporting VS Code has become a priority that led us to explore using the Yeoman framework for project and file generation to provide developers a way to jump start their Fuse/Camel development efforts.

This article describes the Yeoman framework and the new Yeoman-based Camel-Project generator the Fuse Tooling team created, and it shows how to install and run the generator.

What is Yeoman?

The Yeoman homepage describes the framework as “…a generic scaffolding system allowing the creation of any kind of app. It allows for rapidly getting started on new projects and streamlines the maintenance of existing projects.”

  • The framework provides an app-agnostic generator ecosystem that can be used to put together entire projects or just parts.
  • It is based on node.js and can be managed using the npm package manager.
  • Yeoman provides an extensive (and growing) array of “generators” available for Angular, Backbone, React, Polymer, and nearly 6,000 other projects.
Learn more at yeoman.io

Learn more at Yeoman.io

Common use cases for Yeoman generators include:

  • Create a project
  • Create a new chunk of a project, like a unit test
  • Create a module or package
  • Bootstrap a new service
  • Enforce standards, best practices, and style guides in generated code
  • Gets users started quickly with sample apps

It’s very easy to install Yeoman once you have NPM on a system:

  1. At a command prompt such as Cygwin or Git Bash on Windows or Terminal on Mac or Linux machines, type npm install yo (or npm install -g yo to install the package globally for all users, though this works only if you have admin privileges or by using sudo, if that is allowed).
  2. To install a specific Yeoman generator, type npm install generator-webapp (see above comment about -g!).
  3. And run it, type yo webapp.

You can learn a great deal more at the Yeoman website and start developing your own generators.

Everything you need to grow your career.

With your free Red Hat Developer program membership, unlock our library of cheat sheets and ebooks on next-generation application development.

SIGN UP

How did the Fuse Tooling team get involved?

We started working with the Yeoman framework in the middle of 2018 to build a simple generator to help developers create new Camel projects from templates in a manner similar to using the New Project Wizard in the Eclipse-based Fuse Tooling. We’ve come a long way since then and now offer integration with the SOAP-to-REST functionality we previously explored with the Fuse Tools in Eclipse (see How to migrate your SOAP web service to REST with Camel).

Though VS Code doesn’t have the concept of a wizard, there are several examples where Yeoman was used to scaffold projects quickly. We decided to try the same approach for Camel projects.

The new Yeoman-based Camel-Project generator scaffolds a new Camel project and gets it ready to run, setting up the necessary folder structure for Maven-ized Spring, Blueprint, or Java-based Camel development. Now, when you add wsdl2rest to the equation, you can add all the necessary CXF and Camel Rest DSL bits to that generated project to wrap your old WSDL-based JAX-WS service in a RESTful way.

Installing and running the generator

To run the generator, you must first install Yeoman, as described above.

Then install the Camel-Project generator by typing npm install -g generator-camel-project. (See the previous notes about -g and constraints when installing globally.)

Once the generator is installed, create a new directory, change to it, and run the generator:

  1. Type mkdir myproject.
  2. Type cd myproject.
  3. Type yo camel-project.

A few notes about the generator:

  • You provide an application name (it defaults to the folder name), the Camel version (which defaults to 2.22.2), your Camel DSL type (spring, blueprint, or Java; it defaults to spring), and a package name (it defaults to com. + the project name).
  • If all is well, it creates a simple project based on the DSL-flavored template you provided.
  • To build and run the project after it’s created, type mvn install and mvn camel:run (or combine them into one command like mvn install camel:run).

Here is an example where I created a Spring-based project. The basic project I create logs a simple Hello message with a timer when it runs.

Example of creating a Spring-based project

We hope that this new generator will help users quickly get up to speed so they can do their own Camel development in any IDE where Yeoman is supported, and we plan on continuing to add functionality a little at a time.

SOAP-to-REST support

Our first chunk of new functionality for the generator focused on the wsd2rest tool we exposed in our Eclipse-based Fuse Tooling earlier in the year. By pairing the Camel-Project generator with wsdl2rest, users automatically gain a quick way to map some simple SOAP-based web services over to REST using Camel’s REST DSL.

To activate the new functionality, simply add --wsdl2rest when you call the generator, for example, yo camel-project --wsdl2rest.

There are a few new prompts, including the URL to the WSDL, the name of the output directory where the utility will put the generated CXF artifacts, the web address of the generated JAX-RS endpoint, and the web address of the source JAX-WS endpoint.

For example, if I have a simple “Hello, world” service running locally, the process would look something like this:

Simple “Hello, world” service running locally

Once the Camel service is running locally, you can open your local browser to the URL localhost:8081/jaxrs/hello/"test" and you should see “Hello test” as a response. This demonstrates the Camel-provided REST service is running and accessing the SOAP service to return valid output.

Verifying that the Camel-provided REST service is running

The wsdl2rest utility provides support for basic types of WSDL implementations, but it does not include any of the WS-* extensions for security and so on. It is simply meant as a quick tool to help migrate simple JAX-WS services to a RESTful paradigm.

The future

If you like this tool, be sure to let us know! We’d love to hear what features you might want to see next as we continue to expand its capabilities.

For more information about the Camel-Project generator, check out the NPMJS page.

For more information about the wsdl2rest tool, check out its GitHub page.

Also see the Red Hat Fuse page.

 

Join Red Hat Developer (it’s free) and get access to software, cheat sheets, books, and more.

Download and learn more about Red Hat JBoss Fuse, an innovative modular, cloud-ready architecture, powerful management and automation, and world class developer productivity. It is Java™ EE 7 certified and features powerful, enterprise-grade features such as high availability clustering, distributed caching, messaging, transactions, and a full web services stack.

Share