In this chapter, let us discuss about what Apache CXF is and how it can be helpful in developing SOAP and Rest Web Services.
Apache CXF is a web service development framework that can be utilized to develop SOAP and Rest web services. CXF is fully compliant with JAX-RS and JAX-Ws standard.
It is most widely used web service development framework now. CXF has learned and improved over Axis2 which is now gradually being replaced by CXF.
CXF | Axis2 | |
---|---|---|
Improvements | CXF is most used framework as of now. It has lot improvements over Axis2 |
Axis2 is gradually being replaced by CXf. It requires more code as compared to CXF |
Code required | CXF requires less code as compared to Axis2 |
Axis2 requires more code comparatively |
Standard Compliance | CSF is fully compliant with JAX-RS and JAX-WS |
Axis2 is not fully compliant with JAX-RS and JAX-WS |
Compatible with Spring | Yes |
No |
Separation of front-ends | Clean separation of front-end from JAX-WS code |
No clean separation is provided |
SOAP stands for Simple Object Access Protocol. It is a protocol for exchanging structured information over web services between two systems. It mostly relies on XML for structuring data and uses HTTP or SMTP for message negotiation and transmission.
There are two approaches to develop SOAP web services −
Code first − In this approach, WSDL is generated from code.
Contract first − In contract first, code is generated from WSDL.
Add the following profile to your settings.xml of Maven.
<profiles> <profile> <id>Jboss-Fuse</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>fusesource</id> <url>http://repo.fusesource.com/nexus/content/groups/public/</url> <snapshots> <enabled>false</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> </profile> </profiles>
mvn archetype:generate -DarchetypeGroupId = org.apache.servicemix.tooling -DarchetypeArtifactId = servicemix-cxf-code-first-osgi-bundle -DarchetypeVersion=2012.01.0.redhat-60024 -DgroupId = org.fusesource.example -DartifactId = cxf-basic -Dversion = 1.0-SNAPSHOT
Build Web Service Project.
mvn clean install
Install web-service into Fuse using the following command.
JBossFuse:karaf@root>install -s mvn:org.fusesource.example/cxf-basic/1.0-SNAPSH
Check if bundle has registered SOQP web-service
Open URL http://localhost:8181/cxf
The web-service should be listed as follows.
Testing Web-Service
mvn -Pclient
INFO − Creating Service {http://ws.totorials.com/} PersonService from class com.to
torials.ws.Person Invoking getPerson... getPerson._getPerson_personId = Guillaume getPerson._getPerson_ssn = 000-000-0000 getPerson._getPerson_name = Guillaume [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 30.668 s [INFO] Finished at: 2016-02-15T21:01:20+05:30 [INFO] Final Memory: 10M/37M [INFO] ------------------------------------------------------------------------