DNA-Evolutions / Java-REST-Client-Examples

Examples for using DNA-Evolutions RESTful products

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java-REST-Client-Examples by DNA-Evolutions

DNA-Evolutions

Containerizing an application helps to use it more conveniently across different platforms and, most importantly, as a microservice. Further, scaling an application becomes more straightforward as various standardized orchestration tools can be utilized. A Microservice can be launched either (locally) or, for example, as a highly-scalable web-micro-service in a Kubernetes cluster.

Short Introduction

This repository is part of our JOpt-REST-Suite. It provides examples of how to set up a REST client in Java to access the following DNA Evolution's web services:

  • JOpt-TourOptimizer based on JOpt-Core (available as local Container and via Azure)
  • JOpt-GeoCoder based on JOpt-Core and Pelias (available via Azure)
  • JOpt-RoutePlanner based on JOpt-Core and Valhalla (available via Azure)

You can find an extensive collection of examples for the core library in our Java-TourOptimizer-Examples repository. Please let us know if you need help to port an example and run it by a REST-Service.

The service can be called via an API-Key using our Microsoft Azure-Kubernetes Infrastructure. If you are interested in hosting our JOpt-REST-GeoCoder and JOpt-REST-GeoRouter products in your environment, please get in touch with us.

All our RESTful Services utilise Spring WebFlux and Swagger. Internally the Java version of TourOptimizer is used. Indeed all specifications for the different services are derived from the core library, leading to guaranteed compatibility between all three services.

DNA-Evolutions Integration

JOpt-GeoCoder

Forward-/Reverse geocode Addresses or Positions.

JOpt-RoutePlanner

Find distances and driving times between points. Either as turn-by-turn result optionally providing driving instructions and route shapes or as matrix request for multiple routings.

JOpt-TourOptimizer

Optimize a problem consisting of Nodes, Resources, and optionally externally provided connections. In contrast to our other services, we allow you to host your JOpt-TourOptimizer locally.


Outline of this repository

The project is subdivided into five major types of examples:

  1. Fullstack examples
  2. GeoCoder creation
  3. Route Planner Examples
  4. TourOptimizer Examples
  5. Secrets creation

Each of the example-sections has its own README.


Architecture of the generated REST-Client-API

The REST-Client class files used by the examples of this repository will be automatically generated from the provided API-docs (OpenAPI 3 Specification) in the resources swagger folder once the project gets built utilizing the openapi-generator-maven-plugin by OpenAPI Tools.

OpenApi Generator allows setting some generation configuration. Indeed, it is vital to adjust the generator to slightly create the correct client files.

As we use the maven-plugin, we define the configuration directly inside the pom.xml. For example, for our TourOptimizer endpoint, we use:

<configuration>
	...
	<generatorName>java</generatorName>
	
	<typeMappings>
		<typeMapping>OffsetDateTime=Instant</typeMapping>
	</typeMappings>
	
	<importMappings>
		<importMapping>java.time.OffsetDateTime=java.time.Instant</importMapping>
	</importMappings>
	
	<library>webclient</library>
	
	...
</configuration>

Please see the pom.xml for the entire configuration description. Besides some mappings, we use the WebClient library to enable Flux and Mono compatible access to our swagger endpoints.

You can also generate a client in the programming language of your choice utilizing our API-docs. REST facilitates software integration in your desired language (including famous ones like C#, Java, JS, Scala, Python, and many more ). Don't hesitate to contact us if you need help setting up your client.


Getting started

You can start using our examples in different ways.

In any case, you need to provide a secrets.json file. Please follow the README.md file inside the Secrets creation package.

Prerequisites

  • In your IDE as native Java dependency: Install at least Java 8, Maven
  • In our sandbox: Working Docker environment

Clone this repository

Clone this repository, import it as Maven project in your IDE, create a secrets.json and start any example.

Use our sandbox in your browser (Docker required)

If you want to get started without the hassle of installing Java, Maven and an IDE, we provide a sandbox. The sandbox is based on code-server and can be used inside your browser, and the interface itself is based on Visual Code. The sandbox is available via DockerHub (here). You have to host the sandbox in your Docker environment (Please provide at least 2-4Gb of Ram and 2 Cores). You can pull the sandbox from our DockerHub account (The Dockerfile for creating the sandbox is included in this repository). The latest version of our examples is cloned by default on launching the Docker container, and you can start testing JOpt-REST right away.

Starting the sandbox and persist your changes

You must mount a volume to which the examples of this project are downloaded on the container's startup. After re-launching the container, the latest version of our examples is only cloned if the folder is not already existing, keeping your files safe from being overridden.

Launching a sandbox and mount your current directory ('$PWD') or any other directory you want:

docker run -it -d --name jopt-rest-examples -p 127.0.0.1:8043:8080 -v "$PWD/:/home/coder/project" dnaevolutions/jopt_rest_example_server:latest

Using the sandbox

After starting the container, you can open http://localhost:8043/ with your browser and login with the password:

joptrest

During the run of your first example file, some dependencies are downloaded, and it will take some time (below 1 minute depending on your internet connection). In case you need help, contact us.


Further Documentation, Contact and Links

If you need any help, please contact us via our company website www.dna-evolutions.com or write an email to info@dna-evolutions.com.


Why using JOpt products from DNA Evolutions?

Originally, JOpt is a flexible routing optimization-engine written in Java, allowing to solve tour-optimization problems that are highly restricted, for example, regarding time windows, skills, and even mandatory constraints can be applied.

Click, to open our video:

Introduction Video for DNA's JOpt


Agreement

For reading our license agreement and for further information about license plans, please visit www.dna-evolutions.com.


Authors

A product by dna-evolutions ©

About

Examples for using DNA-Evolutions RESTful products

License:Other


Languages

Language:Java 99.6%Language:Shell 0.2%Language:Dockerfile 0.2%