Try now Demo en
  • en
  • fr
  • de
  • Product
    • Platform
      • Software TourFeatures & capabilities overview
      • Why eXoeXo Platform key differentiators
      • InternationalisationSupporting multilingual environments
      • MobileResponsive & available on any device
    • Technology
      • No CodeTailor eXo platform to your needs
      • ArchitectureAn overview of eXo Platform technology
      • IntegrationsAvailable connectors & integration capabilities
      • SecurityeXo Platform security measures
      • Open sourceComponents & licensing
  • Solutions
    • Communication
      • Modern IntranetBuild your company culture
      • Knowledge managementCentralize and share your company knowledge
      • Community managementEngage your community
      • ExtranetInvolve your clients and partners
    • Collaboration
      • Social NetworkConnect all your employees
      • Collaboration PlatformEmpower your teams
      • Employee PortalCentralize your work environment
      • Employee EngagementEngage & empower your employees
    • For
      • Public Sector
      • Networks
      • Education
      • Enterprises
  • Pricing
  • Resources
    • Resource center
      • Case studies
      • White Papers
      • Datasheets
      • Videos
    • Migration guide
      • Alternative to Microsoft 365
      • Alternative to Sharepoint
      • Alternative to Workplace from Meta
    • From The Blog
      • eXo Platform 6.5 is released: personalized navigation, multi-sites management and more
      • eXo launches its online community platform – eXo Tribe!
      • Cloud Vs On-premise Digital Workplace: Which one is right for your business?
  • Community
    • CommunityJoin our online community platform
    • DownloadLaunch eXo platform in your infrastructure
    • Source codeSource code on github
    • FAQsAbout the software, the community and our offers
    • REST APIs & DocumentationAll REST APIs available in eXo Platform
  • Company
    • Customers
    • Partners
    • Services
    • About us
    • Contact us
    • Newsroom
  • Menu mobile
    • Pricing
    • About us
    • Careers
    • Resource center
    • Blog
    • Contact us
    • Try eXo
Platform
  • Software Tour Features & capabilities overview
  • Why eXo eXo Platform key differentiators
  • Internationalisation Supporting multilingual environments
  • Mobile Responsive & available on any device
Technology
  • No Code Tailor eXo platform to your needs
  • Architecture An overview of eXo Platform technology
  • Integrations Available connectors & integration capabilities
  • Security eXo Platform security measures
  • Open source Components & licensing
Communication
  • Modern Intranet Build your company culture
  • Knowledge management Centralize and share your company knowledge
  • Community management Engage your community
  • Extranet Involve your clients and partners
Collaboration
  • Social Network Connect all your employees
  • Collaboration Platform Empower your teams
  • Employee Portal Centralize your work environment
  • Employee Engagement Engage & empower your employees
For
  • Public Sector
  • Networks
  • Education
  • Enterprises
Resource center
  • Case studies
  • White Papers
  • Datasheets
  • Videos
Migration guide
  • Alternative to Microsoft 365
  • Alternative to Sharepoint
  • Alternative to Workplace from Meta
From The Blog
  • eXo Platform 6.5 is released: personalized navigation, multi-sites management and more
  • eXo launches its online community platform – eXo Tribe!
  • Cloud Vs On-premise Digital Workplace: Which one is right for your business?
Community Join our online community platform
Download Launch eXo platform in your infrastructure
Source code Source code on github
FAQs About the software, the community and our offers
REST APIs & Documentation All REST APIs available in eXo Platform
Customers
Partners
Services
About us
Contact us
Newsroom
Pricing
About us
Careers
Resource center
Blog
Contact us
Try eXo
  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