{scrollbar}

top

CXF examples

This example leverages CXF and Spring-DM to create a web service and expose it through the OSGi HTTP Service.

Installing the CXF examples on ServiceMix Kernel

Quick steps

You will need the latest versions of ServiceMix Kernel. You can either build one yourself or grab one from here.

Unzip the tar.gz or zip, and launch ServiceMix Kernel by running bin/servicemix.

When inside the console, just run the following commands:

features addUrl mvn:org.apache.servicemix.nmr/apache-servicemix-nmr/1.0-m2-SNAPSHOT/xml/features features addUrl mvn:org.apache.servicemix.features/apache-servicemix/4.0-m2-SNAPSHOT/xml/features features install examples-cxf-osgi Recent change in subshell syntax

If you get the error below it may be due to a recent change in the latest GShell - see SMX4-153

> features list ERROR CommandLineExecutionFailed: org.apache.geronimo.gshell.command.CommandException: org.apache.geronimo.gshell.clp.ProcessingException: No argument is allowed: list

The new syntax is:

features/addUrl mvn:org.apache.servicemix.nmr/apache-servicemix-nmr/1.0-m2-SNAPSHOT/xml/features features/addUrl mvn:org.apache.servicemix.features/apache-servicemix/4.0-m2-SNAPSHOT/xml/features features/install examples-cxf-osgi

At this point, it will certainly fail if you don't have the examples inside your local repository. This is because all the required bundles are not released yet and SNAPSHOTs are not published in maven public repositories. To pass this step, you'll have to build ServiceMix 4 (see Building).

If you have all the bundles available in your local repo, the installation of the example will be very fast, else it may take some time to download everything needed.

Testing the example

Just open your browser and go to the following url:

http://localhost:8080/cxf/HelloWorld?wsdl

It should display the WSDL of the service (if you use Safari, make sure to right click the window and select 'Show Source', else the page will be blank).
Or you can also test it from ServiceMix console using"

utils cat http://localhost:8080/cxf/HelloWorld?wsdl

How does it work ?

The installation leverages ServiceMix Kernel by installing what's called 'features'. You can see the features definition file using the following command inside ServiceMix console:

utils cat mvn:org.apache.servicemix.features/apache-servicemix/4.0-m2-SNAPSHOT/xml/features

The list of available features can be obtained using:

features list

Inside the example

This example leverages CXF and Spring-DM to create a web service.

The bundle for this example is quite simple and it contains two classes for the service definition and the spring definition file.

org/apache/servicemix/examples/cxf/HelloWorld.javajava package org.apache.servicemix.examples.cxf; import javax.jws.WebService; @WebService public interface HelloWorld { String sayHi(String text); } org/apache/servicemix/examples/cxf/HelloWorldImpl.javajava package org.apache.servicemix.examples.cxf; import javax.jws.WebService; @WebService(endpointInterface = "org.apache.servicemix.examples.cxf.HelloWorld") public class HelloWorldImpl implements HelloWorld { public String sayHi(String text) { return "Hello " + text; } } META-INF/spring/beans.xmlxml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" /> <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" /> <jaxws:endpoint id="helloWorld" implementor="org.apache.servicemix.examples.cxf.HelloWorldImpl" address="/HelloWorld"/> </beans>

Note that we use the OSGi transport so that this web service will be exposed through the standard OSGi HTTP service.

Also, you need to make sure the MANIFEST contains the needed OSGi headers, in our case:

Import-Package: META-INF.cxf,META-INF.cxf.osgi,javax.jws Require-Bundle: org.apache.servicemix.bundles.woodstox-3.2.3

Exposing the service to ServiceMix internal bus

We can go a step beyond and try to expose the same service to ServiceMix internal bus (NMR) so that we can connect it to multiple components (BPEL engine, Rules engine, XSLT engine, etc...). We will see that in the next example.

Resources

Source code for this example is available at the following location:

http://svn.apache.org/repos/asf/servicemix/smx4/features/trunk/examples/cxf-osgi/

#top

{scrollbar}
  • No labels