Skip to content

Commit

Permalink
Feature/filenamefilter (#247)
Browse files Browse the repository at this point in the history
* Release notes

* Allow ignoring files based on a file name regex

* Fix the returned set of attributes from the MANIFEST file.
  • Loading branch information
uhurusurfa authored Dec 10, 2021
1 parent f97977c commit 6a342d7
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 39 deletions.
16 changes: 9 additions & 7 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# OpenAS2 Server
# Version 2.13.1
# Version 2.14.0
# RELEASE NOTES
-----
The OpenAS2 project is pleased to announce the release of OpenAS2 2.13.1
The OpenAS2 project is pleased to announce the release of OpenAS2 2.14.0

The release download file is: OpenAS2Server-2.13.1.zip
The release download file is: OpenAS2Server-2.14.0.zip

<span style="color:red">**IMPORTANT:** If you are currently running 2.13.1 then you should upgrade to this release ASAP</span>

The zip file contains a PDF document (OpenAS2HowTo.pdf) providing information on installing and using the application.
## NOTE: Testing covers Java 8 to 17. The application should work for older versions down to Java 7 but they are not tested as part of the CI/CD pipeline.

Version 2.13.1 - 2021-12-02
This is a minor enhancement release and windows bat files bugfix:
Version 2.14.0 - 2021-12-10
This is a minor enhancement release and OS file handle release bugfix:
**IMPORTANT NOTE**: Please review upgrade notes below if you are upgrading


1. Fix error when resender is invoked.
2. Fix directory polling module dying when specific errors occur that are not caught at source and end up in the module base invocation.
1. Add an additional way to filter files based on a regular expression. This allows filtering files based on text within the file name and not just the file extension. See the section **Restricting Directory Files By Extension Or Name** in the documentation for details of use.
2. Fix directory polling module not releasing file handles and eventually starving the OS of file handles.


##Upgrade Notes
Expand Down
2 changes: 1 addition & 1 deletion Remote/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>net.sf.openas2</groupId>
<artifactId>OpenAS2</artifactId>
<version>2.13.1</version>
<version>2.14.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion Server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- DO NOT CHANGE THIS "groupId" WITHOUT CHANGING XMLSession.getManifestAttributes.MANIFEST_VENDOR_ID_ATTRIB -->
<groupId>net.sf.openas2</groupId>
<artifactId>OpenAS2</artifactId>
<version>2.13.1</version>
<version>2.14.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
12 changes: 8 additions & 4 deletions Server/src/main/java/org/openas2/app/OpenAS2Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,27 @@ public static Attributes getManifestAttributes() {
InputStream is = url.openStream();
if (is != null) {
Manifest manifest = new Manifest(is);
manifestAttributes = manifest.getMainAttributes();
Attributes attribs = manifest.getMainAttributes();
is.close();
String vendor = manifestAttributes.getValue(MANIFEST_VENDOR_ID_ATTRIB);
String vendor = attribs.getValue(MANIFEST_VENDOR_ID_ATTRIB);
if (vendor != null && VENDOR_ID.equals(vendor)) {
// We have an OpenAS2 jar at least - check the project name
String project = manifestAttributes.getValue(MANIFEST_TITLE_ATTRIB);
String project = attribs.getValue(MANIFEST_TITLE_ATTRIB);
if (project != null && PROJECT_NAME.equals(project)) {
if (openAS2Manifest != null) {
// A duplicate detected
throw new OpenAS2Exception("Duplicate manifests detected: " + openAS2Manifest.getPath() + " ::: " + url.getPath());
}
openAS2Manifest = url;
manifestAttributes = attribs;
}
}
} else {
LOGGER.warn("MANIFEST input stream not opened for: " + url.toString());
}

} catch (Exception e) {
// Silently ignore wrong manifests on classpath?
LOGGER.info("MANIFEST not accessed: " + e.getMessage(), e);
}
}
} catch (IOException e1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public abstract class DirectoryPollingModule extends PollingModule {
public static final String PARAM_OUTBOX_DIRECTORY = "outboxdir";
public static final String PARAM_FILE_EXTENSION_FILTER = "fileextensionfilter";
public static final String PARAM_FILE_EXTENSION_EXCLUDE_FILTER = "fileextensionexcludefilter";
public static final String PARAM_FILE_NAME_EXCLUDE_FILTER = "filenameexcluderegexfilter";
private Map<String, Long> trackedFiles;
private String outboxDir;
private String errorDir;
private String sentDir = null;
private List<String> allowExtensions;
private List<String> excludeExtensions;
private String excludeFilenameRegexFilter = null;

private Log logger = LogFactory.getLog(DirectoryPollingModule.class.getSimpleName());

Expand All @@ -43,6 +45,7 @@ public void init(Session session, Map<String, String> options) throws OpenAS2Exc
IOUtil.getDirectoryFile(pendingFolder);
String allowExtensionFilter = getParameter(PARAM_FILE_EXTENSION_FILTER, "");
String excludeExtensionFilter = getParameter(PARAM_FILE_EXTENSION_EXCLUDE_FILTER, "");
String excludeFilenameRegexFilter = getParameter(PARAM_FILE_NAME_EXCLUDE_FILTER, "");

if (allowExtensionFilter == null || allowExtensionFilter.length() < 1) {
this.allowExtensions = new ArrayList<String>();
Expand All @@ -54,6 +57,9 @@ public void init(Session session, Map<String, String> options) throws OpenAS2Exc
} else {
this.excludeExtensions = Arrays.asList(excludeExtensionFilter.split("\\s*,\\s*"));
}
if (excludeFilenameRegexFilter != null && excludeFilenameRegexFilter.length() > 0) {
this.excludeFilenameRegexFilter = excludeFilenameRegexFilter;
}

} catch (IOException e) {
throw new OpenAS2Exception("Failed to initialise directory poller.", e);
Expand Down Expand Up @@ -90,39 +96,49 @@ protected void scanDirectory(String directory) throws IOException, InvalidParame
/* Claudio.Degioanni - Versione modificata 20210628 2.11 - Start */

/**
* Rispetto alla versione tesi ho aggiunto il supporto per allowExtensions e excludeExtensions aggiunto nelle versioni dopo
* Rispetto alla versione tesi ho aggiunto il supporto per allowExtensions e
* excludeExtensions aggiunto nelle versioni dopo
*/

if (logger.isDebugEnabled()) {
logger.debug("Polling module scanning directory: " + directory);
}
File directoryAsFile = IOUtil.getDirectoryFile(directory);

DirectoryStream<Path> dirs = Files.newDirectoryStream(directoryAsFile.toPath(), entry -> {
String name = entry.getFileName().toString();
String extension = name.substring(name.lastIndexOf(".") + 1);
boolean isAllowed = true;
if (!allowExtensions.isEmpty()) {
isAllowed = allowExtensions.contains(extension);
if (!isAllowed) {
// Wrap in try-with-resources block to ensure close() is called
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(directoryAsFile.toPath(), entry -> {
String name = entry.getFileName().toString();
if (Files.isDirectory(entry)) {
return false;
}
}
// Check for the excluded filters
if (!excludeExtensions.isEmpty()) {
isAllowed = !excludeExtensions.contains(extension);
}
return isAllowed;
if (logger.isDebugEnabled()) {
logger.debug("Polling module file name found: " + name);
}
String extension = name.substring(name.lastIndexOf(".") + 1);
boolean isAllowed = true;
if (!allowExtensions.isEmpty()) {
isAllowed = allowExtensions.contains(extension);
}
// Check for the excluded filters if not already disallowed
if (isAllowed && !excludeExtensions.isEmpty()) {
isAllowed = !excludeExtensions.contains(extension);
}
// Check if there are filename regex exclusions if not already disallowed
if (isAllowed && excludeFilenameRegexFilter != null) {
isAllowed = !name.matches(excludeFilenameRegexFilter);
}
return isAllowed;

});
})) {

for (Path dir : dirs) {
File currentFile = dir.toFile();
for (Path dir : dirs) {
File currentFile = dir.toFile();

if (checkFile(currentFile)) {
// start watching the file's size if it's not already being watched
trackFile(currentFile);
if (checkFile(currentFile)) {
// start watching the file's size if it's not already being watched
trackFile(currentFile);
}
}
/* Claudio.degioanni - Versione modificata 20210628 2.11 - End */
}

/* Claudio.degioanni - Versione modificata 20210628 2.11 - End */
}

protected boolean checkFile(File file) {
Expand Down
9 changes: 8 additions & 1 deletion changes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
Version 2.13.0 - 2021-12-02
Version 2.14.0 - 2021-12-10
This is a enhancement and bugfix release:
**IMPORTANT NOTE**: Please review upgrade notes in the RELEASE-NOTES.md if you are upgrading

1. Add an additional way to filter files based on a regular expression. This allows filtering files based on text within the file name and not just the file extension. See the section **Restricting Directory Files By Extension Or Name** in the documentation for details of use.
2. Fix directory polling module not releasing file handles and eventually starving the OS of file handles.

Version 2.13.1 - 2021-12-02
This is a bugfix release:
**IMPORTANT NOTE**: Please review upgrade notes in the RELEASE-NOTES.md if you are upgrading

Expand Down
Binary file modified docs/OpenAS2HowTo.odt
Binary file not shown.
Binary file modified docs/OpenAS2HowTo.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.sf.openas2</groupId>
<artifactId>OpenAS2</artifactId>
<version>2.13.1</version>
<version>2.14.0</version>
<name>OpenAS2</name>
<packaging>pom</packaging>

Expand Down

0 comments on commit 6a342d7

Please sign in to comment.