From 1b66ffb04249d0be14c5047bb64d29795c2121e8 Mon Sep 17 00:00:00 2001 From: Christopher Broderick Date: Mon, 11 Mar 2019 19:27:54 +0000 Subject: [PATCH] Enhance manifest lookup (#141) * Change MANIFEST.MF lookup Old method did not cater for folders with the same name as the jar string being searched. * Enhance MANIFEST.MF lookup * Updated release numbers * Upgrade notes for 2.7.1 --- Bundle/pom.xml | 2 +- RELEASE-NOTES.md | 15 +- Remote/pom.xml | 2 +- Server/pom.xml | 4 +- .../src/main/java/org/openas2/XMLSession.java | 418 +++++++++--------- changes.txt | 8 + pom.xml | 2 +- 7 files changed, 224 insertions(+), 227 deletions(-) diff --git a/Bundle/pom.xml b/Bundle/pom.xml index 9a4ae4ea..81bd6c9a 100644 --- a/Bundle/pom.xml +++ b/Bundle/pom.xml @@ -6,7 +6,7 @@ net.sf.openas2 OpenAS2 - 2.7.0 + 2.7.1 openas2-osgi diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index fab620f2..fe7c1672 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,21 +1,20 @@ # OpenAS2 Server -# Version 2.7.0 +# Version 2.7.1 # RELEASE NOTES ----- -The OpenAS2 project is pleased to announce the release of OpenAS2 2.7.0 +The OpenAS2 project is pleased to announce the release of OpenAS2 2.7.1 -The release download file is: OpenAS2Server-2.7.0.zip +The release download file is: OpenAS2Server-2.7.1.zip The zip file contains a PDF document (OpenAS2HowTo.pdf) providing information on installing and using the application. -Version 2.7.0 - 2019-03-03 +Version 2.7.1 - 2019-03-11 This is a minor enhancement release: **IMPORTANT NOTE**: Please review upgrade notes if you are upgrading - 1. Add an exclude filter option for the file polling module to support large files using a temporary extension until file is copied to directory - 2. Add support for including extra parts of a parsed file name into the final parameter in the "format" attribute for file name parsing. - 3. Support HTTP authentication on a per partnership basis. - 4. Document the use of HTTP authentication, file filters and file name parsing functionality. + 1. Modify the way the application identifies the correct manifest file to determine title and version of the app. + 2. Alter the file cleanup logging messages to make it easier to debig issues. + 3. Correct minor spelling errors in logging statements ##Upgrade Notes See the openAS2HowTo appendix for the general process on upgrading OpenAS2. diff --git a/Remote/pom.xml b/Remote/pom.xml index 66559690..6faefdc3 100644 --- a/Remote/pom.xml +++ b/Remote/pom.xml @@ -4,7 +4,7 @@ net.sf.openas2 OpenAS2 - 2.7.0 + 2.7.1 4.0.0 diff --git a/Server/pom.xml b/Server/pom.xml index 37f60958..84e41105 100644 --- a/Server/pom.xml +++ b/Server/pom.xml @@ -4,13 +4,15 @@ 4.0.0 + net.sf.openas2 OpenAS2 - 2.7.0 + 2.7.1 openas2-server + OpenAS2 Server Open source implementation of the AS2 standard for signed encrypted and compressed document transfer diff --git a/Server/src/main/java/org/openas2/XMLSession.java b/Server/src/main/java/org/openas2/XMLSession.java index 36a9604b..fc731bed 100644 --- a/Server/src/main/java/org/openas2/XMLSession.java +++ b/Server/src/main/java/org/openas2/XMLSession.java @@ -50,275 +50,263 @@ public class XMLSession extends BaseSession { private static final String EL_PARTNERSHIPS = "partnerships"; private static final String EL_COMMANDS = "commands"; private static final String EL_LOGGERS = "loggers"; - //private static final String PARAM_BASE_DIRECTORY = "basedir"; + // private static final String PARAM_BASE_DIRECTORY = "basedir"; private CommandRegistry commandRegistry; private CommandManager cmdManager = new CommandManager(); + private static final String MANIFEST_VENDOR_ID_ATTRIB = "Implementation-Vendor-Id"; + private static final String MANIFEST_VERSION_ATTRIB = "Implementation-Version"; + private static final String MANIFEST_TITLE_ATTRIB = "Implementation-Title"; + private static final String VENDOR_ID = "net.sf.openas2"; + private static final String PROJECT_NAME = "OpenAS2 Server"; + private Attributes manifestAttributes = null; private String VERSION; private String TITLE; private static final Log LOGGER = LogFactory.getLog(XMLSession.class.getSimpleName()); - public XMLSession(String configAbsPath) throws Exception - { - File configXml = new File(configAbsPath); - File configDir = configXml.getParentFile(); + public XMLSession(String configAbsPath) throws Exception { + File configXml = new File(configAbsPath); + File configDir = configXml.getParentFile(); + getManifestAttributes(); - FileInputStream configAsStream = new FileInputStream(configXml); - setBaseDirectory(configDir.getAbsolutePath()); + FileInputStream configAsStream = new FileInputStream(configXml); + setBaseDirectory(configDir.getAbsolutePath()); - load(configAsStream); + load(configAsStream); - // scheduler should be initializer after all modules - addSchedulerComponent(); + // scheduler should be initializer after all modules + addSchedulerComponent(); } - private void addSchedulerComponent() throws OpenAS2Exception - { - SchedulerComponent comp = new SchedulerComponent(); - setComponent("scheduler", comp); - comp.init(this, Collections.emptyMap()); + private void addSchedulerComponent() throws OpenAS2Exception { + SchedulerComponent comp = new SchedulerComponent(); + setComponent("scheduler", comp); + comp.init(this, Collections.emptyMap()); } - - protected void load(InputStream in) throws Exception - { - Document document = XMLUtil.parseXML(in, new PropertyReplacementFilter()); - - Element root = document.getDocumentElement(); - - NodeList rootNodes = root.getChildNodes(); - Node rootNode; - String nodeName; - - // this is used by all other objects to access global configs and functionality - LOGGER.info("Loading configuration..."); - for (int i = 0; i < rootNodes.getLength(); i++) - { - rootNode = rootNodes.item(i); - - nodeName = rootNode.getNodeName(); - - // enter the command processing loop - if (nodeName.equals(EL_PROPERTIES)) - { - loadProperties(rootNode); - } else if (nodeName.equals(EL_CERTIFICATES)) - { - loadCertificates(rootNode); - } else if (nodeName.equals(EL_PROCESSOR)) - { - loadProcessor(rootNode); - } else if (nodeName.equals(EL_CMDPROCESSOR)) - { - loadCommandProcessors(rootNode); - } else if (nodeName.equals(EL_PARTNERSHIPS)) - { - loadPartnerships(rootNode); - } else if (nodeName.equals(EL_COMMANDS)) - { - loadCommands(rootNode); - } else if (nodeName.equals(EL_LOGGERS)) - { - loadLoggers(rootNode); - } else if (nodeName.equals("#text")) - { - // do nothing - } else if (nodeName.equals("#comment")) - { - // do nothing - } else - { - throw new OpenAS2Exception("Undefined tag: " + nodeName); - } - } - - cmdManager.registerCommands(commandRegistry); + protected void load(InputStream in) throws Exception { + Document document = XMLUtil.parseXML(in, new PropertyReplacementFilter()); + + Element root = document.getDocumentElement(); + + NodeList rootNodes = root.getChildNodes(); + Node rootNode; + String nodeName; + + // this is used by all other objects to access global configs and functionality + LOGGER.info("Loading configuration..."); + for (int i = 0; i < rootNodes.getLength(); i++) { + rootNode = rootNodes.item(i); + + nodeName = rootNode.getNodeName(); + + // enter the command processing loop + if (nodeName.equals(EL_PROPERTIES)) { + loadProperties(rootNode); + } else if (nodeName.equals(EL_CERTIFICATES)) { + loadCertificates(rootNode); + } else if (nodeName.equals(EL_PROCESSOR)) { + loadProcessor(rootNode); + } else if (nodeName.equals(EL_CMDPROCESSOR)) { + loadCommandProcessors(rootNode); + } else if (nodeName.equals(EL_PARTNERSHIPS)) { + loadPartnerships(rootNode); + } else if (nodeName.equals(EL_COMMANDS)) { + loadCommands(rootNode); + } else if (nodeName.equals(EL_LOGGERS)) { + loadLoggers(rootNode); + } else if (nodeName.equals("#text")) { + // do nothing + } else if (nodeName.equals("#comment")) { + // do nothing + } else { + throw new OpenAS2Exception("Undefined tag: " + nodeName); + } + } + + cmdManager.registerCommands(commandRegistry); } - private void loadProperties(Node propNode) - { - LOGGER.info("Loading properties..."); + private void loadProperties(Node propNode) { + LOGGER.info("Loading properties..."); - Map properties = XMLUtil.mapAttributes(propNode, false); - // Make key things accessible via static object for things that do not have accesss to session object - properties.put(Properties.APP_TITLE_PROP, getAppTitle()); - properties.put(Properties.APP_VERSION_PROP, getAppVersion()); - Properties.setProperties(properties); + Map properties = XMLUtil.mapAttributes(propNode, false); + // Make key things accessible via static object for things that do not have + // accesss to session object + properties.put(Properties.APP_TITLE_PROP, getAppTitle()); + properties.put(Properties.APP_VERSION_PROP, getAppVersion()); + Properties.setProperties(properties); } - private void loadCertificates(Node rootNode) throws OpenAS2Exception - { - CertificateFactory certFx = (CertificateFactory) XMLUtil.getComponent( - rootNode, this); - setComponent(CertificateFactory.COMPID_CERTIFICATE_FACTORY, certFx); + private void loadCertificates(Node rootNode) throws OpenAS2Exception { + CertificateFactory certFx = (CertificateFactory) XMLUtil.getComponent(rootNode, this); + setComponent(CertificateFactory.COMPID_CERTIFICATE_FACTORY, certFx); } - private void loadCommands(Node rootNode) throws OpenAS2Exception - { - Component component = XMLUtil.getComponent(rootNode, this); - commandRegistry = (CommandRegistry) component; + private void loadCommands(Node rootNode) throws OpenAS2Exception { + Component component = XMLUtil.getComponent(rootNode, this); + commandRegistry = (CommandRegistry) component; } - private void loadLoggers(Node rootNode) throws OpenAS2Exception - { - LOGGER.info("Loading log manager(s)..."); - - LogManager manager = LogManager.getLogManager(); - if (LogManager.isRegisteredWithApache()) - { - ; // continue - } else - { - // if using the OpenAS2 loggers the log manager must registered with the jvm argument - // -Dorg.apache.commons.logging.Log=org.openas2.logging.Log - throw new OpenAS2Exception("the OpenAS2 loggers' log manager must be registered with the jvm argument -Dorg.apache.commons.logging.Log=org.openas2.logging.Log"); - } - NodeList loggers = rootNode.getChildNodes(); - Node logger; - - for (int i = 0; i < loggers.getLength(); i++) - { - logger = loggers.item(i); - - if (logger.getNodeName().equals("logger")) - { - loadLogger(manager, logger); - } - } + private void loadLoggers(Node rootNode) throws OpenAS2Exception { + LOGGER.info("Loading log manager(s)..."); + + LogManager manager = LogManager.getLogManager(); + if (LogManager.isRegisteredWithApache()) { + ; // continue + } else { + // if using the OpenAS2 loggers the log manager must registered with the jvm + // argument + // -Dorg.apache.commons.logging.Log=org.openas2.logging.Log + throw new OpenAS2Exception( + "the OpenAS2 loggers' log manager must be registered with the jvm argument -Dorg.apache.commons.logging.Log=org.openas2.logging.Log"); + } + NodeList loggers = rootNode.getChildNodes(); + Node logger; + + for (int i = 0; i < loggers.getLength(); i++) { + logger = loggers.item(i); + + if (logger.getNodeName().equals("logger")) { + loadLogger(manager, logger); + } + } } - private void loadLogger(LogManager manager, Node loggerNode) - throws OpenAS2Exception - { - Logger logger = (Logger) XMLUtil.getComponent(loggerNode, this); - manager.addLogger(logger); + private void loadLogger(LogManager manager, Node loggerNode) throws OpenAS2Exception { + Logger logger = (Logger) XMLUtil.getComponent(loggerNode, this); + manager.addLogger(logger); } - private void loadCommandProcessors(Node rootNode) throws OpenAS2Exception - { + private void loadCommandProcessors(Node rootNode) throws OpenAS2Exception { - // get a registry of Command objects, and add Commands for the Session - LOGGER.info("Loading command processor(s)..."); + // get a registry of Command objects, and add Commands for the Session + LOGGER.info("Loading command processor(s)..."); - NodeList cmdProcessor = rootNode.getChildNodes(); - Node processor; + NodeList cmdProcessor = rootNode.getChildNodes(); + Node processor; - for (int i = 0; i < cmdProcessor.getLength(); i++) - { - processor = cmdProcessor.item(i); + for (int i = 0; i < cmdProcessor.getLength(); i++) { + processor = cmdProcessor.item(i); - if (processor.getNodeName().equals("commandProcessor")) - { - loadCommandProcessor(cmdManager, processor); - } - } + if (processor.getNodeName().equals("commandProcessor")) { + loadCommandProcessor(cmdManager, processor); + } + } } - private void loadCommandProcessor(CommandManager manager, - Node cmdPrcessorNode) throws OpenAS2Exception - { - BaseCommandProcessor cmdProcesor = (BaseCommandProcessor) XMLUtil - .getComponent(cmdPrcessorNode, this); - manager.addProcessor(cmdProcesor); + private void loadCommandProcessor(CommandManager manager, Node cmdPrcessorNode) throws OpenAS2Exception { + BaseCommandProcessor cmdProcesor = (BaseCommandProcessor) XMLUtil.getComponent(cmdPrcessorNode, this); + manager.addProcessor(cmdProcesor); - setComponent(cmdProcesor.getName(), cmdProcesor); + setComponent(cmdProcesor.getName(), cmdProcesor); } - private void loadPartnerships(Node rootNode) throws OpenAS2Exception - { - LOGGER.info("Loading partnerships..."); + private void loadPartnerships(Node rootNode) throws OpenAS2Exception { + LOGGER.info("Loading partnerships..."); - PartnershipFactory partnerFx = (PartnershipFactory) XMLUtil - .getComponent(rootNode, this); - setComponent(PartnershipFactory.COMPID_PARTNERSHIP_FACTORY, partnerFx); + PartnershipFactory partnerFx = (PartnershipFactory) XMLUtil.getComponent(rootNode, this); + setComponent(PartnershipFactory.COMPID_PARTNERSHIP_FACTORY, partnerFx); } - private void loadProcessor(Node rootNode) throws OpenAS2Exception - { - Processor proc = (Processor) XMLUtil.getComponent(rootNode, this); - setComponent(Processor.COMPID_PROCESSOR, proc); + private void loadProcessor(Node rootNode) throws OpenAS2Exception { + Processor proc = (Processor) XMLUtil.getComponent(rootNode, this); + setComponent(Processor.COMPID_PROCESSOR, proc); + + LOGGER.info("Loading processor modules..."); - LOGGER.info("Loading processor modules..."); + NodeList modules = rootNode.getChildNodes(); + Node module; - NodeList modules = rootNode.getChildNodes(); - Node module; + for (int i = 0; i < modules.getLength(); i++) { + module = modules.item(i); - for (int i = 0; i < modules.getLength(); i++) - { - module = modules.item(i); + if (module.getNodeName().equals("module")) { + loadProcessorModule(proc, module); + } + } + } - if (module.getNodeName().equals("module")) - { - loadProcessorModule(proc, module); - } - } + private void loadProcessorModule(Processor proc, Node moduleNode) throws OpenAS2Exception { + ProcessorModule procmod = (ProcessorModule) XMLUtil.getComponent(moduleNode, this); + proc.getModules().add(procmod); } - private void loadProcessorModule(Processor proc, Node moduleNode) - throws OpenAS2Exception - { - ProcessorModule procmod = (ProcessorModule) XMLUtil.getComponent( - moduleNode, this); - proc.getModules().add(procmod); + private void getManifestAttributes() throws OpenAS2Exception { + Enumeration resEnum; + URL openAS2Manifest = null; + try { + resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); + while (resEnum.hasMoreElements()) { + try { + URL url = (URL) resEnum.nextElement(); + InputStream is = url.openStream(); + if (is != null) { + Manifest manifest = new Manifest(is); + Attributes mainAttribs = manifest.getMainAttributes(); + is.close(); + String vendor = mainAttribs.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 = mainAttribs.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 = mainAttribs; + } + } + } + } catch (Exception e) { + // Silently ignore wrong manifests on classpath? + } + } + } catch (IOException e1) { + // Silently ignore wrong manifests on classpath? + } + if (openAS2Manifest == null) { + LOGGER.warn("Failed to find a MANIFEST.MF with the desired vendor and project name."); + } + else { + LOGGER.info("Using MANIFEST " + openAS2Manifest.getPath()); + } } @Nullable - private String getManifestAttribValue(@Nonnull String attrib) - { - Enumeration resEnum; - try - { - resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME); - while (resEnum.hasMoreElements()) - { - try - { - URL url = (URL) resEnum.nextElement(); - if (!url.getPath().contains("openas2")) - { - continue; - } - InputStream is = url.openStream(); - if (is != null) - { - Manifest manifest = new Manifest(is); - Attributes mainAttribs = manifest.getMainAttributes(); - String value = mainAttribs.getValue(attrib); - if (value != null) - { - return value; - } - } - } catch (Exception e) - { - // Silently ignore wrong manifests on classpath? - } - } - } catch (IOException e1) - { - // Silently ignore wrong manifests on classpath? - } - return null; + private String getManifestAttribValue(@Nonnull String attrib) throws OpenAS2Exception { + if (manifestAttributes != null) return manifestAttributes.getValue(attrib); + return "NO MANIFEST"; } - public String getAppVersion() - { - if (VERSION == null) - { - VERSION = getManifestAttribValue("Implementation-Version"); - } - return VERSION; + public String getAppVersion() { + if (VERSION == null) { + try { + VERSION = getManifestAttribValue(MANIFEST_VERSION_ATTRIB); + } catch (OpenAS2Exception e) { + LOGGER.warn(e.getMessage()); + ; + } + } + return VERSION; } - public String getAppTitle() - { - if (TITLE == null) - { - TITLE = getManifestAttribValue("Implementation-Title") + " v" + getAppVersion(); - } - return TITLE; + public String getAppTitle() { + if (TITLE == null) { + try { + TITLE = getManifestAttribValue(MANIFEST_TITLE_ATTRIB) + " v" + getAppVersion(); + } catch (OpenAS2Exception e) { + LOGGER.warn(e.getMessage()); + ; + } + } + return TITLE; } } diff --git a/changes.txt b/changes.txt index 133eb25c..55ada0dc 100644 --- a/changes.txt +++ b/changes.txt @@ -1,3 +1,11 @@ +ersion 2.7.1 - 2019-03-11 +This is a minor enhancement release: + **IMPORTANT NOTE**: Please review upgrade notes in the RELEASE-NOTES.md if you are upgrading + + 1. Modify the way the application identifies the correct manifest file to determine title and version of the app. + 2. Alter the file cleanup logging messages to make it easier to debig issues. + 3. Correct minor spelling errors in logging statements + Version 2.7.0 - 2019-03-03 This is a minor enhancement release: **IMPORTANT NOTE**: Please review upgrade notes in the RELEASE-NOTES.md if you are upgrading diff --git a/pom.xml b/pom.xml index 8571b13a..e0ecb482 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 net.sf.openas2 OpenAS2 - 2.7.0 + 2.7.1 OpenAS2 pom