Locked History Attachments

Bennu/Projects/WebServiceUtils

web-service-utils project

Description

This module provides a Jersey REST client. The main goal is to substitute the remote module so that developers should implement a REST server which provides the data to be imported using this client.

Usage

<dependency>
    <groupId>pt.ist</groupId>
    <artifactId>web-service-utils</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Features

SERVER (Fénix)

  • In Fénix a REST server endpoint is defined on net.sourceforge.fenixedu.webServices.jersey.JerseyServices

  • The usual use case is to implement a method that returns a JSON String

Configuration

  • The remote-plugin defines RemoteHost class whose objects contain each client configuration

   1 class RemoteHost {
   2         String name; // name of the client (not used)
   3         Strings url; // client address when connecting to server
   4         String username;
   5         String password;
   6         Boolean allowInvocationAccess; // if true accepts connections
   7 }
  • You should use fénix-scripts project to create your clients.
  • Beware that the same client can have multiple internet addresses (ipv4 and ipv6) so you should add all your client interfaces to remoteHost addresses.

Example :

protected void run() { 
      Strings clientAddresses = new Strings(new String [] { "127.0.0.1", "localhost"});
      new RemoteHost(clientAddresses, "username", "password", Boolean.TRUE); 
    }

Server method example

  • Each method must have at least 3 annotations (@<HttpMethod>, @Produces(<MediaType>), @Path(<String>))

   1 @GET
   2 @Produces(MediaType.TEXT_PLAIN)
   3 @Path("hellofenix")
   4 public String hellofenix(@QueryParam("name") String name, @QueryParam("surname") String surname ) {
   5   return String.format("Hello %s %s !",name, surname);
   6 }

CLIENT (Bennu)

  • The client was designed to connect to server using HTTP GET method returning a Java primitive type.
  • The WSURemoteSystem defines a static method called getFenixJerseyClient() that returns a JerseyClient which connects to a host called fenix.

Configuration

  • You must add servers configuration interface to bennu
    • Configuração
    • Menus e Interfaces
    • Adicionar Funcionalidade
    • Adicionar Interface de Communicação Jersey
  • You must define a new host with name fenix

Usage

After all configuration steps the following code:

   1 JerseyClient fenixClient = WSURemoteSystem.getFenixJerseyClient();
   2 String returnValue = fenixClient.method("hellofenix").arg("name", "Bennu")
   3                         .arg("surname", "User").get();

returns "Hello Bennu User!"

Version ChangeLog

Version 1.0