本文整理了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
[英]Returns the DittoHeaders which are associated with this object.
[中]返回与此对象关联的DittoHeaders。
代码示例来源:origin: eclipse/ditto
private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
if (object instanceof WithDittoHeaders) {
@Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
if (null != dittoHeaders) {
return dittoHeaders;
}
LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
object);
}
return DittoHeaders.empty();
}
代码示例来源:origin: eclipse/ditto
/**
* Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
* {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
*
* @param slf4jLogger the SLF4J logger to log with.
* @param withDittoHeaders where to extract a possible correlationId from.
* @param additionalMdcFields additional fields which should bet set to the MDC.
* @param logConsumer the consumer with which the caller must log.
*/
public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
final Map<String, String> additionalMdcFields, final Consumer<Logger> logConsumer) {
logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), additionalMdcFields, logConsumer);
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-akka
/**
* Enhances the MDC around the passed SLF4J {@code Logger} with the {@code correlation-id} extracted from the passed
* {@code withDittoHeaders}. Invokes the passed in {@code logConsumer} around the MDC setting/removing.
*
* @param slf4jLogger the SLF4J logger to log with.
* @param withDittoHeaders where to extract a possible correlationId from.
* @param logConsumer the consumer with which the caller must log.
*/
public static void logWithCorrelationId(final Logger slf4jLogger, final WithDittoHeaders<?> withDittoHeaders,
final Consumer<Logger> logConsumer) {
logWithCorrelationId(slf4jLogger, withDittoHeaders.getDittoHeaders(), logConsumer);
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-cluster
private static DittoHeaders getDittoHeadersOrEmpty(final Object object) {
if (object instanceof WithDittoHeaders) {
@Nullable final DittoHeaders dittoHeaders = ((WithDittoHeaders) object).getDittoHeaders();
if (null != dittoHeaders) {
return dittoHeaders;
}
LOG.warn("Object <{}> did not contain DittoHeaders although it should! Using empty DittoHeaders instead.",
object);
}
return DittoHeaders.empty();
}
代码示例来源:origin: eclipse/ditto
private Jsonifiable.WithPredicate<JsonObject, JsonField> publishResponsePublishedEvent(
final Jsonifiable.WithPredicate<JsonObject, JsonField> jsonifiable) {
if (jsonifiable instanceof CommandResponse) {
// only create ResponsePublished for CommandResponses, not for Events with the same correlationId
((WithDittoHeaders) jsonifiable).getDittoHeaders()
.getCorrelationId()
.map(ResponsePublished::new)
.ifPresent(eventStream::publish);
}
return jsonifiable;
}
代码示例来源:origin: eclipse/ditto
/**
* @param withPotentialDittoHeaders the object which potentially contains DittoHeaders from which a
* {@code correlation-id} can be extracted in order to enhance the returned DiagnosticLoggingAdapter
* @return the diagnostic logging adapter.
*/
protected DiagnosticLoggingAdapter log(final Object withPotentialDittoHeaders) {
if (withPotentialDittoHeaders instanceof WithDittoHeaders) {
return log(((WithDittoHeaders<?>) withPotentialDittoHeaders).getDittoHeaders());
}
return context.log;
}
代码示例来源:origin: eclipse/ditto
/**
* Enhances the default slf4j {@link org.slf4j.MDC} with a {@code correlationId} of the passed
* {@code withDittoHeaders} (if present), else a random correlation id.
*
* @param withDittoHeaders where to extract a possible correlationId from.
*/
public static void enhanceLogWithCorrelationIdOrRandom(final WithDittoHeaders<?> withDittoHeaders) {
LogUtil.enhanceLogWithCorrelationIdOrRandom(withDittoHeaders.getDittoHeaders());
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-connectivity-messaging
private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
try {
finishTrace(correlationId, cause);
} catch (final IllegalArgumentException e) {
log.debug("Trace missing for response: '{}'", response);
}
});
}
代码示例来源:origin: eclipse/ditto
private void finishTrace(final WithDittoHeaders<? extends Signal> response, @Nullable final Throwable cause) {
response.getDittoHeaders().getCorrelationId().ifPresent(correlationId -> {
try {
finishTrace(correlationId, cause);
} catch (final IllegalArgumentException e) {
log.debug("Trace missing for response: '{}'", response);
}
});
}
代码示例来源:origin: eclipse/ditto
private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
final DittoHeaders dittoHeaders = response.getDittoHeaders();
final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
.flatMap(EntityTag::fromEntity);
if (entityTagOpt.isPresent()) {
final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
return response.setDittoHeaders(newDittoHeaders);
}
return response;
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence
@Override
protected void doApply(final Object message) {
log.debug("Unexpected message after initialization of actor received: {} - "
+ "Terminating this actor and sending <{}> to requester ...", message,
ThingNotAccessibleException.class.getName());
final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
}
代码示例来源:origin: eclipse/ditto
@Override
protected void doApply(final Object message) {
log.debug("Unexpected message after initialization of actor received: {} - "
+ "Terminating this actor and sending <{}> to requester ...", message,
ThingNotAccessibleException.class.getName());
final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
scheduleCheckForThingActivity(activityCheckInterval.getSeconds());
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-policies-persistence
private WithDittoHeaders appendETagHeader(final C command, final WithDittoHeaders response) {
final DittoHeaders dittoHeaders = response.getDittoHeaders();
final Optional<EntityTag> entityTagOpt = determineETagEntity(command)
.flatMap(EntityTag::fromEntity);
if (entityTagOpt.isPresent()) {
final DittoHeaders newDittoHeaders = dittoHeaders.toBuilder().eTag(entityTagOpt.get()).build();
return response.setDittoHeaders(newDittoHeaders);
}
return response;
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-policies-persistence
@Override
protected void doApply(final Object message) {
final PolicyNotAccessibleException.Builder builder = PolicyNotAccessibleException.newBuilder(policyId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-things-persistence
@Override
protected void doApply(final Object message) {
final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
}
代码示例来源:origin: eclipse/ditto
@Override
protected void doApply(final Object message) {
final PolicyNotAccessibleException.Builder builder = PolicyNotAccessibleException.newBuilder(policyId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
}
代码示例来源:origin: eclipse/ditto
@Override
protected void doApply(final Object message) {
final ThingNotAccessibleException.Builder builder = ThingNotAccessibleException.newBuilder(thingId);
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
notifySender(builder.build());
}
代码示例来源:origin: eclipse/ditto
public void hasDittoHeaders(final DittoHeaders expectedDittoHeaders) {
final DittoHeaders actualDittoHeaders = actual.getDittoHeaders();
Assertions.assertThat(actualDittoHeaders)
.overridingErrorMessage("Expected object to have command headers\n<%s> but it had\n<%s>",
expectedDittoHeaders, actualDittoHeaders)
.isEqualTo(expectedDittoHeaders);
}
代码示例来源:origin: eclipse/ditto
private static DittoRuntimeException buildError(final WithDittoHeaders withDittoHeaders) {
final JsonParseException jsonException = JsonParseException.newBuilder()
.message("JSON contains forbidden character '\\u0000'")
.build();
return new DittoJsonException(jsonException).setDittoHeaders(withDittoHeaders.getDittoHeaders());
}
}
代码示例来源:origin: eclipse/ditto
public void containsAuthorizationSubject(final String... expectedAuthSubject) {
final DittoHeaders actualDittoHeaders = actual.getDittoHeaders();
final List<String> actualAuthorizationSubjects = actualDittoHeaders.getAuthorizationSubjects();
Assertions.assertThat(actualAuthorizationSubjects)
.overridingErrorMessage("Expected command headers to contain <%s> but it did not", expectedAuthSubject)
.contains(expectedAuthSubject);
}
内容来源于网络,如有侵权,请联系作者删除!