add developer module

This commit is contained in:
_Bastler 2023-12-11 23:55:47 +01:00
parent 5286d4f171
commit 5f5d505892
6 changed files with 108 additions and 29 deletions

20
.gitignore vendored
View File

@ -8,24 +8,4 @@ hs_err*.log
application.properties
usernames.txt
# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# Visual Studio Code
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*
# System files
.DS_Store
Thumbs.db

View File

@ -130,6 +130,16 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>developer</id>
<dependencies>
<dependency>
<groupId>de.bstly.we</groupId>
<artifactId>webstly-developer</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</profile>
</profiles>
<build>

View File

@ -7,19 +7,19 @@ import java.io.IOException;
import java.lang.reflect.Type;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.util.MimeType;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import com.google.gson.Gson;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
/**
* The Class JsonStringBodyControllerAdvice.
@ -27,8 +27,6 @@ import com.google.gson.JsonPrimitive;
@ControllerAdvice
public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, ResponseBodyAdvice<String> {
private Gson gson = new Gson();
/*
* @see org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice#
* supports(org.springframework.core.MethodParameter, java.lang.reflect.Type,
@ -49,6 +47,11 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
if (inputMessage.getHeaders() == null || inputMessage.getHeaders().getContentType() == null || !inputMessage
.getHeaders().getContentType().equalsTypeAndSubtype(MimeType.valueOf("application/json"))) {
throw new EntityResponseStatusException(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
}
return inputMessage;
}
@ -84,7 +87,7 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon
*/
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return converterType == StringHttpMessageConverter.class;
return returnType.getParameterType() == String.class;
}
/*
@ -99,8 +102,11 @@ public class JsonStringBodyControllerAdvice implements RequestBodyAdvice, Respon
public String beforeBodyWrite(String body, MethodParameter returnType, MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request,
ServerHttpResponse response) {
response.getHeaders().set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
return gson.toJson(new JsonPrimitive(body));
if (body == null) {
return "";
}
JsonElement json = JsonParser.parseString(body);
return json.toString();
}
}

31
developer/pom.xml Executable file
View File

@ -0,0 +1,31 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.bstly.we</groupId>
<artifactId>webstly-main</artifactId>
<version>${revision}</version>
</parent>
<properties>
<springdoc-openapi-ui.version>1.6.9</springdoc-openapi-ui.version>
</properties>
<name>developer</name>
<artifactId>webstly-developer</artifactId>
<dependencies>
<dependency>
<groupId>de.bstly.we</groupId>
<artifactId>webstly-core</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,51 @@
/**
*
*/
package de.bstly.we.developer;
import org.springdoc.core.GroupedOpenApi;
import org.springdoc.core.GroupedOpenApi.Builder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
/**
* The SpringDocConfig Class.
*/
@Configuration
public class SpringDocConfig {
@Autowired
private BuildProperties buildProperties;
/**
* api.
*
* @return GroupedOpenApi
*/
@Bean
public GroupedOpenApi api() {
Builder builder = GroupedOpenApi.builder();
builder.group("<ALL MODULES>").packagesToScan("de.bstly.we");
return builder.build();
}
/**
* apiInfo.
*
* @return OpenAPI
*/
@Bean
public OpenAPI apiInfo() {
return new OpenAPI()
.info(new Info()
.title("we.bstly - Api").contact(new Contact().name("Bastelei e. V.")
.url("https://www.bstly.de").email("api@bstly.de"))
.version(buildProperties.getVersion()));
}
}

View File

@ -28,6 +28,7 @@
<module>application</module>
<module>borrow</module>
<module>core</module>
<module>developer</module>
<module>dyndns</module>
<module>email</module>
<module>i18n</module>