Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #132 from FraunhoferISST/develop
Browse files Browse the repository at this point in the history
Release v4.0.2
  • Loading branch information
juliapampus authored Feb 4, 2021
2 parents 13ece8f + 0ce1279 commit 2606b5e
Show file tree
Hide file tree
Showing 18 changed files with 407 additions and 146 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Changelog
All notable changes to this project will be documented in this file.

## [4.0.2] - 2021-02-04

### Added
- Add message handler for `ContractAgreementMessage`.

### Changed
- Answer with a `MessageProcessedNotificationMessage` to the consumer's `ContractAgreementMessage`.
- Save the `ContractAgreement` to the database and the Clearing House when the second
`AgreementMessage` has been processed.
- Refine exception handling in the message building and sending process.
- Update from IDS Framework v4.0.2 to v4.0.3.

### Fixed
- Send `ContractAgreementMessage` as request message.

## [4.0.1] - 2021-01-28

### Changed
Expand Down
2 changes: 1 addition & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ info:
license:
name: Apache License, Version 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.txt
version: 4.0.1
version: 4.0.2
servers:
- url: https://localhost:8080
description: Generated server url
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
</profiles>

<properties>
<revision>4.0.1</revision>
<ids-framework.version>4.0.2</ids-framework.version>
<revision>4.0.2</revision>
<ids-framework.version>4.0.3</ids-framework.version>

