use of de.fraunhofer.iais.eis.RequestInProcessMessage in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractRequestHandler method handleRequest.
@Override
@Nullable
public MultipartResponse handleRequest(@NotNull MultipartRequest multipartRequest, @NotNull ClaimToken claimToken) {
Objects.requireNonNull(multipartRequest);
Objects.requireNonNull(claimToken);
var message = (ContractRequestMessage) multipartRequest.getHeader();
ContractRequest contractRequest;
try {
contractRequest = objectMapper.readValue(multipartRequest.getPayload(), ContractRequest.class);
} catch (IOException e) {
monitor.severe("ContractRequestHandler: Contract Request is invalid", e);
return createBadParametersErrorMultipartResponse(message);
}
var idsWebhookAddress = message.getProperties().get(IDS_WEBHOOK_ADDRESS_PROPERTY);
if (idsWebhookAddress == null || idsWebhookAddress.toString().isBlank()) {
var msg = "Ids webhook address is invalid";
monitor.debug(String.format("ContractRequestHandler: %s", msg));
return createBadParametersErrorMultipartResponse(message, msg);
}
// extract target from contract request
var permission = contractRequest.getPermission().stream().findFirst().orElse(null);
if (permission == null) {
monitor.debug("ContractRequestHandler: Contract Request is invalid");
return createBadParametersErrorMultipartResponse(message);
}
var target = permission.getTarget();
if (target == null || String.valueOf(target).isBlank()) {
monitor.debug("ContractRequestHandler: Contract Request is invalid");
return createBadParametersErrorMultipartResponse(message);
}
// search for matching asset
var assetId = IdsIdParser.parse(String.valueOf(target));
var asset = assetIndex.findById(assetId.getValue());
if (asset == null) {
var msg = "Target id is invalid";
monitor.debug(String.format("ContractRequestHandler: %s", msg));
return createBadParametersErrorMultipartResponse(message, msg);
}
// Create contract offer request
var input = ContractTransformerInput.Builder.newInstance().contract(contractRequest).asset(asset).build();
Result<ContractOffer> result = transformerRegistry.transform(input, ContractOffer.class);
if (result.failed()) {
monitor.debug(String.format("Could not transform contract request: [%s]", String.join(", ", result.getFailureMessages())));
return createBadParametersErrorMultipartResponse(message);
}
var contractOffer = result.getContent();
var requestObj = ContractOfferRequest.Builder.newInstance().protocol(Protocols.IDS_MULTIPART).connectorAddress(idsWebhookAddress.toString()).type(ContractOfferRequest.Type.INITIAL).connectorId(String.valueOf(message.getIssuerConnector())).correlationId(String.valueOf(message.getTransferContract())).contractOffer(contractOffer).build();
Message response;
try {
response = responseMessageFactory.createRequestInProcessMessage(message);
} catch (Exception e) {
if (e instanceof InvalidCorrelationMessageException) {
monitor.debug(String.format("Rejecting invalid IDS contract request message [Msg-ID: %s]", message.getId()), e);
} else {
monitor.severe(String.format("Exception while creating IDS RequestInProcessMessage to answer contract request [Msg-ID: %s]", message.getId()), e);
}
response = responseMessageFactory.createRejectionMessage(message, e);
}
if (response instanceof RequestInProcessMessage) {
// Start negotiation process
negotiationManager.requested(claimToken, requestObj);
}
return MultipartResponse.Builder.newInstance().header(response).build();
}
use of de.fraunhofer.iais.eis.RequestInProcessMessage in project DataSpaceConnector by eclipse-dataspaceconnector.
the class MultipartArtifactRequestSender method getResponseContent.
@Override
protected MultipartRequestInProcessResponse getResponseContent(IdsMultipartParts parts) throws Exception {
Message header = getObjectMapper().readValue(parts.getHeader(), Message.class);
String payload = null;
if (parts.getPayload() != null) {
payload = new String(parts.getPayload().readAllBytes());
}
if (header instanceof RequestInProcessMessage) {
// TODO Update TransferProcess State Machine
} else {
// TODO Update TransferProcess State Machine
}
return MultipartRequestInProcessResponse.Builder.newInstance().header(header).payload(payload).build();
}
use of de.fraunhofer.iais.eis.RequestInProcessMessage in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ContractOfferHandler method handleRequest.
@Override
@Nullable
public MultipartResponse handleRequest(@NotNull MultipartRequest multipartRequest, @NotNull ClaimToken claimToken) {
Objects.requireNonNull(multipartRequest);
Objects.requireNonNull(claimToken);
var message = (ContractOfferMessage) multipartRequest.getHeader();
ContractOffer contractOffer = null;
try {
contractOffer = objectMapper.readValue(multipartRequest.getPayload(), ContractOffer.class);
} catch (IOException e) {
monitor.severe("ContractOfferHandler: Contract Offer is invalid", e);
return createBadParametersErrorMultipartResponse(message);
}
Message response;
try {
response = responseMessageFactory.createRequestInProcessMessage(message);
} catch (Exception e) {
if (e instanceof InvalidCorrelationMessageException) {
monitor.debug(String.format("Rejecting invalid IDS contract offer message [Msg-ID: %s]", message.getId()), e);
} else {
monitor.severe(String.format("Exception while creating IDS RequestInProcessMessage to answer contract offer [Msg-ID: %s]", message.getId()), e);
}
response = responseMessageFactory.createRejectionMessage(message, e);
}
if (response instanceof RequestInProcessMessage) {
// TODO similar implementation to ContractRequestHandler (only required if counter offers supported, not needed for M1)
}
return MultipartResponse.Builder.newInstance().header(response).build();
}
Aggregations