From 7c967d9fd6f069e569a9ee653d05c25d7c219d25 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Tue, 22 Feb 2022 12:09:06 +0100 Subject: [PATCH 01/24] Add SCIP methods response POJOs --- .../uni/stuttgart/de/config/Application.java | 18 ++++----- .../de/config/ObjectMapperProvider.java | 2 - .../model/responses/InvocationResponse.java | 38 +++++++++++++++++++ .../model/responses/Occurrence.java | 32 ++++++++++++++++ .../model/responses/Parameter.java | 23 +++++++++++ .../model/responses/QueryResultResponse.java | 25 ++++++++++++ .../model/responses/SubscriptionResponse.java | 38 +++++++++++++++++++ .../model/response/CallbackMessage.java | 8 ++-- 8 files changed, 170 insertions(+), 14 deletions(-) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java index 1de500d..fac8672 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java @@ -1,13 +1,5 @@ -package blockchains.iaas.uni.stuttgart.de.config; - - -import org.glassfish.jersey.jackson.JacksonFeature; -import org.glassfish.jersey.server.ResourceConfig; - -import javax.ws.rs.ApplicationPath; - /******************************************************************************** - * Copyright (c) 2018 Institute for the Architecture of Application System - + * Copyright (c) 2018-2022 Institute for the Architecture of Application System - * University of Stuttgart * Author: Ghareeb Falazi * @@ -17,6 +9,14 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.config; + +import org.glassfish.jersey.jackson.JacksonFeature; +import org.glassfish.jersey.server.ResourceConfig; + +import javax.ws.rs.ApplicationPath; + @ApplicationPath("") public class Application extends ResourceConfig { public Application() { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java index f5def96..bf4d3a2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java @@ -19,8 +19,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; - - @Provider public class ObjectMapperProvider implements ContextResolver { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java new file mode 100644 index 0000000..7ecdbbb --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; + +import java.util.List; + +import lombok.Data; + +/** + * Represents the asynchronous result of an INVOKE method. + */ +@Data +public class InvocationResponse { + /** + * A list of the invocation's returned parameters (variables). + */ + List params; + + /** + * A copy of the correlation identifier that was used to issue the INVOKE method. + */ + String correlationIdentifier; + + /** + * The UTC timestamp of the transaction that invoked the function. If the function did not require a transaction, + * this field remains empty. + */ + String timestamp; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java new file mode 100644 index 0000000..1a396d3 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; + +import java.util.List; + +import lombok.Data; + +/** + * A single occurrence of an event or a smart contract function invocation. + */ +@Data +public class Occurrence { + /** + * A list of parameters associated with the reported occurrence. + */ + List params; + + /** + * The UTC timestamp of the transaction associated with the occurrence. + */ + String timestamp; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java new file mode 100644 index 0000000..89f9e5f --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; + +import lombok.Data; + +/** + * Represents a return value of a smart contract function invocation. + */ +@Data +public class Parameter { + private String name; + private String value; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java new file mode 100644 index 0000000..d59ddfe --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; + +import java.util.List; + +import lombok.Data; + +/** + * A synchronous response message for the QUERY method. Represents the set of all event or smart contract function + * invocation occurrences that match with the QUERY. + */ +@Data +public class QueryResultResponse { + List occurrences; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java new file mode 100644 index 0000000..8ecdfdc --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; + +import java.util.List; + +import lombok.Data; + +/** + * One of the asynchronous response messages of a SUBSCRIBE method. Every instance of this class represents a single + * occurrence of the event or smart contract function invocation that is being monitored by the SUBSCRIBE method. + */ +@Data +public class SubscriptionResponse { + /** + * A list of parameters associated with the reported occurrence. + */ + List params; + + /** + * A copy of the correlation identifier that was used to issue the SUBSCRIBE method. + */ + String correlationIdentifier; + + /** + * The UTC timestamp of the transaction associated with the occurrence. + */ + String timestamp; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/response/CallbackMessage.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/response/CallbackMessage.java index 660598d..1935373 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/response/CallbackMessage.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/response/CallbackMessage.java @@ -1,7 +1,5 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.model.response; - /******************************************************************************** - * Copyright (c) 2018-2019 Institute for the Architecture of Application System - + * Copyright (c) 2018-2022 Institute for the Architecture of Application System - * University of Stuttgart * Author: Ghareeb Falazi * @@ -11,6 +9,10 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.restapi.model.response; + + public class CallbackMessage { } From dd1f8c1c8e8b39560f2fd460c4d356e211ee9965 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Tue, 22 Feb 2022 13:19:54 +0100 Subject: [PATCH 02/24] Create initial JsonRpcBinding --- pom.xml | 10 +- .../de/adaptation/AdapterManager.java | 4 +- .../adapters/bitcoin/BitcoinAdapter.java | 10 +- .../adapters/ethereum/EthereumAdapter.java | 18 ++-- .../adapters/ethereum/EthereumTypeMapper.java | 2 +- .../adapters/ethereum/ParameterDecoder.java | 2 +- .../adapters/ethereum/ParameterEncoder.java | 2 +- .../adapters/fabric/FabricAdapter.java | 15 ++- .../adapters/fabric/GatewayManager.java | 4 +- .../interfaces/BlockchainAdapter.java | 7 +- .../utils/JsonSchemaToJavaTypeMapper.java | 4 +- .../externalapi/bindings/AbstractBinding.java | 26 +++++ .../bindings/jsonrpc/JsonRpcBinding.java | 99 +++++++++++++++++++ .../model}/exceptions/BalException.java | 4 +- .../BlockchainIdNotFoundException.java | 9 +- .../BlockchainNodeUnreachableException.java | 9 +- .../model}/exceptions/ExceptionCode.java | 4 +- .../InvalidScipParameterException.java | 4 +- .../InvalidTransactionException.java | 9 +- .../InvokeSmartContractFunctionFailure.java | 4 +- .../InvokeSmartContractFunctionRevoke.java | 2 +- .../exceptions/NotSupportedException.java | 4 +- .../model}/exceptions/ParameterException.java | 4 +- .../SmartContractNotFoundException.java | 4 +- .../model}/exceptions/TimeoutException.java | 4 +- .../TransactionNotFoundException.java | 9 +- .../model}/exceptions/UnknownException.java | 4 +- .../model/responses/Occurrence.java | 32 ------ .../model/responses/QueryResultResponse.java | 25 ----- .../uni/stuttgart/de/jsonrpc/BalService.java | 2 +- .../de/jsonrpc/model/ScipResponse.java | 2 +- .../de/management/BlockchainManager.java | 18 ++-- .../management/callback/CallbackManager.java | 2 +- .../callback/ScipMessageTranslator.java | 2 +- .../de/adaptation/AdapterManagerTest.java | 2 +- .../bindings/jsonrpc/JsonRpcBindingTest.java | 41 ++++++++ 36 files changed, 257 insertions(+), 146 deletions(-) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/BalException.java (86%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/BlockchainIdNotFoundException.java (80%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/BlockchainNodeUnreachableException.java (81%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/ExceptionCode.java (95%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/InvalidScipParameterException.java (87%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/InvalidTransactionException.java (81%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/InvokeSmartContractFunctionFailure.java (84%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/InvokeSmartContractFunctionRevoke.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/NotSupportedException.java (87%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/ParameterException.java (87%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/SmartContractNotFoundException.java (87%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/TimeoutException.java (89%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/TransactionNotFoundException.java (81%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{ => externalapi/model}/exceptions/UnknownException.java (84%) delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java create mode 100644 src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java diff --git a/pom.xml b/pom.xml index a18c02a..452ef73 100644 --- a/pom.xml +++ b/pom.xml @@ -180,7 +180,13 @@ org.junit.jupiter junit-jupiter-api - RELEASE + ${org.junit.jupiter} + test + + + org.junit.jupiter + junit-jupiter-params + ${org.junit.jupiter} test @@ -211,8 +217,10 @@ + + 5.8.2 2.9.1 [2.9.9.2,) 0.10 diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java index 90b1456..7630e5a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java @@ -19,8 +19,8 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.AbstractConnectionProfile; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java index 6e14088..fa6e675 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java @@ -19,11 +19,11 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; import blockchains.iaas.uni.stuttgart.de.adaptation.adapters.AbstractAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.PoWConfidenceCalculator; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Block; import blockchains.iaas.uni.stuttgart.de.model.LinearChainTransaction; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java index f6acc97..c1a22b8 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java @@ -34,15 +34,15 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.utils.BooleanExpressionEvaluator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.PoWConfidenceCalculator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.SmartContractPathParser; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; -import blockchains.iaas.uni.stuttgart.de.exceptions.SmartContractNotFoundException; -import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.SmartContractNotFoundException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.model.Block; import blockchains.iaas.uni.stuttgart.de.model.LinearChainTransaction; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java index aa673ee..532c132 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java @@ -18,7 +18,7 @@ import javax.json.JsonObject; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.MathUtils; -import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; import org.web3j.abi.datatypes.AbiTypes; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java index 19f8435..3b7d420 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java @@ -12,7 +12,7 @@ import java.math.BigInteger; -import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; import org.web3j.abi.datatypes.Bytes; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java index be9800f..c7725a2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java @@ -15,7 +15,7 @@ import javax.xml.bind.DatatypeConverter; -import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java index 7fb340a..b64ed21 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java @@ -24,14 +24,13 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.BooleanExpressionEvaluator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.SmartContractPathParser; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionRevoke; -import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java index b0b42fc..4cbf2d5 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java @@ -20,8 +20,8 @@ import blockchains.iaas.uni.stuttgart.de.connectionprofiles.AbstractConnectionProfile; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.profiles.FabricConnectionProfile; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; import org.hyperledger.fabric.gateway.Contract; import org.hyperledger.fabric.gateway.Gateway; import org.hyperledger.fabric.gateway.Network; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java index beffec6..2cd48b3 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java @@ -13,13 +13,12 @@ package blockchains.iaas.uni.stuttgart.de.adaptation.interfaces; import java.math.BigDecimal; -import java.time.Period; import java.util.List; import java.util.concurrent.CompletableFuture; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java index 9e33653..2b3d9b4 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java @@ -18,8 +18,8 @@ import javax.json.JsonObject; import javax.xml.bind.DatatypeConverter; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Parameter; public class JsonSchemaToJavaTypeMapper { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java new file mode 100644 index 0000000..f0b72ff --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.bindings; + +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; + +public interface AbstractBinding { + String getBindingIdentifier(); + + void sendInvocationResponse(String endpointUrl, InvocationResponse response); + + void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response); + + void sendErrorResponse(String endpointUrl, BalException exception); +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java new file mode 100644 index 0000000..b822bb1 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc; + +import java.io.IOException; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; +import com.github.arteam.simplejsonrpc.client.JsonRpcClient; +import com.github.arteam.simplejsonrpc.client.Transport; +import com.github.arteam.simplejsonrpc.client.builder.NotificationRequestBuilder; +import com.google.common.base.Charsets; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.jetbrains.annotations.NotNull; + +public class JsonRpcBinding implements AbstractBinding { + + @Override + public String getBindingIdentifier() { + return "json-rpc"; + } + + @Override + public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { + NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); + + builder.param("correlationIdentifier", response.getCorrelationIdentifier()) + .param("parameters", response.getParams() == null ? "" : response.getParams()) + .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) + .execute(); + } + + @Override + public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { + NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); + + builder.param("correlationIdentifier", response.getCorrelationIdentifier()) + .param("parameters", response.getParams() == null ? "" : response.getParams()) + .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) + .execute(); + } + + @Override + public void sendErrorResponse(String endpointUrl, BalException exception) { + NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); + + builder = builder.param("errorCode", exception.getCode()); + builder = builder.param("errorMessage", exception.getMessage()); + + if (exception instanceof TimeoutException) { + builder = builder.param("transactionHash", ((TimeoutException) exception).getTransactionHash()); + builder = builder.param("reachedDoC", ((TimeoutException) exception).getDoc()); + } + + builder.execute(); + } + + private NotificationRequestBuilder createNotificationBuilder(final String endpointUrl) { + final String METHOD_NAME = "ReceiveResponse"; + JsonRpcClient client = new JsonRpcClient(new Transport() { + CloseableHttpClient httpClient = HttpClients.createDefault(); + + @NotNull + @Override + public String pass(@NotNull String request) throws IOException { + // Used Apache HttpClient 4.3.1 as an example + HttpPost post = new HttpPost(endpointUrl); + post.setEntity(new StringEntity(request, Charsets.UTF_8)); + post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + try (CloseableHttpResponse httpResponse = httpClient.execute(post)) { + return EntityUtils.toString(httpResponse.getEntity(), Charsets.UTF_8); + } + } + }); + + return client.createNotification() + .method(METHOD_NAME); + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java similarity index 86% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BalException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java index a3b4e77..eabccd7 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BalException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; public abstract class BalException extends RuntimeException { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainIdNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainIdNotFoundException.java similarity index 80% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainIdNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainIdNotFoundException.java index 0a9b626..99c2601 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainIdNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainIdNotFoundException.java @@ -1,6 +1,5 @@ -/******************************************************************************** - * Copyright (c) 2018-2019 Institute for the Architecture of Application System - - * University of Stuttgart +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,8 +7,8 @@ * which is available at https://www.apache.org/licenses/LICENSE-2.0. * * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; + *******************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainNodeUnreachableException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainNodeUnreachableException.java similarity index 81% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainNodeUnreachableException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainNodeUnreachableException.java index b6b1807..1d93bd0 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainNodeUnreachableException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainNodeUnreachableException.java @@ -1,6 +1,5 @@ -/******************************************************************************** - * Copyright (c) 2018-2019 Institute for the Architecture of Application System - - * University of Stuttgart +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,8 +7,8 @@ * which is available at https://www.apache.org/licenses/LICENSE-2.0. * * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; + *******************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ExceptionCode.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ExceptionCode.java similarity index 95% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ExceptionCode.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ExceptionCode.java index 7bd99e0..7a05c9e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ExceptionCode.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ExceptionCode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; public class ExceptionCode { public static final int UnknownError = 0; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidScipParameterException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidScipParameterException.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidScipParameterException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidScipParameterException.java index 51714ba..cbf2867 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidScipParameterException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidScipParameterException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidTransactionException.java similarity index 81% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidTransactionException.java index fb0ffb1..145db82 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidTransactionException.java @@ -1,6 +1,5 @@ -/******************************************************************************** - * Copyright (c) 2018-2019 Institute for the Architecture of Application System - - * University of Stuttgart +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,8 +7,8 @@ * which is available at https://www.apache.org/licenses/LICENSE-2.0. * * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; + *******************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionFailure.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java similarity index 84% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionFailure.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java index d9edca5..bfafb1e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionFailure.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019-2022 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionRevoke.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionRevoke.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionRevoke.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionRevoke.java index 6d5d522..1b0241a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionRevoke.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionRevoke.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/NotSupportedException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/NotSupportedException.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/NotSupportedException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/NotSupportedException.java index a1fcde6..3fd70e8 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/NotSupportedException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/NotSupportedException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ParameterException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ParameterException.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ParameterException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ParameterException.java index c12a544..b19ec45 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ParameterException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ParameterException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/SmartContractNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/SmartContractNotFoundException.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/SmartContractNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/SmartContractNotFoundException.java index 895a6ea..d9a2883 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/SmartContractNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/SmartContractNotFoundException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TimeoutException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java similarity index 89% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TimeoutException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java index 12182c5..7935ff2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TimeoutException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; import lombok.Getter; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TransactionNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TransactionNotFoundException.java similarity index 81% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TransactionNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TransactionNotFoundException.java index 48319bd..ff787dd 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TransactionNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TransactionNotFoundException.java @@ -1,6 +1,5 @@ -/******************************************************************************** - * Copyright (c) 2018-2019 Institute for the Architecture of Application System - - * University of Stuttgart +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,8 +7,8 @@ * which is available at https://www.apache.org/licenses/LICENSE-2.0. * * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; + *******************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/UnknownException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/UnknownException.java similarity index 84% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/UnknownException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/UnknownException.java index 50bff97..d2376d5 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/UnknownException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/UnknownException.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.exceptions; +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java deleted file mode 100644 index 1a396d3..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Occurrence.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - *******************************************************************************/ - -package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; - -import java.util.List; - -import lombok.Data; - -/** - * A single occurrence of an event or a smart contract function invocation. - */ -@Data -public class Occurrence { - /** - * A list of parameters associated with the reported occurrence. - */ - List params; - - /** - * The UTC timestamp of the transaction associated with the occurrence. - */ - String timestamp; -} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java deleted file mode 100644 index d59ddfe..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/QueryResultResponse.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - *******************************************************************************/ - -package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; - -import java.util.List; - -import lombok.Data; - -/** - * A synchronous response message for the QUERY method. Represents the set of all event or smart contract function - * invocation occurrences that match with the QUERY. - */ -@Data -public class QueryResultResponse { - List occurrences; -} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/BalService.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/BalService.java index 889cd6b..98a6155 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/BalService.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/BalService.java @@ -13,7 +13,7 @@ import java.util.List; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java index 303c7d9..4a56f6a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java @@ -13,7 +13,7 @@ import java.util.List; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CallbackMessage; import lombok.Builder; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainManager.java index bfd0834..9d93bb6 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainManager.java @@ -21,15 +21,15 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.AdapterManager; import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.MathUtils; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.exceptions.TransactionNotFoundException; -import blockchains.iaas.uni.stuttgart.de.exceptions.UnknownException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TransactionNotFoundException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.UnknownException; import blockchains.iaas.uni.stuttgart.de.management.callback.CallbackManager; import blockchains.iaas.uni.stuttgart.de.management.callback.CamundaMessageTranslator; import blockchains.iaas.uni.stuttgart.de.management.callback.ScipMessageTranslator; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java index 5fc4145..d43582b 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java @@ -24,7 +24,7 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; import blockchains.iaas.uni.stuttgart.de.config.ObjectMapperProvider; -import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.jsonrpc.model.ScipResponse; import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CallbackMessage; import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CamundaMessage; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java index 32c655a..eb0fa48 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java @@ -13,7 +13,7 @@ import java.util.List; -import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; import blockchains.iaas.uni.stuttgart.de.jsonrpc.model.Occurrence; import blockchains.iaas.uni.stuttgart.de.jsonrpc.model.ScipResponse; import blockchains.iaas.uni.stuttgart.de.model.Parameter; diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java index 6f7e5fc..4d00fb4 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java @@ -13,7 +13,7 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; -import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainIdNotFoundException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java new file mode 100644 index 0000000..abe4bff --- /dev/null +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class JsonRpcBindingTest { + + @Test + void getBindingIdentifier() { + JsonRpcBinding binding = new JsonRpcBinding(); + Assertions.assertEquals("json-rpc", binding.getBindingIdentifier()); + } + + @ParameterizedTest + @ + void sendInvocationResponse() { + JsonRpcBinding binding = new JsonRpcBinding(); + + } + + @Test + void sendSubscriptionResponse() { + } + + @Test + void sendErrorResponse() { + } +} \ No newline at end of file From 97163b71c5c0a449d2b9ab01db96ebca9ff4d644 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Tue, 22 Feb 2022 14:37:42 +0100 Subject: [PATCH 03/24] Add unit test for invocationresponse json-rpc binding --- pom.xml | 11 ++- .../bindings/jsonrpc/JsonRpcBinding.java | 4 +- .../model/responses/InvocationResponse.java | 6 +- .../model/responses/Parameter.java | 7 +- .../model/responses/SubscriptionResponse.java | 5 +- .../bindings/jsonrpc/JsonRpcBindingTest.java | 93 ++++++++++++++++++- 6 files changed, 114 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 452ef73..38865c9 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ org.projectlombok lombok - 1.18.8 + 1.18.22 provided @@ -190,6 +190,15 @@ test + + com.squareup.okhttp3 + mockwebserver + 3.8.1 + test + + + + com.github.arteam simple-json-rpc-server diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java index b822bb1..d5b5aa8 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java @@ -12,6 +12,7 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc; import java.io.IOException; +import java.util.Collections; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; @@ -45,7 +46,7 @@ public void sendInvocationResponse(String endpointUrl, InvocationResponse respon NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); builder.param("correlationIdentifier", response.getCorrelationIdentifier()) - .param("parameters", response.getParams() == null ? "" : response.getParams()) + .param("parameters", response.getParams() == null ? Collections.emptyList() : response.getParams()) .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) .execute(); } @@ -53,7 +54,6 @@ public void sendInvocationResponse(String endpointUrl, InvocationResponse respon @Override public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); - builder.param("correlationIdentifier", response.getCorrelationIdentifier()) .param("parameters", response.getParams() == null ? "" : response.getParams()) .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java index 7ecdbbb..0547a39 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java @@ -13,12 +13,16 @@ import java.util.List; +import lombok.Builder; import lombok.Data; +import lombok.NonNull; + /** * Represents the asynchronous result of an INVOKE method. */ @Data +@Builder public class InvocationResponse { /** * A list of the invocation's returned parameters (variables). @@ -28,7 +32,7 @@ public class InvocationResponse { /** * A copy of the correlation identifier that was used to issue the INVOKE method. */ - String correlationIdentifier; + @NonNull String correlationIdentifier; /** * The UTC timestamp of the transaction that invoked the function. If the function did not require a transaction, diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java index 89f9e5f..8cc951a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java @@ -11,13 +11,16 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; +import lombok.Builder; import lombok.Data; +import lombok.NonNull; /** * Represents a return value of a smart contract function invocation. */ @Data +@Builder public class Parameter { - private String name; - private String value; + @NonNull private String name; + @NonNull private String value; } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java index 8ecdfdc..cd4256e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java @@ -13,13 +13,16 @@ import java.util.List; +import lombok.Builder; import lombok.Data; +import lombok.NonNull; /** * One of the asynchronous response messages of a SUBSCRIBE method. Every instance of this class represents a single * occurrence of the event or smart contract function invocation that is being monitored by the SUBSCRIBE method. */ @Data +@Builder public class SubscriptionResponse { /** * A list of parameters associated with the reported occurrence. @@ -29,7 +32,7 @@ public class SubscriptionResponse { /** * A copy of the correlation identifier that was used to issue the SUBSCRIBE method. */ - String correlationIdentifier; + @NonNull String correlationIdentifier; /** * The UTC timestamp of the transaction associated with the occurrence. diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java index abe4bff..d09e4e0 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java @@ -11,12 +11,40 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc; +import java.io.IOException; +import java.util.Collections; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; class JsonRpcBindingTest { + private MockWebServer mockWebServer; + private static final Logger log = LoggerFactory.getLogger(JsonRpcBindingTest.class); + + @BeforeEach + void init() { + this.mockWebServer = new MockWebServer(); + this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); + } + + @AfterEach + void destroy() throws IOException { + this.mockWebServer.close(); + } @Test void getBindingIdentifier() { @@ -25,10 +53,14 @@ void getBindingIdentifier() { } @ParameterizedTest - @ - void sendInvocationResponse() { + @MethodSource + void sendInvocationResponse(InvocationResponse response) throws InterruptedException { + String endpointUrl = this.mockWebServer.url("/").toString(); JsonRpcBinding binding = new JsonRpcBinding(); - + binding.sendInvocationResponse(endpointUrl, response); + RecordedRequest recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + // todo test contents of request message } @Test @@ -38,4 +70,55 @@ void sendSubscriptionResponse() { @Test void sendErrorResponse() { } + + private static Stream sendInvocationResponse() { + Parameter param1 = Parameter + .builder() + .name("param1") + .value("Great Test!") + .build(); + Parameter param2 = Parameter + .builder() + .name("param2") + .value("Super Test!") + .build(); + // here everything is provided + InvocationResponse response1 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // a missing corrId throws an exception + // here the timestamp is missing + InvocationResponse response3 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // here the parameters are missing + InvocationResponse response4 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .build(); + // here the parameters are provided as an empty collection + InvocationResponse response5 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Collections.emptyList()) + .build(); + + return Stream.of( + Arguments.of(response1), + Arguments.of(response3), + Arguments.of(response4), + Arguments.of(response5) + ); + } } \ No newline at end of file From 2b794300600f95a9936a09adf959c0e98c081c3a Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Tue, 22 Feb 2022 22:00:06 +0100 Subject: [PATCH 04/24] add unit tests for jsonrpc binding --- .../bindings/camunda/CamundaBinding.java | 39 ++++++++++ .../bindings/camunda/model/Variable.java | 18 +++++ .../bindings/jsonrpc/JsonRpcBinding.java | 2 +- .../bindings/jsonrpc/JsonRpcBindingTest.java | 78 ++++++++++++++++++- 4 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java new file mode 100644 index 0000000..8412573 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda; + +import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; + +public class CamundaBinding implements AbstractBinding { + @Override + public String getBindingIdentifier() { + return "camunda"; + } + + @Override + public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { + + } + + @Override + public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { + + } + + @Override + public void sendErrorResponse(String endpointUrl, BalException exception) { + + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java new file mode 100644 index 0000000..8d67917 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model; + + +public class Variable { + private String value; + private String type; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java index d5b5aa8..562612a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java @@ -55,7 +55,7 @@ public void sendInvocationResponse(String endpointUrl, InvocationResponse respon public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); builder.param("correlationIdentifier", response.getCorrelationIdentifier()) - .param("parameters", response.getParams() == null ? "" : response.getParams()) + .param("parameters", response.getParams() == null ? Collections.emptyList() : response.getParams()) .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) .execute(); } diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java index d09e4e0..c10141e 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java @@ -16,8 +16,11 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; @@ -63,12 +66,30 @@ void sendInvocationResponse(InvocationResponse response) throws InterruptedExcep // todo test contents of request message } - @Test - void sendSubscriptionResponse() { + @ParameterizedTest + @MethodSource + void sendSubscriptionResponse(SubscriptionResponse response) throws InterruptedException { + String endpointUrl = this.mockWebServer.url("/").toString(); + JsonRpcBinding binding = new JsonRpcBinding(); + binding.sendSubscriptionResponse(endpointUrl, response); + RecordedRequest recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + // todo test contents of request message } @Test - void sendErrorResponse() { + void sendErrorResponses() throws InterruptedException { + InvalidScipParameterException e1 = new InvalidScipParameterException("The first Exception occurred"); + TimeoutException e2 = new TimeoutException("The second exception occurred", "CRAZYHASH123", 0.3); + String endpointUrl = this.mockWebServer.url("/").toString(); + JsonRpcBinding binding = new JsonRpcBinding(); + binding.sendErrorResponse(endpointUrl, e1); + binding.sendErrorResponse(endpointUrl, e2); + RecordedRequest recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + // todo test contents of request message } private static Stream sendInvocationResponse() { @@ -121,4 +142,55 @@ private static Stream sendInvocationResponse() { Arguments.of(response5) ); } + + private static Stream sendSubscriptionResponse() { + Parameter param1 = Parameter + .builder() + .name("param1") + .value("Great Test!") + .build(); + Parameter param2 = Parameter + .builder() + .name("param2") + .value("Super Test!") + .build(); + // here everything is provided + SubscriptionResponse response1 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // a missing corrId throws an exception + // here the timestamp is missing + SubscriptionResponse response3 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // here the parameters are missing + SubscriptionResponse response4 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .build(); + // here the parameters are provided as an empty collection + SubscriptionResponse response5 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Collections.emptyList()) + .build(); + + return Stream.of( + Arguments.of(response1), + Arguments.of(response3), + Arguments.of(response4), + Arguments.of(response5) + ); + } } \ No newline at end of file From 0511832b60226e5b02638139706685d32b46dfda Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Tue, 22 Feb 2022 22:16:44 +0100 Subject: [PATCH 05/24] Add initial implementation for CamundaBinding --- .../bindings/camunda/CamundaBinding.java | 40 +++++++++++++++++++ .../bindings/camunda/model/Message.java | 29 ++++++++++++++ .../bindings/camunda/model/Variable.java | 9 ++++- .../bindings/camunda/CamundaBindingTest.java | 35 ++++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java create mode 100644 src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java index 8412573..12ba3f2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java @@ -11,12 +11,28 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model.Message; +import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model.Variable; import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; +import org.glassfish.jersey.jackson.JacksonFeature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class CamundaBinding implements AbstractBinding { + private static final Logger log = LoggerFactory.getLogger(CamundaBinding.class); + @Override public String getBindingIdentifier() { return "camunda"; @@ -24,7 +40,31 @@ public String getBindingIdentifier() { @Override public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { + final Map variables = new HashMap<>(); + response.getParams().forEach(parameter -> { + Variable current = Variable + .builder() + .value(parameter.getValue()) + .type("String") + .build(); + variables.put(parameter.getName(), current); + }); + + final Message message = Message + .builder() + .messageName("result_INOKE_" + response.getCorrelationIdentifier()) + .processInstanceId(response.getCorrelationIdentifier()) + .processVariables(variables) + .build(); + + final Client client = ClientBuilder.newBuilder() + .register(JacksonFeature.class) + .build(); + final Entity entity = Entity.entity(message, MediaType.APPLICATION_JSON); + final Response postResponse = client.target(endpointUrl).request(MediaType.APPLICATION_JSON) + .post(entity); + log.info("Callback client responded with code({})", postResponse.getStatus()); } @Override diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java new file mode 100644 index 0000000..c3caf43 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model; + +import java.util.Map; + +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; + +@Data +@Builder +public class Message { + @NonNull + private String processInstanceId; + @NonNull + private String messageName; + @NonNull + private Map processVariables; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java index 8d67917..c79a227 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java @@ -11,8 +11,13 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; +@Data +@Builder public class Variable { - private String value; - private String type; + @NonNull private String value; + @NonNull private String type; } diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java new file mode 100644 index 0000000..12ee37f --- /dev/null +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class CamundaBindingTest { + + @Test + void getBindingIdentifier() { + } + + @Test + void sendInvocationResponse() { + } + + @Test + void sendSubscriptionResponse() { + } + + @Test + void sendErrorResponse() { + } +} \ No newline at end of file From 8b0e446d105a450ac5b1cee41265696e7b3792c6 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Tue, 22 Feb 2022 22:27:42 +0100 Subject: [PATCH 06/24] Add initial test for camunda binding --- .../bindings/camunda/CamundaBinding.java | 18 ++-- .../bindings/camunda/CamundaBindingTest.java | 94 ++++++++++++++++++- 2 files changed, 102 insertions(+), 10 deletions(-) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java index 12ba3f2..2569445 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java @@ -41,14 +41,16 @@ public String getBindingIdentifier() { @Override public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { final Map variables = new HashMap<>(); - response.getParams().forEach(parameter -> { - Variable current = Variable - .builder() - .value(parameter.getValue()) - .type("String") - .build(); - variables.put(parameter.getName(), current); - }); + if (response.getParams() != null) { + response.getParams().forEach(parameter -> { + Variable current = Variable + .builder() + .value(parameter.getValue()) + .type("String") + .build(); + variables.put(parameter.getName(), current); + }); + } final Message message = Message .builder() diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java index 12ee37f..d338106 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java @@ -11,18 +11,57 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda; +import java.io.IOException; +import java.util.Collections; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc.JsonRpcBinding; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import static org.junit.jupiter.api.Assertions.*; class CamundaBindingTest { + private MockWebServer mockWebServer; + private static final Logger log = LoggerFactory.getLogger(CamundaBindingTest.class); + + @BeforeEach + void init() { + this.mockWebServer = new MockWebServer(); + this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); + } + + @AfterEach + void destroy() throws IOException { + this.mockWebServer.close(); + } @Test void getBindingIdentifier() { } - @Test - void sendInvocationResponse() { + @ParameterizedTest + @MethodSource + void sendInvocationResponse(InvocationResponse response) throws InterruptedException { + String endpointUrl = this.mockWebServer.url("/").toString(); + CamundaBinding binding = new CamundaBinding(); + binding.sendInvocationResponse(endpointUrl, response); + RecordedRequest recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + // todo test contents of request message } @Test @@ -32,4 +71,55 @@ void sendSubscriptionResponse() { @Test void sendErrorResponse() { } + + private static Stream sendInvocationResponse() { + Parameter param1 = Parameter + .builder() + .name("param1") + .value("Great Test!") + .build(); + Parameter param2 = Parameter + .builder() + .name("param2") + .value("Super Test!") + .build(); + // here everything is provided + InvocationResponse response1 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // a missing corrId throws an exception + // here the timestamp is missing + InvocationResponse response3 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // here the parameters are missing + InvocationResponse response4 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .build(); + // here the parameters are provided as an empty collection + InvocationResponse response5 = InvocationResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Collections.emptyList()) + .build(); + + return Stream.of( + Arguments.of(response1), + Arguments.of(response3), + Arguments.of(response4), + Arguments.of(response5) + ); + } } \ No newline at end of file From 7172e1d940c9d53bf820b2191f5911c2aee543fc Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Wed, 23 Feb 2022 10:04:00 +0100 Subject: [PATCH 07/24] Fix Jackson/Jersey compatibility --- pom.xml | 17 +++++++++++------ .../bindings/camunda/model/Message.java | 5 +++++ .../bindings/camunda/model/Variable.java | 10 ++++++++-- .../bindings/camunda/CamundaBindingTest.java | 4 ---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 38865c9..f8464bd 100644 --- a/pom.xml +++ b/pom.xml @@ -66,24 +66,29 @@ ${jersey.version} + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + + com.fasterxml.jackson.core - jackson-core + jackson-databind ${jackson.version} - com.fasterxml.jackson.core jackson-annotations ${jackson.version} - com.fasterxml.jackson.core - jackson-databind + jackson-core ${jackson.version} + org.web3j core @@ -230,8 +235,8 @@ 5.8.2 - 2.9.1 - [2.9.9.2,) + 2.35 + 2.12.1 0.10 1.7.25 1.2.3 diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java index c3caf43..e44bc6f 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java @@ -13,12 +13,17 @@ import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Builder; import lombok.Data; import lombok.NonNull; +import lombok.extern.jackson.Jacksonized; @Data @Builder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) public class Message { @NonNull private String processInstanceId; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java index c79a227..08a8b6c 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java @@ -11,13 +11,19 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Builder; import lombok.Data; import lombok.NonNull; +import lombok.extern.jackson.Jacksonized; @Data @Builder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) public class Variable { - @NonNull private String value; - @NonNull private String type; + @NonNull + private String value; + @NonNull + private String type; } diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java index d338106..589e584 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc.JsonRpcBinding; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; import okhttp3.mockwebserver.MockResponse; @@ -25,15 +24,12 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.jupiter.api.Assertions.*; - class CamundaBindingTest { private MockWebServer mockWebServer; private static final Logger log = LoggerFactory.getLogger(CamundaBindingTest.class); From 7a0279cfbf7b0be88861eecd5625b11b608cf6fb Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Wed, 23 Feb 2022 12:05:06 +0100 Subject: [PATCH 08/24] Fix web3j dependencies - Add Camunda tests for subscribe method - Fix EthereumAdapter test --- pom.xml | 20 +++--- .../bindings/camunda/CamundaBinding.java | 57 +++++++++++------ .../ethereum/EthereumAdapterTest.java | 4 +- .../bindings/camunda/CamundaBindingTest.java | 63 ++++++++++++++++++- 4 files changed, 110 insertions(+), 34 deletions(-) diff --git a/pom.xml b/pom.xml index f8464bd..3604b58 100644 --- a/pom.xml +++ b/pom.xml @@ -77,22 +77,17 @@ jackson-databind ${jackson.version} - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - org.web3j core - 4.5.6 + ${org.web3j.version} + + + + org.bouncycastle + bcprov-jdk15on + 1.63 @@ -234,6 +229,7 @@ + 4.9.0 5.8.2 2.35 2.12.1 diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java index 2569445..a242679 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java @@ -12,6 +12,7 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.ws.rs.client.Client; @@ -25,6 +26,7 @@ import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model.Variable; import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; import org.glassfish.jersey.jackson.JacksonFeature; import org.slf4j.Logger; @@ -40,9 +42,41 @@ public String getBindingIdentifier() { @Override public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { + final Map variables = parseParameters(response.getParams()); + + final Message message = Message + .builder() + .messageName("result_INOKE_" + response.getCorrelationIdentifier()) + .processInstanceId(response.getCorrelationIdentifier()) + .processVariables(variables) + .build(); + + sendCamundaMessage(message, endpointUrl); + } + + @Override + public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { + final Map variables = parseParameters(response.getParams()); + + final Message message = Message + .builder() + .messageName("result_SUBSCRIBE_" + response.getCorrelationIdentifier()) + .processInstanceId(response.getCorrelationIdentifier()) + .processVariables(variables) + .build(); + + sendCamundaMessage(message, endpointUrl); + } + + @Override + public void sendErrorResponse(String endpointUrl, BalException exception) { + + } + + private Map parseParameters(List parameterList) { final Map variables = new HashMap<>(); - if (response.getParams() != null) { - response.getParams().forEach(parameter -> { + if (parameterList != null) { + parameterList.forEach(parameter -> { Variable current = Variable .builder() .value(parameter.getValue()) @@ -52,13 +86,10 @@ public void sendInvocationResponse(String endpointUrl, InvocationResponse respon }); } - final Message message = Message - .builder() - .messageName("result_INOKE_" + response.getCorrelationIdentifier()) - .processInstanceId(response.getCorrelationIdentifier()) - .processVariables(variables) - .build(); + return variables; + } + private void sendCamundaMessage(Message message, String endpointUrl) { final Client client = ClientBuilder.newBuilder() .register(JacksonFeature.class) .build(); @@ -68,14 +99,4 @@ public void sendInvocationResponse(String endpointUrl, InvocationResponse respon log.info("Callback client responded with code({})", postResponse.getStatus()); } - - @Override - public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { - - } - - @Override - public void sendErrorResponse(String endpointUrl, BalException exception) { - - } } diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapterTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapterTest.java index 1429966..1d0c4fb 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapterTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapterTest.java @@ -101,12 +101,12 @@ void testInvokeSmartContract() throws Exception { String argument = new BigInteger(bytes).toString(16); List inputs = Collections.singletonList(new Parameter("publicKey", BYTES_TYPE, argument)); List outputs = Collections.emptyList(); - LinearChainTransaction init = (LinearChainTransaction) this.adapter.invokeSmartContract(smartContractPath, functionIdentifier, inputs, outputs, REQUIRED_CONFIDENCE, 0).get(); + LinearChainTransaction init = (LinearChainTransaction) this.adapter.invokeSmartContract(smartContractPath, functionIdentifier, inputs, outputs, REQUIRED_CONFIDENCE, 50000).get(); log.info("initial transaction {}", init.getTransactionHash()); functionIdentifier = "getPublicKey"; inputs = Collections.singletonList(new Parameter("ethereumAddress", ADDRESS_TYPE, "0x90645Dc507225d61cB81cF83e7470F5a6AA1215A")); outputs = Collections.singletonList(new Parameter("return", BYTES_TYPE, null)); - Transaction result = this.adapter.invokeSmartContract(smartContractPath, functionIdentifier, inputs, outputs, REQUIRED_CONFIDENCE, 0).get(); + Transaction result = this.adapter.invokeSmartContract(smartContractPath, functionIdentifier, inputs, outputs, REQUIRED_CONFIDENCE, 50000).get(); String value = result.getReturnValues().get(0).getValue(); log.debug(value); String retrievedMessage = new String(new BigInteger(value, 16).toByteArray(), StandardCharsets.UTF_8); diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java index 589e584..7b38a9e 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java @@ -18,6 +18,7 @@ import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; @@ -60,8 +61,15 @@ void sendInvocationResponse(InvocationResponse response) throws InterruptedExcep // todo test contents of request message } - @Test - void sendSubscriptionResponse() { + @ParameterizedTest + @MethodSource + void sendSubscriptionResponse(SubscriptionResponse response) throws InterruptedException { + String endpointUrl = this.mockWebServer.url("/").toString(); + CamundaBinding binding = new CamundaBinding(); + binding.sendSubscriptionResponse(endpointUrl, response); + RecordedRequest recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + // todo test contents of request message } @Test @@ -118,4 +126,55 @@ private static Stream sendInvocationResponse() { Arguments.of(response5) ); } + + private static Stream sendSubscriptionResponse() { + Parameter param1 = Parameter + .builder() + .name("param1") + .value("Great Test!") + .build(); + Parameter param2 = Parameter + .builder() + .name("param2") + .value("Super Test!") + .build(); + // here everything is provided + SubscriptionResponse response1 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // a missing corrId throws an exception + // here the timestamp is missing + SubscriptionResponse response3 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .params(Stream + .of(param1, param2) + .collect(Collectors.toList())) + .build(); + // here the parameters are missing + SubscriptionResponse response4 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .build(); + // here the parameters are provided as an empty collection + SubscriptionResponse response5 = SubscriptionResponse + .builder() + .correlationIdentifier("1234") + .timestamp("654321") + .params(Collections.emptyList()) + .build(); + + return Stream.of( + Arguments.of(response1), + Arguments.of(response3), + Arguments.of(response4), + Arguments.of(response5) + ); + } } \ No newline at end of file From f229f15b2cdfbf847f318adc152f1dc5cc5d3f2f Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Wed, 23 Feb 2022 20:10:58 +0100 Subject: [PATCH 09/24] Finalize Camunda Binding - Fix dependencies - Initial support for asynchronous errors - Fix tests --- pom.xml | 4 ++- .../de/adaptation/AdapterManager.java | 2 +- .../externalapi/bindings/AbstractBinding.java | 3 +- .../bindings/camunda/CamundaBinding.java | 30 +++++++++++++++-- .../bindings/jsonrpc/JsonRpcBinding.java | 4 ++- .../exceptions/AsynchronousBalException.java | 32 +++++++++++++++++++ .../model/exceptions/BalException.java | 8 ----- .../InvokeSmartContractFunctionFailure.java | 2 +- .../model/exceptions/TimeoutException.java | 2 +- .../bindings/camunda/CamundaBindingTest.java | 24 +++++++++++++- .../bindings/jsonrpc/JsonRpcBindingTest.java | 10 ++++-- 11 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/AsynchronousBalException.java diff --git a/pom.xml b/pom.xml index 3604b58..64d804d 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,8 @@ ${org.web3j.version} + org.bouncycastle bcprov-jdk15on @@ -193,7 +195,7 @@ com.squareup.okhttp3 mockwebserver - 3.8.1 + 4.9.0 test diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java index 7630e5a..f5339ce 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java @@ -45,7 +45,7 @@ public static AdapterManager getInstance() { public BlockchainAdapter getAdapter(String blockchainId) throws BlockchainIdNotFoundException, BlockchainNodeUnreachableException { AbstractConnectionProfile connectionProfile = ConnectionProfilesManager.getInstance().getConnectionProfiles().get(blockchainId); - // no connection profile! + // no connection profiles! if (connectionProfile == null) { final String msg = String.format("blockchain-id <%s> does not exist!", blockchainId); log.error(msg); diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java index f0b72ff..14a6cd7 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java @@ -11,6 +11,7 @@ package blockchains.iaas.uni.stuttgart.de.externalapi.bindings; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.AsynchronousBalException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; @@ -22,5 +23,5 @@ public interface AbstractBinding { void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response); - void sendErrorResponse(String endpointUrl, BalException exception); + void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException exception); } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java index a242679..e707af2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java @@ -24,7 +24,8 @@ import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.AbstractBinding; import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model.Message; import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model.Variable; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; @@ -69,8 +70,33 @@ public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse re } @Override - public void sendErrorResponse(String endpointUrl, BalException exception) { + public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException exception) { + final Map variables = new HashMap<>(); + + if (exception instanceof TimeoutException) { + final Variable txHash = Variable + .builder() + .value(((TimeoutException) exception).getTransactionHash()) + .type("String") + .build(); + + final Variable doc = Variable + .builder() + .value(String.valueOf(((TimeoutException) exception).getDoc())) + .type("String") + .build(); + + variables.put("reachedDoC", doc); + variables.put("transactionHash", txHash); + } + Message message = Message + .builder() + .messageName("error_SUBSCRIBE_" + exception.getCorrelationIdentifier()) + .processInstanceId(exception.getCorrelationIdentifier()) + .processVariables(variables).build(); + + sendCamundaMessage(message, endpointUrl); } private Map parseParameters(List parameterList) { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java index 562612a..2a45a7c 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java @@ -17,6 +17,7 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.AsynchronousBalException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.AbstractBinding; @@ -61,11 +62,12 @@ public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse re } @Override - public void sendErrorResponse(String endpointUrl, BalException exception) { + public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException exception) { NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); builder = builder.param("errorCode", exception.getCode()); builder = builder.param("errorMessage", exception.getMessage()); + builder = builder.param("correlationIdentifier", exception.getCorrelationIdentifier()); if (exception instanceof TimeoutException) { builder = builder.param("transactionHash", ((TimeoutException) exception).getTransactionHash()); diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/AsynchronousBalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/AsynchronousBalException.java new file mode 100644 index 0000000..4377c51 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/AsynchronousBalException.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; + +public abstract class AsynchronousBalException extends BalException { + private String correlationIdentifier; + + public AsynchronousBalException() { + } + + public AsynchronousBalException(String message) { + super(message); + } + + + public String getCorrelationIdentifier() { + return correlationIdentifier; + } + + public void setCorrelationIdentifier(String correlationIdentifier) { + this.correlationIdentifier = correlationIdentifier; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java index eabccd7..0a45ecb 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java @@ -19,13 +19,5 @@ public BalException(String message) { super(message); } - public BalException(String message, Throwable cause) { - super(message, cause); - } - - public BalException(Throwable cause) { - super(cause); - } - public abstract int getCode(); } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java index bfafb1e..aa0b505 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java @@ -13,7 +13,7 @@ import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; @JsonRpcError(code = ExceptionCode.InvocationError, message = "The smart contract function invocation failed.") -public class InvokeSmartContractFunctionFailure extends BalException { +public class InvokeSmartContractFunctionFailure extends AsynchronousBalException { public InvokeSmartContractFunctionFailure() { } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java index 7935ff2..42c0ccd 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java @@ -18,7 +18,7 @@ @JsonRpcError(code = ExceptionCode.Timeout, message = "Timeout was reached before the desired DoC was fulfilled.") @Setter @Getter -public class TimeoutException extends BalException { +public class TimeoutException extends AsynchronousBalException { private String transactionHash; private double doc; diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java index 7b38a9e..d990be1 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java @@ -16,6 +16,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; @@ -23,6 +25,7 @@ import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -39,6 +42,9 @@ class CamundaBindingTest { void init() { this.mockWebServer = new MockWebServer(); this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); + this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); + this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); + this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); } @AfterEach @@ -48,6 +54,8 @@ void destroy() throws IOException { @Test void getBindingIdentifier() { + CamundaBinding biniding = new CamundaBinding(); + Assertions.assertEquals("camunda", biniding.getBindingIdentifier()); } @ParameterizedTest @@ -73,7 +81,21 @@ void sendSubscriptionResponse(SubscriptionResponse response) throws InterruptedE } @Test - void sendErrorResponse() { + void sendErrorResponse() throws InterruptedException { + InvokeSmartContractFunctionFailure e1 = new InvokeSmartContractFunctionFailure("The first Exception occurred"); + e1.setCorrelationIdentifier("654321ABC"); + TimeoutException e2 = new TimeoutException("The second exception occurred", "CRAZYHASH123", 0.3); + e2.setCorrelationIdentifier("XXX654321ABC"); + String endpointUrl = this.mockWebServer.url("/").toString(); + CamundaBinding binding = new CamundaBinding(); + binding.sendAsyncErrorResponse(endpointUrl, e1); + binding.sendAsyncErrorResponse(endpointUrl, e2); + RecordedRequest recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + recordedRequest = this.mockWebServer.takeRequest(); + log.debug(recordedRequest.getBody().readUtf8()); + + // todo test contents of request message } private static Stream sendInvocationResponse() { diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java index c10141e..7439764 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java @@ -17,6 +17,7 @@ import java.util.stream.Stream; import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; @@ -42,6 +43,7 @@ class JsonRpcBindingTest { void init() { this.mockWebServer = new MockWebServer(); this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); + this.mockWebServer.enqueue(new MockResponse().setResponseCode(200)); } @AfterEach @@ -79,12 +81,14 @@ void sendSubscriptionResponse(SubscriptionResponse response) throws InterruptedE @Test void sendErrorResponses() throws InterruptedException { - InvalidScipParameterException e1 = new InvalidScipParameterException("The first Exception occurred"); + InvokeSmartContractFunctionFailure e1 = new InvokeSmartContractFunctionFailure("The first Exception occurred"); + e1.setCorrelationIdentifier("654321ABC"); TimeoutException e2 = new TimeoutException("The second exception occurred", "CRAZYHASH123", 0.3); + e2.setCorrelationIdentifier("XXX654321ABC"); String endpointUrl = this.mockWebServer.url("/").toString(); JsonRpcBinding binding = new JsonRpcBinding(); - binding.sendErrorResponse(endpointUrl, e1); - binding.sendErrorResponse(endpointUrl, e2); + binding.sendAsyncErrorResponse(endpointUrl, e1); + binding.sendAsyncErrorResponse(endpointUrl, e2); RecordedRequest recordedRequest = this.mockWebServer.takeRequest(); log.debug(recordedRequest.getBody().readUtf8()); recordedRequest = this.mockWebServer.takeRequest(); From d149761c850743b95df98dd1c58bab45a3f74455 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Wed, 23 Feb 2022 23:20:28 +0100 Subject: [PATCH 10/24] Use new mechanism - Switch BlockchainManager to using the new mechanism - Introduce GenericAsynchronousBalException - Add test cases - Reorganize packages --- .../{management => }/BlockchainManager.java | 144 +++++++++++------- .../de/adaptation/AdapterManager.java | 4 +- .../adapters/bitcoin/BitcoinAdapter.java | 10 +- .../adapters/ethereum/EthereumAdapter.java | 18 +-- .../adapters/ethereum/EthereumTypeMapper.java | 2 +- .../adapters/ethereum/ParameterDecoder.java | 2 +- .../adapters/ethereum/ParameterEncoder.java | 2 +- .../adapters/fabric/FabricAdapter.java | 14 +- .../adapters/fabric/GatewayManager.java | 4 +- .../interfaces/BlockchainAdapter.java | 6 +- .../utils/JsonSchemaToJavaTypeMapper.java | 4 +- .../de/jsonrpc/model/ScipResponse.java | 32 ---- .../management/callback/CallbackManager.java | 134 ---------------- .../callback/ScipMessageTranslator.java | 50 ------ .../callback/CamundaMessageTranslator.java | 10 +- .../restapi/callback/RestCallbackManager.java | 70 +++++++++ .../ConnectionProfilesController.java | 4 +- .../EnsureTransactionStateController.java | 6 +- ...InvokeSmartContractFunctionController.java | 6 +- .../OrphanedTransactionController.java | 6 +- .../ReceiveTransactionController.java | 6 +- .../ReceiveTransactionsController.java | 6 +- .../RootController.java | 29 ++-- .../SubmitTransactionController.java | 6 +- .../SubscriptionController.java | 10 +- .../BalService.java => scip/ScipService.java} | 12 +- .../bindings/AbstractBinding.java | 9 +- .../de/scip/bindings/BindingsManager.java | 66 ++++++++ .../de/scip/bindings/EndpointBindings.java | 89 +++++++++++ .../bindings/camunda/CamundaBinding.java | 18 +-- .../bindings/camunda/model/Message.java | 3 +- .../bindings/camunda/model/Variable.java | 2 +- .../bindings/jsonrpc/JsonRpcBinding.java | 13 +- .../de/scip/callback/ScipCallbackManager.java | 58 +++++++ .../exceptions/AsynchronousBalException.java | 5 +- .../model/exceptions/BalException.java | 6 +- .../BlockchainIdNotFoundException.java | 2 +- .../BlockchainNodeUnreachableException.java | 2 +- .../model/exceptions/ExceptionCode.java | 2 +- .../GenericAsynchronousBalException.java | 25 +++ .../InvalidScipParameterException.java | 2 +- .../InvalidTransactionException.java | 2 +- .../InvokeSmartContractFunctionFailure.java | 2 +- .../InvokeSmartContractFunctionRevoke.java | 2 +- .../exceptions/NotSupportedException.java | 2 +- .../model/exceptions/ParameterException.java | 2 +- .../SmartContractNotFoundException.java | 2 +- .../model/exceptions/TimeoutException.java | 2 +- .../TransactionNotFoundException.java | 4 +- .../model/exceptions/UnknownException.java | 2 +- .../model/responses/InvocationResponse.java | 2 +- .../model/responses}/Occurrence.java | 6 +- .../model/responses/Parameter.java | 2 +- .../model/responses/SubscriptionResponse.java | 2 +- .../SubscriptionManager.java | 10 +- .../model/CompletableFutureSubscription.java | 2 +- .../model/MonitorOccurrencesSubscription.java | 2 +- .../model/ObservableSubscription.java | 2 +- .../model/Subscription.java | 2 +- .../model/SubscriptionKey.java | 2 +- .../model/SubscriptionType.java | 2 +- .../de/adaptation/AdapterManagerTest.java | 2 +- .../de/scip/bindings/BindingsManagerTest.java | 40 +++++ .../scip/bindings/EndpointBindingsTest.java | 59 +++++++ .../bindings/camunda/CamundaBindingTest.java | 12 +- .../bindings/jsonrpc/JsonRpcBindingTest.java | 13 +- .../SubscriptionManagerTest.java | 6 +- 67 files changed, 655 insertions(+), 430 deletions(-) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => }/BlockchainManager.java (81%) delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => restapi}/callback/CamundaMessageTranslator.java (94%) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/ConnectionProfilesController.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/EnsureTransactionStateController.java (88%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/InvokeSmartContractFunctionController.java (91%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/OrphanedTransactionController.java (88%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/ReceiveTransactionController.java (89%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/ReceiveTransactionsController.java (87%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/RootController.java (88%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/SubmitTransactionController.java (87%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/{Controllers => controllers}/SubscriptionController.java (91%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{jsonrpc/BalService.java => scip/ScipService.java} (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/bindings/AbstractBinding.java (66%) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManager.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/bindings/camunda/CamundaBinding.java (85%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/bindings/camunda/model/Message.java (88%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/bindings/camunda/model/Variable.java (91%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/bindings/jsonrpc/JsonRpcBinding.java (87%) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/callback/ScipCallbackManager.java rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/AsynchronousBalException.java (85%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/BalException.java (81%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/BlockchainIdNotFoundException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/BlockchainNodeUnreachableException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/ExceptionCode.java (97%) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/InvalidScipParameterException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/InvalidTransactionException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/InvokeSmartContractFunctionFailure.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/InvokeSmartContractFunctionRevoke.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/NotSupportedException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/ParameterException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/SmartContractNotFoundException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/TimeoutException.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/TransactionNotFoundException.java (87%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/exceptions/UnknownException.java (92%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/responses/InvocationResponse.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{jsonrpc/model => scip/model/responses}/Occurrence.java (80%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/responses/Parameter.java (91%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/model/responses/SubscriptionResponse.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/SubscriptionManager.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/model/CompletableFutureSubscription.java (95%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/model/MonitorOccurrencesSubscription.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/model/ObservableSubscription.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/model/Subscription.java (92%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/model/SubscriptionKey.java (96%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/model/SubscriptionType.java (92%) create mode 100644 src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManagerTest.java create mode 100644 src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java rename src/test/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/bindings/camunda/CamundaBindingTest.java (93%) rename src/test/java/blockchains/iaas/uni/stuttgart/de/{externalapi => scip}/bindings/jsonrpc/JsonRpcBindingTest.java (92%) rename src/test/java/blockchains/iaas/uni/stuttgart/de/{management => subscription}/SubscriptionManagerTest.java (86%) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java similarity index 81% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainManager.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java index 9d93bb6..8b2b7d0 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/BlockchainManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java @@ -1,6 +1,5 @@ -/******************************************************************************** - * Copyright (c) 2019-2022 Institute for the Architecture of Application System - - * University of Stuttgart +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,8 +7,8 @@ * which is available at https://www.apache.org/licenses/LICENSE-2.0. * * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management; + *******************************************************************************/ +package blockchains.iaas.uni.stuttgart.de; import java.math.BigDecimal; import java.math.BigInteger; @@ -17,33 +16,38 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; +import java.util.stream.Collectors; import blockchains.iaas.uni.stuttgart.de.adaptation.AdapterManager; import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.MathUtils; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainIdNotFoundException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TransactionNotFoundException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.UnknownException; -import blockchains.iaas.uni.stuttgart.de.management.callback.CallbackManager; -import blockchains.iaas.uni.stuttgart.de.management.callback.CamundaMessageTranslator; -import blockchains.iaas.uni.stuttgart.de.management.callback.ScipMessageTranslator; -import blockchains.iaas.uni.stuttgart.de.management.model.CompletableFutureSubscription; -import blockchains.iaas.uni.stuttgart.de.management.model.MonitorOccurrencesSubscription; -import blockchains.iaas.uni.stuttgart.de.management.model.ObservableSubscription; -import blockchains.iaas.uni.stuttgart.de.management.model.Subscription; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionKey; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; import blockchains.iaas.uni.stuttgart.de.model.TimeFrame; import blockchains.iaas.uni.stuttgart.de.model.Transaction; import blockchains.iaas.uni.stuttgart.de.model.TransactionState; +import blockchains.iaas.uni.stuttgart.de.restapi.callback.CamundaMessageTranslator; +import blockchains.iaas.uni.stuttgart.de.restapi.callback.RestCallbackManager; +import blockchains.iaas.uni.stuttgart.de.scip.callback.ScipCallbackManager; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.GenericAsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TransactionNotFoundException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.UnknownException; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; +import blockchains.iaas.uni.stuttgart.de.subscription.SubscriptionManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.CompletableFutureSubscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.MonitorOccurrencesSubscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.ObservableSubscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.Subscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionKey; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import com.google.common.base.Strings; import io.reactivex.disposables.Disposable; import org.slf4j.Logger; @@ -79,10 +83,10 @@ public void submitNewTransaction(final String correlationId, final String to, fi thenAccept(tx -> { if (tx != null) { if (tx.getState() == TransactionState.CONFIRMED) { - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, tx, false)); } else {// it is NOT_FOUND - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, tx, true)); } } else @@ -91,10 +95,10 @@ public void submitNewTransaction(final String correlationId, final String to, fi exceptionally((e) -> { log.info("Failed to submit a transaction. Reason: {}", e.getMessage()); if (e.getCause() instanceof BlockchainNodeUnreachableException) - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, true, ((BlockchainNodeUnreachableException) e).getCode())); else if (e.getCause() instanceof InvalidTransactionException) - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.INVALID, true, ((InvalidTransactionException) e).getCode())); // ManualUnsubscriptionException is also captured here @@ -110,11 +114,11 @@ else if (e.getCause() instanceof InvalidTransactionException) SubscriptionManager.getInstance().createSubscription(correlationId, blockchainId, subscription); } catch (InvalidTransactionException e) { // This (should only) happen when something is wrong with the transaction data - CallbackManager.getInstance().sendCallbackAsync(epUrl, + RestCallbackManager.getInstance().sendCallbackAsync(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.INVALID, true, e.getCode())); } catch (BlockchainIdNotFoundException | NotSupportedException e) { // This (should only) happen when the blockchainId is not found - CallbackManager.getInstance().sendCallbackAsync(epUrl, + RestCallbackManager.getInstance().sendCallbackAsync(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, true, e.getCode())); } } @@ -147,7 +151,7 @@ public void receiveTransactions(final String correlationId, final String from, f .doOnError(throwable -> log.error("Failed to receive transaction. Reason:{}", throwable.getMessage())) .subscribe(transaction -> { if (transaction != null) { - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, transaction, false)); } else { log.error("received transaction is null!"); @@ -196,7 +200,7 @@ public void receiveTransaction(final String correlationId, final String from, fi log.error("Failed to receive transaction. Reason: " + throwable.getMessage()); if (throwable instanceof BlockchainNodeUnreachableException || throwable.getCause() instanceof BlockchainNodeUnreachableException) { - CallbackManager.getInstance().sendCallbackAsync(epUrl, + RestCallbackManager.getInstance().sendCallbackAsync(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, true, (new BlockchainNodeUnreachableException()).getCode())); } else { log.error("Unhandled exception. Exception details: " + throwable.getMessage()); @@ -205,7 +209,7 @@ public void receiveTransaction(final String correlationId, final String from, fi .take(1) .subscribe(transaction -> { if (transaction != null) { - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, transaction, false)); log.info("usubscribing from receiveTransactions"); } else { @@ -219,7 +223,7 @@ public void receiveTransaction(final String correlationId, final String from, fi } catch (BlockchainIdNotFoundException | NotSupportedException e) { // This (should only) happen when the blockchainId is not found Or // if trying to receive a monetary transaction via, e.g., Fabric - CallbackManager.getInstance().sendCallbackAsync(epUrl, + RestCallbackManager.getInstance().sendCallbackAsync(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, true, e.getCode())); } } @@ -248,7 +252,7 @@ public void detectOrphanedTransaction(final String correlationId, final String t future. thenAccept(txState -> { if (txState != null) { - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, txState, false, 0)); } else // we should never reach here! log.error("resulting transactionState is null"); @@ -257,7 +261,7 @@ public void detectOrphanedTransaction(final String correlationId, final String t log.info("Failed to monitor a transaction. Reason: {}", e.getMessage()); // This happens when a communication error, or an error with the tx exist. if (e.getCause() instanceof BlockchainNodeUnreachableException) - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, false, 0)); // ManualUnsubscriptionException is also captured here @@ -273,7 +277,7 @@ public void detectOrphanedTransaction(final String correlationId, final String t } catch (BlockchainIdNotFoundException | NotSupportedException e) { // This (should only) happen when the blockchainId is not found Or // if trying to receive a monetary transaction via, e.g., Fabric - CallbackManager.getInstance().sendCallbackAsync(epUrl, + RestCallbackManager.getInstance().sendCallbackAsync(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, false, 0)); } } @@ -305,10 +309,10 @@ public void ensureTransactionState(final String correlationId, final String tran thenAccept(txState -> { if (txState != null) { if (txState == TransactionState.CONFIRMED) - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, txState, false, 0)); else - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, txState, true, 0)); } else // we should never reach here! log.error("resulting transactionState is null"); @@ -317,7 +321,7 @@ public void ensureTransactionState(final String correlationId, final String tran log.info("Failed to monitor a transaction. Reason: {}", e.getMessage()); // This happens when a communication error, or an error with the tx exist. if (e.getCause() instanceof BlockchainNodeUnreachableException) - CallbackManager.getInstance().sendCallback(epUrl, + RestCallbackManager.getInstance().sendCallback(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, true, ((BlockchainNodeUnreachableException) e.getCause()).getCode())); // ManualUnsubscriptionException is also captured here @@ -333,7 +337,7 @@ public void ensureTransactionState(final String correlationId, final String tran } catch (BlockchainIdNotFoundException | NotSupportedException e) { // This (should only) happen when the blockchainId is not found Or // if trying to monitor a monetary transaction via, e.g., Fabric - CallbackManager.getInstance().sendCallbackAsync(epUrl, + RestCallbackManager.getInstance().sendCallbackAsync(epUrl, CamundaMessageTranslator.convert(correlationId, TransactionState.UNKNOWN, true, e.getCode())); } } @@ -394,21 +398,31 @@ public void invokeSmartContractFunction( thenAccept(tx -> { if (tx != null) { if (tx.getState() == TransactionState.CONFIRMED || tx.getState() == TransactionState.RETURN_VALUE) { - CallbackManager.getInstance().sendCallback(callbackUrl, - ScipMessageTranslator.getInvocationResponseMessage( - correlationId, - tx.getReturnValues())); + InvocationResponse response = InvocationResponse + .builder() + .correlationIdentifier(correlationId) + .params(tx + .getReturnValues() + .stream() + .map(p -> blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter + .builder() + .name(p.getName()) + .value(p.getValue()) + .build() + ).collect(Collectors.toList())) + .build(); + ScipCallbackManager.getInstance().sendInvocationResponse(callbackUrl, response); } else {// it is NOT_FOUND (it was dropped from the system due to invalidation) or ERRORED if (tx.getState() == TransactionState.NOT_FOUND) { - CallbackManager.getInstance().sendCallback(callbackUrl, - ScipMessageTranslator.getAsynchronousErrorResponseMessage( - correlationId, - new TransactionNotFoundException("The transaction associated with a function invocation is invalidated after it was mined."))); + TransactionNotFoundException txNotFoundException = + new TransactionNotFoundException("The transaction associated with a function invocation is invalidated after it was mined."); + txNotFoundException.setCorrelationIdentifier(correlationId); + ScipCallbackManager.getInstance().sendAsyncErrorResponse(callbackUrl, txNotFoundException); } else { - CallbackManager.getInstance().sendCallback(callbackUrl, - ScipMessageTranslator.getAsynchronousErrorResponseMessage( - correlationId, - new InvokeSmartContractFunctionFailure("The smart contract function invocation reported an error."))); + InvokeSmartContractFunctionFailure invocationException = + new InvokeSmartContractFunctionFailure("The smart contract function invocation reported an error."); + invocationException.setCorrelationIdentifier(correlationId); + ScipCallbackManager.getInstance().sendAsyncErrorResponse(callbackUrl, invocationException); } } } else { @@ -418,9 +432,12 @@ public void invokeSmartContractFunction( exceptionally((e) -> { log.info("Failed to invoke smart contract function. Reason: {}", e.getMessage()); // happens if the node is unreachable, or something goes wrong while trying to invoke the sc function. - if (e.getCause() instanceof BalException) - CallbackManager.getInstance().sendCallback(callbackUrl, - ScipMessageTranslator.getAsynchronousErrorResponseMessage(correlationId, (BalException) e.getCause())); + // todo figure out how to handle this case + if (e.getCause() instanceof BalException) { + GenericAsynchronousBalException exception = + new GenericAsynchronousBalException((BalException) e.getCause(), correlationId); + ScipCallbackManager.getInstance().sendAsyncErrorResponse(callbackUrl, exception); + } // ManualUnsubscriptionException is also captured here return null; @@ -467,8 +484,21 @@ public void subscribeToEvent( .doOnError(throwable -> log.error("Failed to detect an occurrence. Reason:{}", throwable.getMessage())) .subscribe(occurrence -> { if (occurrence != null) { - CallbackManager.getInstance().sendCallback(callbackUrl, - ScipMessageTranslator.getSubscriptionResponseMessage(correlationIdentifier, occurrence.getParameters(), occurrence.getIsoTimestamp())); + SubscriptionResponse response = SubscriptionResponse + .builder() + .correlationIdentifier(correlationIdentifier) + .timestamp(occurrence.getIsoTimestamp()) + .params(occurrence + .getParameters() + .stream() + .map(p -> blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter + .builder() + .name(p.getName()) + .value(p.getValue()) + .build() + ).collect(Collectors.toList())) + .build(); + ScipCallbackManager.getInstance().sendSubscriptionResponse(callbackUrl, response); } else { log.error("detected occurrence is null!"); } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java index f5339ce..ad5c5ea 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java @@ -19,8 +19,8 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.AbstractConnectionProfile; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainIdNotFoundException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java index fa6e675..dd79b7e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java @@ -19,11 +19,11 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; import blockchains.iaas.uni.stuttgart.de.adaptation.adapters.AbstractAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.PoWConfidenceCalculator; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Block; import blockchains.iaas.uni.stuttgart.de.model.LinearChainTransaction; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java index c1a22b8..14bae14 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java @@ -34,15 +34,15 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.utils.BooleanExpressionEvaluator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.PoWConfidenceCalculator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.SmartContractPathParser; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.SmartContractNotFoundException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.SmartContractNotFoundException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.model.Block; import blockchains.iaas.uni.stuttgart.de.model.LinearChainTransaction; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java index 532c132..f40eb66 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java @@ -18,7 +18,7 @@ import javax.json.JsonObject; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.MathUtils; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; import org.web3j.abi.datatypes.AbiTypes; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java index 3b7d420..d78ccb0 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java @@ -12,7 +12,7 @@ import java.math.BigInteger; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; import org.web3j.abi.datatypes.Bytes; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java index c7725a2..fe972ed 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java @@ -15,7 +15,7 @@ import javax.xml.bind.DatatypeConverter; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java index b64ed21..e2d17e8 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java @@ -24,13 +24,13 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.BooleanExpressionEvaluator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.SmartContractPathParser; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java index 4cbf2d5..b210935 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java @@ -20,8 +20,8 @@ import blockchains.iaas.uni.stuttgart.de.connectionprofiles.AbstractConnectionProfile; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.profiles.FabricConnectionProfile; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; import org.hyperledger.fabric.gateway.Contract; import org.hyperledger.fabric.gateway.Gateway; import org.hyperledger.fabric.gateway.Network; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java index 2cd48b3..b9ea5dd 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java @@ -16,9 +16,9 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java index 2b3d9b4..608f2b2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java @@ -18,8 +18,8 @@ import javax.json.JsonObject; import javax.xml.bind.DatatypeConverter; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Parameter; public class JsonSchemaToJavaTypeMapper { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java deleted file mode 100644 index 4a56f6a..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/ScipResponse.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - *******************************************************************************/ - -package blockchains.iaas.uni.stuttgart.de.jsonrpc.model; - -import java.util.List; - -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.model.Parameter; -import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CallbackMessage; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -@Builder -@Setter -@Getter -public class ScipResponse extends CallbackMessage { - private String correlationIdentifier; - private List parameters; - private String isoTimestamp; - private List occurrences; - private BalException exception; -} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java deleted file mode 100644 index d43582b..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CallbackManager.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - *******************************************************************************/ - -package blockchains.iaas.uni.stuttgart.de.management.callback; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; -import blockchains.iaas.uni.stuttgart.de.config.ObjectMapperProvider; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; -import blockchains.iaas.uni.stuttgart.de.jsonrpc.model.ScipResponse; -import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CallbackMessage; -import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CamundaMessage; -import com.github.arteam.simplejsonrpc.client.JsonRpcClient; -import com.github.arteam.simplejsonrpc.client.Transport; -import com.github.arteam.simplejsonrpc.client.builder.NotificationRequestBuilder; -import com.google.common.base.Charsets; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.glassfish.jersey.jackson.JacksonFeature; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CallbackManager { - private static CallbackManager instance = null; - private static final Logger log = LoggerFactory.getLogger(BlockchainAdapterFactory.class); - private ExecutorService executorService = Executors.newFixedThreadPool(2); - - private CallbackManager() { - - } - - public static CallbackManager getInstance() { - if (instance == null) - instance = new CallbackManager(); - - return instance; - } - - public void sendCallback(final String endpointUrl, final CallbackMessage responseBody) { - if (responseBody instanceof CamundaMessage) { - this.sendRestCallback(endpointUrl, responseBody); - } else if (responseBody instanceof ScipResponse) { - this.sendJsonRpcCallback(endpointUrl, (ScipResponse) responseBody); - } else { - log.error("The sepcified response message has an unknown callback protocol."); - } - } - - private void sendRestCallback(final String endpointUrl, final CallbackMessage responseBody) { - final Client client = ClientBuilder.newBuilder() - .register(ObjectMapperProvider.class) // No need to register this provider if no special configuration is required. - .register(JacksonFeature.class) - .build(); - final Entity entity = Entity.entity(responseBody, MediaType.APPLICATION_JSON); - final Response response = client.target(endpointUrl).request(MediaType.APPLICATION_JSON) - .post(entity); - - log.info("Callback client responded with code({})", response.getStatus()); - } - - private void sendJsonRpcCallback(final String endpointUrl, final ScipResponse response) { - final String METHOD_NAME = "ReceiveResponse"; - JsonRpcClient client = new JsonRpcClient(new Transport() { - CloseableHttpClient httpClient = HttpClients.createDefault(); - - @NotNull - @Override - public String pass(@NotNull String request) throws IOException { - // Used Apache HttpClient 4.3.1 as an example - HttpPost post = new HttpPost(endpointUrl); - post.setEntity(new StringEntity(request, Charsets.UTF_8)); - post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); - try (CloseableHttpResponse httpResponse = httpClient.execute(post)) { - return EntityUtils.toString(httpResponse.getEntity(), Charsets.UTF_8); - } - } - }); - - NotificationRequestBuilder builder = client.createNotification() - .method(METHOD_NAME) - .param("correlationIdentifier", response.getCorrelationIdentifier()); - - if (response.getException() == null) { - if (response.getParameters() != null) { - builder = builder.param("parameters", response.getParameters()); - } - - if (response.getIsoTimestamp() != null) { - builder = builder.param("timestamp", response.getIsoTimestamp()); - } - - if (response.getOccurrences() != null) { - builder = builder.param("occurrences", response.getOccurrences()); - } - } else { - builder = builder.param("errorCode", response.getException().getCode()); - builder = builder.param("errorMessage", response.getException().getMessage()); - - if (response.getException() instanceof TimeoutException) { - builder = builder.param("transactionHash", ((TimeoutException) response.getException()).getTransactionHash()); - builder = builder.param("reachedDoC", ((TimeoutException) response.getException()).getDoc()); - } - } - - builder.execute(); - } - - public void sendCallbackAsync(final String endpointUrl, final CallbackMessage responseBody) { - this.executorService.execute(() -> sendCallback(endpointUrl, responseBody)); - } -} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java deleted file mode 100644 index eb0fa48..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/ScipMessageTranslator.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - *******************************************************************************/ - -package blockchains.iaas.uni.stuttgart.de.management.callback; - -import java.util.List; - -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.jsonrpc.model.Occurrence; -import blockchains.iaas.uni.stuttgart.de.jsonrpc.model.ScipResponse; -import blockchains.iaas.uni.stuttgart.de.model.Parameter; - -public class ScipMessageTranslator { - public static ScipResponse getInvocationResponseMessage(String correlationId, List outputs) { - return ScipResponse.builder() - .correlationIdentifier(correlationId) - .parameters(outputs) - .build(); - } - - public static ScipResponse getSubscriptionResponseMessage(String correlationId, List parameters, String isoTimestamp) { - return ScipResponse.builder() - .correlationIdentifier(correlationId) - .parameters(parameters) - .isoTimestamp(isoTimestamp) - .build(); - } - - public static ScipResponse getQueryResultResponseMessage(String correlationId, List occurrences) { - return ScipResponse.builder() - .correlationIdentifier(correlationId) - .occurrences(occurrences) - .build(); - } - - public static ScipResponse getAsynchronousErrorResponseMessage(String correlationId, BalException exception) { - return ScipResponse.builder() - .correlationIdentifier(correlationId) - .exception(exception) - .build(); - } -} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CamundaMessageTranslator.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/CamundaMessageTranslator.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CamundaMessageTranslator.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/CamundaMessageTranslator.java index 206652e..6914e55 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/callback/CamundaMessageTranslator.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/CamundaMessageTranslator.java @@ -1,6 +1,5 @@ -/******************************************************************************** - * Copyright (c) 2019 Institute for the Architecture of Application System - - * University of Stuttgart +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -8,8 +7,8 @@ * which is available at https://www.apache.org/licenses/LICENSE-2.0. * * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management.callback; + *******************************************************************************/ +package blockchains.iaas.uni.stuttgart.de.restapi.callback; import java.util.Map; @@ -28,7 +27,6 @@ public static CallbackMessage convert(String subscriptionId, Transaction transac result.setMessageName(msgName); result.setProcessInstanceId(processInstanceId); Map variables = result.getProcessVariables(); - variables.put("status", new CamundaVariable(state.toString(), "String")); // todo handle communication between Camunda and Fabric diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java new file mode 100644 index 0000000..be00407 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.restapi.callback; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; +import blockchains.iaas.uni.stuttgart.de.config.ObjectMapperProvider; +import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CallbackMessage; +import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CamundaMessage; +import org.glassfish.jersey.jackson.JacksonFeature; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RestCallbackManager { + private static RestCallbackManager instance = null; + private static final Logger log = LoggerFactory.getLogger(BlockchainAdapterFactory.class); + private ExecutorService executorService = Executors.newFixedThreadPool(2); + + private RestCallbackManager() { + + } + + public static RestCallbackManager getInstance() { + if (instance == null) + instance = new RestCallbackManager(); + + return instance; + } + + public void sendCallback(final String endpointUrl, final CallbackMessage responseBody) { + if (responseBody instanceof CamundaMessage) { + this.sendRestCallback(endpointUrl, responseBody); + } else { + log.error("The sepcified response message has an unknown callback protocol."); + } + } + + private void sendRestCallback(final String endpointUrl, final CallbackMessage responseBody) { + final Client client = ClientBuilder.newBuilder() + .register(ObjectMapperProvider.class) // No need to register this provider if no special configuration is required. + .register(JacksonFeature.class) + .build(); + final Entity entity = Entity.entity(responseBody, MediaType.APPLICATION_JSON); + final Response response = client.target(endpointUrl).request(MediaType.APPLICATION_JSON) + .post(entity); + + log.info("Callback client responded with code({})", response.getStatus()); + } + + public void sendCallbackAsync(final String endpointUrl, final CallbackMessage responseBody) { + this.executorService.execute(() -> sendCallback(endpointUrl, responseBody)); + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ConnectionProfilesController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ConnectionProfilesController.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ConnectionProfilesController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ConnectionProfilesController.java index 6957e63..cc1c304 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ConnectionProfilesController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ConnectionProfilesController.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; import java.util.Map; @@ -25,7 +25,7 @@ import blockchains.iaas.uni.stuttgart.de.connectionprofiles.AbstractConnectionProfile; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; import com.fasterxml.jackson.core.JsonProcessingException; @Path("configure") diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/EnsureTransactionStateController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/EnsureTransactionStateController.java similarity index 88% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/EnsureTransactionStateController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/EnsureTransactionStateController.java index 4644d44..dcf1b3c 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/EnsureTransactionStateController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/EnsureTransactionStateController.java @@ -1,7 +1,7 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.restapi.model.request.EnsureTransactionStateRequest; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/InvokeSmartContractFunctionController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/InvokeSmartContractFunctionController.java similarity index 91% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/InvokeSmartContractFunctionController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/InvokeSmartContractFunctionController.java index 292c460..dbbc953 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/InvokeSmartContractFunctionController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/InvokeSmartContractFunctionController.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -17,8 +17,8 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.restapi.model.request.InvokeSmartContractFunctionRequest; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; import org.slf4j.Logger; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/OrphanedTransactionController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/OrphanedTransactionController.java similarity index 88% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/OrphanedTransactionController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/OrphanedTransactionController.java index 44e6c5a..9d624f0 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/OrphanedTransactionController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/OrphanedTransactionController.java @@ -1,7 +1,7 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.restapi.model.request.DetectOrphanedTransactionRequest; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ReceiveTransactionController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ReceiveTransactionController.java similarity index 89% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ReceiveTransactionController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ReceiveTransactionController.java index 44d784f..ac9368a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ReceiveTransactionController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ReceiveTransactionController.java @@ -1,7 +1,7 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.restapi.model.request.ReceiveTransactionsRequest; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; //import io.swagger.v3.oas.annotations.Operation; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ReceiveTransactionsController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ReceiveTransactionsController.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ReceiveTransactionsController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ReceiveTransactionsController.java index 96a5082..ed85f99 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/ReceiveTransactionsController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/ReceiveTransactionsController.java @@ -1,7 +1,7 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.restapi.model.request.ReceiveTransactionsRequest; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/RootController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/RootController.java similarity index 88% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/RootController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/RootController.java index 9d3d0ec..e2f2676 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/RootController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/RootController.java @@ -1,4 +1,16 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +/******************************************************************************** + * Copyright (c) 2018-2022 Institute for the Architecture of Application System - + * University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -8,22 +20,11 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; -import blockchains.iaas.uni.stuttgart.de.jsonrpc.BalService; +import blockchains.iaas.uni.stuttgart.de.scip.ScipService; import blockchains.iaas.uni.stuttgart.de.restapi.model.response.LinkCollectionResponse; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; import com.github.arteam.simplejsonrpc.server.JsonRpcServer; -/******************************************************************************** - * Copyright (c) 2018 Institute for the Architecture of Application System - - * University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ @Path("/") public class RootController { @Context @@ -36,7 +37,7 @@ public Response performJsonRpcCall(String jsonRequest) { final String blockchainId = queryParameters.getFirst("blockchain-id"); final String smartContractAddress = queryParameters.getFirst("address"); - BalService service = new BalService(blockchainType, blockchainId, smartContractAddress); + ScipService service = new ScipService(blockchainType, blockchainId, smartContractAddress); JsonRpcServer server = new JsonRpcServer(); String response = server.handle(jsonRequest, service); diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/SubmitTransactionController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/SubmitTransactionController.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/SubmitTransactionController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/SubmitTransactionController.java index 2052044..c6dedee 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/SubmitTransactionController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/SubmitTransactionController.java @@ -1,4 +1,4 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -7,8 +7,8 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.restapi.model.request.SubmitTransactionRequest; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; import org.slf4j.Logger; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/SubscriptionController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/SubscriptionController.java similarity index 91% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/SubscriptionController.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/SubscriptionController.java index d676616..7530a4c 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/Controllers/SubscriptionController.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/SubscriptionController.java @@ -1,4 +1,4 @@ -package blockchains.iaas.uni.stuttgart.de.restapi.Controllers; +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; import java.util.Collection; @@ -10,10 +10,10 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; -import blockchains.iaas.uni.stuttgart.de.management.SubscriptionManager; -import blockchains.iaas.uni.stuttgart.de.management.model.Subscription; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionKey; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.subscription.SubscriptionManager; +import blockchains.iaas.uni.stuttgart.de.subscription.model.Subscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionKey; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.restapi.model.response.LinkCollectionResponse; import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/BalService.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/ScipService.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/BalService.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/ScipService.java index 98a6155..1b4508d 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/BalService.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/ScipService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,12 +9,12 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.jsonrpc; +package blockchains.iaas.uni.stuttgart.de.scip; import java.util.List; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.management.BlockchainManager; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.BlockchainManager; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; import blockchains.iaas.uni.stuttgart.de.model.TimeFrame; @@ -29,8 +29,8 @@ @JsonRpcService @AllArgsConstructor -public class BalService { - private static final Logger log = LoggerFactory.getLogger(BalService.class); +public class ScipService { + private static final Logger log = LoggerFactory.getLogger(ScipService.class); private final String blockchainType; private final String blockchainId; private final String smartContractPath; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/AbstractBinding.java similarity index 66% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/AbstractBinding.java index 14a6cd7..3b45934 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/AbstractBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/AbstractBinding.java @@ -9,12 +9,11 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.bindings; +package blockchains.iaas.uni.stuttgart.de.scip.bindings; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.AsynchronousBalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; public interface AbstractBinding { String getBindingIdentifier(); diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManager.java new file mode 100644 index 0000000..4956809 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManager.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.bindings; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.CamundaBinding; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.jsonrpc.JsonRpcBinding; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Manages the registered SCIP bindings + */ +public class BindingsManager { + private static BindingsManager instance = null; + private static final Logger log = LoggerFactory.getLogger(BindingsManager.class); + private final Map bindings; + + private BindingsManager() { + final CamundaBinding camunda = new CamundaBinding(); + final JsonRpcBinding jsonrpc = new JsonRpcBinding(); + bindings = new HashMap<>(); + bindings.put(camunda.getBindingIdentifier(), camunda); + bindings.put(jsonrpc.getBindingIdentifier(), jsonrpc); + } + + public static BindingsManager getInstance() { + if (instance == null) + instance = new BindingsManager(); + + return instance; + } + + /** + * Retrieves the binding object that corresponds to the provided binding identifier + * @param bindingIdentifier the identifier of the binding to be retrieved + * @return the binding that corresponds to the provided identifier, or null if no binding is mapped to it. + */ + public AbstractBinding getBinding(String bindingIdentifier) { + return bindings.get(bindingIdentifier); + } + + /** + * Retrieves a collection of all the binding identifiers available. + * @return a collection of all the binding identifiers available. + */ + public Collection getAvailableBindingIdentifiers() { + return bindings.keySet(); + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java new file mode 100644 index 0000000..f4f9f16 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.bindings; + +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Manages a map between endpoints and bindings. The goal is to allow clients to specify the binding to be + * used when sending asynchronous responses to different endpoints. + * Endpoints are specified using urls with possible wildcards (*). + * For example: http://my-awsome-endpoint.com/* + * + * When sending an asynchronous response to some endpoint, this map is checked. If any entry (rule) is matched to + * the endpoint the corresponding binding is used. + * If no rules were matched, a default binding, i.e., "json-rpc" is used. + */ +public class EndpointBindings { + private static EndpointBindings instance = null; + private static final Logger log = LoggerFactory.getLogger(EndpointBindings.class); + private static final String DEFAULT_BINDING_IDENTIFIER = "json-rpc"; + private Map rules; + + private EndpointBindings() { + rules = new HashMap<>(); + } + + public static EndpointBindings getInstance() { + if (instance == null) + instance = new EndpointBindings(); + + return instance; + } + + /** + * Add a new endpoint binding rule. + * + * @param url the regex to match the endpoints + * @param bindingIdentifier the identifier of the binding to match to the provided endpoint + */ + public void addRule(String url, String bindingIdentifier) { + if (BindingsManager.getInstance().getAvailableBindingIdentifiers().contains(bindingIdentifier)) { + rules.put(url, bindingIdentifier); + } else { + throw new IllegalArgumentException("The specified binding does not exist!"); + } + } + + public AbstractBinding getBindingForEndpoint(String endpointUrl) { + final String bindingId = getBindingIdentifierForEndpoint(endpointUrl); + + return BindingsManager.getInstance().getBinding(bindingId); + } + + String getBindingIdentifierForEndpoint(String endpointUrl) { + String binding = DEFAULT_BINDING_IDENTIFIER; ; + + for(String key: rules.keySet()) { + String url = preprocess(key); + + if (endpointUrl.matches(url)) { + binding = rules.get(key); + break; + } + } + + return binding; + } + + String preprocess(String url) { + return url + .replaceAll("\\*", "\\\\S*") + .replaceAll("\\+", "\\\\+") + .replaceAll("\\.", "\\\\.") + .replaceAll("\\?", "\\\\?"); + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java similarity index 85% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java index e707af2..5586c0d 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda; +package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda; import java.util.HashMap; import java.util.List; @@ -21,14 +21,14 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.AbstractBinding; -import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model.Message; -import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model.Variable; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.AsynchronousBalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Message; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Variable; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; import org.glassfish.jersey.jackson.JacksonFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Message.java similarity index 88% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Message.java index e44bc6f..4949a39 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Message.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Message.java @@ -9,11 +9,10 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model; +package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Variable.java similarity index 91% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Variable.java index 08a8b6c..ceda873 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/model/Variable.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Variable.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda.model; +package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Builder; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java index 2a45a7c..7692000 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc; +package blockchains.iaas.uni.stuttgart.de.scip.bindings.jsonrpc; import java.io.IOException; import java.util.Collections; @@ -17,12 +17,11 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.AsynchronousBalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; -import blockchains.iaas.uni.stuttgart.de.externalapi.bindings.AbstractBinding; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; import com.github.arteam.simplejsonrpc.client.JsonRpcClient; import com.github.arteam.simplejsonrpc.client.Transport; import com.github.arteam.simplejsonrpc.client.builder.NotificationRequestBuilder; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/callback/ScipCallbackManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/callback/ScipCallbackManager.java new file mode 100644 index 0000000..bd26d1d --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/callback/ScipCallbackManager.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.callback; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; +import blockchains.iaas.uni.stuttgart.de.restapi.callback.RestCallbackManager; +import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CallbackMessage; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.EndpointBindings; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ScipCallbackManager { + private static ScipCallbackManager instance = null; + private static final Logger log = LoggerFactory.getLogger(ScipCallbackManager.class); + private ExecutorService executorService = Executors.newFixedThreadPool(2); + + private ScipCallbackManager() { + + } + + public static ScipCallbackManager getInstance() { + if (instance == null) + instance = new ScipCallbackManager(); + + return instance; + } + + public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { + AbstractBinding binding = EndpointBindings.getInstance().getBindingForEndpoint(endpointUrl); + this.executorService.execute(() -> binding.sendInvocationResponse(endpointUrl, response)); + } + + public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { + AbstractBinding binding = EndpointBindings.getInstance().getBindingForEndpoint(endpointUrl); + this.executorService.execute(() -> binding.sendSubscriptionResponse(endpointUrl, response)); + } + + public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException exception) { + AbstractBinding binding = EndpointBindings.getInstance().getBindingForEndpoint(endpointUrl); + this.executorService.execute(() -> binding.sendAsyncErrorResponse(endpointUrl, exception)); + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/AsynchronousBalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/AsynchronousBalException.java similarity index 85% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/AsynchronousBalException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/AsynchronousBalException.java index 4377c51..1ac1e55 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/AsynchronousBalException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/AsynchronousBalException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; public abstract class AsynchronousBalException extends BalException { private String correlationIdentifier; @@ -21,6 +21,9 @@ public AsynchronousBalException(String message) { super(message); } + public AsynchronousBalException(String message, Throwable cause) { + super(message, cause); + } public String getCorrelationIdentifier() { return correlationIdentifier; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BalException.java similarity index 81% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BalException.java index 0a45ecb..2bb8b4c 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BalException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BalException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; public abstract class BalException extends RuntimeException { @@ -19,5 +19,9 @@ public BalException(String message) { super(message); } + public BalException(String message, Throwable cause) { + super(message, cause); + } + public abstract int getCode(); } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainIdNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainIdNotFoundException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainIdNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainIdNotFoundException.java index 99c2601..9a654a6 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainIdNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainIdNotFoundException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainNodeUnreachableException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainNodeUnreachableException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainNodeUnreachableException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainNodeUnreachableException.java index 1d93bd0..120c0f2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/BlockchainNodeUnreachableException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainNodeUnreachableException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ExceptionCode.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ExceptionCode.java similarity index 97% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ExceptionCode.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ExceptionCode.java index 7a05c9e..f65d768 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ExceptionCode.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ExceptionCode.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; public class ExceptionCode { public static final int UnknownError = 0; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java new file mode 100644 index 0000000..47a5229 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; + +public class GenericAsynchronousBalException extends AsynchronousBalException { + + public GenericAsynchronousBalException(BalException exception, String correlationIdentifier) { + super(exception.getMessage(), exception); + setCorrelationIdentifier(correlationIdentifier); + } + + @Override + public int getCode() { + return ((BalException)getCause()).getCode(); + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidScipParameterException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidScipParameterException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidScipParameterException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidScipParameterException.java index cbf2867..3d01a58 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidScipParameterException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidScipParameterException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidTransactionException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidTransactionException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidTransactionException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidTransactionException.java index 145db82..d77e017 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvalidTransactionException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidTransactionException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionFailure.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionFailure.java index aa0b505..7b3258a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionFailure.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionFailure.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionRevoke.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionRevoke.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionRevoke.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionRevoke.java index 1b0241a..980a91e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/InvokeSmartContractFunctionRevoke.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionRevoke.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/NotSupportedException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/NotSupportedException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/NotSupportedException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/NotSupportedException.java index 3fd70e8..29d4148 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/NotSupportedException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/NotSupportedException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ParameterException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ParameterException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ParameterException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ParameterException.java index b19ec45..25e0911 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/ParameterException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ParameterException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/SmartContractNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/SmartContractNotFoundException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/SmartContractNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/SmartContractNotFoundException.java index d9a2883..8dde5b2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/SmartContractNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/SmartContractNotFoundException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TimeoutException.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TimeoutException.java index 42c0ccd..838a92f 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TimeoutException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TimeoutException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; import lombok.Getter; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TransactionNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TransactionNotFoundException.java similarity index 87% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TransactionNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TransactionNotFoundException.java index ff787dd..463123e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/TransactionNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TransactionNotFoundException.java @@ -8,12 +8,12 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; @JsonRpcError(code = ExceptionCode.TransactionInvalidatedException, message = "The transaction associated with an function invocation is invalidated after it was mined.") -public class TransactionNotFoundException extends BalException { +public class TransactionNotFoundException extends AsynchronousBalException { public TransactionNotFoundException() { } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/UnknownException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/UnknownException.java similarity index 92% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/UnknownException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/UnknownException.java index d2376d5..468d89a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/exceptions/UnknownException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/UnknownException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/InvocationResponse.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/InvocationResponse.java index 0547a39..530bc94 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/InvocationResponse.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/InvocationResponse.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; +package blockchains.iaas.uni.stuttgart.de.scip.model.responses; import java.util.List; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/Occurrence.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/Occurrence.java similarity index 80% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/Occurrence.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/Occurrence.java index 12b83ba..3209f56 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/jsonrpc/model/Occurrence.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/Occurrence.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Institute for the Architecture of Application System - University of Stuttgart + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart * Author: Ghareeb Falazi * * This program and the accompanying materials are made available under the @@ -9,13 +9,15 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.jsonrpc.model; +package blockchains.iaas.uni.stuttgart.de.scip.model.responses; import java.util.List; import blockchains.iaas.uni.stuttgart.de.model.Parameter; +import lombok.Builder; import lombok.Data; +@Builder @Data public class Occurrence { private String isoTimestamp; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/Parameter.java similarity index 91% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/Parameter.java index 8cc951a..b47d074 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/Parameter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/Parameter.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; +package blockchains.iaas.uni.stuttgart.de.scip.model.responses; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/SubscriptionResponse.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/SubscriptionResponse.java index cd4256e..ec243d3 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/externalapi/model/responses/SubscriptionResponse.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/responses/SubscriptionResponse.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.model.responses; +package blockchains.iaas.uni.stuttgart.de.scip.model.responses; import java.util.List; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/SubscriptionManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManager.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/SubscriptionManager.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManager.java index 4e76433..4f573fc 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/SubscriptionManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManager.java @@ -10,7 +10,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management; +package blockchains.iaas.uni.stuttgart.de.subscription; import java.util.Collection; import java.util.Collections; @@ -19,10 +19,10 @@ import java.util.Map; import java.util.stream.Collectors; -import blockchains.iaas.uni.stuttgart.de.management.model.MonitorOccurrencesSubscription; -import blockchains.iaas.uni.stuttgart.de.management.model.Subscription; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionKey; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.subscription.model.MonitorOccurrencesSubscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.Subscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionKey; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/CompletableFutureSubscription.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/CompletableFutureSubscription.java similarity index 95% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/CompletableFutureSubscription.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/CompletableFutureSubscription.java index 4ffbc9a..1909bc6 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/CompletableFutureSubscription.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/CompletableFutureSubscription.java @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management.model; +package blockchains.iaas.uni.stuttgart.de.subscription.model; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/MonitorOccurrencesSubscription.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/MonitorOccurrencesSubscription.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/MonitorOccurrencesSubscription.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/MonitorOccurrencesSubscription.java index 3cc72d2..21320eb 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/MonitorOccurrencesSubscription.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/MonitorOccurrencesSubscription.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management.model; +package blockchains.iaas.uni.stuttgart.de.subscription.model; import java.util.List; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/ObservableSubscription.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/ObservableSubscription.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/ObservableSubscription.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/ObservableSubscription.java index 1fe4eef..e7c8899 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/ObservableSubscription.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/ObservableSubscription.java @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management.model; +package blockchains.iaas.uni.stuttgart.de.subscription.model; import io.reactivex.disposables.Disposable; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/Subscription.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/Subscription.java similarity index 92% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/Subscription.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/Subscription.java index 9d9034c..c0eeb5f 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/Subscription.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/Subscription.java @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management.model; +package blockchains.iaas.uni.stuttgart.de.subscription.model; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/SubscriptionKey.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/SubscriptionKey.java similarity index 96% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/SubscriptionKey.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/SubscriptionKey.java index f25a96f..3b0f868 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/SubscriptionKey.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/SubscriptionKey.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management.model; +package blockchains.iaas.uni.stuttgart.de.subscription.model; import java.util.Objects; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/SubscriptionType.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/SubscriptionType.java similarity index 92% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/SubscriptionType.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/SubscriptionType.java index 159ce9a..2d513b2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/management/model/SubscriptionType.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/SubscriptionType.java @@ -9,7 +9,7 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management.model; +package blockchains.iaas.uni.stuttgart.de.subscription.model; public enum SubscriptionType { SUBMIT_TRANSACTION, diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java index 4d00fb4..22b19df 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java @@ -13,7 +13,7 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainIdNotFoundException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManagerTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManagerTest.java new file mode 100644 index 0000000..88a684f --- /dev/null +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/BindingsManagerTest.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.bindings; + +import java.util.Collection; +import java.util.Collections; + +import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.CamundaBinding; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.jsonrpc.JsonRpcBinding; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BindingsManagerTest { + + @Test + void getBinding() { + AbstractBinding binding = BindingsManager.getInstance().getBinding("camunda"); + Assertions.assertTrue(binding instanceof CamundaBinding); + binding = BindingsManager.getInstance().getBinding("json-rpc"); + Assertions.assertTrue(binding instanceof JsonRpcBinding); + } + + @Test + void getAvailableBindingIdentifiers() { + Collection bindingIds = BindingsManager.getInstance().getAvailableBindingIdentifiers(); + Assertions.assertTrue(bindingIds.contains("camunda")); + Assertions.assertTrue(bindingIds.contains("json-rpc")); + } +} \ No newline at end of file diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java new file mode 100644 index 0000000..dbf1ece --- /dev/null +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.bindings; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class EndpointBindingsTest { + + @Test + void addInvalidRule() { + String url = "http://test.com"; + Assertions.assertThrows(IllegalArgumentException.class, () -> { + EndpointBindings.getInstance().addRule(url, "abc"); + }); + } + + @Test + void addSimpleRule() { + String url = "http://test.com"; + EndpointBindings.getInstance().addRule(url, "camunda"); + String id = EndpointBindings.getInstance().getBindingIdentifierForEndpoint(url); + Assertions.assertEquals("camunda", id); + } + + @Test + void addRuleWithWildcards() { + String url = "http://*.abc.com/*"; + EndpointBindings.getInstance().addRule(url, "camunda"); + String id = EndpointBindings.getInstance().getBindingIdentifierForEndpoint("aaa"); + Assertions.assertEquals("json-rpc", id); + id = EndpointBindings.getInstance().getBindingIdentifierForEndpoint("http://gg.abc.com/home?a=b&k=f+2"); + Assertions.assertEquals("camunda", id); + } + + @Test + void getDefaultBindingIdentifier() { + String url = "http://test.com"; + String id = EndpointBindings.getInstance().getBindingIdentifierForEndpoint(url); + Assertions.assertEquals("json-rpc", id); + } + + @Test + void preprocess() { + String url = "http://hotmail.com/*/ghareeb?aaa=x+y"; + String processed = "http://hotmail\\.com/\\S*/ghareeb\\?aaa=x\\+y"; + + Assertions.assertEquals(processed, EndpointBindings.getInstance().preprocess(url)); + } +} \ No newline at end of file diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBindingTest.java similarity index 93% rename from src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java rename to src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBindingTest.java index d990be1..2087f76 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/camunda/CamundaBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBindingTest.java @@ -9,18 +9,18 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.camunda; +package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda; import java.io.IOException; import java.util.Collections; import java.util.stream.Collectors; import java.util.stream.Stream; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBindingTest.java similarity index 92% rename from src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java rename to src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBindingTest.java index 7439764..770f01e 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/externalapi/bindings/jsonrpc/JsonRpcBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBindingTest.java @@ -9,19 +9,18 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.externalapi.bindings.jsonrpc; +package blockchains.iaas.uni.stuttgart.de.scip.bindings.jsonrpc; import java.io.IOException; import java.util.Collections; import java.util.stream.Collectors; import java.util.stream.Stream; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.exceptions.TimeoutException; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.InvocationResponse; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.Parameter; -import blockchains.iaas.uni.stuttgart.de.externalapi.model.responses.SubscriptionResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter; +import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/management/SubscriptionManagerTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManagerTest.java similarity index 86% rename from src/test/java/blockchains/iaas/uni/stuttgart/de/management/SubscriptionManagerTest.java rename to src/test/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManagerTest.java index 6c9fa2f..fa6fc28 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/management/SubscriptionManagerTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManagerTest.java @@ -9,12 +9,12 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.management; +package blockchains.iaas.uni.stuttgart.de.subscription; import java.util.Collections; -import blockchains.iaas.uni.stuttgart.de.management.model.MonitorOccurrencesSubscription; -import blockchains.iaas.uni.stuttgart.de.management.model.SubscriptionType; +import blockchains.iaas.uni.stuttgart.de.subscription.model.MonitorOccurrencesSubscription; +import blockchains.iaas.uni.stuttgart.de.subscription.model.SubscriptionType; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; From 5f027d953b83cfe06cabdafe548ff3d725eccf6f Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Thu, 24 Feb 2022 09:30:47 +0100 Subject: [PATCH 11/24] Reorganize Exceptions - Use a dedicated final class to represent asynchronous exceptions. It encapsulates a BalException as a cause, and adds an obligatory correlation identifier. The class should be instantiated only by the blockchain manager because it knows the context + it has the correlation identifier. --- .../uni/stuttgart/de/BlockchainManager.java | 33 ++++++++++--------- .../de/adaptation/AdapterManager.java | 4 +-- .../adapters/bitcoin/BitcoinAdapter.java | 10 +++--- .../adapters/ethereum/EthereumAdapter.java | 18 +++++----- .../adapters/ethereum/EthereumTypeMapper.java | 2 +- .../adapters/ethereum/ParameterDecoder.java | 2 +- .../adapters/ethereum/ParameterEncoder.java | 2 +- .../adapters/fabric/FabricAdapter.java | 14 ++++---- .../adapters/fabric/GatewayManager.java | 4 +-- .../interfaces/BlockchainAdapter.java | 6 ++-- .../utils/JsonSchemaToJavaTypeMapper.java | 4 +-- .../model => }/exceptions/BalException.java | 2 +- .../BlockchainIdNotFoundException.java | 2 +- .../BlockchainNodeUnreachableException.java | 2 +- .../model => }/exceptions/ExceptionCode.java | 2 +- .../InvalidScipParameterException.java | 2 +- .../InvalidTransactionException.java | 2 +- .../InvokeSmartContractFunctionFailure.java | 7 ++-- .../InvokeSmartContractFunctionRevoke.java | 2 +- .../exceptions/NotSupportedException.java | 2 +- .../exceptions/ParameterException.java | 2 +- .../SmartContractNotFoundException.java | 2 +- .../exceptions/TimeoutException.java | 4 +-- .../TransactionNotFoundException.java | 7 ++-- .../exceptions/UnknownException.java | 2 +- .../uni/stuttgart/de/scip/ScipService.java | 2 +- .../scip/bindings/camunda/CamundaBinding.java | 8 ++--- .../scip/bindings/jsonrpc/JsonRpcBinding.java | 12 ++++--- .../exceptions/AsynchronousBalException.java | 21 +++++------- .../GenericAsynchronousBalException.java | 25 -------------- .../de/adaptation/AdapterManagerTest.java | 2 +- .../bindings/camunda/CamundaBindingTest.java | 15 +++++---- .../bindings/jsonrpc/JsonRpcBindingTest.java | 15 +++++---- 33 files changed, 111 insertions(+), 128 deletions(-) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/BalException.java (92%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/BlockchainIdNotFoundException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/BlockchainNodeUnreachableException.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/ExceptionCode.java (97%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/InvalidScipParameterException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/InvalidTransactionException.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/InvokeSmartContractFunctionFailure.java (76%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/InvokeSmartContractFunctionRevoke.java (94%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/NotSupportedException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/ParameterException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/SmartContractNotFoundException.java (93%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/TimeoutException.java (89%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/TransactionNotFoundException.java (78%) rename src/main/java/blockchains/iaas/uni/stuttgart/de/{scip/model => }/exceptions/UnknownException.java (92%) delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java index 8b2b7d0..b07cd61 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java @@ -29,16 +29,16 @@ import blockchains.iaas.uni.stuttgart.de.restapi.callback.CamundaMessageTranslator; import blockchains.iaas.uni.stuttgart.de.restapi.callback.RestCallbackManager; import blockchains.iaas.uni.stuttgart.de.scip.callback.ScipCallbackManager; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainIdNotFoundException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.GenericAsynchronousBalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TransactionNotFoundException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.UnknownException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.exceptions.TransactionNotFoundException; +import blockchains.iaas.uni.stuttgart.de.exceptions.UnknownException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; import blockchains.iaas.uni.stuttgart.de.subscription.SubscriptionManager; @@ -413,17 +413,18 @@ public void invokeSmartContractFunction( .build(); ScipCallbackManager.getInstance().sendInvocationResponse(callbackUrl, response); } else {// it is NOT_FOUND (it was dropped from the system due to invalidation) or ERRORED + AsynchronousBalException exception; if (tx.getState() == TransactionState.NOT_FOUND) { TransactionNotFoundException txNotFoundException = new TransactionNotFoundException("The transaction associated with a function invocation is invalidated after it was mined."); - txNotFoundException.setCorrelationIdentifier(correlationId); - ScipCallbackManager.getInstance().sendAsyncErrorResponse(callbackUrl, txNotFoundException); + exception = new AsynchronousBalException(txNotFoundException, correlationId); } else { InvokeSmartContractFunctionFailure invocationException = new InvokeSmartContractFunctionFailure("The smart contract function invocation reported an error."); - invocationException.setCorrelationIdentifier(correlationId); - ScipCallbackManager.getInstance().sendAsyncErrorResponse(callbackUrl, invocationException); + exception = new AsynchronousBalException(invocationException, correlationId); } + + ScipCallbackManager.getInstance().sendAsyncErrorResponse(callbackUrl, exception); } } else { log.info("resulting transaction is null"); @@ -434,8 +435,8 @@ public void invokeSmartContractFunction( // happens if the node is unreachable, or something goes wrong while trying to invoke the sc function. // todo figure out how to handle this case if (e.getCause() instanceof BalException) { - GenericAsynchronousBalException exception = - new GenericAsynchronousBalException((BalException) e.getCause(), correlationId); + AsynchronousBalException exception = + new AsynchronousBalException((BalException) e.getCause(), correlationId); ScipCallbackManager.getInstance().sendAsyncErrorResponse(callbackUrl, exception); } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java index ad5c5ea..da4ece9 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManager.java @@ -19,8 +19,8 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.AbstractConnectionProfile; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainIdNotFoundException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java index dd79b7e..6e14088 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/bitcoin/BitcoinAdapter.java @@ -19,11 +19,11 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; import blockchains.iaas.uni.stuttgart.de.adaptation.adapters.AbstractAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.PoWConfidenceCalculator; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Block; import blockchains.iaas.uni.stuttgart.de.model.LinearChainTransaction; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java index 14bae14..f6acc97 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java @@ -34,15 +34,15 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.utils.BooleanExpressionEvaluator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.PoWConfidenceCalculator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.SmartContractPathParser; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.SmartContractNotFoundException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.SmartContractNotFoundException; +import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.model.Block; import blockchains.iaas.uni.stuttgart.de.model.LinearChainTransaction; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java index f40eb66..aa673ee 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapper.java @@ -18,7 +18,7 @@ import javax.json.JsonObject; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.MathUtils; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; import org.web3j.abi.datatypes.AbiTypes; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java index d78ccb0..19f8435 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterDecoder.java @@ -12,7 +12,7 @@ import java.math.BigInteger; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; import org.web3j.abi.datatypes.Bytes; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java index fe972ed..be9800f 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/ParameterEncoder.java @@ -15,7 +15,7 @@ import javax.xml.bind.DatatypeConverter; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import org.web3j.abi.datatypes.Address; import org.web3j.abi.datatypes.Bool; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java index e2d17e8..9e095e8 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/FabricAdapter.java @@ -24,13 +24,13 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.BooleanExpressionEvaluator; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.SmartContractPathParser; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java index b210935..b0b42fc 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/fabric/GatewayManager.java @@ -20,8 +20,8 @@ import blockchains.iaas.uni.stuttgart.de.connectionprofiles.AbstractConnectionProfile; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.profiles.FabricConnectionProfile; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainNodeUnreachableException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; import org.hyperledger.fabric.gateway.Contract; import org.hyperledger.fabric.gateway.Gateway; import org.hyperledger.fabric.gateway.Network; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java index b9ea5dd..5a7bd3d 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/interfaces/BlockchainAdapter.java @@ -16,9 +16,9 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidTransactionException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.NotSupportedException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidTransactionException; +import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; import blockchains.iaas.uni.stuttgart.de.model.Occurrence; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java index 608f2b2..9e33653 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/utils/JsonSchemaToJavaTypeMapper.java @@ -18,8 +18,8 @@ import javax.json.JsonObject; import javax.xml.bind.DatatypeConverter; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.ParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.ParameterException; import blockchains.iaas.uni.stuttgart.de.model.Parameter; public class JsonSchemaToJavaTypeMapper { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BalException.java similarity index 92% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BalException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BalException.java index 2bb8b4c..c150da3 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BalException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BalException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; public abstract class BalException extends RuntimeException { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainIdNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainIdNotFoundException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainIdNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainIdNotFoundException.java index 9a654a6..f06518a 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainIdNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainIdNotFoundException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainNodeUnreachableException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainNodeUnreachableException.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainNodeUnreachableException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainNodeUnreachableException.java index 120c0f2..d890487 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/BlockchainNodeUnreachableException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/BlockchainNodeUnreachableException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ExceptionCode.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ExceptionCode.java similarity index 97% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ExceptionCode.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ExceptionCode.java index f65d768..40e6667 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ExceptionCode.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ExceptionCode.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; public class ExceptionCode { public static final int UnknownError = 0; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidScipParameterException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidScipParameterException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidScipParameterException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidScipParameterException.java index 3d01a58..82023db 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidScipParameterException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidScipParameterException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidTransactionException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidTransactionException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java index d77e017..7c052de 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvalidTransactionException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java @@ -8,7 +8,7 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionFailure.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionFailure.java similarity index 76% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionFailure.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionFailure.java index 7b3258a..34b4dc2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionFailure.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionFailure.java @@ -8,12 +8,13 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; -@JsonRpcError(code = ExceptionCode.InvocationError, message = "The smart contract function invocation failed.") -public class InvokeSmartContractFunctionFailure extends AsynchronousBalException { +@JsonRpcError(code = ExceptionCode.InvocationError, + message = "The smart contract function invocation failed.") +public class InvokeSmartContractFunctionFailure extends BalException { public InvokeSmartContractFunctionFailure() { } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionRevoke.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionRevoke.java similarity index 94% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionRevoke.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionRevoke.java index 980a91e..6d5d522 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/InvokeSmartContractFunctionRevoke.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvokeSmartContractFunctionRevoke.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/NotSupportedException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/NotSupportedException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/NotSupportedException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/NotSupportedException.java index 29d4148..aeea08e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/NotSupportedException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/NotSupportedException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ParameterException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ParameterException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ParameterException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ParameterException.java index 25e0911..b286fa8 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/ParameterException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/ParameterException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/SmartContractNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/SmartContractNotFoundException.java similarity index 93% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/SmartContractNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/SmartContractNotFoundException.java index 8dde5b2..44d0152 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/SmartContractNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/SmartContractNotFoundException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TimeoutException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TimeoutException.java similarity index 89% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TimeoutException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TimeoutException.java index 838a92f..9f7fa6b 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TimeoutException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TimeoutException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; import lombok.Getter; @@ -18,7 +18,7 @@ @JsonRpcError(code = ExceptionCode.Timeout, message = "Timeout was reached before the desired DoC was fulfilled.") @Setter @Getter -public class TimeoutException extends AsynchronousBalException { +public class TimeoutException extends BalException { private String transactionHash; private double doc; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TransactionNotFoundException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TransactionNotFoundException.java similarity index 78% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TransactionNotFoundException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TransactionNotFoundException.java index 463123e..987d52b 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/TransactionNotFoundException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/TransactionNotFoundException.java @@ -8,12 +8,13 @@ * * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; -@JsonRpcError(code = ExceptionCode.TransactionInvalidatedException, message = "The transaction associated with an function invocation is invalidated after it was mined.") -public class TransactionNotFoundException extends AsynchronousBalException { +@JsonRpcError(code = ExceptionCode.TransactionInvalidatedException, + message = "The transaction associated with an function invocation is invalidated after it was mined.") +public class TransactionNotFoundException extends BalException { public TransactionNotFoundException() { } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/UnknownException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/UnknownException.java similarity index 92% rename from src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/UnknownException.java rename to src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/UnknownException.java index 468d89a..37978a6 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/UnknownException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/UnknownException.java @@ -9,7 +9,7 @@ * SPDX-License-Identifier: Apache-2.0 *******************************************************************************/ -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; +package blockchains.iaas.uni.stuttgart.de.exceptions; import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/ScipService.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/ScipService.java index 1b4508d..f3e49f5 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/ScipService.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/ScipService.java @@ -13,7 +13,7 @@ import java.util.List; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvalidScipParameterException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvalidScipParameterException; import blockchains.iaas.uni.stuttgart.de.BlockchainManager; import blockchains.iaas.uni.stuttgart.de.model.Parameter; import blockchains.iaas.uni.stuttgart.de.model.QueryResult; diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java index 5586c0d..4867c4e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java @@ -25,7 +25,7 @@ import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Message; import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Variable; import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; @@ -73,16 +73,16 @@ public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse re public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException exception) { final Map variables = new HashMap<>(); - if (exception instanceof TimeoutException) { + if (exception.getCause() instanceof TimeoutException) { final Variable txHash = Variable .builder() - .value(((TimeoutException) exception).getTransactionHash()) + .value(((TimeoutException) exception.getCause()).getTransactionHash()) .type("String") .build(); final Variable doc = Variable .builder() - .value(String.valueOf(((TimeoutException) exception).getDoc())) + .value(String.valueOf(((TimeoutException) exception.getCause()).getDoc())) .type("String") .build(); diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java index 7692000..7a66b59 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java @@ -17,9 +17,9 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.scip.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; import com.github.arteam.simplejsonrpc.client.JsonRpcClient; @@ -68,9 +68,11 @@ public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException builder = builder.param("errorMessage", exception.getMessage()); builder = builder.param("correlationIdentifier", exception.getCorrelationIdentifier()); - if (exception instanceof TimeoutException) { - builder = builder.param("transactionHash", ((TimeoutException) exception).getTransactionHash()); - builder = builder.param("reachedDoC", ((TimeoutException) exception).getDoc()); + if (exception.getCause() instanceof TimeoutException) { + builder = builder.param("transactionHash", + ((TimeoutException) exception.getCause()).getTransactionHash()); + builder = builder.param("reachedDoC", + ((TimeoutException) exception.getCause()).getDoc()); } builder.execute(); diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/AsynchronousBalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/AsynchronousBalException.java index 1ac1e55..6e9b81e 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/AsynchronousBalException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/AsynchronousBalException.java @@ -11,25 +11,22 @@ package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; -public abstract class AsynchronousBalException extends BalException { - private String correlationIdentifier; +import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; - public AsynchronousBalException() { - } - - public AsynchronousBalException(String message) { - super(message); - } +public final class AsynchronousBalException extends BalException { + final private String correlationIdentifier; - public AsynchronousBalException(String message, Throwable cause) { - super(message, cause); + public AsynchronousBalException(BalException cause, String correlationIdentifier) { + super(cause.getMessage(), cause); + this.correlationIdentifier = correlationIdentifier; } public String getCorrelationIdentifier() { return correlationIdentifier; } - public void setCorrelationIdentifier(String correlationIdentifier) { - this.correlationIdentifier = correlationIdentifier; + @Override + public int getCode() { + return ((BalException)getCause()).getCode(); } } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java deleted file mode 100644 index 47a5229..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/model/exceptions/GenericAsynchronousBalException.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - *******************************************************************************/ - -package blockchains.iaas.uni.stuttgart.de.scip.model.exceptions; - -public class GenericAsynchronousBalException extends AsynchronousBalException { - - public GenericAsynchronousBalException(BalException exception, String correlationIdentifier) { - super(exception.getMessage(), exception); - setCorrelationIdentifier(correlationIdentifier); - } - - @Override - public int getCode() { - return ((BalException)getCause()).getCode(); - } -} diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java index 22b19df..6f7e5fc 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/AdapterManagerTest.java @@ -13,7 +13,7 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.connectionprofiles.ConnectionProfilesManager; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.BlockchainIdNotFoundException; +import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBindingTest.java index 2087f76..839fc67 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBindingTest.java @@ -16,8 +16,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; @@ -82,10 +83,12 @@ void sendSubscriptionResponse(SubscriptionResponse response) throws InterruptedE @Test void sendErrorResponse() throws InterruptedException { - InvokeSmartContractFunctionFailure e1 = new InvokeSmartContractFunctionFailure("The first Exception occurred"); - e1.setCorrelationIdentifier("654321ABC"); - TimeoutException e2 = new TimeoutException("The second exception occurred", "CRAZYHASH123", 0.3); - e2.setCorrelationIdentifier("XXX654321ABC"); + AsynchronousBalException e1 = new AsynchronousBalException( + new InvokeSmartContractFunctionFailure("The first Exception occurred"), + "654321ABC"); + AsynchronousBalException e2 = new AsynchronousBalException( + new TimeoutException("The first Exception occurred", "CRAZYHASH123", 0.3), + "XXX654321ABC"); String endpointUrl = this.mockWebServer.url("/").toString(); CamundaBinding binding = new CamundaBinding(); binding.sendAsyncErrorResponse(endpointUrl, e1); diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBindingTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBindingTest.java index 770f01e..bd46b3d 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBindingTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBindingTest.java @@ -16,8 +16,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.InvokeSmartContractFunctionFailure; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.TimeoutException; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; +import blockchains.iaas.uni.stuttgart.de.exceptions.InvokeSmartContractFunctionFailure; +import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; @@ -80,10 +81,12 @@ void sendSubscriptionResponse(SubscriptionResponse response) throws InterruptedE @Test void sendErrorResponses() throws InterruptedException { - InvokeSmartContractFunctionFailure e1 = new InvokeSmartContractFunctionFailure("The first Exception occurred"); - e1.setCorrelationIdentifier("654321ABC"); - TimeoutException e2 = new TimeoutException("The second exception occurred", "CRAZYHASH123", 0.3); - e2.setCorrelationIdentifier("XXX654321ABC"); + AsynchronousBalException e1 = new AsynchronousBalException( + new InvokeSmartContractFunctionFailure("The first Exception occurred"), + "654321ABC"); + AsynchronousBalException e2 = new AsynchronousBalException( + new TimeoutException("The first Exception occurred", "CRAZYHASH123", 0.3), + "XXX654321ABC"); String endpointUrl = this.mockWebServer.url("/").toString(); JsonRpcBinding binding = new JsonRpcBinding(); binding.sendAsyncErrorResponse(endpointUrl, e1); From ab9bb812f6ea5ade06b9d9994e5eac96eb6d0fd0 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Thu, 24 Feb 2022 13:45:33 +0100 Subject: [PATCH 12/24] Fix EndpointBinding tests --- .../de/scip/bindings/EndpointBindings.java | 23 +++++++++++++++++-- .../de/subscription/SubscriptionManager.java | 5 ++-- .../model/ObservableSubscription.java | 6 +++-- .../scip/bindings/EndpointBindingsTest.java | 6 +++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java index f4f9f16..7820f3f 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java @@ -64,7 +64,13 @@ public AbstractBinding getBindingForEndpoint(String endpointUrl) { return BindingsManager.getInstance().getBinding(bindingId); } - String getBindingIdentifierForEndpoint(String endpointUrl) { + /** + * FOR INTERNAL USE AND TESTING! + * + * @param endpointUrl an endpoint url with potential wildcards, i.e., *. + * @return the binding identifier associated with this url, or the default binding identifier. + */ + protected String getBindingIdentifierForEndpoint(String endpointUrl) { String binding = DEFAULT_BINDING_IDENTIFIER; ; for(String key: rules.keySet()) { @@ -79,7 +85,20 @@ String getBindingIdentifierForEndpoint(String endpointUrl) { return binding; } - String preprocess(String url) { + /** + * ONLY FOR TESTING! + * Please do not use this method for any production code. + */ + protected void resetRules() { + rules.clear(); + } + + /** + * FOR INTERNAL USE AND TESTING! + * @param url a url in clear text with possible wildcards, i.e., *. + * @return a regex that escapes special characters and properly handles the wildcard + */ + protected String preprocess(String url) { return url .replaceAll("\\*", "\\\\S*") .replaceAll("\\+", "\\\\+") diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManager.java index 4f573fc..682e066 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/SubscriptionManager.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2019 Institute for the Architecture of Application System - + * Copyright (c) 2019-2022 Institute for the Architecture of Application System - * University of Stuttgart * Author: Ghareeb Falazi * @@ -51,7 +51,8 @@ public void createSubscription(String subscriptionId, String blockchainId, Strin if (this.subscriptions.containsKey(key)) { log.error("Subscription key <{}> already exists! Not subscribing!", key); // to not keep any loose ends - subscription.unsubscribe(); + Subscription old = this.subscriptions.get(key); + old.unsubscribe(); } else { this.subscriptions.put(key, subscription); } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/ObservableSubscription.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/ObservableSubscription.java index e7c8899..c6c9dc9 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/ObservableSubscription.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/subscription/model/ObservableSubscription.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2018-2019 Institute for the Architecture of Application System - + * Copyright (c) 2018-2022 Institute for the Architecture of Application System - * University of Stuttgart * Author: Ghareeb Falazi * @@ -30,6 +30,8 @@ public void setSubscription(Disposable subscription) { } public void unsubscribe() { - this.subscription.dispose(); + if (this.subscription != null) { + this.subscription.dispose(); + } } } diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java index dbf1ece..ad22d38 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindingsTest.java @@ -12,10 +12,16 @@ package blockchains.iaas.uni.stuttgart.de.scip.bindings; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class EndpointBindingsTest { + @BeforeEach + void clearRules() { + EndpointBindings.getInstance().resetRules(); + } + @Test void addInvalidRule() { String url = "http://test.com"; From 15e9b350467742067359e189eaeeb685b262e2b2 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Thu, 24 Feb 2022 14:20:00 +0100 Subject: [PATCH 13/24] Fix project setup --- pom.xml | 18 +++----- .../uni/stuttgart/de/config/Application.java | 28 ------------ .../de/config/ObjectMapperProvider.java | 44 ------------------- .../restapi/callback/RestCallbackManager.java | 6 +-- .../scip/bindings/camunda/CamundaBinding.java | 5 +-- .../webapp/WEB-INF/openapi-configuration.json | 21 --------- src/main/webapp/WEB-INF/web.xml | 7 +-- 7 files changed, 13 insertions(+), 116 deletions(-) delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java delete mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java delete mode 100644 src/main/webapp/WEB-INF/openapi-configuration.json diff --git a/pom.xml b/pom.xml index 64d804d..71c5b42 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.apache.maven.plugins maven-compiler-plugin - 2.5.1 + 3.8.1 true 1.8 @@ -55,28 +55,24 @@ org.glassfish.jersey.containers jersey-container-servlet-core - ${jersey.version} - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - - org.glassfish.jersey.inject jersey-hk2 - ${jersey.version} + org.glassfish.jersey.media + jersey-media-json-binding + + + org.web3j diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java deleted file mode 100644 index fac8672..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/Application.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2018-2022 Institute for the Architecture of Application System - - * University of Stuttgart - * Author: Ghareeb Falazi - * - * This program and the accompanying materials are made available under the - * terms the Apache Software License 2.0 - * which is available at https://www.apache.org/licenses/LICENSE-2.0. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package blockchains.iaas.uni.stuttgart.de.config; - -import org.glassfish.jersey.jackson.JacksonFeature; -import org.glassfish.jersey.server.ResourceConfig; - -import javax.ws.rs.ApplicationPath; - -@ApplicationPath("") -public class Application extends ResourceConfig { - public Application() { - packages("blockchains.iaas.uni.stuttgart.de"); - register(ObjectMapperProvider.class); - register( JacksonFeature.class ); - - } -} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java deleted file mode 100644 index bf4d3a2..0000000 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/config/ObjectMapperProvider.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright 2017 University of Stuttgart - * - * 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 blockchains.iaas.uni.stuttgart.de.config; - -import javax.ws.rs.ext.ContextResolver; -import javax.ws.rs.ext.Provider; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - -@Provider -public class ObjectMapperProvider implements ContextResolver { - - private final ObjectMapper defaultObjectMapper; - - public ObjectMapperProvider() { - defaultObjectMapper = createDefaultMapper(); - } - - @Override - public ObjectMapper getContext(Class type) { - return defaultObjectMapper; - } - - - private static ObjectMapper createDefaultMapper() { - final ObjectMapper result = new ObjectMapper(); - result.configure(SerializationFeature.INDENT_OUTPUT, true); - - return result; - } - -} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java index be00407..c686e4c 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/callback/RestCallbackManager.java @@ -21,10 +21,8 @@ import javax.ws.rs.core.Response; import blockchains.iaas.uni.stuttgart.de.adaptation.BlockchainAdapterFactory; -import blockchains.iaas.uni.stuttgart.de.config.ObjectMapperProvider; import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CallbackMessage; import blockchains.iaas.uni.stuttgart.de.restapi.model.response.CamundaMessage; -import org.glassfish.jersey.jackson.JacksonFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,8 +52,8 @@ public void sendCallback(final String endpointUrl, final CallbackMessage respons private void sendRestCallback(final String endpointUrl, final CallbackMessage responseBody) { final Client client = ClientBuilder.newBuilder() - .register(ObjectMapperProvider.class) // No need to register this provider if no special configuration is required. - .register(JacksonFeature.class) + //.register(ObjectMapperProvider.class) // No need to register this provider if no special configuration is required. + //.register(JacksonFeature.class) .build(); final Entity entity = Entity.entity(responseBody, MediaType.APPLICATION_JSON); final Response response = client.target(endpointUrl).request(MediaType.APPLICATION_JSON) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java index 4867c4e..51ee048 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java @@ -21,15 +21,14 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.scip.bindings.AbstractBinding; import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Message; import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Variable; import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; -import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.Parameter; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; -import org.glassfish.jersey.jackson.JacksonFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -117,7 +116,7 @@ private Map parseParameters(List parameterList) { private void sendCamundaMessage(Message message, String endpointUrl) { final Client client = ClientBuilder.newBuilder() - .register(JacksonFeature.class) + //.register(JacksonFeature.class) .build(); final Entity entity = Entity.entity(message, MediaType.APPLICATION_JSON); final Response postResponse = client.target(endpointUrl).request(MediaType.APPLICATION_JSON) diff --git a/src/main/webapp/WEB-INF/openapi-configuration.json b/src/main/webapp/WEB-INF/openapi-configuration.json deleted file mode 100644 index 285841b..0000000 --- a/src/main/webapp/WEB-INF/openapi-configuration.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "resourcePackages": [ - "blockchains.iaas.uni.stuttgart.de" - ], - "prettyPrint" : true, - "openAPI": { - "info": { - "version": "1.0", - "title": "Swagger Pet Sample App", - "description": "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.", - "termsOfService": "http://swagger.io/terms/", - "contact": { - "email": "apiteam@swagger.io" - }, - "license": { - "name": "Apache 2.0", - "url": "http://www.apache.org/licenses/LICENSE-2.0.html" - } - } - } -} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index defc6fc..750beb7 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -6,12 +6,9 @@ Jersey Web Application org.glassfish.jersey.servlet.ServletContainer - javax.ws.rs.Application - - blockchains.iaas.uni.stuttgart.de.config.Application - + jersey.config.server.provider.packages + blockchains.iaas.uni.stuttgart.de - 1 From 99644eff9843e52ff5bfa639af4a5f7e65688dac Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Thu, 24 Feb 2022 17:42:11 +0100 Subject: [PATCH 14/24] Add support for detecting more Ethereum errors - detect block gas limit reached - detect unknown account - possibly many more errors... - all use -32100 code because details are only available in a string not a code. --- .../adapters/ethereum/EthereumAdapter.java | 22 ++++++++++++++++++- .../InvalidTransactionException.java | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java index f6acc97..1e26f50 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java @@ -211,6 +211,7 @@ private static CompletionException wrapEthereumExceptions(Throwable e) { return new CompletionException(mapEthereumException(e)); } + // todo this code seems fishy. private static BalException mapEthereumException(Throwable e) { BalException result; @@ -245,7 +246,17 @@ public CompletableFuture submitTransaction(String receiverAddress, return Transfer.sendFunds(web3j, credentials, receiverAddress, value, Convert.Unit.WEI) // 1 wei = 10^-18 Ether .sendAsync() // when an exception (e.g., ConnectException happens), the following is skipped - .thenCompose(tx -> subscribeForTxEvent(tx.getTransactionHash(), waitFor, TransactionState.CONFIRMED, TransactionState.NOT_FOUND)) + .thenCompose(tx -> { + if (tx.isStatusOK()) { + // we go here, for example, for block gas limit exceptions. + InvalidTransactionException exception = new InvalidTransactionException( + "Failed to submit transaction. Ethereum JSON-RPC code: " + tx.getStatus()); + log.error("Failed to submit transaction. Ethereum JSON-RPC code: " + tx.getStatus()); + throw new CompletionException(exception); + } + + return subscribeForTxEvent(tx.getTransactionHash(), waitFor, TransactionState.CONFIRMED, TransactionState.NOT_FOUND); + }) .exceptionally((e) -> { throw wrapEthereumExceptions(e); } @@ -621,6 +632,15 @@ private CompletableFuture invokeFunctionByTransaction(long waitFor, .thenCompose(transaction -> web3j.ethSendTransaction(transaction).sendAsync()) .thenCompose(tx -> { final String txHash = tx.getTransactionHash(); + + if (tx.hasError()) { + InvokeSmartContractFunctionFailure exception = new InvokeSmartContractFunctionFailure( + "Failed to invoke smart contract function via tx. Reason: " + tx.getError().getMessage()); + log.error("Transaction submission failed. Code: {}, Reason: {}", tx.getError().getCode(), tx.getError().getMessage()); + + throw new CompletionException(exception); + } + log.info("transaction hash is {}", txHash); return CompletableFuture.completedFuture(txHash); }) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java index 7c052de..06f06b1 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/exceptions/InvalidTransactionException.java @@ -12,7 +12,7 @@ import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcError; -@JsonRpcError(code = ExceptionCode.InvocationError, message = "An error occurred while trying to invoke the smart contract function.") +@JsonRpcError(code = ExceptionCode.InvocationError, message = "An error occurred while trying to submit a transaction.") public class InvalidTransactionException extends BalException { public InvalidTransactionException() { From 91628dea9263450cd5a8825e82ecd0017d72649b Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Thu, 24 Feb 2022 17:46:59 +0100 Subject: [PATCH 15/24] Update pom.xml --- pom.xml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 71c5b42..8ebc50c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ + org.glassfish.jersey.inject jersey-hk2 @@ -68,25 +69,12 @@ jersey-media-json-binding - - org.web3j core ${org.web3j.version} - - - org.bouncycastle - bcprov-jdk15on - 1.63 - org.projectlombok From 32bccb9e10deeaa2b1c93823f4c702ae107c6b87 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Thu, 24 Feb 2022 21:36:40 +0100 Subject: [PATCH 16/24] Correctly handle a timeout value of 0 - if the timeout value is specified to be 0 (or was missing), it is set to Long.MAX_VALUE --- pom.xml | 2 +- .../uni/stuttgart/de/BlockchainManager.java | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 8ebc50c..0a31dd4 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ - + org.glassfish.jersey.inject jersey-hk2 diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java index b07cd61..3f2e5a3 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/BlockchainManager.java @@ -21,15 +21,6 @@ import blockchains.iaas.uni.stuttgart.de.adaptation.AdapterManager; import blockchains.iaas.uni.stuttgart.de.adaptation.interfaces.BlockchainAdapter; import blockchains.iaas.uni.stuttgart.de.adaptation.utils.MathUtils; -import blockchains.iaas.uni.stuttgart.de.model.Parameter; -import blockchains.iaas.uni.stuttgart.de.model.QueryResult; -import blockchains.iaas.uni.stuttgart.de.model.TimeFrame; -import blockchains.iaas.uni.stuttgart.de.model.Transaction; -import blockchains.iaas.uni.stuttgart.de.model.TransactionState; -import blockchains.iaas.uni.stuttgart.de.restapi.callback.CamundaMessageTranslator; -import blockchains.iaas.uni.stuttgart.de.restapi.callback.RestCallbackManager; -import blockchains.iaas.uni.stuttgart.de.scip.callback.ScipCallbackManager; -import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; import blockchains.iaas.uni.stuttgart.de.exceptions.BalException; import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainIdNotFoundException; import blockchains.iaas.uni.stuttgart.de.exceptions.BlockchainNodeUnreachableException; @@ -39,6 +30,15 @@ import blockchains.iaas.uni.stuttgart.de.exceptions.NotSupportedException; import blockchains.iaas.uni.stuttgart.de.exceptions.TransactionNotFoundException; import blockchains.iaas.uni.stuttgart.de.exceptions.UnknownException; +import blockchains.iaas.uni.stuttgart.de.model.Parameter; +import blockchains.iaas.uni.stuttgart.de.model.QueryResult; +import blockchains.iaas.uni.stuttgart.de.model.TimeFrame; +import blockchains.iaas.uni.stuttgart.de.model.Transaction; +import blockchains.iaas.uni.stuttgart.de.model.TransactionState; +import blockchains.iaas.uni.stuttgart.de.restapi.callback.CamundaMessageTranslator; +import blockchains.iaas.uni.stuttgart.de.restapi.callback.RestCallbackManager; +import blockchains.iaas.uni.stuttgart.de.scip.callback.ScipCallbackManager; +import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.SubscriptionResponse; import blockchains.iaas.uni.stuttgart.de.subscription.SubscriptionManager; @@ -352,6 +352,7 @@ public void ensureTransactionState(final String correlationId, final String tran *

* UNKNOWN: the blockchain network is not recognized, or connection to node is not possible or the function is not recognized * INVALID: the submitted transaction failed validation at the node (if a transaction was required) + * ERRORED: the smart contract function threw an exception. * CONFIRMED (along with the tx itself): the submitted transaction received the desired number of block-confirmations * or the result returned from a read-only smart contract function. * @@ -387,12 +388,12 @@ public void invokeSmartContractFunction( || MathUtils.doubleCompare(requiredConfidence, 100.0) > 0) { throw new InvalidScipParameterException(); } - + final long effectiveTimeoutMillis = timeoutMillis == 0 ? Long.MAX_VALUE : timeoutMillis; final AdapterManager adapterManager = AdapterManager.getInstance(); final double minimumConfidenceAsProbability = requiredConfidence / 100.0; final BlockchainAdapter adapter = adapterManager.getAdapter(blockchainIdentifier); final CompletableFuture future = adapter.invokeSmartContract(smartContractPath, - functionIdentifier, inputs, outputs, minimumConfidenceAsProbability, timeoutMillis); + functionIdentifier, inputs, outputs, minimumConfidenceAsProbability, effectiveTimeoutMillis); future. thenAccept(tx -> { From 6cdaa5df689cab95d9a06c79ccbd6f0be4371b36 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Thu, 24 Feb 2022 22:36:52 +0100 Subject: [PATCH 17/24] Implement Endpoint Binding Rules Controller - Add RESTful controller for managing endpoint binding rules at the "bindings" path --- .../controllers/BindingRulesController.java | 70 +++++++++++++++++++ .../de/restapi/model/common/BindingRule.java | 24 +++++++ .../de/scip/bindings/EndpointBindings.java | 26 ++++++- 3 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/BindingRulesController.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/common/BindingRule.java diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/BindingRulesController.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/BindingRulesController.java new file mode 100644 index 0000000..843a4ea --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/controllers/BindingRulesController.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.restapi.controllers; + +import java.util.Collection; +import java.util.stream.Collectors; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import blockchains.iaas.uni.stuttgart.de.restapi.model.common.BindingRule; +import blockchains.iaas.uni.stuttgart.de.restapi.util.UriUtil; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.EndpointBindings; + +@Path("bindings") +public class BindingRulesController { + + @Context + protected UriInfo uriInfo; + + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response acceptRule(BindingRule request) { + try { + EndpointBindings.getInstance().addRule(request.getUrl(), request.getBindingId()); + return Response.ok(UriUtil.generateSelfLink(uriInfo)).build(); + } catch (IllegalArgumentException exception) { + return Response.status(Response.Status.NOT_FOUND).entity(exception.getMessage()).build(); + } + } + + @DELETE + public Response deleteRule() { + final String url = this.uriInfo.getQueryParameters().getFirst("url"); + if (EndpointBindings.getInstance().removeRule(url) == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } + + return Response.noContent().build(); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getAllRules() { + Collection list = EndpointBindings + .getInstance() + .getAllRules() + .stream() + .map(pair -> new BindingRule(pair.left, pair.right)) + .collect(Collectors.toList()); + return Response.ok(list).build(); + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/common/BindingRule.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/common/BindingRule.java new file mode 100644 index 0000000..d1b3204 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/restapi/model/common/BindingRule.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.restapi.model.common; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BindingRule { + private String url; + private String bindingId; +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java index 7820f3f..af2be24 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/EndpointBindings.java @@ -11,9 +11,12 @@ package blockchains.iaas.uni.stuttgart.de.scip.bindings; +import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; +import org.apache.commons.lang3.tuple.ImmutablePair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,12 +61,29 @@ public void addRule(String url, String bindingIdentifier) { } } + /** + * Removes an existing endpoint binding rule. + * + * @param url the url of the endpoint with possible wildcards. + * @return the previous binding id or null if no rule was found. + */ + public String removeRule(String url) { + return rules.remove(url); + } + public AbstractBinding getBindingForEndpoint(String endpointUrl) { final String bindingId = getBindingIdentifierForEndpoint(endpointUrl); return BindingsManager.getInstance().getBinding(bindingId); } + public Collection> getAllRules() { + return rules.entrySet() + .stream() + .map((entry) -> ImmutablePair.of(entry.getKey(), entry.getValue())) + .collect(Collectors.toList()); + } + /** * FOR INTERNAL USE AND TESTING! * @@ -71,9 +91,10 @@ public AbstractBinding getBindingForEndpoint(String endpointUrl) { * @return the binding identifier associated with this url, or the default binding identifier. */ protected String getBindingIdentifierForEndpoint(String endpointUrl) { - String binding = DEFAULT_BINDING_IDENTIFIER; ; + String binding = DEFAULT_BINDING_IDENTIFIER; + ; - for(String key: rules.keySet()) { + for (String key : rules.keySet()) { String url = preprocess(key); if (endpointUrl.matches(url)) { @@ -95,6 +116,7 @@ protected void resetRules() { /** * FOR INTERNAL USE AND TESTING! + * * @param url a url in clear text with possible wildcards, i.e., *. * @return a regex that escapes special characters and properly handles the wildcard */ From aa267bd70c775d87d8d17e3a4d80d5204f469ceb Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Fri, 25 Feb 2022 12:42:23 +0100 Subject: [PATCH 18/24] Fix Error Camunda Binding - write README.md entry --- README.md | 331 +++++++++++++----- .../scip/bindings/camunda/CamundaBinding.java | 33 +- .../camunda/model/DoubleVariable.java | 24 ++ .../bindings/camunda/model/LongVariable.java | 13 + .../camunda/model/StringVariable.java | 27 ++ .../scip/bindings/camunda/model/Variable.java | 22 +- 6 files changed, 325 insertions(+), 125 deletions(-) create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java create mode 100644 src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/StringVariable.java diff --git a/README.md b/README.md index 24e288f..493c2e9 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,35 @@ # Blockchain Access Layer (BAL) - SCIP Gateway -BAL is an extensible abstraction layer that allows client applications to access permissioned and permissionless blockchains using a uniform interface. -BAL is designed to support business process management systems to access blockchains using the [Blockchain Modeling and Execution (BlockME) method](https://link.springer.com/article/10.1007/s00450-019-00399-5). +BAL is an extensible abstraction layer that allows client applications to access permissioned and permissionless +blockchains using a uniform interface. BAL is designed to support business process management systems to access +blockchains using +the [Blockchain Modeling and Execution (BlockME) method](https://link.springer.com/article/10.1007/s00450-019-00399-5). It also implements the [Smart Contract Invocation Protocol (SCIP)](https://github.com/lampajr/scip) as a gateway. -BAL is a Java 8 web application that uses Jersey to expose a [RESTful API](#restful-api) and a [JSON-RPC API](#json-rpc-api). +BAL is a Java 8 web application that uses Jersey to expose a [RESTful API](#restful-api) and +a [JSON-RPC API](#json-rpc-api). ## Configuration -BAL allows simultaneous access to multiple blockchain systems. -Currently, [Ethereum](https://ethereum.org/), [Bitcoin](https://bitcoin.org/), and [Hyperledger Fabric](https://www.hyperledger.org/projects/fabric) are supported. -- To access the Ethereum blockchain, BAL needs to be able to communicate with a [geth node](https://github.com/ethereum/go-ethereum) -which has RPC connections enabled. Furthermore, BAL directly accesses the keystore file holding the private key of an Ethereum account used for sending and receiving transactions. -- To access the Bitcoin blockchain, BAL needs to be able to communicate with a [bitcoind node](https://bitcoin.org/en/bitcoin-core/) -which has RPC connections enabled. -- To access a given Hyperledger Fabric network, it needs to have access to a wallet file with authorized users, and an appropriate [connection profile](https://hyperledger-fabric.readthedocs.io/en/latest/developapps/connectionprofile.html). +BAL allows simultaneous access to multiple blockchain systems. Currently, [Ethereum](https://ethereum.org/) +, [Bitcoin](https://bitcoin.org/), and [Hyperledger Fabric](https://www.hyperledger.org/projects/fabric) are supported. + +- To access the Ethereum blockchain, BAL needs to be able to communicate with + a [geth node](https://github.com/ethereum/go-ethereum) + which has RPC connections enabled. Furthermore, BAL directly accesses the keystore file holding the private key of an + Ethereum account used for sending and receiving transactions. +- To access the Bitcoin blockchain, BAL needs to be able to communicate with + a [bitcoind node](https://bitcoin.org/en/bitcoin-core/) + which has RPC connections enabled. +- To access a given Hyperledger Fabric network, it needs to have access to a wallet file with authorized users, and an + appropriate [connection profile](https://hyperledger-fabric.readthedocs.io/en/latest/developapps/connectionprofile.html) + . ### Configuring Access to Multiple Blockchains -BAL expectes a configuration file with the name `connectionProfiles.json` inside the path `[User Folder]/.bal/`. -An example for this file that accesses a geth node, a bitcoind node and a Hyperledger Fabric network is: + +BAL expectes a configuration file with the name `connectionProfiles.json` inside the path `[User Folder]/.bal/`. An +example for this file that accesses a geth node, a bitcoind node and a Hyperledger Fabric network is: + ```[json] { "eth-0": { @@ -53,25 +64,31 @@ An example for this file that accesses a geth node, a bitcoind node and a Hyperl ## Building and Deployment -After cloning, you can build the project and package it into a WAR -file using the following command: +After cloning, you can build the project and package it into a WAR file using the following command: + ``` mvn install ``` -Then, the WAR file (which can be found in the folder 'target' generated after -a successful build) can be deployed on an Apache Tomcat server. -**Notice:** the build requires a library (btcd-cli4j) to communicate with the Bitcoin Core node. [The used library](https://github.com/pythonmax/btcd-cli4j) is forked from an [unmaintained library](http://btcd-cli4j.neemre.com) to fix some issues resulting from changes in the recent versions of the Bitcoin Core node. However, the used library is not available in a public Maven repository, so we had to provide a local Maven repository which includes the required binaries. This repository is found [here](local-maven-repo). +Then, the WAR file (which can be found in the folder 'target' generated after a successful build) can be deployed on an +Apache Tomcat server. + +**Notice:** the build requires a library (btcd-cli4j) to communicate with the Bitcoin Core +node. [The used library](https://github.com/pythonmax/btcd-cli4j) is forked from +an [unmaintained library](http://btcd-cli4j.neemre.com) to fix some issues resulting from changes in the recent versions +of the Bitcoin Core node. However, the used library is not available in a public Maven repository, so we had to provide +a local Maven repository which includes the required binaries. This repository is found [here](local-maven-repo). ## Accessing the APIs ### RESTful API + The application exposes an asynchronous RESTful API to subscribe and unsubscribe from the provided operations. **To summarize:** -The RESTful api provides the following resources/methods: -* A POST method is provided for each of the following -paths to create the corresponding subscription: +The RESTful api provides the following resources/methods: + +* A POST method is provided for each of the following paths to create the corresponding subscription: ``` {application-URL}/webapi/submit-transaction @@ -84,8 +101,7 @@ paths to create the corresponding subscription: * A GET method is also provided for the aforementioned URLs that lists the currently active subscriptions. -* A DELETE method is provided in each of the following -paths to manually delete the corresponding subscription: +* A DELETE method is provided in each of the following paths to manually delete the corresponding subscription: ``` {application-URL}/webapi/submit-transaction/{subscription-id} @@ -96,29 +112,135 @@ paths to manually delete the corresponding subscription: {application-URL}/webapi/invoke-smart-contract-function ``` -### JSON-RPC API -BAL implements the [JSON-RPC binding](https://github.com/lampajr/scip#json-rpc-binding) described in the SCIP specifications. -It can be accessed with any standard [JSON-RPC client](https://www.jsonrpc.org/archive_json-rpc.org/implementations.html). +### SCIP API + +BAL implements the SCIP protocol via the [JSON-RPC binding](https://github.com/lampajr/scip#json-rpc-binding) described +in the SCIP specifications. It can be accessed with any +standard [JSON-RPC client](https://www.jsonrpc.org/archive_json-rpc.org/implementations.html). + +### Camunda Binding with JSON-RPC API + +When using the SCIP API, you have the option to specify a different format for asynchronous return messages +(both regular callbacks, and asynchronous errors). At the time being, in addition to the regular `JSON-RPC` format, +a `Camunda` format is also available: + +When choosing this format, asynchronous return messages are formatted as follows: + +#### Regular Callbacks + +```json +{ + "messageName": "message__", + "processInstanceId": "", + "processVariables": { + "timestamp": { + "value": , + "type": "Number" + }, + "": { + "value": "", + "type": "String" + }, + "": { + "value": "", + "type": "String" + }, + ... + } +} +``` + +Where: + +- ``: is the name of the SCIP method this callback corresponds to. Either `INVOKE` or `SUBSCRIBE`. +- ``: is the correlation identifier provided in the corresponding SCIP request previously received. +- ``: is the UTC timestamp of the transaction that is related to this request if such a transaction + exists. For `INVOKE` method, if the smart contract function required a transaction to be invoked, i.e., because it is + no read-only, then we have the timestamp of that transaction here; otherwise, we have the value `0`. In case of + the `SUBSCRIBE` + method, here we have the timestamp associated with the transaction of the current occurrence. +- ``, ``: the name and value of the first variable associated with this request. In + case of read-only `INVOKE`'s, this is the first return value of the smart contract function. There are no such entries + in case of non-read-only `INVOKE`'s. In case of `SUBSCRIBE` callbacks, this corresponds to the first parameter of the + event/smart contract function being monitored. Note that the type is always set to `"String"`. +- ``, ``: same as above if a second variable exists... + +#### Error Callbacks + +```json +{ + "messageName": "error__", + "processInstanceId": "", + "processVariables": { + "reachedDoC": { + "type": "Number", + "value": + }, + "transactionHash": { + "type": "String", + "value": "" + }, + "errorMessage": { + "type": "String", + "value": "" + }, + "errorCode": { + "type": "Number", + "value": + } + } +} +``` + +Where: + +- ``,``: are the same as before. +- ``: only available for timeout errors. Indicates the degree-of-confidence [0.0, 1.0[ + reached before the `INVOKE` request timed-out. +- ``: only available for timeout errors. If the `INVOKE` request timed-out after a transaction is submitted, + but before the required Degree-of-Confidence was reached, then the hash of the transaction is provided here. If the + hash was not obtained for some reason, the value is `""`. +- ``: a non-standardized message that describes the reason of the error. +- ``: the error code as defined in the SCIP protocol. + +#### How to Choose the Asynchronous Return Message Binding? + +Clients of the BAL can choose different return message bindings for different callback endpoints. To this end, a +dedicated RESTful resource is provided at `{application-URL}/webapi/bindings/`. This endpoint accepts binding rules in +the following `JSON` format: + +```json +{ + "url": "", + "bindingId": "" +} +``` +Where: +- ``: represents the url of the callback endpoint. The url can include the following wildcard: `*` +that represents any sequence of non-whitespace characters. Example: `http://my-awsome-endpoint.com/*`. +- ``: takes one of two values, `json-rpc`, or `camunda`. + +**Please not that the `json-rpc` binding is the default binding used if no rule matches the callback endpoint.** ## Setting Up Various Blockchains for Testing -BAL needs to have access to a node for each blockchain instance it needs to communicate with. -These nodes can be already running nodes that you have access to. -Otherwise, you need to setup and manage your own nodes. -Below, are basic instructions how to setup Ethereum, Bitcoin, and Hyperledger Fabric nodes. +BAL needs to have access to a node for each blockchain instance it needs to communicate with. These nodes can be already +running nodes that you have access to. Otherwise, you need to setup and manage your own nodes. Below, are basic +instructions how to setup Ethereum, Bitcoin, and Hyperledger Fabric nodes. ### Running a Local geth Node -A geth node is used to access the Ethereum network. For development purposes, it is advised -not to connect to the main Ethereum network, but rather to one of the testnets. -(another, more difficult option would be to run a local private Ethereum network). -In order to connect a geth node to [Rinkeby](https://www.rinkeby.io) (one of Ethereum testnets), you can follow these steps: + +A geth node is used to access the Ethereum network. For development purposes, it is advised not to connect to the main +Ethereum network, but rather to one of the testnets. +(another, more difficult option would be to run a local private Ethereum network). In order to connect a geth node +to [Rinkeby](https://www.rinkeby.io) (one of Ethereum testnets), you can follow these steps: 1. [Install geth](https://github.com/ethereum/go-ethereum/wiki/Installing-Geth): - this differs depending on your operating system. -2. Run geth in the fast-sync mode: This option downlaoads the whole blockchain but does not re-execute all transactions. Syncing -the whole testnet blockchain (which is done once only) takes about 1-4 hours (depending on the hardware, the speed of the network -connection, and the availability of peers). -To start a geth node in the fast-sync mode, execute the following command: + this differs depending on your operating system. +2. Run geth in the fast-sync mode: This option downlaoads the whole blockchain but does not re-execute all transactions. + Syncing the whole testnet blockchain (which is done once only) takes about 1-4 hours (depending on the hardware, the + speed of the network connection, and the availability of peers). To start a geth node in the fast-sync mode, execute + the following command: ``` geth --rpcapi personal,db,eth,net,web3 --rpc --rinkeby --cache=2048 --rpcport "8545" --bootnodes= @@ -126,100 +248,121 @@ To start a geth node in the fast-sync mode, execute the following command: enode://343149e4feefa15d882d9fe4ac7d88f885bd05ebb735e547f12e12080a9fa07c8014ca6fd7f373123488102fe5e34111f8509cf0b7de3f5b44339c9f25e87cb8@52.3.158.184:30303, enode://b6b28890b006743680c52e64e0d16db57f28124885595fa03a562be1d2bf0f3a1da297d56b13da25fb992888fd556d4c1a27b1f39d531bde7de1921c90061cc6@159.89.28.211:30303 ``` - If you want your node to be accessible remotely, apart from configuring your firewall, you also need to use the following extra option, - when running the node: ```--rpcaddr "0.0.0.0"``` + If you want your node to be accessible remotely, apart from configuring your firewall, you also need to use the + following extra option, when running the node: ```--rpcaddr "0.0.0.0"``` 3. Test connection: you can test your connection to a running geth node using the following command -(make sure to install geth on the computer where you run this command):```geth attach http://localhost:8545``` -please replace _localhost_ with the ip address of the computer running the node. + (make sure to install geth on the computer where you run this command):```geth attach http://localhost:8545``` + please replace _localhost_ with the ip address of the computer running the node. ### Running a Local Bitcoin Core Node + A Bitcoin Core node (or _bitcoind_ node) is used to access the Bitcoin network. For development purposes, it is advised not to connect to the main Bitcoin network, but rather to one of the testnets. -(another, more difficult option would be to run a local private Bitcoin network). -In order to connect a _bitcoind_ node to [testnet3](https://en.bitcoin.it/wiki/Testnet) (one of Bitcoin's testnets), you can follow these steps: +(another, more difficult option would be to run a local private Bitcoin network). In order to connect a _bitcoind_ node +to [testnet3](https://en.bitcoin.it/wiki/Testnet) (one of Bitcoin's testnets), you can follow these steps: 1. [Install bitcoind](https://bitcoin.org/en/download): - this differs depending on your operating system. For the installation instructions on Ubuntu you can follow [these steps](https://gist.github.com/rjmacarthy/b56497a81a6497bfabb1). -2. Configure _bitcoind_: This can be done by editing and using the [`bitcoin.conf`](src/main/resources/bitcoin.conf) file when starting the bicoind daemon. -The configuration allows external rpc-based communication with the node, and instructs it to communicate with the testnet rather than -the mainnet. Furthermore, it orders the node to build an index on the blockchain that allows querying even historic transactions. Finally, it instructs the node -to send notifications to the BAL when it detects a new block or a transaction addressed to one of the Bitcoin wallet's addresses. -Syncing the whole testnet blockchain (which is done once only) takes about 1-4 hours (depending on the hardware, the speed of the network -connection, and the availability of peers). + this differs depending on your operating system. For the installation instructions on Ubuntu you can + follow [these steps](https://gist.github.com/rjmacarthy/b56497a81a6497bfabb1). +2. Configure _bitcoind_: This can be done by editing and using the [`bitcoin.conf`](src/main/resources/bitcoin.conf) + file when starting the bicoind daemon. The configuration allows external rpc-based communication with the node, and + instructs it to communicate with the testnet rather than the mainnet. Furthermore, it orders the node to build an + index on the blockchain that allows querying even historic transactions. Finally, it instructs the node to send + notifications to the BAL when it detects a new block or a transaction addressed to one of the Bitcoin wallet's + addresses. Syncing the whole testnet blockchain (which is done once only) takes about 1-4 hours (depending on the + hardware, the speed of the network connection, and the availability of peers). 3. Start the pre-configured _bitcoind_ node with the following command:```bitcoind -daemon``` 4. Test connection: you can test your connection to a running _bitcoind_ node using the following command -(make sure to install bitcoin-cli (shipped with _bitcoind_) on the computer where you run this command): + (make sure to install bitcoin-cli (shipped with _bitcoind_) on the computer where you run this command): + ``` bitcoin-cli -getinfo -rpcconnect= -rpcport= -rpcuser= -rpcpassword= ``` ### Setting-up a Basic Hyperledger Fabric Network + Please follow these steps [Fabric Setup](https://hyperledger-fabric.readthedocs.io/en/latest/getting_started.html) #### Note -The included Fabric unit test depends on the [FabCar official example](https://hyperledger-fabric.readthedocs.io/en/release-1.4/write_first_app.html), so in order to run it -ensure the following: -1. follow the steps of running the first Fabric tutorial at: https://hyperledger-fabric.readthedocs.io/en/release-1.4/write_first_app.html (use the javascript smart contract). +The included Fabric unit test depends on +the [FabCar official example](https://hyperledger-fabric.readthedocs.io/en/release-1.4/write_first_app.html), so in +order to run it ensure the following: + +1. follow the steps of running the first Fabric tutorial + at: https://hyperledger-fabric.readthedocs.io/en/release-1.4/write_first_app.html (use the javascript smart contract) + . 2. execute the enrollAdmin.js and the registerUser.js node programs. 3. alter the local hosts file by adding the following entries: - * 127.0.0.1 orderer.example.com - * 127.0.0.1 peer0.org1.example.com - * 127.0.0.1 peer0.org2.example.com - * 127.0.0.1 peer1.org1.example.com - * 127.0.0.1 peer1.org2.example.com - + * 127.0.0.1 orderer.example.com + * 127.0.0.1 peer0.org1.example.com + * 127.0.0.1 peer0.org2.example.com + * 127.0.0.1 peer1.org1.example.com + * 127.0.0.1 peer1.org2.example.com + This ensures that the SDK is able to find the orderer and network peers. ## Case Studies ### BlockME Case Study -[Blockchain Modeling Extension (BlockME)](https://link.springer.com/article/10.1007/s00450-019-00399-5) is an extension to BPMN 2.0 that allows business processes to communicate with heterogeneous blockchains. -The case study invloves a cryptocurrency exchange service utilitzing the blockchain access layer. -The exchange uses the following simplified BlockME-model: + +[Blockchain Modeling Extension (BlockME)](https://link.springer.com/article/10.1007/s00450-019-00399-5) is an extension +to BPMN 2.0 that allows business processes to communicate with heterogeneous blockchains. The case study invloves a +cryptocurrency exchange service utilitzing the blockchain access layer. The exchange uses the following simplified +BlockME-model: ![](src/main/resources/images/original-model.png) Please follow these instructions: + 1. Configure and run a local geth node (see above). 2. Configure and run a local bitcoind node (see above). -3. Configure the blockchain access layer to communicate with these nodes (see the file [gatewayConfiguration.json](src/main/resources/gatewayConfiguration.json)). +3. Configure the blockchain access layer to communicate with these nodes (see the + file [gatewayConfiguration.json](src/main/resources/gatewayConfiguration.json)). 4. Build and deploy the blockchain access layer (see above). -5. Configure, build, deploy and initiate the process model ([see this Github repository for instructions](https://github.com/ghareeb-falazi/BlockME-UseCase)) -6. Send ethers to the address maintained by the blockchain access layer (the first address of the keyfile mentioned in step 3). -7. Monitor the Tomcat server logs for both applications to see the progress. You can also use the -Camunda Cockpit application (installed as part of step 4) to monitor the current state of instances of deployed process models. +5. Configure, build, deploy and initiate the process + model ([see this Github repository for instructions](https://github.com/ghareeb-falazi/BlockME-UseCase)) +6. Send ethers to the address maintained by the blockchain access layer (the first address of the keyfile mentioned in + step 3). +7. Monitor the Tomcat server logs for both applications to see the progress. You can also use the Camunda Cockpit + application (installed as part of step 4) to monitor the current state of instances of deployed process models. The following series of screenshots show a sample execution of the case study: - 1. Initiating the process instance: - ![](src/main/resources/images/start.png) - - 2. Setting the source, and target addresses (exchange request parameters): - ![](src/main/resources/images/input-params.png) - - 3. Sending a transaction to the address of the crypto-exchange using the Ethereum Wallet application: - ![](src/main/resources/images/send-transaction-form.png) - - 4. While waiting for the resulting Bitcoin transaction sent to the client to receive 1 confirmation, the business process instance looks - as follows: - ![](src/main/resources/images/waiting-for-bitcoin-tx.png) - - 5. The log records produced by the process instance. The final message in the log shows the id of the transaction - the exchange sent to the client. - ![](src/main/resources/images/log.png) - - 6. [BlockCypher](https://live.blockcypher.com/btc-testnet/) can be used to explore Bitcoin testnet3 (and other) blockchains. - The following screenshot represents the result of querying the transaction id reported in the previous step: - ![](src/main/resources/images/blockcypher.png) -You can find the details about the resulting testnet3 Bitcoin transaction [here](https://live.blockcypher.com/btc-testnet/tx/347d8f2bc8dbc7cf62d8313f66d2ae930c9e92632fb5a2cfb2507caaaffa7f71/). - - When we performed this sample execution, the setup was as follows: - +1. Initiating the process instance: + ![](src/main/resources/images/start.png) + +2. Setting the source, and target addresses (exchange request parameters): + ![](src/main/resources/images/input-params.png) + +3. Sending a transaction to the address of the crypto-exchange using the Ethereum Wallet application: + ![](src/main/resources/images/send-transaction-form.png) + +4. While waiting for the resulting Bitcoin transaction sent to the client to receive 1 confirmation, the business + process instance looks as follows: + ![](src/main/resources/images/waiting-for-bitcoin-tx.png) + +5. The log records produced by the process instance. The final message in the log shows the id of the transaction the + exchange sent to the client. + ![](src/main/resources/images/log.png) + +6. [BlockCypher](https://live.blockcypher.com/btc-testnet/) can be used to explore Bitcoin testnet3 (and other) + blockchains. The following screenshot represents the result of querying the transaction id reported in the previous + step: + ![](src/main/resources/images/blockcypher.png) + You can find the details about the resulting testnet3 Bitcoin + transaction [here](https://live.blockcypher.com/btc-testnet/tx/347d8f2bc8dbc7cf62d8313f66d2ae930c9e92632fb5a2cfb2507caaaffa7f71/) + . + +When we performed this sample execution, the setup was as follows: + * a _geth_ node is running on a virtual machine in a VSphere accessible from the local network. * a _bitcoind_ (Bitcoin Core) node is running on a virtual machine in a VSphere accessible from the local network. * The blockchain access layer is running in a local Tomcat server listening to port 8081 * The camunda engine is running in a local Tomcat server listening to port 8080 ### SCIP Case Studies -Two case studies that demonstrate the usage of the BAL as a SCIP gateway can be found [here](https://github.com/ghareeb-falazi/SCIP-CaseStudy) and [here](https://github.com/ghareeb-falazi/SCIP-CaseStudy-2). + +Two case studies that demonstrate the usage of the BAL as a SCIP gateway can be +found [here](https://github.com/ghareeb-falazi/SCIP-CaseStudy) +and [here](https://github.com/ghareeb-falazi/SCIP-CaseStudy-2). diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java index 51ee048..c266357 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java @@ -23,7 +23,10 @@ import blockchains.iaas.uni.stuttgart.de.exceptions.TimeoutException; import blockchains.iaas.uni.stuttgart.de.scip.bindings.AbstractBinding; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.DoubleVariable; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.LongVariable; import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Message; +import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.StringVariable; import blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model.Variable; import blockchains.iaas.uni.stuttgart.de.scip.model.exceptions.AsynchronousBalException; import blockchains.iaas.uni.stuttgart.de.scip.model.responses.InvocationResponse; @@ -43,6 +46,9 @@ public String getBindingIdentifier() { @Override public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { final Map variables = parseParameters(response.getParams()); + long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("")? + 0 : Long.parseLong(response.getTimestamp()); + variables.put("timestamp", new LongVariable(timestamp)); final Message message = Message .builder() @@ -57,6 +63,9 @@ public void sendInvocationResponse(String endpointUrl, InvocationResponse respon @Override public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { final Map variables = parseParameters(response.getParams()); + long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("")? + 0 : Long.parseLong(response.getTimestamp()); + variables.put("timestamp", new LongVariable(timestamp)); final Message message = Message .builder() @@ -73,22 +82,16 @@ public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException final Map variables = new HashMap<>(); if (exception.getCause() instanceof TimeoutException) { - final Variable txHash = Variable - .builder() - .value(((TimeoutException) exception.getCause()).getTransactionHash()) - .type("String") - .build(); - - final Variable doc = Variable - .builder() - .value(String.valueOf(((TimeoutException) exception.getCause()).getDoc())) - .type("String") - .build(); - + final Variable txHash = new StringVariable(((TimeoutException) exception.getCause()).getTransactionHash()); + final Variable doc = new DoubleVariable(((TimeoutException) exception.getCause()).getDoc()); variables.put("reachedDoC", doc); variables.put("transactionHash", txHash); } + final Variable errCode = new LongVariable(exception.getCode()); + final Variable errMessage = new StringVariable(exception.getMessage()); + variables.put("errorCode", errCode); + variables.put("errorMessage", errMessage); Message message = Message .builder() .messageName("error_SUBSCRIBE_" + exception.getCorrelationIdentifier()) @@ -102,11 +105,7 @@ private Map parseParameters(List parameterList) { final Map variables = new HashMap<>(); if (parameterList != null) { parameterList.forEach(parameter -> { - Variable current = Variable - .builder() - .value(parameter.getValue()) - .type("String") - .build(); + Variable current = new StringVariable(parameter.getValue()); variables.put(parameter.getName(), current); }); } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java new file mode 100644 index 0000000..54b1d63 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model; + +import lombok.Getter; + +@Getter +public class DoubleVariable extends Variable { + private final double value; + + public DoubleVariable(double value) { + super("Number"); + this.value = value; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java new file mode 100644 index 0000000..2763df2 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java @@ -0,0 +1,13 @@ +package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model; + +import lombok.Getter; + +@Getter +public class LongVariable extends Variable { + private final long value; + + public LongVariable(long value) { + super("Number"); + this.value = value; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/StringVariable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/StringVariable.java new file mode 100644 index 0000000..5083cd9 --- /dev/null +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/StringVariable.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2022 Institute for the Architecture of Application System - University of Stuttgart + * Author: Ghareeb Falazi + * + * This program and the accompanying materials are made available under the + * terms the Apache Software License 2.0 + * which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: Apache-2.0 + *******************************************************************************/ + +package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model; + +import lombok.Getter; +import lombok.NonNull; +import org.jetbrains.annotations.NotNull; + +@Getter +public class StringVariable extends Variable { + @NonNull + private final String value; + + public StringVariable(@NotNull String value) { + super("String"); + this.value = value; + } +} diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Variable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Variable.java index ceda873..7180fce 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Variable.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Variable.java @@ -11,19 +11,13 @@ package blockchains.iaas.uni.stuttgart.de.scip.bindings.camunda.model; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import lombok.Builder; -import lombok.Data; -import lombok.NonNull; -import lombok.extern.jackson.Jacksonized; +import lombok.Getter; -@Data -@Builder -@Jacksonized -@JsonIgnoreProperties(ignoreUnknown = true) -public class Variable { - @NonNull - private String value; - @NonNull - private String type; +@Getter +public abstract class Variable { + private final String type; + + public Variable(String typeName) { + this.type = typeName; + } } From 49de71b5bb69a445f537631c5eb0a210743f17af Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Fri, 25 Feb 2022 14:53:16 +0100 Subject: [PATCH 19/24] fix bug in submitting transactions --- README.md | 2 +- .../de/adaptation/adapters/ethereum/EthereumAdapter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 493c2e9..aa99a6f 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ Where: Clients of the BAL can choose different return message bindings for different callback endpoints. To this end, a dedicated RESTful resource is provided at `{application-URL}/webapi/bindings/`. This endpoint accepts binding rules in -the following `JSON` format: +the following `JSON` format via `POST`: ```json { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java index 1e26f50..96f5cf2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java @@ -247,7 +247,7 @@ public CompletableFuture submitTransaction(String receiverAddress, .sendAsync() // when an exception (e.g., ConnectException happens), the following is skipped .thenCompose(tx -> { - if (tx.isStatusOK()) { + if (!tx.isStatusOK()) { // we go here, for example, for block gas limit exceptions. InvalidTransactionException exception = new InvalidTransactionException( "Failed to submit transaction. Ethereum JSON-RPC code: " + tx.getStatus()); From f8dbe30fd2a2624778f161570ed18e38c106d71a Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Wed, 16 Mar 2022 19:39:38 +0100 Subject: [PATCH 20/24] Catch all exceptions inside observable Catch all exceptions (instead of only IOException) inside the Observable that fetches Ethereum blocks (otherwise the error will not be handled and will cause a failure "missing onError bla bal") --- .../de/adaptation/adapters/ethereum/EthereumAdapter.java | 3 ++- .../adaptation/adapters/ethereum/EthereumTypeMapperTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java index 96f5cf2..e595b5f 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java @@ -672,7 +672,8 @@ private CompletableFuture waitUntilTransactionIsMined(final result.complete(receipt.getResult()); } } - } catch (IOException e) { + + } catch (Exception e) {// most likely IOException result.completeExceptionally(e); } }); diff --git a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapperTest.java b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapperTest.java index d1652ad..1b88578 100644 --- a/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapperTest.java +++ b/src/test/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumTypeMapperTest.java @@ -23,7 +23,8 @@ import org.web3j.abi.datatypes.generated.Uint160; import static org.junit.jupiter.api.Assertions.*; - +// 2^255 = 57896044618658097711785492504343953926634992332820282019728792003956564819968 +// 2^256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935 class EthereumTypeMapperTest { @Test void testTypes(){ From bc5737a52658bd9e1d27db0d438f36a7cdf78d4c Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Fri, 18 Mar 2022 11:49:23 +0100 Subject: [PATCH 21/24] catch communication errors --- .../scip/bindings/camunda/CamundaBinding.java | 102 ++++++++++-------- .../scip/bindings/jsonrpc/JsonRpcBinding.java | 64 ++++++----- 2 files changed, 97 insertions(+), 69 deletions(-) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java index c266357..1a0bd29 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java @@ -45,60 +45,72 @@ public String getBindingIdentifier() { @Override public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { - final Map variables = parseParameters(response.getParams()); - long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("")? - 0 : Long.parseLong(response.getTimestamp()); - variables.put("timestamp", new LongVariable(timestamp)); - - final Message message = Message - .builder() - .messageName("result_INOKE_" + response.getCorrelationIdentifier()) - .processInstanceId(response.getCorrelationIdentifier()) - .processVariables(variables) - .build(); - - sendCamundaMessage(message, endpointUrl); + try { + final Map variables = parseParameters(response.getParams()); + long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("") ? + 0 : Long.parseLong(response.getTimestamp()); + variables.put("timestamp", new LongVariable(timestamp)); + + final Message message = Message + .builder() + .messageName("result_INOKE_" + response.getCorrelationIdentifier()) + .processInstanceId(response.getCorrelationIdentifier()) + .processVariables(variables) + .build(); + + sendCamundaMessage(message, endpointUrl); + } catch (Exception e) { + log.error("Failed to send Invocation response to {}. Reason: {}", endpointUrl, e.getMessage()); + } } @Override public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { - final Map variables = parseParameters(response.getParams()); - long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("")? - 0 : Long.parseLong(response.getTimestamp()); - variables.put("timestamp", new LongVariable(timestamp)); - - final Message message = Message - .builder() - .messageName("result_SUBSCRIBE_" + response.getCorrelationIdentifier()) - .processInstanceId(response.getCorrelationIdentifier()) - .processVariables(variables) - .build(); - - sendCamundaMessage(message, endpointUrl); + try { + final Map variables = parseParameters(response.getParams()); + long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("") ? + 0 : Long.parseLong(response.getTimestamp()); + variables.put("timestamp", new LongVariable(timestamp)); + + final Message message = Message + .builder() + .messageName("result_SUBSCRIBE_" + response.getCorrelationIdentifier()) + .processInstanceId(response.getCorrelationIdentifier()) + .processVariables(variables) + .build(); + + sendCamundaMessage(message, endpointUrl); + } catch (Exception e) { + log.error("Failed to send Subscription response to {}. Reason: {}", endpointUrl, e.getMessage()); + } } @Override public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException exception) { - final Map variables = new HashMap<>(); - - if (exception.getCause() instanceof TimeoutException) { - final Variable txHash = new StringVariable(((TimeoutException) exception.getCause()).getTransactionHash()); - final Variable doc = new DoubleVariable(((TimeoutException) exception.getCause()).getDoc()); - variables.put("reachedDoC", doc); - variables.put("transactionHash", txHash); + try { + final Map variables = new HashMap<>(); + + if (exception.getCause() instanceof TimeoutException) { + final Variable txHash = new StringVariable(((TimeoutException) exception.getCause()).getTransactionHash()); + final Variable doc = new DoubleVariable(((TimeoutException) exception.getCause()).getDoc()); + variables.put("reachedDoC", doc); + variables.put("transactionHash", txHash); + } + + final Variable errCode = new LongVariable(exception.getCode()); + final Variable errMessage = new StringVariable(exception.getMessage()); + variables.put("errorCode", errCode); + variables.put("errorMessage", errMessage); + Message message = Message + .builder() + .messageName("error_SUBSCRIBE_" + exception.getCorrelationIdentifier()) + .processInstanceId(exception.getCorrelationIdentifier()) + .processVariables(variables).build(); + + sendCamundaMessage(message, endpointUrl); + } catch (Exception e) { + log.error("Failed to send asynchronous error to {}. Reason: {}", endpointUrl, e.getMessage()); } - - final Variable errCode = new LongVariable(exception.getCode()); - final Variable errMessage = new StringVariable(exception.getMessage()); - variables.put("errorCode", errCode); - variables.put("errorMessage", errMessage); - Message message = Message - .builder() - .messageName("error_SUBSCRIBE_" + exception.getCorrelationIdentifier()) - .processInstanceId(exception.getCorrelationIdentifier()) - .processVariables(variables).build(); - - sendCamundaMessage(message, endpointUrl); } private Map parseParameters(List parameterList) { diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java index 7a66b59..cf74d30 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/jsonrpc/JsonRpcBinding.java @@ -33,9 +33,13 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class JsonRpcBinding implements AbstractBinding { + private static final Logger log = LoggerFactory.getLogger(JsonRpcBinding.class); + @Override public String getBindingIdentifier() { return "json-rpc"; @@ -43,45 +47,57 @@ public String getBindingIdentifier() { @Override public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { - NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); - - builder.param("correlationIdentifier", response.getCorrelationIdentifier()) - .param("parameters", response.getParams() == null ? Collections.emptyList() : response.getParams()) - .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) - .execute(); + try { + NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); + + builder.param("correlationIdentifier", response.getCorrelationIdentifier()) + .param("parameters", response.getParams() == null ? Collections.emptyList() : response.getParams()) + .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) + .execute(); + } catch (Exception e) { + log.error("Failed to send Invocation response to {}. Reason: {}", endpointUrl, e.getMessage()); + } } @Override public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { - NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); - builder.param("correlationIdentifier", response.getCorrelationIdentifier()) - .param("parameters", response.getParams() == null ? Collections.emptyList() : response.getParams()) - .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) - .execute(); + try { + NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); + builder.param("correlationIdentifier", response.getCorrelationIdentifier()) + .param("parameters", response.getParams() == null ? Collections.emptyList() : response.getParams()) + .param("timestamp", response.getTimestamp() == null ? "" : response.getTimestamp()) + .execute(); + } catch (Exception e) { + log.error("Failed to send Subscription response to {}. Reason: {}", endpointUrl, e.getMessage()); + } } @Override public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException exception) { - NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); - - builder = builder.param("errorCode", exception.getCode()); - builder = builder.param("errorMessage", exception.getMessage()); - builder = builder.param("correlationIdentifier", exception.getCorrelationIdentifier()); + try { + NotificationRequestBuilder builder = createNotificationBuilder(endpointUrl); + + builder = builder.param("errorCode", exception.getCode()); + builder = builder.param("errorMessage", exception.getMessage()); + builder = builder.param("correlationIdentifier", exception.getCorrelationIdentifier()); + + if (exception.getCause() instanceof TimeoutException) { + builder = builder.param("transactionHash", + ((TimeoutException) exception.getCause()).getTransactionHash()); + builder = builder.param("reachedDoC", + ((TimeoutException) exception.getCause()).getDoc()); + } - if (exception.getCause() instanceof TimeoutException) { - builder = builder.param("transactionHash", - ((TimeoutException) exception.getCause()).getTransactionHash()); - builder = builder.param("reachedDoC", - ((TimeoutException) exception.getCause()).getDoc()); + builder.execute(); + } catch (Exception e) { + log.error("Failed to send asynchronous error to {}. Reason: {}", endpointUrl, e.getMessage()); } - - builder.execute(); } private NotificationRequestBuilder createNotificationBuilder(final String endpointUrl) { final String METHOD_NAME = "ReceiveResponse"; JsonRpcClient client = new JsonRpcClient(new Transport() { - CloseableHttpClient httpClient = HttpClients.createDefault(); + final CloseableHttpClient httpClient = HttpClients.createDefault(); @NotNull @Override From 920b2e2b07a29acfa776be19defeba88ed259f79 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Wed, 23 Mar 2022 13:19:23 +0100 Subject: [PATCH 22/24] Fix Camunda Binding - fix message names - fix data types - update README --- README.md | 11 ++-- .../scip/bindings/camunda/CamundaBinding.java | 54 +++++++++---------- .../camunda/model/DoubleVariable.java | 2 +- .../bindings/camunda/model/LongVariable.java | 2 +- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index aa99a6f..840b805 100644 --- a/README.md +++ b/README.md @@ -130,12 +130,12 @@ When choosing this format, asynchronous return messages are formatted as follows ```json { - "messageName": "message__", + "messageName": "result_", "processInstanceId": "", "processVariables": { "timestamp": { "value": , - "type": "Number" + "type": "Long" }, "": { "value": "", @@ -152,7 +152,6 @@ When choosing this format, asynchronous return messages are formatted as follows Where: -- ``: is the name of the SCIP method this callback corresponds to. Either `INVOKE` or `SUBSCRIBE`. - ``: is the correlation identifier provided in the corresponding SCIP request previously received. - ``: is the UTC timestamp of the transaction that is related to this request if such a transaction exists. For `INVOKE` method, if the smart contract function required a transaction to be invoked, i.e., because it is @@ -169,11 +168,11 @@ Where: ```json { - "messageName": "error__", + "messageName": "error_", "processInstanceId": "", "processVariables": { "reachedDoC": { - "type": "Number", + "type": "Double", "value": }, "transactionHash": { @@ -185,7 +184,7 @@ Where: "value": "" }, "errorCode": { - "type": "Number", + "type": "Long", "value": } } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java index 1a0bd29..08bc7d2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java @@ -46,19 +46,10 @@ public String getBindingIdentifier() { @Override public void sendInvocationResponse(String endpointUrl, InvocationResponse response) { try { - final Map variables = parseParameters(response.getParams()); - long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("") ? - 0 : Long.parseLong(response.getTimestamp()); - variables.put("timestamp", new LongVariable(timestamp)); - - final Message message = Message - .builder() - .messageName("result_INOKE_" + response.getCorrelationIdentifier()) - .processInstanceId(response.getCorrelationIdentifier()) - .processVariables(variables) - .build(); - - sendCamundaMessage(message, endpointUrl); + sendResultResponse(response.getParams(), + response.getTimestamp(), + response.getCorrelationIdentifier(), + endpointUrl); } catch (Exception e) { log.error("Failed to send Invocation response to {}. Reason: {}", endpointUrl, e.getMessage()); } @@ -67,19 +58,10 @@ public void sendInvocationResponse(String endpointUrl, InvocationResponse respon @Override public void sendSubscriptionResponse(String endpointUrl, SubscriptionResponse response) { try { - final Map variables = parseParameters(response.getParams()); - long timestamp = response.getTimestamp() == null || response.getTimestamp().equals("") ? - 0 : Long.parseLong(response.getTimestamp()); - variables.put("timestamp", new LongVariable(timestamp)); - - final Message message = Message - .builder() - .messageName("result_SUBSCRIBE_" + response.getCorrelationIdentifier()) - .processInstanceId(response.getCorrelationIdentifier()) - .processVariables(variables) - .build(); - - sendCamundaMessage(message, endpointUrl); + sendResultResponse(response.getParams(), + response.getTimestamp(), + response.getCorrelationIdentifier(), + endpointUrl); } catch (Exception e) { log.error("Failed to send Subscription response to {}. Reason: {}", endpointUrl, e.getMessage()); } @@ -99,11 +81,12 @@ public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException final Variable errCode = new LongVariable(exception.getCode()); final Variable errMessage = new StringVariable(exception.getMessage()); + final String messageName = "error_" + exception.getCorrelationIdentifier(); variables.put("errorCode", errCode); variables.put("errorMessage", errMessage); Message message = Message .builder() - .messageName("error_SUBSCRIBE_" + exception.getCorrelationIdentifier()) + .messageName(messageName) .processInstanceId(exception.getCorrelationIdentifier()) .processVariables(variables).build(); @@ -125,6 +108,23 @@ private Map parseParameters(List parameterList) { return variables; } + private void sendResultResponse(List parameters, String timestamp, String correlationIdentifier, + String endpointUrl) { + final Map variables = parseParameters(parameters); + long timestampL = timestamp == null || timestamp.equals("") ? + 0 : Long.parseLong(timestamp); + variables.put("timestamp", new LongVariable(timestampL)); + + final Message message = Message + .builder() + .messageName("result_" + correlationIdentifier) + .processInstanceId(correlationIdentifier) + .processVariables(variables) + .build(); + + sendCamundaMessage(message, endpointUrl); + } + private void sendCamundaMessage(Message message, String endpointUrl) { final Client client = ClientBuilder.newBuilder() //.register(JacksonFeature.class) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java index 54b1d63..ba094df 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/DoubleVariable.java @@ -18,7 +18,7 @@ public class DoubleVariable extends Variable { private final double value; public DoubleVariable(double value) { - super("Number"); + super("Double"); this.value = value; } } diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java index 2763df2..7f3a1e7 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/LongVariable.java @@ -7,7 +7,7 @@ public class LongVariable extends Variable { private final long value; public LongVariable(long value) { - super("Number"); + super("Long"); this.value = value; } } From 459fe77e9e5ab5f35f05a636e1f90909c697d217 Mon Sep 17 00:00:00 2001 From: Ghareeb Falazi Date: Wed, 23 Mar 2022 22:37:06 +0100 Subject: [PATCH 23/24] Update EthereumAdapter.java --- .../de/adaptation/adapters/ethereum/EthereumAdapter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java index e595b5f..3e26ef2 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/adaptation/adapters/ethereum/EthereumAdapter.java @@ -98,6 +98,8 @@ public class EthereumAdapter extends AbstractAdapter { private final int averageBlockTimeSeconds; public EthereumAdapter(final String nodeUrl, final int averageBlockTimeSeconds) { + if (averageBlockTimeSeconds <= 0) + throw new IllegalArgumentException("The average block time must be a value larger than 0"); this.nodeUrl = nodeUrl; this.averageBlockTimeSeconds = averageBlockTimeSeconds; // We use a specific implementation so we can change the polling period (useful for prototypes). From 79c8a28d9f673e7d04c6d5a424d37c65ccaa76f3 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 31 Mar 2022 04:58:27 +0200 Subject: [PATCH 24/24] Remove ProcessInstanceID from Camunda Message --- .../uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java | 2 -- .../uni/stuttgart/de/scip/bindings/camunda/model/Message.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java index 08bc7d2..0707347 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/CamundaBinding.java @@ -87,7 +87,6 @@ public void sendAsyncErrorResponse(String endpointUrl, AsynchronousBalException Message message = Message .builder() .messageName(messageName) - .processInstanceId(exception.getCorrelationIdentifier()) .processVariables(variables).build(); sendCamundaMessage(message, endpointUrl); @@ -118,7 +117,6 @@ private void sendResultResponse(List parameters, String timestamp, St final Message message = Message .builder() .messageName("result_" + correlationIdentifier) - .processInstanceId(correlationIdentifier) .processVariables(variables) .build(); diff --git a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Message.java b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Message.java index 4949a39..9fa8552 100644 --- a/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Message.java +++ b/src/main/java/blockchains/iaas/uni/stuttgart/de/scip/bindings/camunda/model/Message.java @@ -24,8 +24,6 @@ @Jacksonized @JsonIgnoreProperties(ignoreUnknown = true) public class Message { - @NonNull - private String processInstanceId; @NonNull private String messageName; @NonNull