Skip to content

Commit

Permalink
Common classes for JSON based REST APIs for integration. (helidon-io#…
Browse files Browse the repository at this point in the history
…2879)

* Common classes for JSON based REST APIs for integration.
  • Loading branch information
tomas-langer authored and aseovic committed Apr 26, 2021
1 parent 5591898 commit 387c989
Show file tree
Hide file tree
Showing 25 changed files with 3,905 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,11 @@
<artifactId>helidon-mp-graal-native-image-extension</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.common</groupId>
<artifactId>helidon-integrations-common-rest</artifactId>
<version>${helidon.version}</version>
</dependency>
<!-- OpenAPI support -->
<dependency>
<groupId>io.helidon.openapi</groupId>
Expand Down
38 changes: 38 additions & 0 deletions integrations/common/pom.xml
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>
75 changes: 75 additions & 0 deletions integrations/common/rest/pom.xml
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>
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;
}
}
}
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);
}
}
Loading

0 comments on commit 387c989

Please sign in to comment.