Thursday, July 18, 2013

WS-Discovery with CXF-based JAX-WS/JAX-RS in WSO2 AS

Apache CXF has added out-of-the-box support for WS-Discovery for CXF based JAX-WS and JAX-RS services starting from CXF 2.7.x versions. This post describes how to add this support to WSO2 Application Server with WSO2 Governance Registry (GReg) acting as the DiscoveryProxy receiver.

All the WSO2 Carbon-based service hosting products like WSO2 Application Server supported WS-Discovery for axis2 services (including data services, proxy services etc.) for a long time. These products can be configured to announce the axis2 services to a Governance Registry instance. But we did not have a way to announce CXF-based JAX-WS and JAX-RS services. But with the out-of-the-box support for WS-Discovery that comes with CXF this is now possible. Following steps describes how to add WS-Discovery to jax webapps.

  1. Download the latest WSO2 Application Server (AS) pack.
  2. Copy the following three jars to {WSO2-AS-HOME}/lib/runtimes/cxf
    • cxf-services-ws-discovery-service  - version 2.7.5
    • cxf-services-ws-discovery-api  - version 2.7.5
    • mina-core - version 2.0.7
  3. Add a CXF Configuration File (cxf.xml) to the WEB-INF/classes/ location of a webapp.
  4. Add a bus property "" which points to the DiscoveryProxy instance residing in GReg. To do that,
    1. Open up cxf.xml we added to the webapp before. There, under the 'cxf' bean (which uses the class org.apache.cxf.bus.spring.SpringBus), add the property "" and set it to the DiscoveryProxy service URL of GReg. The default service URL is https://localhost:9443/services/DiscoveryProxy for a WSO2 GReg instance running in local machine with port offset 0. The properties are stored as a map. A sample cxf.xml would look like the following. [1]

<property name="properties">
        <entry key="" value="https://localhost:9443/services/DiscoveryProxy" />

     5. Deploy the webapp

[1] Sample cxf.xml

<beans xmlns=""

    <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus" destroy-method="shutdown">
        <property name="properties">
                <entry key="" value="http://localhost:8080/services/DiscoveryProxy" />

    <bean id="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor" 
    <bean id="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor" 
    <bean id="org.apache.cxf.bus.spring.BusExtensionPostProcessor" 


Sample Hello Message sent from AS to GReg

<soap:Envelope xmlns:soap=""
        <ns2:Hello xmlns=""
            <ns2:Types xmlns:ns3="http://server.hw.demo/">ns3:HelloWorld</ns2:Types>