Skip to content

Commit

Permalink
Various fixes and enhancements (#94)
Browse files Browse the repository at this point in the history
* Split getMetaData method to allow being used in the stale sent messages
cleanup functionality
Better handling of errors in the cleanup method

* Optimise the getFileName methid
Add logging of ATTRIBUTES in trace log for debug purposes

* Fix resender functionality

* Allow modules to have scheduled tasks

* Add static for property defining how long before a pending file is
deemed stale

* Add scheduled task to track failed sent messages that have not been
cleaned up

* Add note regarding failed sent messages cleanup

* Scheduled tasks in modules allowed

* Add error message when stale file is removed

* Ensure inputstream is closed

* Handle quoted AS2 ID's when they contain a space character

* Helper method to remove double quotes

* Remove unused imports

* Fix the normalisation of AS2 ID from header.
Add Junit Test

* Change to accommodate byte array as response body instead of string

* Partnership classes and attribute statics rationalized and standardized

* Allow attributes in the partnership definition to reference other
attributes and replace at load time

* Fix null pointer exception

* Use HTTPEntoity to exgtract content and store as byte array instead of
string

* Add helper method to enhance attributes

* Update release notes to reflect the changes made in this commit.

* Update to release version number

* Document the items in the 2.5.0 release

* Fix release date
  • Loading branch information
uhurusurfa authored and pete-gilchrist committed Jul 2, 2018
1 parent 0e15c07 commit 0589b49
Show file tree
Hide file tree
Showing 33 changed files with 243 additions and 184 deletions.
2 changes: 1 addition & 1 deletion Bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.sf.openas2</groupId>
<artifactId>OpenAS2</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
</parent>

<artifactId>openas2-osgi</artifactId>
Expand Down
6 changes: 5 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The release download file is: OpenAS2Server-2.5.0.zip

The zip file contains a PDF document (OpenAS2HowTo.pdf) providing information on installing and using the application.

Version 2.5.0 - 2018-05-15
Version 2.5.0 - 2018-07-02
This is an enhancement and bugfix release:
**IMPORTANT NOTE**: Please review upgrade notes below if you are upgrading

Expand All @@ -24,6 +24,9 @@ This is an enhancement and bugfix release:
10. Change attribute name for overriding Message-ID format at partnership level to match name at system level. NB See upgrade notes for attribute name change.
11. Allow modules to have scheduled tasks using the HasSchedule implementation.
12. Add scheduled task to detect failed sent messages where files are not cleaned up. (Fixes https://sourceforge.net/p/openas2/tickets/5/)
13. Allow attributes in partnership element to reference other partnership elements and resolve the references at load time.
14. Default sample in partnerships.xml for "as2_mdn_options" to use the "sign" attribute value for the micalg value.
15. Support AS2 ID with spaces in the value.

##Upgrade Notes
See the openAS2HowTo appendix for the general process on upgrading OpenAS2.
Expand All @@ -34,6 +37,7 @@ This is an enhancement and bugfix release:
### If upgrading from versions older than 2.5.0:
1. Change the name of the MDN sender module from "AsynchMDNSenderModule" to "MDNSenderModule" in the config.xml if using your existing config.xml file in the upgrade.
2. Change the name of the partnership attribute "messageid" to "as2_message_id_format" if used in any partnership definition.
3. Change the "as2_mdn_options" attribute to use $attribute.sign$ instead of hard coded signing algorithm


### If upgrading from versions older than 2.4.1:
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.5.0-SNAPSHOT</version>
<version>2.5.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 @@ -6,7 +6,7 @@
<parent>
<groupId>net.sf.openas2</groupId>
<artifactId>OpenAS2</artifactId>
<version>2.5.0-SNAPSHOT2</version>
<version>2.5.0</version>
</parent>

<artifactId>openas2-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.openas2.message.MessageMDN;
import org.openas2.params.InvalidParameterException;
import org.openas2.partner.Partnership;
import org.openas2.partner.SecurePartnership;
import org.openas2.schedule.HasSchedule;
import org.openas2.support.FileMonitorAdapter;
import org.openas2.util.AS2Util;
Expand All @@ -49,10 +48,10 @@ public String getAlias(Partnership partnership, String partnershipType) throws O

if (partnershipType == Partnership.PTYPE_RECEIVER)
{
alias = partnership.getReceiverID(SecurePartnership.PID_X509_ALIAS);
alias = partnership.getReceiverID(Partnership.PID_X509_ALIAS);
} else if (partnershipType == Partnership.PTYPE_SENDER)
{
alias = partnership.getSenderID(SecurePartnership.PID_X509_ALIAS);
alias = partnership.getSenderID(Partnership.PID_X509_ALIAS);
}

if (alias == null)
Expand Down
12 changes: 0 additions & 12 deletions Server/src/main/java/org/openas2/lib/partner/IPartnership.java

This file was deleted.

7 changes: 3 additions & 4 deletions Server/src/main/java/org/openas2/message/AS2Message.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.openas2.message;

import org.openas2.params.InvalidParameterException;
import org.openas2.partner.AS2Partnership;
import org.openas2.partner.Partnership;


Expand All @@ -26,8 +25,8 @@ public boolean isRequestingMDN() {

public boolean isConfiguredForMDN() {
Partnership p = getPartnership();
return ((p.getAttribute(AS2Partnership.PA_AS2_MDN_TO) != null)
&& (p.getAttribute(AS2Partnership.PA_AS2_MDN_OPTIONS) != null));
return ((p.getAttribute(Partnership.PA_AS2_MDN_TO) != null)
&& (p.getAttribute(Partnership.PA_AS2_MDN_OPTIONS) != null));

}

Expand All @@ -38,7 +37,7 @@ public boolean isRequestingAsynchMDN() {

public boolean isConfiguredForAsynchMDN() {
Partnership p = getPartnership();
return (p.getAttribute(AS2Partnership.PA_AS2_RECEIPT_OPTION) != null);
return (p.getAttribute(Partnership.PA_AS2_RECEIPT_OPTION) != null);
}

public String getAsyncMDNurl() {
Expand Down
20 changes: 0 additions & 20 deletions Server/src/main/java/org/openas2/partner/AS2Partnership.java

This file was deleted.

12 changes: 0 additions & 12 deletions Server/src/main/java/org/openas2/partner/ASXPartnership.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public void updatePartnership(Message msg, boolean overwrite) throws OpenAS2Exce
msg.getPartnership().copy(partnership);
// Now set dynamic parms based on file name if configured to
String filename = msg.getAttribute(FileAttribute.MA_FILENAME);
String filenameToParmsList = msg.getPartnership().getAttribute(AS2Partnership.PA_ATTRIB_NAMES_FROM_FILENAME);
String filenameToParmsList = msg.getPartnership().getAttribute(Partnership.PAIB_NAMES_FROM_FILENAME);
if (filename != null && filenameToParmsList != null && filenameToParmsList.length() > 0)
{
String[] headerNames = filenameToParmsList.split("\\s*,\\s*");

String regex = msg.getPartnership().getAttribute(AS2Partnership.PA_ATTRIB_VALUES_REGEX_ON_FILENAME);
String regex = msg.getPartnership().getAttribute(Partnership.PAIB_VALUES_REGEX_ON_FILENAME);
if (regex != null)
{
Pattern p = Pattern.compile(regex);
Expand Down
39 changes: 33 additions & 6 deletions Server/src/main/java/org/openas2/partner/Partnership.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,51 @@


public class Partnership implements Serializable {

/* identifier to define if context is sending or receiving */
public static final String PTYPE_SENDER = "sender"; // Sender partner type
public static final String PTYPE_RECEIVER = "receiver"; // Receiver partner type

/* partner definition attributes */
public static final String PID_AS2 = "as2_id"; // AS2 ID
public static final String PID_X509_ALIAS = "x509_alias"; // Alias to an X509 Certificate
public static final String PID_EMAIL = "email"; // Email address
public static final String PA_PROTOCOL = "protocol"; // AS1 or AS2

/* partnership definition attributes */
public static final String PA_SUBJECT = "subject"; // Subject sent in messages
public static final String PA_CONTENT_TRANSFER_ENCODING = "content_transfer_encoding"; // optional content transfer enc value
public static final String PA_REMOVE_PROTECTION_ATTRIB = "remove_cms_algorithm_protection_attrib"; // Some AS2 systems do not support the attribute
public static final String PA_SET_CONTENT_TRANSFER_ENCODING_OMBP = "set_content_transfer_encoding_on_outer_mime_bodypart"; // optional content transfer enc value
public static final String PA_RESEND_REQUIRES_NEW_MESSAGE_ID = "resend_requires_new_message_id"; // list of nme/value pairs for setting custom mime headers
/**
*
*/
public static final String PA_COMPRESSION_TYPE = "compression";
public static final String PA_SIGNATURE_ALGORITHM = "sign";
public static final String PA_ENCRYPTION_ALGORITHM = "encrypt";
public static final String PA_AS2_URL = "as2_url"; // URL destination for AS2 transactions
public static final String PA_AS2_MDN_TO = "as2_mdn_to"; // Fill in to request an MDN for a transaction
public static final String PA_AS2_MDN_OPTIONS = "as2_mdn_options"; // Requested options for returned MDN
public static final String PA_AS2_RECEIPT_OPTION = "as2_receipt_option"; // URL destination for an async MDN
public static final String PA_RESEND_MAX_RETRIES = "resend_max_retries"; // format to use for message-id if not default
public static final String PA_CUSTOM_MIME_HEADERS = "custom_mime_headers"; // list of nme/value pairs for setting custom mime headers
public static final String PA_ADD_CUSTOM_MIME_HEADERS_TO_HTTP = "add_custom_mime_headers_to_http"; // Add the custom mime headers (if any) to HTTP header if "true"
public static final String PA_CUSTOM_MIME_HEADER_NAMES_FROM_FILENAME = "custom_mime_header_names_from_filename"; // List of header names to be set from parsed filename
public static final String PA_CUSTOM_MIME_HEADER_NAME_DELIMITERS_IN_FILENAME = "custom_mime_header_name_delimiters_in_filename"; // Delimiters to split filename into values
public static final String PA_CUSTOM_MIME_HEADER_NAMES_REGEX_ON_FILENAME = "custom_mime_header_names_regex_on_filename"; // Regex to split filename into values
public static final String PAIB_NAMES_FROM_FILENAME = "attribute_names_from_filename"; // List of attribute names to be set from parsed filename
public static final String PAIB_VALUES_REGEX_ON_FILENAME = "attribute_values_regex_on_filename"; // Regex to split filename into values

/*
* If set and an error occurs while processing a document, an error MDN will not be sent. This
* flag was made because some AS2 products don't provide email or some other external notification
* when an error MDN is received.
*/
public static final String PA_BLOCK_ERROR_MDN = "blockerrormdn";


private static final long serialVersionUID = -8365608387462470629L;
private Map<String,String> attributes;
private Map<String,Object> receiverIDs;
private Map<String,Object> senderIDs;
private String name;

public String getName() {
return name;
}
Expand Down Expand Up @@ -173,7 +200,7 @@ public void copy(Partnership partnership) {

public boolean isAsyncMDN()
{
String receiptOptions = getAttribute(AS2Partnership.PA_AS2_RECEIPT_OPTION);
String receiptOptions = getAttribute(Partnership.PA_AS2_RECEIPT_OPTION);
return (receiptOptions != null && receiptOptions.length() > 0);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openas2.WrappedException;
import org.openas2.params.InvalidParameterException;
import org.openas2.support.FileMonitorAdapter;
import org.openas2.util.AS2Util;
import org.openas2.util.XMLUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -128,6 +129,7 @@ private void loadAttributes(Node node, Partnership partnership)
{
Map<String, String> nodes = XMLUtil.mapAttributeNodes(node.getChildNodes(), "attribute", "name", "value");

AS2Util.attributeEnhancer(nodes);
partnership.getAttributes().putAll(nodes);
}

Expand Down Expand Up @@ -155,7 +157,7 @@ private void loadPartnerIDs(Map<String, Object> partners, String partnershipName

if (partnerNode == null)
{
throw new OpenAS2Exception("Partnership " + partnershipName + " is missing sender");
throw new OpenAS2Exception("Partnership \"" + partnershipName + "\" is missing sender");
}

Map<String, String> partnerAttr = XMLUtil.mapAttributes(partnerNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

import org.openas2.OpenAS2Exception;
import org.openas2.Session;
import org.openas2.lib.partner.IPartnership;
import org.openas2.message.AS2MessageMDN;
import org.openas2.message.Message;
import org.openas2.message.MessageMDN;
import org.openas2.partner.AS2Partnership;
import org.openas2.partner.Partnership;
import org.openas2.processor.BaseProcessorModule;
import org.openas2.processor.resender.ResenderModule;

Expand Down Expand Up @@ -59,19 +58,19 @@ protected Map<String, String> buildMap(Message msg, Map<Object, Object> options)
map.put(FIELDS.RESEND_COUNT, (String) options.get(ResenderModule.OPTION_RETRIES));
}
//map.put(FIELDS.RESEND_COUNT, );
String sender = msg.getPartnership().getSenderID(AS2Partnership.PID_AS2);
if (sender == null) sender = mdn.getPartnership().getSenderID(AS2Partnership.PID_AS2);
String sender = msg.getPartnership().getSenderID(Partnership.PID_AS2);
if (sender == null) sender = mdn.getPartnership().getSenderID(Partnership.PID_AS2);
map.put(FIELDS.SENDER_ID, sender);
String receiver = msg.getPartnership().getReceiverID(AS2Partnership.PID_AS2);
if (receiver == null) receiver = mdn.getPartnership().getReceiverID(AS2Partnership.PID_AS2);
String receiver = msg.getPartnership().getReceiverID(Partnership.PID_AS2);
if (receiver == null) receiver = mdn.getPartnership().getReceiverID(Partnership.PID_AS2);
map.put(FIELDS.RECEIVER_ID, receiver);
map.put(FIELDS.STATUS, msg.getStatus());
String state = (String) options.get("STATE");
map.put(FIELDS.STATE, state);
map.put(FIELDS.STATE_MSG, Message.STATE_MSGS.get(state));
map.put(FIELDS.SIGNATURE_ALGORITHM, msg.getPartnership().getAttribute(IPartnership.ATTRIBUTE_SIGNATURE_ALGORITHM));
map.put(FIELDS.ENCRYPTION_ALGORITHM, msg.getPartnership().getAttribute(IPartnership.ATTRIBUTE_ENCRYPTION_ALGORITHM));
map.put(FIELDS.COMPRESSION, msg.getPartnership().getAttribute(IPartnership.ATTRIBUTE_COMPRESSION_TYPE));
map.put(FIELDS.SIGNATURE_ALGORITHM, msg.getPartnership().getAttribute(Partnership.PA_SIGNATURE_ALGORITHM));
map.put(FIELDS.ENCRYPTION_ALGORITHM, msg.getPartnership().getAttribute(Partnership.PA_ENCRYPTION_ALGORITHM));
map.put(FIELDS.COMPRESSION, msg.getPartnership().getAttribute(Partnership.PA_COMPRESSION_TYPE));
map.put(FIELDS.FILE_NAME, msg.getPayloadFilename());
map.put(FIELDS.CONTENT_TYPE, msg.getContentType());
map.put(FIELDS.CONTENT_TRANSFER_ENCODING, msg.getHeader("Content-Transfer-Encoding"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.openas2.message.AS2MessageMDN;
import org.openas2.message.Message;
import org.openas2.message.MessageMDN;
import org.openas2.partner.AS2Partnership;
import org.openas2.partner.Partnership;
import org.openas2.util.AS2Util;
import org.openas2.util.ByteArrayDataSource;
import org.openas2.util.HTTPUtil;
Expand Down Expand Up @@ -102,8 +102,8 @@ public void handle(NetModule owner, Socket s)
String to = msg.getHeader("AS2-To");
msg.setHeader("AS2-To", msg.getHeader("AS2-From"));
msg.setHeader("AS2-From", to);
msg.getPartnership().setSenderID(AS2Partnership.PID_AS2, msg.getHeader("AS2-From"));
msg.getPartnership().setReceiverID(AS2Partnership.PID_AS2, msg.getHeader("AS2-To"));
msg.getPartnership().setSenderID(Partnership.PID_AS2, msg.getHeader("AS2-From"));
msg.getPartnership().setReceiverID(Partnership.PID_AS2, msg.getHeader("AS2-To"));
getModule().getSession().getPartnershipFactory().updatePartnership(msg, true);

// Create a MessageMDN
Expand Down
Loading

0 comments on commit 0589b49

Please sign in to comment.