private Route thingMessages(final RequestContext ctx, final DittoHeaders dittoHeaders,
final String thingId, final String inboxOutbox) {
final MessageDirection direction = PATH_INBOX.equalsIgnoreCase(inboxOutbox) ? MessageDirection.TO :
MessageDirection.FROM;
return rawPathPrefix(mergeDoubleSlashes().concat(PathMatchers.segment(PATH_MESSAGES).slash()),
() ->
extractUnmatchedPath(msgSubject ->
parameterOptional(Unmarshaller.sync(Long::parseLong), TIMEOUT_PARAMETER,
optionalTimeout ->
withCustomRequestTimeout(optionalTimeout,
this::checkMessageTimeout,
defaultMessageTimeout,
timeout ->
extractDataBytes(payloadSource ->
handleMessage(ctx, payloadSource,
buildSendThingMessage(
direction,
ctx,
dittoHeaders,
thingId,
msgSubject,
timeout
)
)
)
)
)
)
);
}