This is a simple realization of custom messages pre/post processing in spring-boot HTTP/Stream requests & responses

Overview

spring-boot-custom-message-converting-instances

This is a simple realization of custom messages converting in spring-boot HTTP requests and responses.

last commit

license


Java Spring Boot Swagger

📇 Table of Contents

📖 About

This is a collection of small and focused instances, each of which covers a single and defined approach to Java application development and an required technologies implementation. This project provides an example of the implementation of centralized message converting of HTTP requests/responses. In this case, the API accepts a DTO with attributes in the Cyrillic alphabet. But the API must and can accept a JSON object with attributes in the Latin alphabet. This example implements a custom incoming/outgoing message converting that simply translates the field names from Latin to Cyrillic and vice versa.

🎚 Features

The project with instances of the custom message converting realization.

To Do

  • For more information on an upcoming development, please read the todo list.

Changelog

  • For more information on a releases, a features and a changes, please read the changelog notes.

🚦 Getting Started

These instructions allow to get a copy of this project and run it on a local machine.

Prerequisites

Before using it, make sure that follows software are installed on the local machine:

If any of the listed software is not installed, then it can be installed by instruction as described below.

  1. Oracle JDK 11+

    • Install Oracle JDK 11+ according to instructions from an official instruction.
  2. Maven 3+

    • Install Maven 3+ according to instructions from an official source.

Installing

In order to install it is quite simple to clone or download this repository.

Cloning

For the cloning this repository to a local machine, just use the follows link:

https://github.com/innopolis-university-java-team/spring-boot-custom-message-converting-instances.git

Using

To use it is necessary to:

1 - Build the project 2 - Launch the instances 3 - Send http request

Building

To do the full build, execute maven goal package in the project directory by the following command:

mvn clean package

Launching in command line

To do the run example, execute maven goal spring-boot:run in the project directory by the following command:

mvn spring-boot:run

Launching in IDE

You can simply import this project in either Eclipse, NetBeanse or IntelliJ IDEA and run it in IDE.

Sending http request

To do the sending requests to the service, just open specifications by address and try it:

http://localhost:8080/swagger-ui.html

This service contains one controller - Request Repeater Controller. This controller contains four endpoints, such as:

  1. fizz-buzz/translated - allows to send the JSON object with attributes named in both Cyrillic or latin. In this case, the custom message converter will translate request attributes into Cyrillic names. For the evaluating this trick just send one of follows requests and see an APIs logs:

    1.1.1. Request:

curl -X POST "http://localhost:8080/fizz-buzz/translated" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"buzz\": \"1\", \"fizz\": \"2\"}"
1.1.2.  Response body:
{
  "fizz": "2",
  "buzz": "1"
}
1.1.3.  Logs:
21:17:55.000 INFO JSONTMessageConverter : Convert input message into map - {buzz=1, fizz=2}
21:17:55.005 INFO JSONTMessageConverter : Transliterate input message map from EN to RU - {физз=2, бузз=1}
21:17:55.041 INFO JSONTMessageConverter : Convert transliterated input message map into object - TranslatedFizzBuzz(fizz=2, buzz=1)
21:17:55.049 INFO RequestRepeaterController : Получили запрос с транслированными полями ФиззБузз - TranslatedFizzBuzz(fizz=2, buzz=1)
21:17:55.060 INFO JSONTMessageConverter : Convert output message into map - {физз=2, бузз=1}
21:17:55.062 INFO JSONTMessageConverter : Transliterate output message map from EN to RU - {fizz=2, buzz=1}
21:17:55.066 INFO JSONTMessageConverter : Convert transliterated output message map into object - {"fizz":"2","buzz":"1"}
1.2.1.  Request:
curl -X POST "http://localhost:8080/fizz-buzz/translated" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"бузз\": \"1\", \"физз\": \"2\"}"
1.1.2.  Response body:
{
  "fizz": "2",
  "buzz": "1"
}
1.1.3.  Logs:
21:21:21.176 INFO JSONTMessageConverter : Convert input message into map - {бузз=1, физз=2}
21:21:21.177 INFO JSONTMessageConverter : Transliterate input message map from EN to RU - {физз=2, бузз=1}
21:21:21.178 INFO JSONTMessageConverter : Convert transliterated input message map into object - TranslatedFizzBuzz(fizz=2, buzz=1)
21:21:21.178 INFO RequestRepeaterController : Получили запрос с транслированными полями ФиззБузз - TranslatedFizzBuzz(fizz=2, buzz=1)
21:21:21.179 INFO JSONTMessageConverter : Convert output message into map - {физз=2, бузз=1}
21:21:21.180 INFO JSONTMessageConverter : Transliterate output message map from EN to RU - {fizz=2, buzz=1}
21:21:21.180 INFO JSONTMessageConverter : Convert transliterated output message map into object - {"fizz":"2","buzz":"1"}
  1. fizz-buzz/origin - allows to send the JSON object with attributes named in only Cyrillic. In this case, the custom message converter willn't be used. For the evaluating this trick just send one of follows requests and see an APIs logs:

    2.1.1. Request:

curl -X POST "http://localhost:8080/fizz-buzz/origin" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"buzz\": \"1\", \"fizz\": \"2\"}"
2.1.2.  Response body:
{
  "физз": null,
  "бузз": null
}
2..1.3.  Logs:
21:22:54.925 INFO RequestRepeaterController : Получили запрос с оригинальным FizzBuzz - OriginFizzBuzz(fizz=null, buzz=null)

*BATASH =)

