-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Common classes for JSON based REST APIs for integration.
- Loading branch information
1 parent
e315326
commit b7b77e3
Showing
24 changed files
with
3,900 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2021 Oracle and/or its affiliates. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<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>io.helidon.integrations</groupId> | ||
<artifactId>helidon-integrations-project</artifactId> | ||
<version>2.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<packaging>pom</packaging> | ||
<groupId>io.helidon.integrations.common</groupId> | ||
<artifactId>helidon-integrations-common-project</artifactId> | ||
<name>Helidon Integrations Common Project</name> | ||
|
||
<description>Common classes for integration modules</description> | ||
|
||
<modules> | ||
<module>rest</module> | ||
</modules> | ||
</project> |
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,75 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2021 Oracle and/or its affiliates. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<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>io.helidon.integrations.common</groupId> | ||
<artifactId>helidon-integrations-common-project</artifactId> | ||
<version>2.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>helidon-integrations-common-rest</artifactId> | ||
<name>Helidon Integrations Common REST</name> | ||
|
||
<description>Common classes for integrating third party systems over REST API with JSON</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.common</groupId> | ||
<artifactId>helidon-common-http</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.webclient</groupId> | ||
<artifactId>helidon-webclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.media</groupId> | ||
<artifactId>helidon-media-jsonp</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.fault-tolerance</groupId> | ||
<artifactId>helidon-fault-tolerance</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.opentracing</groupId> | ||
<artifactId>opentracing-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.webserver</groupId> | ||
<artifactId>helidon-webserver</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
73 changes: 73 additions & 0 deletions
73
...ions/common/rest/src/main/java/io/helidon/integrations/common/rest/ApiEntityResponse.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,73 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.integrations.common.rest; | ||
|
||
/** | ||
* Response from a remote server with an entity. | ||
*/ | ||
public abstract class ApiEntityResponse extends ApiResponse { | ||
/** | ||
* Create a new instance. | ||
* | ||
* @param builder the builder | ||
*/ | ||
protected ApiEntityResponse(Builder<?, ?, ?> builder) { | ||
super(builder); | ||
} | ||
|
||
/** | ||
* Fluent API builder base to build subclasses of {@link io.helidon.integrations.common.rest.ApiEntityResponse}. | ||
* | ||
* @param <B> type of the builder (subclass of this class) | ||
* @param <T> type of the response being built | ||
* @param <X> type of the entity supported ({@link javax.json.JsonObject}, {@link io.helidon.common.reactive.Multi}, or | ||
* {@code byte[]}) | ||
*/ | ||
public abstract static class Builder<B extends Builder<B, T, X>, T extends ApiEntityResponse, X> | ||
extends ApiResponse.Builder<B, T> | ||
implements ResponseBuilder<B, T, X> { | ||
private X entity; | ||
|
||
/** | ||
* Create a new builder instance. | ||
*/ | ||
protected Builder() { | ||
} | ||
|
||
/** | ||
* This method is invoked by {@link io.helidon.integrations.common.rest.RestApi} when an entity | ||
* is received. | ||
* | ||
* @param entity entity | ||
* @return updated builder | ||
*/ | ||
public B entity(X entity) { | ||
this.entity = entity; | ||
return me(); | ||
} | ||
|
||
/** | ||
* Accessor to entity that can be used in subclasses of {@link io.helidon.integrations.common.rest.ApiEntityResponse} | ||
* to set up fields. | ||
* | ||
* @return received entity | ||
*/ | ||
public X entity() { | ||
return entity; | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
integrations/common/rest/src/main/java/io/helidon/integrations/common/rest/ApiException.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,57 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.integrations.common.rest; | ||
|
||
/** | ||
* API exception that is not related to processing of a response. | ||
* | ||
* @see io.helidon.integrations.common.rest.RestException | ||
*/ | ||
public class ApiException extends RuntimeException { | ||
/** | ||
* New exception without a cause and message. | ||
*/ | ||
public ApiException() { | ||
} | ||
|
||
/** | ||
* New exception with a message and without a cause. | ||
* @param message message to use | ||
*/ | ||
public ApiException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* New exception with a cause and message. | ||
* | ||
* @param message message to use | ||
* @param cause throwable that caused this exception | ||
*/ | ||
public ApiException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
/** | ||
* New exception with a cause and without a message. | ||
* | ||
* @param cause throwable that caused this exception | ||
*/ | ||
public ApiException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
Oops, something went wrong.