Try now Demo en
  • en
  • fr
  • de
  • Solutions
    • Use cases
      • Modern IntranetBuild strong internal culture & sense of belonging
      • Collaboration PlatformEfficient teamwork and project collaboration
      • Social NetworkEngage users & recognize contributions
      • Knowledge hubCentralize, organize and share company knowledge
      • Application PortalUnified access to business applications and information
    • Switch to eXo
      • Microsoft 365 AlternativeAn open-source digital workplace alternative to M365
      • Migrate to eXo PlatformA guided, secure migration path from your existing tools to eXo
  • Product
    • Overview
      • Platform overviewExplore core capabilities
      • Why eXoKey differentiators
      • InternationalisationMultilingual environments
      • MobileBranded mobile applications
    • Platform
      • No CodeTailor to your needs without code
      • IntegrationsConnectors & extension capabilities
      • Controlled AIGoverned, extensible AI
    • Technology
      • ArchitectureArchitecture & technology
      • SecuritySecurity measures
      • Open sourceComponents & licensing
  • Offers
    • EnterprisePrivate cloud or on-premise deployments
    • eXo HubsReady-to-use SaaS edition for teams
    • Compare EditionsCompare editions and choose the right fit
    • OEM EditionFor software vendors & service providers
    • ServicesDiscover eXo professional services
  • Resources
    • Resource center
      • Case studies
      • White Papers
      • Datasheets
      • Videos
    • FAQsAbout the software, the community and our offers
      • Platform & Use Cases
      • AI & Responsible AI
      • Deployment, Security & Compliance
      • Open-source, Pricing & Services
    • From The Blog
      • eXo Platform 7.1 is released
      • Digital sovereignty: when public organizations move from words to action
      • 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
    • REST APIs & DocumentationAll REST APIs available in eXo Platform
  • Company
    • About us
    • Customers
    • Partners
    • Contact us
    • Newsroom
  • Menu mobile
    • Enterprise Offers
    • Blog
    • About us
    • Resource center
    • Careers
    • Contact us
    • Try eXo
Use cases
  • Modern Intranet Build strong internal culture & sense of belonging
  • Collaboration Platform Efficient teamwork and project collaboration
  • Social Network Engage users & recognize contributions
  • Knowledge hub Centralize, organize and share company knowledge
  • Application Portal Unified access to business applications and information
Switch to eXo
  • Microsoft 365 Alternative An open-source digital workplace alternative to M365
  • Migrate to eXo Platform A guided, secure migration path from your existing tools to eXo
Overview
  • Platform overview Explore core capabilities
  • Why eXo Key differentiators
  • Internationalisation Multilingual environments
  • Mobile Branded mobile applications
Platform
  • No Code Tailor to your needs without code
  • Integrations Connectors & extension capabilities
  • Controlled AI Governed, extensible AI
Technology
  • Architecture Architecture & technology
  • Security Security measures
  • Open source Components & licensing
Enterprise Private cloud or on-premise deployments
eXo Hubs Ready-to-use SaaS edition for teams
Compare Editions Compare editions and choose the right fit
OEM Edition For software vendors & service providers
Services Discover eXo professional services
Resource center
  • Case studies
  • White Papers
  • Datasheets
  • Videos
FAQs About the software, the community and our offers
  • Platform & Use Cases
  • AI & Responsible AI
  • Deployment, Security & Compliance
  • Open-source, Pricing & Services
From The Blog
  • eXo Platform 7.1 is released
  • Digital sovereignty: when public organizations move from words to action
  • 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
REST APIs & Documentation All REST APIs available in eXo Platform
About us
Customers
Partners
Contact us
Newsroom
Enterprise Offers
Blog
About us
Resource center
Careers
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
    • Internationalisation
    • Mobile
    • No Code
    • Architecture
    • Integrations
    • Security
    • Open Source
  • Uses cases
    • Employee Portal
    • Knowledge management
    • Entreprise Social Network
    • Employee Engagement
    • Community Management
    • Extranet
  • Guides
    • What is a digital workplace?
    • Intranet guide
    • What is an extranet?
    • Employee engagement
    • Collaboration guide
    • Teamwork guide
    • Internal Communication guide
  • Enterprise
    • Product offer
    • Services Offer
    • Customers
    • About us
  • Resources
    • FAQs
    • Resource Center
    • Intranet Portal
    • What Is a Collaboration Software?
    • Talent Management
    • Employee Connection
    • Employee Intranet
    • Improve internal communication
    • eXo Tribe
  • Terms and Conditions
  • Legal
  • Privacy Policy
  • Accessibility
  • Contact us
  • Sitemap
  • Facebook
  • Twitter
  • LinkedIn
wpDiscuz