<java.version>11</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.fraunhofer.isst.dataspaceconnector.exceptions.contract.ContractException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageBuilderException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageNotSentException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageResponseException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.resource.InvalidResourceException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.resource.ResourceException;
Expand Down Expand Up @@ -123,17 +124,22 @@ public ResponseEntity<String> requestMetadata(
try {
// Send DescriptionRequestMessage.
descriptionMessageService.setRequestParameters(recipient, resourceId);
response = descriptionMessageService.sendMessage("");
response = descriptionMessageService.sendRequestMessage("");
} catch (MessageBuilderException exception) {
// Failed to send the description request message.
LOGGER.info("Failed to send or build a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to send description request message.",
// Failed to build the description request message.
LOGGER.warn("Failed to build a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to build the ids message.",
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MessageResponseException exception) {
// Failed to read the description response message.
LOGGER.info("Received invalid ids response. [exception=({})]", exception.getMessage());
LOGGER.debug("Received invalid ids response. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to read the ids response message.",
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MessageNotSentException exception) {
// Failed to send the description request message.
LOGGER.warn("Failed to send a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to send the ids message.",
HttpStatus.INTERNAL_SERVER_ERROR);
}

String header, payload;
Expand Down Expand Up @@ -206,21 +212,26 @@ public ResponseEntity<String> requestContract(
final var request = negotiationService.buildContractRequest(contractOffer, artifactId);
// Send ContractRequestMessage.
contractMessageService.setRequestParameters(recipient, request.getId());
response = contractMessageService.sendMessage(request.toRdf());
response = contractMessageService.sendRequestMessage(request.toRdf());
} catch (IllegalArgumentException exception) {
LOGGER.warn("Failed to build contract request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to build contract request.",
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MessageBuilderException exception) {
// Failed to send the contract request message.
LOGGER.info("Failed to send or build a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to send contract request message.",
HttpStatus.INTERNAL_SERVER_ERROR);
// Failed to build the contract request message.
LOGGER.warn("Failed to build a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to build the ids message.",
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MessageResponseException exception) {
// Failed to read the contract response message.
LOGGER.info("Received invalid ids response. [exception=({})]", exception.getMessage());
LOGGER.debug("Received invalid ids response. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to read the ids response message.",
HttpStatus.INTERNAL_SERVER_ERROR);
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MessageNotSentException exception) {
// Failed to send the contract request message.
LOGGER.warn("Failed to send a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to send the ids message.",
HttpStatus.INTERNAL_SERVER_ERROR);
}

String header, payload;
Expand Down Expand Up @@ -315,17 +326,22 @@ public ResponseEntity<String> requestData(
try {
// Send ArtifactRequestMessage.
artifactMessageService.setRequestParameters(recipient, artifactId, contractId);
response = artifactMessageService.sendMessage("");
response = artifactMessageService.sendRequestMessage("");
} catch (MessageBuilderException exception) {
// Failed to send the artifact request message.
LOGGER.info("Failed to send or build a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to send artifact request message.",
HttpStatus.INTERNAL_SERVER_ERROR);
// Failed to build the artifact request message.
LOGGER.warn("Failed to build a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to build the ids message.",
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MessageResponseException exception) {
// Failed to read the artifact response message.
LOGGER.info("Received invalid ids response. [exception=({})]", exception.getMessage());
LOGGER.debug("Received invalid ids response. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to read the ids response message.",
HttpStatus.INTERNAL_SERVER_ERROR);
HttpStatus.INTERNAL_SERVER_ERROR);
} catch (MessageNotSentException exception) {
// Failed to send the artifact request message.
LOGGER.warn("Failed to send a request. [exception=({})]", exception.getMessage());
return new ResponseEntity<>("Failed to send the ids message.",
HttpStatus.INTERNAL_SERVER_ERROR);
}

String header, payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ public class MessageNotSentException extends MessageException {
public MessageNotSentException(String msg) {
super(msg);
}

/**
* Construct a MessageNotSentException with the specified detail message and cause.
*
* @param msg The detail message.
* @param cause The cause.
*/
public MessageNotSentException(String msg, Throwable cause) {
super(msg, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public MessageService(IDSHttpService idsHttpService, IdsUtils idsUtils,
* Build an IDS message as request header.
*
* @return the message.
* @throws MessageException if the message could not be created.
* @throws MessageBuilderException if the message could not be created.
*/
public abstract Message buildRequestHeader() throws MessageException;
public abstract Message buildRequestHeader() throws MessageBuilderException;

/**
* Build an IDS message as response header.
*
* @return the message.
* @throws MessageException if the message could not be created.
* @throws MessageBuilderException if the message could not be created.
*/
public abstract Message buildResponseHeader() throws MessageException;
public abstract Message buildResponseHeader() throws MessageBuilderException;

/**
* Returns the recipient.
Expand All @@ -97,13 +97,13 @@ public SerializerProvider getSerializerProvider() {
}

/**
* Sends an IDS message with header and payload using the IDS Framework.
* Sends an IDS request message with header and payload using the IDS Framework.
*
* @param payload the message payload.
* @return the HTTP response.
* @throws MessageException if a header could not be built or the message could not be sent.
*/
public Map<String, String> sendMessage(String payload) throws MessageException {
public Map<String, String> sendRequestMessage(String payload) throws MessageException {
Message message;
try {
message = buildRequestHeader();
Expand All @@ -118,9 +118,37 @@ public Map<String, String> sendMessage(String payload) throws MessageException {
} catch (ClaimsException exception) {
LOGGER.warn("Invalid DAT in incoming message. [exception=({})]", exception.getMessage());
throw new MessageResponseException("Unexpected message answer.", exception);
} catch (MessageNotSentException | FileUploadException | IOException exception) {
} catch (FileUploadException | IOException exception) {
LOGGER.warn("Message could not be sent. [exception=({})]", exception.getMessage());
throw new MessageBuilderException("Message could not be sent.", exception);
throw new MessageNotSentException("Message could not be sent.", exception);
}
}

/**
* Sends an IDS response message with header and payload using the IDS Framework.
*
* @param payload the message payload.
* @return the HTTP response.
* @throws MessageException if a header could not be built or the message could not be sent.
*/
public Map<String, String> sendResponseMessage(String payload) throws MessageException {
Message message;
try {
message = buildResponseHeader();
} catch (MessageBuilderException exception) {
LOGGER.warn("Message could not be built. [exception=({})]", exception.getMessage());
throw new MessageBuilderException("Message could not be built.", exception);
}

try {
MultipartBody body = InfomodelMessageBuilder.messageWithString(message, payload);
return idsHttpService.sendAndCheckDat(body, getRecipient());
} catch (ClaimsException exception) {
LOGGER.warn("Invalid DAT in incoming message. [exception=({})]", exception.getMessage());
throw new MessageResponseException("Unexpected message answer.", exception);
} catch (FileUploadException | IOException exception) {
LOGGER.warn("Message could not be sent. [exception=({})]", exception.getMessage());
throw new MessageNotSentException("Message could not be sent.", exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.fraunhofer.isst.dataspaceconnector.exceptions.RequestFormatException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.contract.ContractException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.contract.UnsupportedPatternException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageBuilderException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageNotSentException;
import de.fraunhofer.isst.dataspaceconnector.exceptions.message.MessageResponseException;
Expand Down Expand Up @@ -73,15 +74,16 @@ public NegotiationService(ContractMessageService contractMessageService,
* @param artifactId ID of the artifact.
* @return The http response.
* @throws IllegalArgumentException if the contract could not be deserialized.
* @throws MessageException if the message could not be built.
*/
public ContractRequest buildContractRequest(String contractAsString, URI artifactId)
throws IllegalArgumentException {
throws IllegalArgumentException, MessageException {
Contract contract;
try {
// Validate contract input.
contract = policyHandler.validateContract(contractAsString);
} catch (RequestFormatException exception) {
LOGGER.warn("Could not deserialize contract. [exception=({})]",
LOGGER.debug("Could not deserialize contract. [exception=({})]",
exception.getMessage());
throw new RequestFormatException("Malformed contract. " + exception.getMessage());
}
Expand Down Expand Up @@ -132,13 +134,22 @@ public URI contractAccepted(URI recipient, String header, String payload) throws
// Send ContractAgreementMessage to recipient.
messageService.setResponseParameters(recipient, correlationMessage, contract.getId());
ContractAgreement agreement = messageService.buildContractAgreement(contract);
response = messageService.sendMessage(agreement.toRdf());
} catch (MessageException exception) {
// Failed to send a contract agreement message.
LOGGER.warn("Could not send contract agreement message. [exception=({})]",
exception.getMessage());
throw new MessageNotSentException("Could not send contract agreement message. "
+ exception.getMessage());
response = messageService.sendResponseMessage(agreement.toRdf());
} catch (MessageBuilderException exception) {
// Failed to build the contract agreement message.
LOGGER.warn("Failed to build a request. [exception=({})]", exception.getMessage());
throw new MessageNotSentException("Failed to build the ids message. " +
"[exception=({})]", exception);
} catch (MessageResponseException exception) {
// Failed to read the contract agreement message.
LOGGER.debug("Received invalid ids response. [exception=({})]", exception.getMessage());
throw new MessageResponseException("Failed to read the ids response message. " +
"[exception=({})]", exception);
} catch (MessageNotSentException exception) {
// Failed to send the contract agreement message.
LOGGER.warn("Failed to send a request. [exception=({})]", exception.getMessage());
throw new MessageNotSentException("Failed to send the ids message. " +
"[exception=({})]", exception);
}

if (response != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
import java.util.UUID;

/**
* This @{@link ArtifactMessageHandler} handles all
* This @{@link ArtifactRequestHandler} handles all
* incoming messages that have a {@link de.fraunhofer.iais.eis.ArtifactRequestMessageImpl} as part
* one in the multipart message. This header must have the correct '@type' reference as defined in
* the {@link de.fraunhofer.iais.eis.ArtifactRequestMessageImpl} JsonTypeName annotation.
*/
@Component
@SupportedMessageType(ArtifactRequestMessageImpl.class)
public class ArtifactMessageHandler implements MessageHandler<ArtifactRequestMessageImpl> {
public class ArtifactRequestHandler implements MessageHandler<ArtifactRequestMessageImpl> {

public static final Logger LOGGER = LoggerFactory.getLogger(ArtifactMessageHandler.class);
public static final Logger LOGGER = LoggerFactory.getLogger(ArtifactRequestHandler.class);

private final ResourceService resourceService;
private final PolicyHandler policyHandler;
Expand All @@ -67,11 +67,11 @@ public class ArtifactMessageHandler implements MessageHandler<ArtifactRequestMes
* @throws IllegalArgumentException if one of the passed parameters is null
*/
@Autowired
public ArtifactMessageHandler(OfferedResourceServiceImpl offeredResourceService,
PolicyHandler policyHandler, NegotiationService negotiationService,
ArtifactMessageService messageService,
ContractAgreementService contractAgreementService,
ConfigurationContainer configurationContainer)
public ArtifactRequestHandler(OfferedResourceServiceImpl offeredResourceService,
PolicyHandler policyHandler, NegotiationService negotiationService,
ArtifactMessageService messageService,
ContractAgreementService contractAgreementService,
ConfigurationContainer configurationContainer)
throws IllegalArgumentException {
if (offeredResourceService == null)
throw new IllegalArgumentException("The OfferedResourceService cannot be null.");
Expand Down Expand Up @@ -122,7 +122,7 @@ public MessageResponse handleMessage(ArtifactRequestMessageImpl requestMessage,

// Check if version is supported.
if (!messageService.versionSupported(requestMessage.getModelVersion())) {
LOGGER.warn("Information Model version of requesting connector is not supported.");
LOGGER.debug("Information Model version of requesting connector is not supported.");
return ErrorResponse.withDefaultHeader(
RejectionReason.VERSION_NOT_SUPPORTED,
"Information model version not supported.",
Expand Down
Loading

0 comments on commit 2606b5e

Please sign in to comment.