2.2.1.  Request:
curl -X POST "http://localhost:8080/fizz-buzz/origin" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"бузз\": \"1\", \"физз\": \"2\"}"
2.1.2.  Response body:
{
  "физз": "2",
  "бузз": "1"
}
2.1.3.  Logs:
21:23:49.972 INFO RequestRepeaterController : Получили запрос с оригинальным FizzBuzz - OriginFizzBuzz(fizz=2, buzz=1)

As you can see, the use of such an approach (use custom message converting - the 1 case translated) allows centralized processing of requests to the API and responses from the API.

🛠 Built With

  • JDK - the java development kit;
  • Maven - the dependency management;
  • Swagger - documentation and form generator.

©️ Authors

  • Alexander A. Kropotin - initial work - ololx.

🔏 Licensing

This project is unlicensed - see the lisence document for details.

You might also like...

Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

Jan 5, 2023

httpx - CLI to test HTTP/gRPC/RSocket/Kafka... services by HTTP DSL

httpx: CLI for run http file httpx is a CLI to execute requests from JetBrains Http File. Request types supported by httpx HTTP REST PUB/SUB - Apache

Dec 15, 2022

Decorating Spring Boot Reactive WebClient for tracing the request and response data for http calls.

Decorating Spring Boot Reactive WebClient for tracing the request and response data for http calls.

SpringBoot Reactive WebClient 🔍 Tracing HTTP Request through a single pane of glass Decorating Spring Boot Reactive WebClient for tracing the request

Jul 13, 2022

about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。

about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。

Spring Boot 学习示例 Spring Boot 使用的各种示例,以最简单、最实用为标准,此开源项目中的每个示例都以最小依赖,最简单为标准,帮助初学者快速掌握 Spring Boot 各组件的使用。 Spring Boot 中文索引 | Spring Cloud学习示例代码 | Spring

Jan 1, 2023

spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。另外写博客,用 OpenWrite。

spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。另外写博客,用 OpenWrite。

推荐工具: 微信公众号 Markdown 编辑器 - OpenWrite:Markdown 微信编辑器是一款专业强大的微信公众平台在线编辑排版工具,提供手机预览功能,让用户在微信图文 、文章、内容排版、文本编辑、素材编辑上更加方便。 - 更多介绍 博客群发平台 一、支持泥瓦匠 Spring Boot

Jan 5, 2023

Spring-Boot-Plus is a easy-to-use, high-speed, high-efficient,feature-rich, open source spring boot scaffolding

Spring-Boot-Plus is a easy-to-use, high-speed, high-efficient,feature-rich, open source spring boot scaffolding

Everyone can develop projects independently, quickly and efficiently! What is spring-boot-plus? A easy-to-use, high-speed, high-efficient, feature-ric

Dec 31, 2022

Two Spring-boot applications registering themselves to an spring-boot-admin-server application as separate clients for the purpose of monitoring and managing the clients

Two Spring-boot applications registering themselves to an spring-boot-admin-server application as separate clients for the purpose of monitoring and managing the clients

Spring-boot-admin implementation with 1 Server and 2 clients Creating a Server application to monitor and manage Spring boot applications (clients) un

Dec 6, 2022

The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker.

gke-springboot-sampleapp 👋 The Spring Boot Sample App on K8S has been implemented using GKE K8S Cluster, Spring Boot, Maven, and Docker. Usage To be

Feb 1, 2022

Spring Boot Migrator (SBM) - a tool for automated code migrations to upgrade or migrate to Spring Boot

Spring Boot Migrator (SBM) - a tool for automated code migrations to upgrade or migrate to Spring Boot

Spring Boot Migrator uses and is compatible to OpenRewrite, a powerful mass refactoring ecosystem for Java and other source code.

Jan 2, 2023
Owner
Innopolis University Java Team
The main aim is the unificating technology stack and the sharing experience between the Innopolis University Java Developers.
Innopolis University Java Team
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

mrbird 24.8k Jan 6, 2023
A simple blog post api made with spring,mysql.Following tutorial by @FadatareRamesh(Java Guides)

blogAPI A simple blog post api made with spring,mysql.Following tutorial by @FadatareRamesh(Java Guides) Frontend server(made using Angular) can be fo

null 1 Feb 2, 2022
Custom Minecraft death messages

Death Messages Plus by Zyneak Customize the death messages of your Minecraft server. Official release version hosted here https://www.curseforge.com/m

Jordan Schnur 3 Jul 2, 2022
Spring JPA @Query for custom query in Spring Boot example

Spring JPA @Query example (Custom query) in Spring Boot Use Spring JPA @Query for custom query in Spring Boot example: Way to use JPQL (Java Persisten

null 17 Dec 3, 2022
Pre-release of JavaGachi

JavaGachi-PreRelease Pre-release of JavaGachi Despite having Gradle resources, delegate building to IDEA if you are interested in deploying the applic

null 1 Jan 6, 2022
Brain/out is a multiplayer shooter with a nostalgic post-soviet feel

Brain / Out Source code for Brain / Out, the game. How To Build From Source First, clone this repo. Use Gradle Wrapper: ./gradlew <command> on mac/lin

Alex Siryi 69 Jan 7, 2023
A pre-authenticated RCE exploit for Inductive Automation Ignition

Randy What This is a pre-authenticated RCE exploit for Inductive Automation Ignition that impacts versions <= 8.1.16. We failed to exploit the bugs at

Source Incite 36 Sep 23, 2022
Code4Me provides automatic intelligent code completion based on large pre-trained language models

Code4Me Code4Me provides automatic intelligent code completion based on large pre-trained language models. Code4Me predicts statement (line) completio

Code4Me 38 Dec 5, 2022
Google's ML-Kit-Vision demo (android) for pre encoded video.

Android ML Kit Vision demo with Video Google's ML-Kit-Vision demo (android) for pre encoded video. Demos for camera preview and still image are also i

null 17 Dec 29, 2022