-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted dump filename providers into a public class
- Loading branch information
Showing
5 changed files
with
183 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
phase4-lib/src/main/java/com/helger/phase4/dump/IAS4IncomingDumperFileProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2015-2024 Philip Helger (www.helger.com) | ||
* philip[at]helger[dot]com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.helger.phase4.dump; | ||
|
||
import java.io.File; | ||
import java.time.OffsetDateTime; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import com.helger.commons.http.HttpHeaderMap; | ||
import com.helger.commons.io.file.FilenameHelper; | ||
import com.helger.commons.string.StringHelper; | ||
import com.helger.datetime.util.PDTIOHelper; | ||
import com.helger.phase4.config.AS4Configuration; | ||
import com.helger.phase4.incoming.IAS4IncomingMessageMetadata; | ||
|
||
/** | ||
* Callback interface to create a file based on the provided metadata. | ||
* | ||
* @author Philip Helger | ||
* @since 0.9.8 | ||
*/ | ||
@FunctionalInterface | ||
public interface IAS4IncomingDumperFileProvider | ||
{ | ||
/** The default file extension to be used */ | ||
String DEFAULT_FILE_EXTENSION = ".as4in"; | ||
|
||
/** | ||
* Get the {@link File} to write the dump to. The filename must be globally | ||
* unique. The resulting file should be an absolute path. | ||
* | ||
* @param aMessageMetadata | ||
* The message metadata of the incoming message. Never | ||
* <code>null</code>. | ||
* @param aHttpHeaderMap | ||
* The HTTP headers of the incoming message. Never <code>null</code>. | ||
* @return A non-<code>null</code> {@link File}. | ||
* @see AS4Configuration#getDumpBasePath() | ||
*/ | ||
@Nonnull | ||
File createFile (@Nonnull IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull HttpHeaderMap aHttpHeaderMap); | ||
|
||
@Nonnull | ||
static String getDefaultDirectoryName (@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata) | ||
{ | ||
final OffsetDateTime aLDT = aMessageMetadata.getIncomingDT (); | ||
return aLDT.getYear () + | ||
"/" + | ||
StringHelper.getLeadingZero (aLDT.getMonthValue (), 2) + | ||
"/" + | ||
StringHelper.getLeadingZero (aLDT.getDayOfMonth (), 2); | ||
} | ||
|
||
@Nonnull | ||
static String getDefaultFilename (@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata) | ||
{ | ||
final OffsetDateTime aLDT = aMessageMetadata.getIncomingDT (); | ||
return PDTIOHelper.getTimeForFilename (aLDT.toLocalTime ()) + | ||
'-' + | ||
FilenameHelper.getAsSecureValidASCIIFilename (aMessageMetadata.getIncomingUniqueID ()) + | ||
DEFAULT_FILE_EXTENSION; | ||
} | ||
|
||
@Nonnull | ||
static String getDefaultDirectoryAndFilename (@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata) | ||
{ | ||
return getDefaultDirectoryName (aMessageMetadata) + "/" + getDefaultFilename (aMessageMetadata); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
phase4-lib/src/main/java/com/helger/phase4/dump/IAS4OutgoingDumperFileProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2015-2024 Philip Helger (www.helger.com) | ||
* philip[at]helger[dot]com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.helger.phase4.dump; | ||
|
||
import java.io.File; | ||
import java.time.OffsetDateTime; | ||
|
||
import javax.annotation.Nonnegative; | ||
import javax.annotation.Nonnull; | ||
|
||
import com.helger.commons.annotation.Nonempty; | ||
import com.helger.commons.io.file.FilenameHelper; | ||
import com.helger.commons.string.StringHelper; | ||
import com.helger.datetime.util.PDTIOHelper; | ||
import com.helger.phase4.config.AS4Configuration; | ||
import com.helger.phase4.messaging.EAS4MessageMode; | ||
import com.helger.phase4.mgr.MetaAS4Manager; | ||
|
||
@FunctionalInterface | ||
public interface IAS4OutgoingDumperFileProvider | ||
{ | ||
/** The default file extension to be used */ | ||
String DEFAULT_FILE_EXTENSION = ".as4out"; | ||
|
||
/** | ||
* Get the {@link File} to write the dump to. The filename must be globally | ||
* unique. The resulting file should be an absolute path. | ||
* | ||
* @param eMsgMode | ||
* Are we dumping a request or a response? Never <code>null</code>. | ||
* Added in v1.2.0. | ||
* @param sAS4MessageID | ||
* The AS4 message ID that was send out. Neither <code>null</code> nor | ||
* empty. | ||
* @param nTry | ||
* The number of the try to send the message. The initial try has value | ||
* 0, the first retry has value 1 etc. | ||
* @return A non-<code>null</code> {@link File}. | ||
* @see AS4Configuration#getDumpBasePath() | ||
*/ | ||
@Nonnull | ||
File getFile (@Nonnull EAS4MessageMode eMsgMode, @Nonnull @Nonempty String sAS4MessageID, @Nonnegative int nTry); | ||
|
||
@Nonnull | ||
static String getDefaultDirectoryName (@Nonnull final OffsetDateTime aNow) | ||
{ | ||
return aNow.getYear () + | ||
"/" + | ||
StringHelper.getLeadingZero (aNow.getMonthValue (), 2) + | ||
"/" + | ||
StringHelper.getLeadingZero (aNow.getDayOfMonth (), 2); | ||
} | ||
|
||
@Nonnull | ||
static String getDefaultFilename (@Nonnull final OffsetDateTime aNow, | ||
@Nonnull @Nonempty final String sAS4MessageID, | ||
@Nonnegative final int nTry) | ||
{ | ||
return PDTIOHelper.getTimeForFilename (aNow.toLocalTime ()) + | ||
"-" + | ||
FilenameHelper.getAsSecureValidASCIIFilename (sAS4MessageID) + | ||
"-" + | ||
nTry + | ||
DEFAULT_FILE_EXTENSION; | ||
} | ||
|
||
@Nonnull | ||
static String getDefaultDirectoryAndFilename (@Nonnull @Nonempty final String sAS4MessageID, | ||
@Nonnegative final int nTry) | ||
{ | ||
final OffsetDateTime aNow = MetaAS4Manager.getTimestampMgr ().getCurrentDateTime (); | ||
return getDefaultDirectoryName (aNow) + '/' + getDefaultFilename (aNow, sAS4MessageID, nTry); | ||
} | ||
} |
Oops, something went wrong.