diff --git a/.gitignore b/.gitignore index 3517dbc..c58fcc7 100755 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/application/pom.xml b/application/pom.xml index e931b24..93aa76e 100755 --- a/application/pom.xml +++ b/application/pom.xml @@ -130,6 +130,16 @@ + + developer + + + de.bstly.we + webstly-developer + ${revision} + + + diff --git a/core/src/main/java/de/bstly/we/controller/support/JsonStringBodyControllerAdvice.java b/core/src/main/java/de/bstly/we/controller/support/JsonStringBodyControllerAdvice.java index 1a24a6d..2e7ceae 100644 --- a/core/src/main/java/de/bstly/we/controller/support/JsonStringBodyControllerAdvice.java +++ b/core/src/main/java/de/bstly/we/controller/support/JsonStringBodyControllerAdvice.java @@ -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 { - 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> 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> 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> 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(); } } \ No newline at end of file diff --git a/developer/pom.xml b/developer/pom.xml new file mode 100755 index 0000000..2020597 --- /dev/null +++ b/developer/pom.xml @@ -0,0 +1,31 @@ + + 4.0.0 + + de.bstly.we + webstly-main + ${revision} + + + + 1.6.9 + + + developer + webstly-developer + + + + de.bstly.we + webstly-core + ${revision} + + + + org.springdoc + springdoc-openapi-ui + ${springdoc-openapi-ui.version} + + + diff --git a/developer/src/main/java/de/bstly/we/developer/SpringDocConfig.java b/developer/src/main/java/de/bstly/we/developer/SpringDocConfig.java new file mode 100644 index 0000000..0500c7a --- /dev/null +++ b/developer/src/main/java/de/bstly/we/developer/SpringDocConfig.java @@ -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("").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())); + } +} diff --git a/pom.xml b/pom.xml index c6fbb1e..c6957b9 100755 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ application borrow core + developer dyndns email i18n