/
ExternalMessage.java
128 lines (107 loc) · 3.48 KB
/
ExternalMessage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 2017-2018 Bosch Software Innovations GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/index.php
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.models.connectivity;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.Optional;
import org.eclipse.ditto.model.base.auth.AuthorizationContext;
import org.eclipse.ditto.model.base.headers.DittoHeaderDefinition;
import org.eclipse.ditto.services.models.connectivity.placeholder.EnforcementFilter;
/**
* Simple wrapper around the headers and the payload received from or sent to external AMQP (0.9 or 1.0)
* sources/targets.
*/
public interface ExternalMessage {
/**
* Message header for the Content-Type.
*/
String CONTENT_TYPE_HEADER = DittoHeaderDefinition.CONTENT_TYPE.getKey();
/**
* Message header for the reply to address. MUST be lower-case.
* "reply-to" is a standard internet message header (RFC-5322).
*/
String REPLY_TO_HEADER = "reply-to";
/**
* @return the headers of the ExternalMessage
*/
Map<String, String> getHeaders();
/**
* @param key the header key
* @param value the header value
* @return new instance of {@link ExternalMessage} including the provided header
*/
ExternalMessage withHeader(String key, String value);
/**
* @param additionalHeaders headers added to message headers
* @return new instance of {@link ExternalMessage} including the provided headers
*/
ExternalMessage withHeaders(Map<String, String> additionalHeaders);
/**
* @return the optional value of the Content-Type header
*/
default Optional<String> findContentType() {
return findHeaderIgnoreCase(CONTENT_TYPE_HEADER);
}
/**
* @param key the key to look up in the headers
* @return the optional value of the specified header {@code key}
*/
Optional<String> findHeader(String key);
/**
* @param key the key to look up in the headers case insensitively
* @return the optional value of the specified header {@code key}
*/
Optional<String> findHeaderIgnoreCase(String key);
/**
* @return whether this ExternalMessage is a text message
*/
boolean isTextMessage();
/**
* @return whether this ExternalMessage is a bytes message
*/
boolean isBytesMessage();
/**
* @return the text payload
*/
Optional<String> getTextPayload();
/**
* @return the bytes payload
*/
Optional<ByteBuffer> getBytePayload();
/**
* @return the PayloadType of this ExternalMessage
*/
PayloadType getPayloadType();
/**
* @return {@code true} if this message is a response
*/
boolean isResponse();
/**
* @return {@code true} if this message is an error
*/
boolean isError();
/**
* @return the {@link AuthorizationContext} assigned to this message
*/
Optional<AuthorizationContext> getAuthorizationContext();
/**
* @return the required data to apply the enforcement (if enforcement is enabled), empty otherwise
*/
Optional<EnforcementFilter<String>> getEnforcementFilter();
/**
* The known payload types of ExternalMessages.
*/
enum PayloadType {
TEXT,
BYTES,
UNKNOWN
}
}