Skip to content

L2p Service Migration v0.5 to v0.6

Jasper Nalbach edited this page Nov 2, 2016 · 6 revisions

REST services (BREAKING CHANGE)

API

  • From now on, REST services should inherit from the RESTService class. You should remove getRestMapping and debugMapping from your service class.

  • Also, in the unit tests, the testDebugMapping can be removed. Furthermore, the following lines can be safely removed:

    connector.updateServiceList();
    
    // avoid timing errors: wait for the repository manager to get all services before continuing
    try
    {
      System.out.println("waiting..");
    	Thread.sleep(10000);
    } catch (InterruptedException e)
    {
      e.printStackTrace();
    }
  • The @Version annotation is deprecated and will be removed in future, since it's not used anymore (and was never used).

v0.6.1 changes

The current REST mapper implementation has been replaced. Jersey is used for REST APIs, read more about it here: RESTful services

The simplest way to migrate a service:

  • define a resource as static inner class

    @ServicePath("myService") // change Path to ServicePath
    public class MyService extends RESTService {
      @Override
      protected void initResources() {
        getResourceConfig().register(Resource.class);
      }
    
      @Path("/") // this is the root resource
      public static class Resource {
        // put here all your service methods
      }
    }

    Please note that you cannot access the service class directly anymore. See below for a solution.

  • replace HttpResponse

    @GET
    public Response getMethod() {
      return Response.status(HttpURLConnection.HTTP_OK).entity("Response body").build();
    }
  • remove @ContentParam

    @POST
    @Consumes(MediaType.TEXT_PLAIN)
    public void postMethod(String requestBody) {
      ...
    }
  • How to access the service API from a resource class

    See the next section for details.

Service API

The Context is now a interface defined in i5.las2peer.api and is backwards compatible to the old Context (and will be refactored successively). You can get the context from everywhere in your code using Context.getCurrent() (as before).

The Context has a getService() method that returns the current service.

This step was neccessary to allow full access to the service API from JAX-RS Resources. The Context will be refactored gradually while supporting the existing API until it can be replaced.

Additionally, the following methods have been added to the context for easier access:

  • Context.invoke: same as Service.invokeServiceMethod
  • Context.invokeInternally: same as Service.invokeInternally

The old context object is still available as AgentContext (same package as before), but should be avoided.

Service paths

From now on, services are determined by the first path segment. That means, that services cannot share a common path prefix.

If you have two services running at /my/service1 and /my/service2, this is not possible anymore.

This has been changed in las2peer 0.6.2. From this version on, deep service paths are possible again (with the limitation that service paths must be prefix free). Read RESTful services for details.

Moved Swagger endpoint

The Swagger endpoint runs now at /service/swagger.json instead of /swagger.json and serves documentation for only one service.

Service versions in URIs

A service version can optionally be specified in the URI. Read more about it here.

Service Agents

Starting a service has been made easier, read more about it here.

Storage

las2peer has a new distributed storage as described here.

Clone this wiki locally