Two big reason why chose Apache CXF over Metro WS

DZone 's Guide to

Two big reason why chose Apache CXF over Metro WS

· Integration Zone ·
Free Resource


Apache CXF and Metro WS are two very popular webservice frameworks(which fully implements JAX-WS specification).Both are equally popular and widely used. Metro WS project has been receiving lot of attention, thanks to some good advertising and promotions by Sun Microsystem(now Oracle).Based on my experiences with the two frameworks,the following are two major reasons why i would prefer CXF over Metro.


Metro forces you to expose the implementing class

         In  a real world application one prefers to just expose the interface and hide the actual implementation class.For eg: you might want to do something like the below code,


public interface HelloWorldService {

public String sayHello(String input);


public class HelloWorldServiceImpl {

public String sayHello(String input)


return "hello world"+input;



When you try to execute the above code with Metro,you will get this exception 
saying  "JAXB can't handle interfaces".

Metro forces you to add the JAX-WS annotations on implementing class(HelloWorldServiceImpl)

even if you had already annotated the interface.You cannot just annotate interfaces and hope subclasses will be "annotated".

Many a times you might have something similar to jaxb-api.jar and jaxb-impl.jar,where API's are packaged seperately from the actual implementation.In such cases you don't want the developers writing the implementations to worry about exposing web services or JAX-WS annotations.CXF handles this pretty well and lets you add all those JAX-WS annotations just at the interface level.


CXF supports both jax-ws and jax-rs very well

      CXF supports usage of both JAX-WS  and JAX-RS annotations together without any trouble.It means,one can expose any interface in both SOAP and REST format and still keep the implementing class ignorant of all this.


@WebService(serviceName = "HelloWorld", name = "HelloWorldService")
public interface HelloWorldService {
HelloWorld sayHello();

 As you can see in the above example,HelloWorldService interface has both SOAP and REST annotations and it works with CXF framework. For some reason,Sun maintains two separate projects Metro and Jersey to support SOAP and REST (Metro for SOAP and Jersey for REST).It is possible to get Metro and Jersey working together but might require some plumbing work to be done.       


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}