Proxy API - 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
Talend ESB
Design and Development
Installation and Upgrade

Proxy based API lets reuse the existing JAX-RS annotated interfaces or implementation classes as proxies. The proxy call will lead to a proper URI and HTTP headers passed to the server, exactly the way the JAX-RS annotated service expects. Proxies can also check the actual HTTP Response, modify request URI and headers, as well as be converted to WebClients. For example, given the following sample interface and the client code:

public interface BookStore {

   Book getBook(@PathParam("id") long id);

   Response addBook(Book newBook);

   BookStore getStore();

   Books getAll();

   public class RESTClient {

      public void consumeRESTfulService(String baseAddress) {
         BookStore proxy = 
            JAXRSClientFactory.create(baseAddress, BookStore.class);
         // get a single book
         Book book = proxy.getBook(1);
         // further introspect the response headers
         Client theClient = WebClient.getClient(proxy);  response = theClient.getResponse();
         // add new book
         Response addNewBookResponse = proxy.addBook(new Book(
            "User Guide")); 
         if (201 == addNewBookResponse.getStatus()) {
            URI bookResourceLocation = 
            Book theBookProxy = JAXRSClientFactory.create(
               bookResourceLocation, Book.class);
         } else {

         // get all books
         BookStore proxy2 = proxy.getStore();
         Books books = proxy2.getAll();


the proxy.getBook(1) call will lead to a 'GET http://localhost:8080/store/books/1' HTTP request being sent to the server, with Accept header set to application/xml.

Note the proxy.getStore() and proxy2.getAll() calls. The BookStore.getStore() resource method is a subresource locator as it has only a @Path annotation. This locator returns the BookStore root instance itself. Thus proxy.getStore() only returns a proxy and the subsequent proxy2.getAll() call will lead to the 'GET http://localhost:8080/store/books/all' HTTP request being sent.