Contact us
  • en
  • fr
  • Solutions
    • Company IntranetDiscover our company intranet software to connect and engage your employees
    • Collaboration PlatformDiscover our digital collaboration platform that boost your employee engagement and performance
    • Knowledge ManagementHow To build and manage your knowledge base with eXo Platform
    • Employee EngagementDiscover how to boost your employee engagement
  • Product
    • Overview
      • Software TourAn overview of our software capabilities
      • Why eXoHow eXo improves your employee experience
    • Features
      • CommunicationFeatures to facilitate employee communications
      • CollaborationFeatures to create efficient teams
      • KnowledgeKnowledge management capabilities
      • ProductivityEmployee productivity tools to engage employees
    • Technology
      • Open sourceAn overview of our technology
      • IntegrationsDiscover how eXo integrates with your tools and systems
      • SecurityHow eXo Platform ensures your data security
  • Pricing
    • Product pricingLearn about our business model and pricing
    • ServicesLearn about our professional services
    • FAQsQuestions about the software, the community and our offers
  • Resources
    • Resource center
      • Case studies
      • White Papers
      • Datasheets
      • Videos
    • Technical documentation
      • Getting started
      • Developer Guide
      • Technical administration guide
      • REST APIs
    • From The Blog
      • eXo Platform 6.4 is here, available in both Enterprise and Community editions!
      • eXo Platform community edition is back
      • Cloud Vs On-premise Digital Workplace: Which one is right for your business?
  • Company
    • About us
    • Careers
    • Customers
    • Newsroom
    • Contact us
    • Partners
  • Menu mobile
    • Pricing
    • About us
    • Services
    • FAQs
    • Customers
    • Resource center
    • Contact us
    • Blog
Company Intranet Discover our company intranet software to connect and engage your employees
Collaboration Platform Discover our digital collaboration platform that boost your employee engagement and performance
Knowledge Management How To build and manage your knowledge base with eXo Platform
Employee Engagement Discover how to boost your employee engagement
Overview
  • Software Tour An overview of our software capabilities
  • Why eXo How eXo improves your employee experience
Features
  • Communication Features to facilitate employee communications
  • Collaboration Features to create efficient teams
  • Knowledge Knowledge management capabilities
  • Productivity Employee productivity tools to engage employees
Technology
  • Open source An overview of our technology
  • Integrations Discover how eXo integrates with your tools and systems
  • Security How eXo Platform ensures your data security
Product pricing Learn about our business model and pricing
Services Learn about our professional services
FAQs Questions about the software, the community and our offers
Resource center
  • Case studies
  • White Papers
  • Datasheets
  • Videos
Technical documentation
  • Getting started
  • Developer Guide
  • Technical administration guide
  • REST APIs
From The Blog
  • eXo Platform 6.4 is here, available in both Enterprise and Community editions!
  • eXo Platform community edition is back
  • Cloud Vs On-premise Digital Workplace: Which one is right for your business?
About us
Careers
Customers
Newsroom
Contact us
Partners
Pricing
About us
Services
FAQs
Customers
Resource center
Contact us
Blog
  1. Accueil
  2. Uncategorized
  3. eXo REST framework use case

eXo REST framework use case

The new version of eXo comes with a powerful REST framework following the guidelines defined in the JSR 311 specification (JAX-RS)

The idea of the REST framework is to provide a simple way to create server side APIs that allows to expose to third party systems most of the platform functionalities.

Note that that trend is extremely popular in the consumer web where corp like Yahoo or Google expose many services using the REST paradigm. Even the server side part of the new OpenSocial specification is REST based… and could be implemented using eXo REST framework!

1) Some samples

We have exposed several services using the framework from the low level layers like WebDAV to the higher one like providing a Facebook application using the REST framework to browse eXo Document Management repository.

Another sample is a REST service that expose all the contact of an eXo Collaboration Suite user. We also have a Flex based client that read the exposed XML and displays the contacts. The flex can be embedded inside a portlet, a widget or any other web application:

[Update]  I also paste a screenshot of the iGoogle gadget that allows to browse the document repository on eXo. It leverages the WebDAV protocol that itself is implemented over the REST framework

 

2) Technical aspects of the framework

So any eXo Java service can be exposed via REST, it just has to use Java annotations inside services to dynamically map an URL and Java entities.

One of the most important type of annotation is @URITemplate, applicable for TYPE and METHOD scope which define relative URL to expose given service via HTTP.

In simple cases, a RESTable method is uniquely addressed as a concatenation of a base URL, a TYPE scoped URITemplate annotation (if any) and a METHOD scoped URITemplate annotation. Parameters of the service can also be mapped to some elements of the URL as shown in the next code fragment. There an HTTP call to the URL “server.com/level1/toto/titi/tata” would directly invoke the method3 method with “toto”, “titi” and “tata” as the value of the 3 method arguments.

@URITemplate("/level1/{id1}/")
public class ResourceContainer_TEST implements ResourceContainer {

  @HTTPMethod("GET")
  @URITemplate("/{id2}/{id3}/")
  public Response method3(@URIParam("id1") String param1,
                                     @URIParam("id2") String param2,
                                     @URIParam("id3") String param3) {
    System.out.println("=== method3 called: id1 = " + param1);
    System.out.println("=== method3 called: id2 = " + param2);
    System.out.println("=== method3 called: id3 = " + param3);
    Response resp = Response.Builder.noContent().build();
    return resp;
  }
}

All HTTP methods like standard PUT, POST, DELETE ones can be used and referenced using the HTTPMethod annotation. A Response object is returned to the container, in our sample the Response does not contain anything; the ok method returns a 200 HTTP status code.

More complex URL template are also supported especially the one of type ?param1=value1&param2=value2 as shown in the next code fragment where the parameters are directly mapped to the method signature arguments:

