-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made client compatible with Spring Boot 3
- Loading branch information
1 parent
eba5c31
commit 22a3567
Showing
7 changed files
with
235 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<!-- definition of parent Maven project --> | ||
<parent> | ||
<groupId>cz.muni.chat</groupId> | ||
<artifactId>chat-service-parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<!-- this module definition --> | ||
<artifactId>chat-client-java-lib</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
<name>Chat client library in Java</name> | ||
<description>Client library generated using OpenAPI Generator</description> | ||
|
||
<build> | ||
<finalName>chat-client-java-lib</finalName> | ||
<defaultGoal>install</defaultGoal> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.openapitools</groupId> | ||
<artifactId>openapi-generator-maven-plugin</artifactId> | ||
<version>6.2.1</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>generate</goal> | ||
</goals> | ||
<configuration> | ||
<!-- see https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/README.md --> | ||
<inputSpec>${project.basedir}/../openapi.yml</inputSpec> | ||
<generatorName>java</generatorName> | ||
<apiPackage>cz.muni.chat.client</apiPackage> | ||
<modelPackage>cz.muni.chat.client.model</modelPackage> | ||
<invokerPackage>cz.muni.chat.client.invoker</invokerPackage> | ||
<verbose>false</verbose> | ||
<generateApiTests>false</generateApiTests> | ||
<generateModelTests>false</generateModelTests> | ||
<generateApiDocumentation>true</generateApiDocumentation> | ||
<generateModelDocumentation>true</generateModelDocumentation> | ||
<configOptions> | ||
<annotationLibrary>none</annotationLibrary> | ||
<!-- see https://openapi-generator.tech/docs/generators/java/ --> | ||
<library>native</library> | ||
<hideGenerationTimestamp>true</hideGenerationTimestamp> | ||
</configOptions> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.swagger</groupId> | ||
<artifactId>swagger-annotations</artifactId> | ||
<version>${swagger-annotations-version}</version> | ||
</dependency> | ||
|
||
<!-- JSON processing: jackson --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.openapitools</groupId> | ||
<artifactId>jackson-databind-nullable</artifactId> | ||
<version>${jackson-databind-nullable-version}</version> | ||
</dependency> | ||
|
||
<!-- @Nullable annotation --> | ||
<dependency> | ||
<groupId>com.google.code.findbugs</groupId> | ||
<artifactId>jsr305</artifactId> | ||
<version>3.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.annotation</groupId> | ||
<artifactId>jakarta.annotation-api</artifactId> | ||
<version>${jakarta-annotation-version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
<properties> | ||
<!-- generated by OpenAPI Generator, but replaced with newer --> | ||
<swagger-annotations-version>1.6.9</swagger-annotations-version> | ||
<jackson-databind-nullable-version>0.2.4</jackson-databind-nullable-version> | ||
<jakarta-annotation-version>2.1.1</jakarta-annotation-version> | ||
</properties> | ||
</project> |
72 changes: 72 additions & 0 deletions
72
chat-client-java-lib/src/main/java/cz/muni/chat/client/ChatException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package cz.muni.chat.client; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import cz.muni.chat.client.invoker.ApiException; | ||
import cz.muni.chat.client.model.ErrorMessage; | ||
|
||
import java.io.IOException; | ||
import java.time.OffsetDateTime; | ||
|
||
/** | ||
* Exception created from ErrorMessage sent from ChatService for non-200 HTTP status codes. | ||
*/ | ||
public class ChatException extends Exception { | ||
|
||
public ChatException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
private OffsetDateTime timestamp; | ||
|
||
private Integer httpStatus; | ||
|
||
private String httpStatusName; | ||
|
||
private String path; | ||
|
||
private static ObjectMapper objectMapper = | ||
new ObjectMapper() | ||
.findAndRegisterModules() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
|
||
public static ChatException from(ApiException ex) { | ||
try { | ||
ErrorMessage em = objectMapper.readValue(ex.getResponseBody(), ErrorMessage.class); | ||
ChatException che = new ChatException(em.getMessage(), ex); | ||
che.timestamp = em.getTimestamp(); | ||
che.httpStatus = em.getStatus(); | ||
che.httpStatusName = em.getError(); | ||
che.path = em.getPath(); | ||
return che; | ||
} catch (IOException ioe) { | ||
return new ChatException("cannot parse remote Exception", ex); | ||
} | ||
} | ||
|
||
public OffsetDateTime getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public Integer getHttpStatus() { | ||
return httpStatus; | ||
} | ||
|
||
public String getHttpStatusName() { | ||
return httpStatusName; | ||
} | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ChatException: " + | ||
getMessage() + '\'' + | ||
", httpStatus=" + httpStatus + " (" + httpStatusName + ')' + | ||
", path='" + path + '\'' + | ||
", timestamp=" + timestamp | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.