Skip to content

Commit

Permalink
[#1228] fixed classCastException in usage of CommandHeaderRestoration
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Dec 14, 2021
1 parent 75d98da commit d55cfd9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ default JsonSchemaVersion getImplementedSchemaVersion() {

/**
* Indicates whether this response is of a type contained in
* {@link org.eclipse.ditto.base.model.headers.DittoHeaderDefinition#EXPECTED_RESPONSE_TYPES} header or whether it
* was a {@code "live"} response which always is expected.
* {@link org.eclipse.ditto.base.model.headers.DittoHeaderDefinition#EXPECTED_RESPONSE_TYPES} header.
*
* @return true if this response is expected, false if not.
* @since 1.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ static boolean isLiveQueryCommandWithTimeoutStrategy(final Signal<?> command) {
SignalInformationPoint.isChannelLive(command);
}

private static <T extends DittoHeadersSettable<T>> T setAdditionalHeaders(final DittoHeadersSettable<T> settable,
private static <T extends DittoHeadersSettable<?>> T setAdditionalHeaders(final T settable,
final DittoHeaders commandHeaders) {
// TODO: ensure pre-enforcer headers in responses
final T dittoHeadersSettable =
CommandHeaderRestoration.restoreCommandConnectivityHeaders(settable, commandHeaders);
return dittoHeadersSettable.setDittoHeaders(dittoHeadersSettable.getDittoHeaders()
final DittoHeaders dittoHeaders = settable.getDittoHeaders();
final DittoHeadersSettable<?> theSettable = settable.setDittoHeaders(dittoHeaders
.toBuilder()
.putHeaders(getAdditionalLiveResponseHeaders(dittoHeadersSettable.getDittoHeaders()))
.putHeaders(getAdditionalLiveResponseHeaders(dittoHeaders))
.build());
return (T) CommandHeaderRestoration.restoreCommandConnectivityHeaders(theSettable, commandHeaders);
}

private static CompletionStage<ThingQueryCommandResponse<?>> applyTimeoutStrategy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,11 @@ private int dispatchIncomingSignal(final IncomingSignal incomingSignal) {
return ConnectivityErrorResponse.of(dre, originalHeaders);
}
})
.thenAccept(response -> sender.tell(response, ActorRef.noSender()));
.thenAccept(response -> sender.tell(response, ActorRef.noSender()))
.exceptionally(throwable -> {
logger.warn("Error during dispatching incoming signal <{}>", incomingSignal, throwable);
return null;
});
} else {
proxyActor.tell(signal, sender);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public Receive createReceive() {
.build();
}

private void forwardCommandResponse(final WithDittoHeaders acknowledgement) {
log.withCorrelationId(acknowledgement)
private void forwardCommandResponse(final WithDittoHeaders acknowledgementOrResponse) {
log.withCorrelationId(acknowledgementOrResponse)
.debug("Received Acknowledgement / live CommandResponse, forwarding to original requester <{}>: " +
"<{}>", acknowledgementRequester, acknowledgement);
acknowledgementRequester.tell(acknowledgement, getSender());
"<{}>", acknowledgementRequester, acknowledgementOrResponse);
acknowledgementRequester.tell(acknowledgementOrResponse, getSender());
}

private void handleReceiveTimeout(final ReceiveTimeout receiveTimeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private CommandHeaderRestoration() {
*/
@SuppressWarnings("unchecked")
public static <T extends DittoHeadersSettable<?>> T restoreCommandConnectivityHeaders(
final DittoHeadersSettable<?> signal,
final T signal,
final DittoHeaders headersToRestoreFrom) {

final var signalDittoHeaders = signal.getDittoHeaders();
Expand Down

0 comments on commit d55cfd9

Please sign in to comment.