Configuration - 6.3

Talend ESB Service Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Installation and Upgrade
Talend ESB

CXF JAX-RS endpoints and clients can be configured declaratively (using Spring or web.xml only) and programmatically.

Configuration of Endpoints

Providing a custom implementation is the only portable way to register root resource and provider classes and indicate what lifecycle model the individual resources follow. For example:

package server;

import java.util.HashSet;
import java.util.Set;

public class BookApplication extends Application {

   public Set<Class<?>> getClasses() {
      Set<Class<?>> classes = new HashSet<Class<?>>();
      return classes;

   public Set<Object> getSingletons() {
      Set<Object> classes = new HashSet<Object>();
      classes.add(new SearchService());
      classes.add(new BookExceptionMapper());
      return classes;

The BookApplication indicates to the runtime that BookStore root resource has the per-request lifecycle. The SearchService root resource and BookExceptionMapper provider are singletons. In CXF one can register JAX-RS Applications in web.xml using a CXFNonSpringJaxrsServlet:

   <display-name>CXF Servlet</display-name>

Spring users can configure the JAX-RS endpoints using one or more jaxrs:server declarations:

<beans xmlns=""

   <import resource="classpath:META-INF/cxf/cxf.xml"/>
   <import resource=
   <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

   <bean class="org.apache.cxf.systest.jaxrs.BookStore" id="serviceBean"/>
   <bean class="org.apache.cxf.systest.jaxrs.provider.JAXBElementProvider"
      <!-- customize the default JAXBElementProvider 
           by setting some of its properties -->
   <jaxrs:server id="bookservice" address="/bookstore">
      <ref bean="serviceBean" />

      <ref bean="jaxbProvider"/>

      <!-- Register CXF features such as FastInfoset or Logging -->
      <!-- Register CXF in interceptors, example, reuse common in 
           interceptors between JAX-WS and JAX-RS endpoints -->
      <!-- Register CXF out interceptors, example, reuse common out 
           interceptors between JAX-WS and JAX-RS endpoints -->

A single JAX-RS endpoint is registered with a jaxrs:server declaration. This declaration may reference multiple root resource beans with jaxrs:serviceBeans and multiple providers using jaxrs:providers. Note a jaxrs:server/@address attribute. It allows for registering multiple jaxrs:server endpoints with all of them referencing the same service beans but using differently configured JAX-RS providers.

The jaxrs:server endpoints can register CXF features, in and out CXF interceptors.

Configuration of Clients

CXF JAX-RS clients can be configured programmatically or from Spring.

Configuring the clients from Spring often implies that the client instances are injected into JAX-RS or JAX-WS endpoints so that the incoming request can be further delegated to the RESTful service. Both proxies and WebClient instances can be configured from Spring:

<jaxrs:client id="restClient"
      <entry key="Accept" value="text/xml"/>
<bean id="webClient" class="org.apache.cxf.jaxrs.client.WebClient" 
   <constructor-arg type="java.lang.String" 
   value="http://localhost:9000/books/" />