fi.evolver.basics.spring.messaging.sender.DisabledSender Maven / Gradle / Ivy
package fi.evolver.basics.spring.messaging.sender;
import java.io.InputStream;
import java.net.URI;
import java.time.LocalDateTime;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import fi.evolver.basics.spring.log.MessageLogService;
import fi.evolver.basics.spring.log.entity.MessageLog;
import fi.evolver.basics.spring.log.entity.MessageLog.Direction;
import fi.evolver.basics.spring.messaging.SendResult;
import fi.evolver.basics.spring.messaging.entity.Message;
import fi.evolver.basics.spring.messaging.util.SendUtils;
@Component
public class DisabledSender implements Sender {
private static final Logger LOG = LoggerFactory.getLogger(DisabledSender.class);
private final MessageLogService messageLogService;
@Autowired
public DisabledSender(MessageLogService messageLogService) {
this.messageLogService = messageLogService;
}
@Override
public SendResult send(Message message, URI uri) {
int requestSize = 0;
try (InputStream in = message.getDataStream()) {
while (in.read() != -1)
++requestSize;
}
catch (Exception e) {
LOG.warn("FAILED counting request size", e);
}
MessageLog logMessage = messageLogService.createLogMessageFromZippedData(
LocalDateTime.now(),
message.getMessageType(),
"disabled",
message.getTargetUri(),
messageLogService.getApplicationName(),
message.getTargetSystem(),
Direction.OUTBOUND,
requestSize,
message.getCompressedData(),
null,
0,
null,
null,
SendUtils.mapMetadata(message.getMetadata()));
messageLogService.logMessage(logMessage, "DISABLED", "Not sent, URI disabled");
return SendResult.success();
}
@Override
public Set getSupportedProtocols() {
return Set.of("disabled");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy