private void handleOutboundSignal(final OutboundSignal outbound) { final Signal<?> signal = outbound.getSource(); enhanceLogUtil(signal); log.debug("Handling outbound signal: {}", signal); mapToExternalMessage(signal) .map(message -> OutboundSignalFactory.newMappedOutboundSignal(outbound, message)) .ifPresent(outboundSignal -> publisherActor.forward(outboundSignal, getContext())); }
private void handleOutboundSignal(final OutboundSignal outbound) { final Signal<?> signal = outbound.getSource(); enhanceLogUtil(signal); log.debug("Handling outbound signal: {}", signal); mapToExternalMessage(signal) .map(message -> OutboundSignalFactory.newMappedOutboundSignal(outbound, message)) .ifPresent(outboundSignal -> publisherActor.forward(outboundSignal, getContext())); }
private void handle(final ExternalMessage externalMessage) { ConditionChecker.checkNotNull(externalMessage); final String correlationId = externalMessage.getHeaders().get(DittoHeaderDefinition.CORRELATION_ID.getKey()); LogUtil.enhanceLogWithCorrelationId(log, correlationId); LogUtil.enhanceLogWithCustomField(log, BaseClientData.MDC_CONNECTION_ID, connectionId); log.debug("Handling ExternalMessage: {}", externalMessage); try { final ExternalMessage messageWithAuthSubject = placeholderSubstitution.apply(externalMessage); final Optional<InboundExternalMessage> inboundMessageOpt = processor.process(messageWithAuthSubject); inboundMessageOpt.ifPresent(inboundMessage -> { final Signal<?> signal = inboundMessage.getSignal(); enhanceLogUtil(signal); applySignalIdEnforcement.accept(messageWithAuthSubject, signal); final Signal<?> adjustedSignal = mapHeaders .andThen(mappedHeaders -> adjustHeaders.apply(messageWithAuthSubject, mappedHeaders)) .andThen(signal::setDittoHeaders) .apply(inboundMessage); startTrace(adjustedSignal); // This message is important to check if a command is accepted for a specific connection, as this // happens quite a lot this is going to the debug level. Use best with a connection-id filter. log.debug("Message successfully mapped to signal: '{}'. Passing to conciergeForwarder", adjustedSignal .getType()); conciergeForwarder.tell(adjustedSignal, getSelf()); }); } catch (final DittoRuntimeException e) { handleDittoRuntimeException(e, externalMessage.getHeaders()); } catch (final Exception e) { log.warning("Got <{}> when message was processed: <{}>", e.getClass().getSimpleName(), e.getMessage()); } }
private void handle(final ExternalMessage externalMessage) { ConditionChecker.checkNotNull(externalMessage); final String correlationId = externalMessage.getHeaders().get(DittoHeaderDefinition.CORRELATION_ID.getKey()); LogUtil.enhanceLogWithCorrelationId(log, correlationId); LogUtil.enhanceLogWithCustomField(log, BaseClientData.MDC_CONNECTION_ID, connectionId); log.debug("Handling ExternalMessage: {}", externalMessage); try { final ExternalMessage messageWithAuthSubject = placeholderSubstitution.apply(externalMessage); final Optional<InboundExternalMessage> inboundMessageOpt = processor.process(messageWithAuthSubject); inboundMessageOpt.ifPresent(inboundMessage -> { final Signal<?> signal = inboundMessage.getSignal(); enhanceLogUtil(signal); applySignalIdEnforcement.accept(messageWithAuthSubject, signal); final Signal<?> adjustedSignal = mapHeaders .andThen(mappedHeaders -> adjustHeaders.apply(messageWithAuthSubject, mappedHeaders)) .andThen(signal::setDittoHeaders) .apply(inboundMessage); startTrace(adjustedSignal); // This message is important to check if a command is accepted for a specific connection, as this // happens quite a lot this is going to the debug level. Use best with a connection-id filter. log.debug("Message successfully mapped to signal: '{}'. Passing to conciergeForwarder", adjustedSignal .getType()); conciergeForwarder.tell(adjustedSignal, getSelf()); }); } catch (final DittoRuntimeException e) { handleDittoRuntimeException(e, externalMessage.getHeaders()); } catch (final Exception e) { log.warning("Got <{}> when message was processed: <{}>", e.getClass().getSimpleName(), e.getMessage()); } }
private void handleDittoRuntimeException(final DittoRuntimeException exception, final Map<String, String> dittoHeaders) { final ThingErrorResponse errorResponse = ThingErrorResponse.of(exception, DittoHeaders.newBuilder(exception.getDittoHeaders()) .putHeaders(dittoHeaders) .build()); enhanceLogUtil(exception); final String stackTrace = stackTraceAsString(exception); log.info("Got DittoRuntimeException '{}' when ExternalMessage was processed: {} - {}. StackTrace: {}", exception.getErrorCode(), exception.getMessage(), exception.getDescription().orElse(""), stackTrace); handleCommandResponse(errorResponse); }
private void handleDittoRuntimeException(final DittoRuntimeException exception, final Map<String, String> dittoHeaders) { final ThingErrorResponse errorResponse = ThingErrorResponse.of(exception, DittoHeaders.newBuilder(exception.getDittoHeaders()) .putHeaders(dittoHeaders) .build()); enhanceLogUtil(exception); final String stackTrace = stackTraceAsString(exception); log.info("Got DittoRuntimeException '{}' when ExternalMessage was processed: {} - {}. StackTrace: {}", exception.getErrorCode(), exception.getMessage(), exception.getDescription().orElse(""), stackTrace); handleCommandResponse(errorResponse); }
private void handleCommandResponse(final CommandResponse<?> response) { enhanceLogUtil(response); finishTrace(response); if (response.getDittoHeaders().isResponseRequired()) { if (response.getStatusCodeValue() < HttpStatusCode.BAD_REQUEST.toInt()) { log.debug("Received response: {}", response); } else { log.debug("Received error response: {}", response.toJsonString()); } handleSignal(response); } else { log.debug("Requester did not require response (via DittoHeader '{}') - not mapping back to ExternalMessage", DittoHeaderDefinition.RESPONSE_REQUIRED); } }
private void handleCommandResponse(final CommandResponse<?> response) { enhanceLogUtil(response); finishTrace(response); if (response.getDittoHeaders().isResponseRequired()) { if (response.getStatusCodeValue() < HttpStatusCode.BAD_REQUEST.toInt()) { log.debug("Received response: {}", response); } else { log.debug("Received error response: {}", response.toJsonString()); } handleSignal(response); } else { log.debug("Requester did not require response (via DittoHeader '{}') - not mapping back to ExternalMessage", DittoHeaderDefinition.RESPONSE_REQUIRED); } }