API Platform Micro Service Launchpad

A simple base project that could be extended when building microservices.

License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.adobe.api.platform
ArtifactId

ArtifactId

launchpad
Last Version

Last Version

1.3.7
Release Date

Release Date

Type

Type

jar
Description

Description

API Platform Micro Service Launchpad
A simple base project that could be extended when building microservices.

Download launchpad

How to add to project

<!-- https://jarcasting.com/artifacts/com.adobe.api.platform/launchpad/ -->
<dependency>
    <groupId>com.adobe.api.platform</groupId>
    <artifactId>launchpad</artifactId>
    <version>1.3.7</version>
</dependency>
// https://jarcasting.com/artifacts/com.adobe.api.platform/launchpad/
implementation 'com.adobe.api.platform:launchpad:1.3.7'
// https://jarcasting.com/artifacts/com.adobe.api.platform/launchpad/
implementation ("com.adobe.api.platform:launchpad:1.3.7")
'com.adobe.api.platform:launchpad:jar:1.3.7'
<dependency org="com.adobe.api.platform" name="launchpad" rev="1.3.7">
  <artifact name="launchpad" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.adobe.api.platform', module='launchpad', version='1.3.7')
)
libraryDependencies += "com.adobe.api.platform" % "launchpad" % "1.3.7"
[com.adobe.api.platform/launchpad "1.3.7"]

Dependencies

compile (15)

Group / Artifact Type Version
org.jboss.resteasy : resteasy-undertow jar 3.5.1.Final
org.jboss.resteasy : resteasy-jackson2-provider jar 3.5.1.Final
javax.ws.rs : javax.ws.rs-api jar 2.1.1
org.apache.httpcomponents : httpcore jar 4.4.10
org.apache.httpcomponents : httpcore-nio jar 4.4.10
org.apache.httpcomponents : httpclient jar 4.5.6
org.apache.httpcomponents : httpasyncclient jar 4.1.4
org.jboss.resteasy : resteasy-validator-provider-11 jar 3.5.1.Final
javax.el : el-api jar 2.2
org.glassfish.web : el-impl jar 2.2
io.undertow : undertow-core jar 1.1.0.Final
io.undertow : undertow-servlet jar 1.1.0.Final
org.springframework.boot : spring-boot-starter jar 1.3.5.RELEASE
org.slf4j : slf4j-api jar 1.6.1
commons-lang : commons-lang jar 2.5

Project Modules

There are no modules declared in this project.

micro-service-container

A Java micro-services container based on Undertow, RESTEasy and Spring Boot.

Maven setup

Micro-services implementation only need to inherit the com.adobe.api.platform.msc:micro-service-container-parent Maven POM and implement JAX-RS resource classes.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.adobe.api.platform</groupId>
        <artifactId>micro-service-container-parent</artifactId>
        <version>1.0.3</version>
        <relativePath/>
    </parent>

    <groupId>com.adobe.api.platform.sample</groupId>
    <artifactId>sample-micro-service</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>API Platform Sample micro service</name>

    ...
</project>
Configure version endpoint

To display information about your application version, add buildnumber-maven-plugin plugin to the build:

	<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

Also, add the following properties to your application.properties file:

[email protected]@
[email protected]@
build.timestamp=@timestamp@
build.number=@buildNumber@

where

  • timestamp and buildNumber are buildnumber-maven-plugin properties
  • project.artifactId and project.version are predefined maven properties

Running the service

The Maven build will then generate a single executable JAR file which will contain the micro-service code and the required libraries.

Use java -jar target/sample-micro-service-1.0-SNAPSHOT.jar to run the service.

Exposing REST services

The container recognizes JAX-RS resources and exposes them under the /api context.

import com.adobe.api.platform.msc.support.JaxRsComponent;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

@JaxRsComponent
@Produces(MediaType.APPLICATION_JSON)
@Path("/test")
public class Resource {

    @Autowired
    private MyService myService;

    @GET
    public SampleBean get() {

        return new SampleBean()
    }
}

Run curl http://localhost:8080/api/test to test the sample service.

The key is to annotate the JAX-RS resources with com.adobe.api.platform.msc.support.JaxRsComponent. Also, the container defines a root Spring context which scans the classpath for any Spring components under the com.adobe.api.platform package.

For more Spring fine-tunning you can define another Spring Configuration class.

The JAX-RS component are managed by Spring so you can inject any Spring components using @Autowired.

Configuration

The container reads any configuration properties it find in the application.properties file. Possible locations:

  • A /config subdir of the current directory.
  • The current directory
  • A classpath /config package
  • The classpath root

The list is ordered by precedence (locations higher in the list override lower items).

Integration tests

Writing integration tests is very easy. The MSC container will be started on port 50000 for each integration test and you can use the provided HTTP client to test the REST services.

You just need to extend a MSC container class, com.adobe.api.platform.msc.test.BaseTest.

import com.adobe.api.platform.msc.test.BaseTest;
import org.junit.Test;

import javax.ws.rs.core.Response;
import java.util.Map;

import static org.junit.Assert.assertNotNull;

public class IntegrationTest extends BaseTest {

    @Test
    public void test() {

        SampleBean sampleBean = getRestClient()
                .path("test")
                .get(SampleBean.class);

        assertNotNull(sampleBean);
    }
}
com.adobe.api.platform

Versions

Version
1.3.7
1.3.6
1.3.5
1.3.2
1.3.1
1.3.0
1.2.1
1.1.16
1.1.11