-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #559: Introduced new internal module for
Signal
related funct…
…ionality. * Made `CommandAndCommandResponseMatchingValidator` more generic to make it re-usable throughout several services. * Introduced `HttpPushRoundTripSignalValidator` to substitute previous version of `CommandAndCommandResponseMatchingValidator` which was specialized for HTTP push scenario. Signed-off-by: Juergen Fickel <juergen.fickel@bosch.io>
- Loading branch information
Juergen Fickel
committed
Oct 22, 2021
1 parent
388e000
commit 1e18aaf
Showing
20 changed files
with
1,293 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 0 additions & 207 deletions
207
...o/connectivity/service/messaging/httppush/CommandAndCommandResponseMatchingValidator.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ipse/ditto/connectivity/service/messaging/httppush/HttpPushRoundTripSignalsValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.connectivity.service.messaging.httppush; | ||
|
||
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
import javax.annotation.concurrent.NotThreadSafe; | ||
|
||
import org.eclipse.ditto.base.model.common.HttpStatus; | ||
import org.eclipse.ditto.base.model.signals.SignalWithEntityId; | ||
import org.eclipse.ditto.base.model.signals.commands.CommandResponse; | ||
import org.eclipse.ditto.connectivity.model.MessageSendingFailedException; | ||
import org.eclipse.ditto.connectivity.service.messaging.monitoring.logs.ConnectionLogger; | ||
import org.eclipse.ditto.internal.models.signal.correlation.CommandAndCommandResponseMatchingValidator; | ||
|
||
/** | ||
* Validates that a specified {@link org.eclipse.ditto.base.model.signals.SignalWithEntityId} and | ||
* {@link CommandResponse} are associated with each other, i.e. that the command response correlates to a command. | ||
* <p> | ||
* Both signals correlate if | ||
* <ul> | ||
* <li>their correlation IDs match,</li> | ||
* <li>their signal types match and</li> | ||
* <li>their entity IDs match.</li> | ||
* </ul> | ||
* </p> | ||
* <p> | ||
* If any of the above evaluates to {@code false} a {@link MessageSendingFailedException} is thrown with a detail | ||
* message describing the cause. | ||
* Furthermore the exception gets logged for the command response via | ||
* {@link ConnectionLogger#failure(org.eclipse.ditto.base.model.signals.Signal, org.eclipse.ditto.base.model.exceptions.DittoRuntimeException)}. | ||
* </p> | ||
*/ | ||
@NotThreadSafe | ||
final class HttpPushRoundTripSignalsValidator implements BiConsumer<SignalWithEntityId<?>, CommandResponse<?>> { | ||
|
||
private final ConnectionLogger connectionLogger; | ||
private final CommandAndCommandResponseMatchingValidator validator; | ||
|
||
private HttpPushRoundTripSignalsValidator(final ConnectionLogger connectionLogger) { | ||
this.connectionLogger = connectionLogger; | ||
validator = CommandAndCommandResponseMatchingValidator.getInstance(); | ||
} | ||
|
||
static HttpPushRoundTripSignalsValidator newInstance(final ConnectionLogger connectionLogger) { | ||
return new HttpPushRoundTripSignalsValidator(checkNotNull(connectionLogger, "connectionLogger")); | ||
} | ||
|
||
@Override | ||
public void accept(final SignalWithEntityId<?> signalWithEntityId, final CommandResponse<?> commandResponse) { | ||
final var validationResult = validator.apply(signalWithEntityId, commandResponse); | ||
if (!validationResult.isSuccess()) { | ||
final var messageSendingFailedException = MessageSendingFailedException.newBuilder() | ||
.httpStatus(HttpStatus.BAD_REQUEST) | ||
.message(validationResult.getDetailMessageOrThrow()) | ||
.dittoHeaders(signalWithEntityId.getDittoHeaders()) | ||
.build(); | ||
connectionLogger.failure(commandResponse, messageSendingFailedException); | ||
throw messageSendingFailedException; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.