Custom Plugin Java Spring Boot Library

Library that allows you to define Mia-Platform custom plugins in java and spring boot easily

License

License

Categories

Categories

Java Languages ORM Data
GroupId

GroupId

eu.mia-platform
ArtifactId

ArtifactId

custom-plugin-java-springboot
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Custom Plugin Java Spring Boot Library
Library that allows you to define Mia-Platform custom plugins in java and spring boot easily
Project URL

Project URL

https://github.com/mia-platform/custom-plugin-java-springboot
Source Code Management

Source Code Management

https://github.com/mia-platform/custom-plugin-java-springboot

Download custom-plugin-java-springboot

How to add to project

<!-- https://jarcasting.com/artifacts/eu.mia-platform/custom-plugin-java-springboot/ -->
<dependency>
    <groupId>eu.mia-platform</groupId>
    <artifactId>custom-plugin-java-springboot</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/eu.mia-platform/custom-plugin-java-springboot/
implementation 'eu.mia-platform:custom-plugin-java-springboot:0.0.2'
// https://jarcasting.com/artifacts/eu.mia-platform/custom-plugin-java-springboot/
implementation ("eu.mia-platform:custom-plugin-java-springboot:0.0.2")
'eu.mia-platform:custom-plugin-java-springboot:jar:0.0.2'
<dependency org="eu.mia-platform" name="custom-plugin-java-springboot" rev="0.0.2">
  <artifact name="custom-plugin-java-springboot" type="jar" />
</dependency>
@Grapes(
@Grab(group='eu.mia-platform', module='custom-plugin-java-springboot', version='0.0.2')
)
libraryDependencies += "eu.mia-platform" % "custom-plugin-java-springboot" % "0.0.2"
[eu.mia-platform/custom-plugin-java-springboot "0.0.2"]

Dependencies

compile (4)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-web jar 2.1.3.RELEASE
io.springfox : springfox-swagger2 jar 2.9.2
io.springfox : springfox-swagger-ui jar 2.9.2
eu.mia-platform : custom-plugin-java jar 0.0.5

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.1.3.RELEASE

Project Modules

There are no modules declared in this project.

custom-plugin-java-springboot

Library that allows you to create Spring Boot services to deploy on Mia-Platform together with custom-plugin-java.

Usage

Route controllers

In order to handle HTTP requests, you have to create a class that extends CPController.

    public class HelloWorldController extends CPController {
        // Endpoints defined here
    }

Status routes

In order to make status routes available you can extend CPStatusController, please note that only one controller has to extend this class, otherwise Springboot will throw a runtime error due to double route registration.

Since CPStatusController extends CPController we suggest to extend this in your main controller and then extend CPController in other controllers.

    public class MyRootController extends CPStatusController {
        // Endpoints defined here
    }

Defining an endpoint

To define an endpoint, you have to add a method to your controller. The method receives a CPRequest as input and can return any class instance. For example:

   @GetMapping("/hello")
   @ResponseBody
   public String helloWorld(@ModelAttribute(CP_REQUEST) CPRequest cpRequest) {
       return "Hello World!";
   }

PRE decorators

To define a PRE decorator, you have to add a controller's method (HTTP POST handler) which receives a PreDecoratorRequest parameter (tagged with @RequestBody for deserialization) and returns a ResponseEntity. The ResponseEntity instance can be obtained through the method DecoratorUtils.getResponseEntityFromDecoratorResponse(DecoratorResponse decoratorResponse). For example:

    @PostMapping("/addToken")
    @ResponseBody
    public ResponseEntity addHeaderToken(@RequestBody PreDecoratorRequest request) {
        Map<String, String> originalHeaders = request.getOriginalRequestHeaders();
        Map<String, String> newHeaders = new HashMap<>(originalHeaders);
        newHeaders.put("x-token", "my-token");
        PreDecoratorRequest updatedRequest = request.changeOriginalRequest()
                .setHeaders(newHeaders)
                .build();

        DecoratorResponse response = DecoratorResponseFactory.makePreDecoratorResponse(updatedRequest);
        return DecoratorUtils.getResponseEntityFromDecoratorResponse(response);
    }

POST decorators

To define a POST decorator, you have to add a controller's method (HTTP POST handler) which receives a PostDecoratorRequest parameter (tagged with @RequestBody for deserialization) and returns a ResponseEntity. The ResponseEntity instance can be obtained through the method DecoratorUtils.getResponseEntityFromDecoratorResponse(DecoratorResponse decoratorResponse). For example:

    @PostMapping("/checkStatusCode")
    @ResponseBody
    public ResponseEntity checkStatusCode(@RequestBody PostDecoratorRequest request) {
        if (request.getOriginalResponseStatusCode == 404) {
            DecoratorResponse decoratorResponse = DecoratorResponseFactory.abortChain(401);
        } else {
            DecoratorResponse decoratorResponse = DecoratorResponseFactory.makePostDecoratorResponse(request.leaveOriginalResponseUnmodified()};
        }
        return DecoratorUtils.getResponseEntityFromDecoratorResponse(decoratorResponse);
    }
eu.mia-platform

Mia-Platform

Mia-Platfrom, the first Digital Integration HUB out-of-the-box

Versions

Version
0.0.2