Code Monkey home page Code Monkey logo

tmplt-server-cxf's Introduction

CXF REST/SOAP

Description

The goal of this template is to have a basic CXF server, ready to be run in Tomcat. Both REST service and SOAP service based on standard JAX-RS and JAX-WS using the Apache CXF framework. The Spring configuration is based on annotations, no XML context files!

The special thing about the CXFServlet is that it detects the presence of the Spring context and will fetch the SOAP and REST configurations directly from this context. You don't need extra wiring to connect Spring and CXF, CXF uses the Spring context automatically as a meeting point for server and service definitions.

Usage

Adding a service

  • Create the service. Don't forget to register it in the JAXRSServerFactoryBean in the AppConfig.java. CXF does not scan the packages to find the resources.
  • If you have new JAXB annotated classes that will be used in the REST interface, you have to register these JAXB classes explicitly in the provider list in AppConfig.java. By default CXF provides a mechanism to create a MessageBodyReader/Writer for each JAXB annotated class.

Features

  • Standard Java web application.
  • CXF REST + SOAP frontends.
  • Spring configuration (annotation based).

Notes

  • At least Java 1.6 needed for the Spring annotations.
  • In Spring +3.1 @ComponentScan becomes available, so you do not need to create the beans explicitly.
  • You should run it as a Tomcat application. It was tested with Tomcat 6 and 7.

Links

Files

  • /README.txt: This file.
  • /pom.xml: The Maven configuration file.
    1. Spring core + web.
    2. CXF core + SOAP front end + REST front end.
  • /src/main/java/com/sdicons/AppConfig.java: The Spring configuration class replacing the XML configuration. It produces all the application instances.
  • /src/main/java/com/sdicons/Message.java: A JAXB annotated class that can be rendered to JSON or to XML.
  • /src/main/java/com/sdicons/RestService.java: A plain JAX-RS 'hello' service.
  • /src/main/java/com/sdicons/SoapService.java: A plain JAX-WS 'hello' service.
  • /src/main/webapp/WEB-INF/web.xml: Standard Java web application.
    1. CXF Servlet configuration.
    2. Spring context setup to pick up our AppConfig class to initialize the context.

Conclusion

The CXF servlet integrates well with Spring. You can rely on it that future versions will do this as well.

It is a plus that the CXF servlet integrates both SOAP as REST services in similar ways.

It can be a burden to register all resource, provider and JAXB class each time. But on the other hand it is a transparent system that you could modify or extend. There is no hidden mechanism in here it follows the JAXRS standard.

tmplt-server-cxf's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.