@HTTPMethod("GET")
@URITemplate("/test/queryfilter/")
@QueryTemplate("method=method1&param1=param1")
@OutputTransformer(StringOutputTransformer.class)
public Response method1(@QueryParam("method") String method,
                                   @QueryParam("param1") String param1) {
  System.out.println(".. method=" + method);
  System.out.println(".. param1=" + param1);
  return Response.Builder.ok("method1", "text/plain").build();
}

Another important feature of that REST framework is the use of Transformer objects that can be easily plugged at the Response generation time.

In the previous example, the transformer class is a simple StringOutputTransformer that will convert the incoming object into a String output of type “text/plain”.

The framework contains several transformers that are ready to use such as XSLT4DOMOutputTransformer which takes a DOM element and will transofrm it using an XSL template file as shown in the next code fragment:

  @HTTPMethod("GET")
  @URITemplate("/test/xslt/{schema-name}/")
  @OutputTransformer(XSLT4DOMOutputTransformer.class)
  public Response method1(@URIParam("schema-name") String schemaName)
              throws Exception {
    Map<string,> p = new HashMap<string,>();
    p.put(XSLTConstants.XSLT_TEMPLATE, schemaName);
    Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder()
        .parse(Thread.currentThread().getContextClassLoader()
        .getResourceAsStream("book-in.xml"));
    return Response.Builder.ok(d, "text/html").setTransformerParameters(p).build();
  }
</string,></string,>

3) The Contact REST Service

The ContactRESTService is a simple sample of an eXo service method that is exposed through a REST API.

Any URL of type “server.com/contact/getContactList/benjamin” will return an XML fragment within the HTTP response that will contain the list of all benjamin’s contacts that are located in the Contact Manager application of eXo CS.

As you can see in the next fragment, the code is simple, we simply get the ContactService and call the getAllContact method on the current user

@URITemplate("/contact/")
public class ContactRestService implements ResourceContainer {

  private ContactService contactService;
  private ThreadLocalSessionProviderService sessionProviderService;

  public ContactRestService(ContactService contactService,
                                      ThreadLocalSessionProviderService sessionProviderService) {
    this.contactService = contactService;
    this.sessionProviderService = sessionProviderService;
  }

  @URITemplate("getContactsList/{username}/")
  @HTTPMethod(HTTPMethods.GET)
  @OutputTransformer(XMLOutputTransformer.class)
  public Response getContact(
      @URIParam("username") String username)
      throws Exception {
	  System.out.println("Entering getContact Rest Method");
	  System.out.println("Get Contact list for username :"+username);
	  SessionProvider sp = sessionProviderService.getSessionProvider(null);
	  java.util.List listcontact = contactService.getAllContact(sp, username);
	  Iterator listiterator = listcontact.iterator();
	  org.w3c.dom.Document d= DocumentBuilderFactory.newInstance().
                   newDocumentBuilder().newDocument();
	  Element contactlist = d.createElement("contactlist");

	  while (listiterator.hasNext())
	  {
		  Contact contactobj = listiterator.next();

		  Element contact = d.createElement("contact");
		  Element exoid = d.createElement("exoid");
		  Element fullname = d.createElement("fullname");
		  Element firstname = d.createElement("firstname");
		  Element job = d.createElement("job");
		  Element nickname = d.createElement("nickname");
		  Element mail = d.createElement("mail");
		  Element birthday = d.createElement("birthday");

		  exoid.setTextContent( contactobj.getId());
		  fullname.setTextContent( contactobj.getFullName());
		  firstname.setTextContent( contactobj.getFirstName());
		  job.setTextContent( contactobj.getJobTitle());
		  nickname.setTextContent( contactobj.getNickName());
		  mail.setTextContent( contactobj.getEmailAddress());
		  if (contactobj.getBirthday()!=null)
                    birthday.setTextContent(contactobj.getBirthday().toString());

		  contact.appendChild(exoid);
		  contact.appendChild(fullname);
		  contact.appendChild(firstname);
		  contact.appendChild(job);
		  contact.appendChild(nickname);
		  contact.appendChild(mail);
		  contact.appendChild(birthday);
		  contactlist.appendChild(contact);
	  }
	  d.appendChild(contactlist);

	  return Response.Builder.ok(d,"text/xml").build();

  }
}

Brahim Jaouane

I am a Digital Marketing specialist specialized in SEO at eXo Platform. Passionate about new technologies and Digital Marketing. With 10 years' experience, I support companies in their digital communication strategies and implement the tools necessary for their success. My approach combines the use of different traffic acquisition levers and an optimization of the user experience to convert visitors into customers. After various digital experiences in communication agencies as well as in B2B company, I have a wide range of skills and I am able to manage the digital marketing strategy of small and medium-sized companies.

Full-featured digital workplace with everything your employees need to work efficiently, smartly integrated for a compelling employee experience

  • Product
    • Software tour
    • Communication
    • Collaboration
    • Knowledge
    • Productivity
    • Open Source
    • Integrations
    • Security
  • Uses cases
    • Digital Workplace
    • Intranet software
    • Collaboration software
    • Knowledge management software
    • Entreprise Social Network
    • Employee Engagement platform
  • Roles
    • Internal Communications
    • Human Resources
    • Information Technology
  • Company
    • Product offer
    • Services Offer
    • Customers
    • Partners
    • About us
  • Resources
    • FAQs
    • Resource Center
    • Collaboration guide
    • What is a Digital workplace?
    • What is an intranet?
    • Employee engagement
  • Terms and Conditions
  • Legal
  • Privacy Policy
  • Accessibility
  • Contact us
  • Sitemap
  • Facebook
  • Twitter
  • LinkedIn
wpDiscuz