-
Hello, As followup to https://stackoverflow.com/questions/71798060/how-to-use-holodeck-with-s3 I would like to ask how phase4 could be used with a self-hosted S3-Storage as filesystem. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Thanks Marco, for asking the question here :) There are two levels of data storage that you might consider:
What you anyone need to do, is to add S3 as a build dependency (e.g. to your pom.xml): <dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.17.192</version>
</dependency> Assuming you want to replace the "outgoing dumper" to write to S3, you could do something like this: private static final class S3OutgoingDumper extends AbstractAS4OutgoingDumperWithHeaders
{
private final ICommonsMap <String, File> m_aMessageIDToFilename = new CommonsConcurrentHashMap <> ();
@Override
public OutputStream openOutputStream (@Nonnull final EAS4MessageMode eMsgMode,
@Nullable final IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable final IAS4MessageState aState,
@Nonnull @Nonempty final String sMessageID,
@Nullable final HttpHeaderMap aCustomHeaders,
@Nonnegative final int nTry) throws IOException
{
final String sUniqueID = aMessageMetadata.getIncomingUniqueID ();
final File aResponseFile = new File (SystemProperties.getTmpDir (),
PDTIOHelper.getLocalDateTimeForFilename (aMessageMetadata.getIncomingDT ()
.toLocalDateTime ()) +
"-" +
FilenameHelper.getAsSecureValidASCIIFilename (sUniqueID) +
".as4out");
LOGGER.info ("Logging outgoing AS4 request to '" + aResponseFile.getAbsolutePath () + "'");
m_aMessageIDToFilename.put (sMessageID, aResponseFile);
return FileHelper.getBufferedOutputStream (aResponseFile);
}
@Override
public void onEndRequest (@Nonnull final EAS4MessageMode eMsgMode,
@Nullable final IAS4IncomingMessageMetadata aMessageMetadata,
@Nullable final IAS4MessageState aState,
@Nonnull @Nonempty final String sMessageID)
{
LOGGER.info ("Now storing outgoing AS4 request for '" + sMessageID + "'");
final File aFile = m_aMessageIDToFilename.remove (sMessageID);
if (aFile != null) {
if (aFile.exists ()) {
LOGGER.info ("File existing: '" + aFile.getAbsolutePath () + "' with " + aFile.length () + " bytes");
final String sTargetBucket = "YOUR_BUCKET_NAME";
final String sTargetKey = "outbound/" +
PDTIOHelper.getLocalDateTimeForFilename (aMessageMetadata.getIncomingDT ().toLocalDateTime ()) +
"/" + aMessageMetadata.getIncomingUniqueID () +"/msg.as4out";
s3Client.putObject (PutObjectRequest.builder ().bucket (sTargetBucket).key (sTargetKey)
.contentType (CMimeType.APPLICATION_OCTET_STREAM.getAsString ()).build (),
RequestBody.fromFile (aFile));
aFile.delete ();
LOGGER.info ("Finished storing outgoing AS4 request for '" + sMessageID + "'");
}
else
LOGGER.error ("File for '" + sMessageID + "' is " + aFile.getAbsolutePath () + " does not exist");
}
else
LOGGER.error ("No file found for '" + sMessageID + "'");
}
} It first dumps the message to a temporary file, and then uploads the file to a custom S3 bucket. If you want to use S3 to store business messages only, than you can use the hth, Philip |
Beta Was this translation helpful? Give feedback.
Thanks Marco, for asking the question here :)
There are two levels of data storage that you might consider:
What you anyone need to do, is to add S3 as a build dependency (e.g. to your pom.xml):
Assuming you want to replace the "outgoing dumper" to write to S3, you could do something like this: