org.eclipse.ditto.model.base.headers.WithDittoHeaders.getDittoHeaders()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中org.eclipse.ditto.model.base.headers.WithDittoHeaders.getDittoHeaders()方法的一些代码示例,展示了WithDittoHeaders.getDittoHeaders()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WithDittoHeaders.getDittoHeaders()方法的具体详情如下:
包路径:org.eclipse.ditto.model.base.headers.WithDittoHeaders
类名称:WithDittoHeaders
方法名:getDittoHeaders

WithDittoHeaders.getDittoHeaders介绍

[英]Returns the DittoHeaders which are associated with this object.
[中]返回与此对象关联的DittoHeaders。

代码示例

代码示例来源:origin: eclipse/ditto

  1. private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
  2. if (object instanceof WithDittoHeaders) {
  3. @Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
  4. if (null != dittoHeaders) {
  5. return dittoHeaders;
  6. }
  7. LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
  8. object);
  9. }
  10. return DittoHeaders.empty();
  11. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
  3. * {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
  4. *
  5. * @param slf4jLogger the SLF4J logger to log with.
  6. * @param withDittoHeaders where to extract a possible correlationId from.
  7. * @param additionalMdcFields additional fields which should bet set to the MDC.
  8. * @param logConsumer the consumer with which the caller must log.
  9. */
  10. public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
  11. final Map<String, String> additionalMdcFields, final Consumer<Logger> logConsumer) {
  12. logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), additionalMdcFields, logConsumer);
  13. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-akka

  1. /**
  2. * Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
  3. * {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
  4. *
  5. * @param slf4jLogger the SLF4J logger to log with.
  6. * @param withDittoHeaders where to extract a possible correlationId from.
  7. * @param logConsumer the consumer with which the caller must log.
  8. */
  9. public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
  10. final Consumer<Logger> logConsumer) {
  11. logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), logConsumer);
  12. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-cluster

  1. private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
  2. if (object instanceof WithDittoHeaders) {
  3. @Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
  4. if (null != dittoHeaders) {
  5. return dittoHeaders;
  6. }
  7. LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
  8. object);
  9. }
  10. return DittoHeaders.empty();
  11. }

代码示例来源:origin: eclipse/ditto

  1. private Jsonifiable.WithPredicate<JsonObject, JsonField> publishResponsePublishedEvent(
  2. final Jsonifiable.WithPredicate<JsonObject, JsonField> jsonifiable) {
  3. if (jsonifiable instanceof CommandResponse) {
  4. // only create ResponsePublished for CommandResponses, not for Events with the same correlationId
  5. ((WithDittoHeaders) jsonifiable).getDittoHeaders()
  6. .getCorrelationId()
  7. .map(ResponsePublished::new)
  8. .ifPresent(eventStream::publish);
  9. }
  10. return jsonifiable;
  11. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * @param withPotentialDittoHeaders the object which potentially contains DittoHeaders from which a
  3. * {@code correlation-id} can be extracted in order to enhance the returned DiagnosticLoggingAdapter
  4. * @return the diagnostic logging adapter.
  5. */
  6. protected DiagnosticLoggingAdapter log(final Object withPotentialDittoHeaders) {
  7. if (withPotentialDittoHeaders instanceof WithDittoHeaders) {
  8. return log(((WithDittoHeaders<?>) withPotentialDittoHeaders).getDittoHeaders());
  9. }
  10. return context.log;
  11. }

代码示例来源:origin: eclipse/ditto

  1. /**
  2. * Enhances the default slf4j {@link org.slf4j.MDC} with a {@code correlationId} of the passed
  3. * {@code withDittoHeaders} (if present), else a random correlation id.
  4. *
  5. * @param withDittoHeaders where to extract a possible correlationId from.
  6. */
  7. public static void enhanceLogWithCorrelationIdOrRandom(final WithDittoHeaders<?> withDittoHeaders) {
  8. LogUtil.enhanceLogWithCorrelationIdOrRandom(withDittoHeaders.getDittoHeaders());
  9. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-connectivity-messaging

  1. private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
  2. response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
  3. try {
  4. finishTrace(correlationId, cause);
  5. } catch (final IllegalArgumentException e) {
  6. log.debug("Trace missing for response: '{}'", response);
  7. }
  8. });
  9. }

代码示例来源:origin: eclipse/ditto

  1. private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
  2. response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
  3. try {
  4. finishTrace(correlationId, cause);
  5. } catch (final IllegalArgumentException e) {
  6. log.debug("Trace missing for response: '{}'", response);
  7. }
  8. });
  9. }

代码示例来源:origin: eclipse/ditto

  1. private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
  2. final DittoHeaders dittoHeaders = response.getDittoHeaders();
  3. final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
  4. .flatMap(EntityTag::fromEntity);
  5. if (entityTagOpt.isPresent()) {
  6. final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
  7. return response.setDittoHeaders(newDittoHeaders);
  8. }
  9. return response;
  10. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence

  1. @Override
  2. protected void doApply(final Object message) {
  3. log.debug("Unexpected message after initialization of actor received: {} - "
  4. + "Terminating this actor and sending <{}> to requester ...", message,
  5. ThingNotAccessibleException.class.getName());
  6. final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
  7. if (message instanceof WithDittoHeaders) {
  8. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  9. }
  10. notifySender(builder.build());
  11. scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
  12. }

代码示例来源:origin: eclipse/ditto

  1. @Override
  2. protected void doApply(final Object message) {
  3. log.debug("Unexpected message after initialization of actor received: {} - "
  4. + "Terminating this actor and sending <{}> to requester ...", message,
  5. ThingNotAccessibleException.class.getName());
  6. final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
  7. if (message instanceof WithDittoHeaders) {
  8. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  9. }
  10. notifySender(builder.build());
  11. scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
  12. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-policies-persistence

  1. private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
  2. final DittoHeaders dittoHeaders = response.getDittoHeaders();
  3. final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
  4. .flatMap(EntityTag::fromEntity);
  5. if (entityTagOpt.isPresent()) {
  6. final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
  7. return response.setDittoHeaders(newDittoHeaders);
  8. }
  9. return response;
  10. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-policies-persistence

  1. @Override
  2. protected void doApply(final Object message) {
  3. final PolicyNotAccessibleException.Builder builder = PolicyNotAccessibleException.newBuilder(policyId);
  4. if (message instanceof WithDittoHeaders) {
  5. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  6. }
  7. notifySender(builder.build());
  8. }

代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence

  1. @Override
  2. protected void doApply(final Object message) {
  3. final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
  4. if (message instanceof WithDittoHeaders) {
  5. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  6. }
  7. notifySender(builder.build());
  8. }

代码示例来源:origin: eclipse/ditto

  1. @Override
  2. protected void doApply(final Object message) {
  3. final PolicyNotAccessibleException.Builder builder = PolicyNotAccessibleException.newBuilder(policyId);
  4. if (message instanceof WithDittoHeaders) {
  5. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  6. }
  7. notifySender(builder.build());
  8. }

代码示例来源:origin: eclipse/ditto

  1. @Override
  2. protected void doApply(final Object message) {
  3. final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
  4. if (message instanceof WithDittoHeaders) {
  5. builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
  6. }
  7. notifySender(builder.build());
  8. }

代码示例来源:origin: eclipse/ditto

  1. public void hasDittoHeaders(final DittoHeaders expectedDittoHeaders) {
  2. final DittoHeaders actualDittoHeaders = actual.getDittoHeaders();
  3. Assertions.assertThat(actualDittoHeaders)
  4. .overridingErrorMessage("Expected object to have command headers\n<%s> but it had\n<%s>",
  5. expectedDittoHeaders, actualDittoHeaders)
  6. .isEqualTo(expectedDittoHeaders);
  7. }

代码示例来源:origin: eclipse/ditto

  1. private static DittoRuntimeException buildError(final WithDittoHeaders withDittoHeaders) {
  2. final JsonParseException jsonException = JsonParseException.newBuilder()
  3. .message("JSON contains forbidden character '\\u0000'")
  4. .build();
  5. return new DittoJsonException(jsonException).setDittoHeaders(withDittoHeaders.getDittoHeaders());
  6. }
  7. }

代码示例来源:origin: eclipse/ditto

  1. public void containsAuthorizationSubject(final String... expectedAuthSubject) {
  2. final DittoHeaders actualDittoHeaders = actual.getDittoHeaders();
  3. final List<String> actualAuthorizationSubjects = actualDittoHeaders.getAuthorizationSubjects();
  4. Assertions.assertThat(actualAuthorizationSubjects)
  5. .overridingErrorMessage("Expected command headers to contain <%s> but it did not", expectedAuthSubject)
  6. .contains(expectedAuthSubject);
  7. }

相关文章