ServiceMix 4.2 – Debugging and more Gotchas

This is the sequel to Getting started with ServiceMix 4.2 and WebServices (with Maven and Eclipse on Windows). Remeber: I’m using Eclipse 3.5.2 on Windows 7 here.

If you want to debug OSGi-bundled code on ServiceMix 4.2, you’ll need to set the environment variable KARAF_DEBUG = true (in System –> Advanced –> Environment Variables, click the “add”-button in the lower list). Then make sure you the console you’re working on (using the “shutdown” command), kill the command window, start a new one (that now knows the environment variable is set) and re-run servicemix. In the console, a message should appear that now a remote debugging port was opened. If not, reread this paragraph (or restart your system).

Then go to the project you’re working on in Eclipse, right click on the project, “Debug As…” –> “Debug Configurations” go to “Remote Java Application”, enter the projects name and the host and port ServiceMix runs on (“localhost” here and the default port 5005). Then click Debug. You should now be able to set Breakpoints and Debug everything nicely. To have debug statements on my Eclipse Console I chose to use a Log4j default debugger. This one logs out to the console as default, which is the connected debug-console when debugging.

  • When re-deploying a bundle containing a WebService that was registered (and worked) before, the connection to the CXF-services break after the update command on the karaf console. The result of a request to the WebService is either a plaintext “No service was found.” or a XML SOAP Fault with the message “No such operation:  (HTTP GET PATH_INFO: /MyServicesName)”. I didn’t find a proper solution for this one yet, but restarting the CXF Service Engine bundle before restarting my own bundle (using osgi:restart [idOfCxfServiceEngineBundle]) containing the WebService works fine. (If someone finds a better solution, please drop a comment)

I’ll update when I find even more ServiceMix gotchas.

Getting started with ServiceMix 4.2 and WebServices (with Maven and Eclipse on Windows)

(Under this post I noted down some great resources for getting started, so if you’re searching for those, have a look at the bottom of this article)

Okay, I had a really hard time getting started with ServiceMix, as there’re so many technologies involved and I knew none of them. Maven. OSGi. ServiceMix. Karaf. Most of the time, you only want something to work so you can apply the same or nearly the same technique again, right? So here’s a little plan what works and where you can start your journey:

- Install maven. Install Eclipse.

- Install the m2 plugin for eclipse.

- Download ServiceMix 4.2.

- Open a windows command terminal. Navigate to %servicemix_home%/bin

- “servicemix.bat” starts ServiceMix. You get into the Karaf console. Typing TAB and “y” shows you a lot of commands you can try out. (If you want, try some … easy administration!)

- Open Eclipse. Seriously. Import –> Maven project

- In the wizard, browse to %servicemix_home%/examples

- Pick the “cfx-osgi” folder and use the pom.xml the wizard finds there for importing the project. Finish the wizard.

- Change the sourcecode of the HelloWorldImpl.java file to do what you want and save that file.

- Right click the project –> Run –> Maven install. A .jar file gets generated.

- Copy that jar file into the %servicemix_home%/deploy folder.

- Get back to Eclipse … there’s a client.html file in the imported project. Right click that –> Open With –> Web Browser

- Click the “send” button. Smile.

- (Optional: Now remove the .jar file from the deploy folder of servicemix. Click the “send” button on the HTML form again. Smile.)

If you want to learn more, you can look into the FUSE ServiceMix documentation (FUSE is documenting and selling support for ServiceMix, but they don’t put much more on top of ServiceMix, so the documentation is pretty good). Or try the text files that come with the examples.

Hope this helped you a bit.

Edits and Updates:

  • I found this tutorial VERY helpful dealing with and understanding BCs: http://servicemix.apache.org/hello-world-bc.html
  • And as you will be using Spring anyways and there’s no way around it, just to understand how simple it works, begin with this small tutorial: Getting started with Spring
  • FUSE is a trademark that’s selling support for servicemix and label servicemix as “FUSE”. No matter if I got that right, FUSE is basically just ServiceMix. As the FUSE people are apt writing nice documentation (and the ServiceMix-page documentation basically sucks), you should head over to FUSE and read their docs (click on documentation and see a lot of nice PDFs). They explain everything you need in a well-written way – OSGi, Spring, Karaf, Maven, CXF, …
  • If you want to use Eclispe and Maven to build OSGi bundles, read this page calmly. It explains how you configure all the OSGi stuff in the pom.xml. Additionally, don’t try to use Eclipse’s plugin-development features as this will mess with your dependency resolution. Maven seems to say: put everything into my hands and you’ll be fine (even if you don’t like me).
  • This is a neat wiki article for getting started with building OSGi bundles for ServiceMix from Eclipse.
  • Here’s a nice article and tutorial explaining how to develop OSGi Bundles with Eclipse.