Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store sender's IP address for inbound messages in DB #204

Merged
merged 17 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- support for Kotlin
- preconditions which observe mdib changes during the test run
- Sender IP adresses of inbound messages are stored in TestRun DB
- storing of IP addresses of inbound messages in the database

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
@Singleton
public class MessageStorage implements AutoCloseable {

public static final String UNKNOWN_SENDER = "unknown";
public static final String UNKNOWN_SENDER = "UNKNOWN";
public static final String DEFAULT_OUTBOUND_SENDER = "SDCcc";
private static final Logger LOG = LogManager.getLogger(MessageStorage.class);

Expand Down Expand Up @@ -322,20 +322,30 @@ protected MessageContent convertMessageToMessageContent(final Message message) {
private String getSender(final Message message) {
final CommunicationContext communicationContext = message.getCommunicationContext();
if (communicationContext == null) {
LOG.warn("Encountered message (uuid={}) without a CommunicationContext.", message);
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
return UNKNOWN_SENDER;
}
final TransportInfo transportInfo = communicationContext.getTransportInfo();
if (transportInfo == null) {
LOG.warn("Encountered message (uuid={}) without a TransportInfo.", message);
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
return UNKNOWN_SENDER;
}
if (message.getDirection() == CommunicationLog.Direction.INBOUND) {
final Optional<String> remoteAddress = transportInfo.getRemoteAddress();
if (remoteAddress.isEmpty()) {
LOG.warn("Encountered inbound message (uuid={}) without a remoteAddress.", message);
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
return UNKNOWN_SENDER;
} else {
return remoteAddress.orElseThrow();
}
return remoteAddress.orElseThrow();
} else {
} else if (message.getDirection() == CommunicationLog.Direction.OUTBOUND) {
return DEFAULT_OUTBOUND_SENDER;
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
} else {
// NOTE: will invalidate the TestRun
LOG.error("Encountered unknown direction {} in message with uuid={}",
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
message.getDirection(),
message.getID());
return UNKNOWN_SENDER;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class MessageContent {
private String uuid;
private boolean isSOAP;

@Column(name = "sender", length = 15)
@Column(name = "sender")
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
private String sender;
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand All @@ -98,8 +98,7 @@ public MessageContent() {}
* @param uuid identifier for ensuring, that a message was written to the database
* @param isSOAP shall be true if a SOAP envelope was found and false otherwise
* @param sender either the String "SDCcc" for outbound messages or the IP Address of the
maximilianpilz marked this conversation as resolved.
Show resolved Hide resolved
* message Sender for inbound messages. NOTE: The String's length must be shorter or
* equal to 15 characters in order to be stored in the database.
* message Sender for inbound messages.
*/
public MessageContent(
final String body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class MessageContent_ {
public static volatile SingularAttribute<MessageContent, String> scheme;
public static volatile SingularAttribute<MessageContent, String> uuid;
public static volatile SingularAttribute<MessageContent, Boolean> isSOAP;
public static volatile SingularAttribute<MessageContent, String> sender;

private MessageContent_() {}
}
Loading