@Override public String toString() { return this.getClass().getName() + " [" + "message='" + getMessage() + '\'' + ", errorCode=" + errorCode + ", statusCode=" + statusCode + ", description='" + description + '\'' + ", href=" + href + ", dittoHeaders=" + dittoHeaders + ']'; }
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 SearchErrorResponse(final DittoRuntimeException dittoRuntimeException, final DittoHeaders dittoHeaders) { super(TYPE, dittoRuntimeException.getStatusCode(), dittoHeaders); this.dittoRuntimeException = requireNonNull(dittoRuntimeException, "The DittoRuntimeException must not be null"); }
private void logDittoRuntimeException(final DittoRuntimeException dre) { if (dre.getDittoHeaders().getCorrelationId().isPresent()) { LogUtil.enhanceLogWithCorrelationId(logger, dre); } logger.info("DittoRuntimeException '{}': {}", dre.getErrorCode(), dre.getMessage()); }
private void logDittoRuntimeException(final DittoRuntimeException exception) { LogUtil.enhanceLogWithCorrelationId(log, exception); final String msgTemplate = "Got DittoRuntimeException '{}' when command via AMQP was processed: {}"; log.info(msgTemplate, exception.getErrorCode(), exception.getMessage()); }
private Optional<ExternalMessage> mapToExternalMessage(final Signal<?> signal) { try { return processor.process(signal); } catch (final DittoRuntimeException e) { log.info("Got DittoRuntimeException during processing Signal: {} - {}", e.getMessage(), e.getDescription().orElse("")); } catch (final Exception e) { log.warning("Got unexpected exception during processing Signal: {}", e.getMessage()); } return Optional.empty(); }
private void handleDittoRuntimeException(final ActorRef delegateActor, final DittoRuntimeException cre) { LogUtil.enhanceLogWithCorrelationId(logger, cre.getDittoHeaders().getCorrelationId()); logger.info("Got 'DittoRuntimeException': {} {}", cre.getClass().getName(), cre.getMessage()); cre.getDittoHeaders().getCorrelationId().ifPresent(outstandingCommandCorrelationIds::remove); if (cre.getDittoHeaders().isResponseRequired()) { delegateActor.forward(cre, getContext()); } else { logger.debug("Requester did not require response (via DittoHeader '{}') - not sending one", DittoHeaderDefinition.RESPONSE_REQUIRED); } }
/** * Creates a new {@code PolicyErrorResponse} for the specified {@code dittoRuntimeException}. * * @param policyId the Policy ID related to the exception. * @param dittoRuntimeException the exception. * @return the response. * @throws NullPointerException if one of the arguments is {@code null}. */ public static PolicyErrorResponse of(final String policyId, final DittoRuntimeException dittoRuntimeException) { return new PolicyErrorResponse(policyId, dittoRuntimeException, dittoRuntimeException.getDittoHeaders()); }
private static ExceptionHandler createExceptionHandler() { return ExceptionHandler.newBuilder().match(DittoRuntimeException.class, cre -> { final Optional<String> correlationIdOpt = Optional.ofNullable(cre.getDittoHeaders()) .flatMap(DittoHeaders::getCorrelationId); if (!correlationIdOpt.isPresent()) { LOGGER.warn("DittoHeaders / correlation-id was missing in DittoRuntimeException <{}>: {}", cre.getClass().getSimpleName(), cre.getMessage()); LOGGER.info("DittoRuntimeException in gateway RootRoute: {}", cre.getMessage()) ); return complete(HttpResponse.create().withStatus(cre.getStatusCode().toInt()) .withEntity(ContentTypes.APPLICATION_JSON, ByteString.fromString(cre.toJsonString()))); }) .match(JsonRuntimeException.class, jre -> {
log.info("Got DittoRuntimeException '{}' when command was parsed: {}", e.getErrorCode(), e.getMessage()); if (headers != null) { messageMappingProcessor.forward(e.setDittoHeaders(DittoHeaders.of(headers)), getContext());
private void handleDittoRuntimeException(final DittoRuntimeException dittoRuntimeException) { LogUtil.enhanceLogWithCorrelationId(log, dittoRuntimeException); log.warning("Received DittoRuntimeException {} from {}: {}", dittoRuntimeException.getClass().getName(), getSender(), dittoRuntimeException); addCommandResponse(DevOpsErrorResponse.of(null, null, dittoRuntimeException.toJson(), dittoRuntimeException.getDittoHeaders())); }
/** * Construct a builder {@code b} such that {@code b.build()} has identical class and fields as {@code this}. * <p> * A subclass should extend this method if it adds another field. * * @return A builder to construct an identical copy of {@code this}. */ public DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> getBuilder() { return getEmptyBuilder() .dittoHeaders(dittoHeaders) .message(getMessage()) .cause(getCause()) .description(description) .href(href); }
/** * Returns a new mutable builder with a fluent API for a {@code dittoRuntimeException}. The builder is already * initialized with the properties of the given exception. * * @param dittoRuntimeException the exception to be copied. * @return the new builder. * @throws NullPointerException if {@code dittoRuntimeException} is {@code null}. */ public static DittoRuntimeExceptionBuilder<? extends DittoRuntimeException> newBuilder( final DittoRuntimeException dittoRuntimeException) { checkNotNull(dittoRuntimeException, "dittoRuntimeException to be copied"); return dittoRuntimeException.getBuilder() .dittoHeaders(dittoRuntimeException.dittoHeaders) .message(dittoRuntimeException.getMessage()) .description(dittoRuntimeException.description) .cause(dittoRuntimeException.getCause()) .href(dittoRuntimeException.href); }
messageMappingProcessor.forward(externalMessage, getContext()); } catch (final DittoRuntimeException e) { log.warning("Processing delivery {} failed: {}", envelope.getDeliveryTag(), e.getMessage(), e); if (headers != null) { messageMappingProcessor.forward(e.setDittoHeaders(DittoHeaders.of(headers)), getContext());
@Override public String getManifest() { return getErrorCode(); }
/** * Returns all non hidden marked fields of this exception. * * @return a JSON object representation of this exception including only non hidden marked fields. */ @Override public JsonObject toJson() { return toJson(FieldType.notHidden()); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final Predicate<JsonField> nonNullAndCustomDefined = predicate.and(JsonField.isValueNonNull()); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder() .set(JsonFields.STATUS, statusCode.toInt(), nonNullAndCustomDefined) .set(JsonFields.ERROR_CODE, errorCode, nonNullAndCustomDefined) .set(JsonFields.MESSAGE, getMessage(), nonNullAndCustomDefined) .set(JsonFields.DESCRIPTION, description, nonNullAndCustomDefined) .set(JsonFields.HREF, href != null ? href.toString() : null, nonNullAndCustomDefined); appendToJson(jsonObjectBuilder, nonNullAndCustomDefined); return jsonObjectBuilder.build(); }
/** * Creates a {@code ThingErrorResponse} from the given {@code adaptable}. * * @param adaptable the adaptable to convert. * @return the ThingErrorResponse. */ private ThingErrorResponse thingErrorResponseFromAdaptable(final Adaptable adaptable) { final DittoHeaders dittoHeaders = headerTranslator.fromExternalHeaders(adaptable.getHeaders().orElse(DittoHeaders.empty())); final TopicPath topicPath = adaptable.getTopicPath(); final DittoRuntimeException dittoRuntimeException = adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(jsonObject -> { try { return errorRegistry.parse(jsonObject, dittoHeaders); } catch (final JsonTypeNotParsableException e) { return DittoRuntimeException.fromUnknownErrorJson(jsonObject, dittoHeaders) .orElseThrow(() -> e); } }) .orElseThrow(() -> new JsonMissingFieldException(ThingCommandResponse.JsonFields.PAYLOAD)); final String thingId = topicPath.getNamespace() + ":" + topicPath.getId(); return ThingErrorResponse.of(thingId, dittoRuntimeException, dittoRuntimeException.getDittoHeaders()); }
signal = adapter.fromAdaptable(jsonifiableAdaptable); } catch (final DittoRuntimeException e) { throw e.setDittoHeaders(e.getDittoHeaders().toBuilder().origin(connectionCorrelationId).build());
private HttpResponse buildResponseWithoutHeadersFromDittoRuntimeException(final DittoRuntimeException dre) { final HttpResponse responseWithoutHeaders = HttpResponse.create().withStatus(dre.getStatusCode().toInt()); if (HttpStatusCode.NOT_MODIFIED.equals(dre.getStatusCode())) { return responseWithoutHeaders; } else { return responseWithoutHeaders.withEntity(CONTENT_TYPE_JSON, ByteString.fromString(dre.toJsonString())); } }