Skip to content

Commit

Permalink
Allow unsigned MDN and control of Content-Transfer-Encoding HTTP head…
Browse files Browse the repository at this point in the history
…er (#122) (#123)

* Switch to the "standard" port for HTTP listener

* Add Content-Type as a static

* Allow Content-Type to be overwritten at partnership level with system
level default override

* Add modules to facilitate simpler server debugging within the IDE

* Allow unsigned MDN to be sent using the "none" keyword for the
as2_mdn_options attribute

* Allow unsigned MDN to be sent using the "none" keyword for the
as2_mdn_options attribute
The Content-Transfer-Encoding header is now a restricted header for HTTP
so allow it to be controlled by config at partnership level

* Control setting Content-Transfer-Encoding when restricted headers are
allowed

* getOrDefault method is Java 8 so make it compatible with Java 7

* Allow override at system level of the setting of
Content-Transfer-Encoding header

* Update documentation for release
  • Loading branch information
uhurusurfa authored and pete-gilchrist committed Sep 26, 2018
1 parent cb13d62 commit c0309bd
Show file tree
Hide file tree
Showing 16 changed files with 510 additions and 467 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.6.1</version>
<version>2.6.2</version>
</parent>

<artifactId>openas2-osgi</artifactId>
Expand Down
13 changes: 8 additions & 5 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# OpenAS2 Server
# Version 2.6.1
# Version 2.6.2
# RELEASE NOTES
-----
The OpenAS2 project is pleased to announce the release of OpenAS2 2.6.1
The OpenAS2 project is pleased to announce the release of OpenAS2 2.6.2

The release download file is: OpenAS2Server-2.6.1.zip
The release download file is: OpenAS2Server-2.6.2.zip

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

Version 2.6.1 - 2018-09-09
Version 2.6.2 - 2018-09-26
This is a minor enhancement release:
**IMPORTANT NOTE**: Please review upgrade notes below if you are upgrading

1. Allow MDN subject to use filename parsing functionality to set the text.
1. Provide ability to use restricted headers in HTTP with partnership level overrides for the "Content-Transfer-Encoding" header
2. Allow unsigned MDN to be sent using the "none" keyword for the "as2_mdn_options" attribute
3. Use a Java 7 compatible method call for a Map class method that required Java 8

##Upgrade Notes
See the openAS2HowTo appendix for the general process on upgrading OpenAS2.
Expand All @@ -24,6 +26,7 @@ This is a minor enhancement release:
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. If "AsynchMDNSenderModule" is not in the config then add the following: <module classname="org.openas2.processor.sender.MDNSenderModule" retries="3"/>
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
4. If you experience issues with partners failing that were working in the previous version, check the troubleshooting section of the OpenAS2HowTo guide - specifically the issues around Content Transfer Encoding and Content Length/Chunking


### 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.6.1</version>
<version>2.6.2</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.6.1</version>
<version>2.6.2</version>
</parent>

<artifactId>openas2-server</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions Server/src/main/java/org/openas2/partner/Partnership.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class Partnership implements Serializable {

/* partnership definition attributes */
public static final String PA_SUBJECT = "subject"; // Subject sent in messages
public static final String PA_CONTENT_TYPE = "content_type"; // optional content type for mime parts
public static final String PA_CONTENT_TRANSFER_ENCODING = "content_transfer_encoding"; // optional content transfer enc value
public static final String PA_SET_CONTENT_TRANSFER_ENCODING_HTTP = "set_content_transfer_encoding_http_header"; // See as an HTTP header
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,125 +1,126 @@
package org.openas2.processor.msgtracking;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;

import org.h2.jdbcx.JdbcConnectionPool;
import org.h2.tools.Server;
import org.openas2.OpenAS2Exception;

class EmbeddedDBHandler extends DbTrackingModule implements IDBHandler {

@Nullable
private JdbcConnectionPool cp = null;

private Server server = null;

private String connectString = "jdbc:h2:file:DB/openas2";

public void createConnectionPool(String connectString, String userName, String pwd) throws OpenAS2Exception
{
// Check that a connection pool is not already running
if (cp != null)
{
throw new OpenAS2Exception(
"Connection pool already initialized. Cannot create a new connection pool. Stop current one first. DB connect string:"
+ connectString + " :: Active pool connect string: " + this.connectString);
}
this.connectString = connectString;

cp = JdbcConnectionPool.create(connectString, userName, pwd);
}

public void start(String connectString, String userName, String pwd, Map<String, String> params) throws OpenAS2Exception
{
createConnectionPool(connectString, userName, pwd);
if ("true".equalsIgnoreCase(params.getOrDefault(PARAM_TCP_SERVER_START, "true")))
{
String tcpPort = params.get(PARAM_TCP_SERVER_PORT);
if (tcpPort == null || tcpPort.length() < 1) tcpPort = "9092";
String tcpPwd = params.get(PARAM_TCP_SERVER_PWD);
if (tcpPwd == null || tcpPwd.length() < 1) tcpPwd = "OpenAS2";
String dbDirectory = params.get(PARAM_DB_DIRECTORY);
if (dbDirectory == null || dbDirectory.length() < 1)
throw new OpenAS2Exception("TCP server requireds parameter: " + PARAM_DB_DIRECTORY);

try
{
server = Server.createTcpServer( "-tcpPort", tcpPort, "-tcpPassword", tcpPwd, "-baseDir", dbDirectory, "-tcpAllowOthers").start();
} catch (SQLException e)
{
throw new OpenAS2Exception("Failed to start TCP server", e);
}
}
}

public void stop()
{
// Stopping the TCP server will stop the database so only do one of them
if (server != null)
{
server.stop();
}
else
{
try
{
shutdown(connectString);
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
destroyConnectionPool();
}
}

public void destroyConnectionPool()
{
if (cp == null)
{
return;
}
cp.dispose();
cp = null;
}

public Connection getConnection() throws SQLException, OpenAS2Exception
{
// Check that a connection pool is running
if (cp == null)
{
throw new OpenAS2Exception("Connection pool not initialized.");
}
return cp.getConnection();
}

public boolean shutdown(String connectString) throws SQLException, OpenAS2Exception
{
// Wait briefly if there are active connections
int waitCount = 0;
try
{
while (cp != null && cp.getActiveConnections() > 0 && waitCount < 10)
{
TimeUnit.MILLISECONDS.sleep(100);
waitCount++;
}
} catch (InterruptedException e)
{
// Do nothing
}
Connection c = getConnection();
Statement st = c.createStatement();

boolean result = st.execute("SHUTDOWN");
c.close();
return result;
}

}
package org.openas2.processor.msgtracking;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;

import org.h2.jdbcx.JdbcConnectionPool;
import org.h2.tools.Server;
import org.openas2.OpenAS2Exception;

class EmbeddedDBHandler extends DbTrackingModule implements IDBHandler {

@Nullable
private JdbcConnectionPool cp = null;

private Server server = null;

private String connectString = "jdbc:h2:file:DB/openas2";

public void createConnectionPool(String connectString, String userName, String pwd) throws OpenAS2Exception
{
// Check that a connection pool is not already running
if (cp != null)
{
throw new OpenAS2Exception(
"Connection pool already initialized. Cannot create a new connection pool. Stop current one first. DB connect string:"
+ connectString + " :: Active pool connect string: " + this.connectString);
}
this.connectString = connectString;

cp = JdbcConnectionPool.create(connectString, userName, pwd);
}

public void start(String connectString, String userName, String pwd, Map<String, String> params) throws OpenAS2Exception
{
createConnectionPool(connectString, userName, pwd);
String isStartSrvr = params.get(PARAM_TCP_SERVER_START);
if (isStartSrvr == null || "true".equalsIgnoreCase(isStartSrvr))
{
String tcpPort = params.get(PARAM_TCP_SERVER_PORT);
if (tcpPort == null || tcpPort.length() < 1) tcpPort = "9092";
String tcpPwd = params.get(PARAM_TCP_SERVER_PWD);
if (tcpPwd == null || tcpPwd.length() < 1) tcpPwd = "OpenAS2";
String dbDirectory = params.get(PARAM_DB_DIRECTORY);
if (dbDirectory == null || dbDirectory.length() < 1)
throw new OpenAS2Exception("TCP server requireds parameter: " + PARAM_DB_DIRECTORY);

try
{
server = Server.createTcpServer( "-tcpPort", tcpPort, "-tcpPassword", tcpPwd, "-baseDir", dbDirectory, "-tcpAllowOthers").start();
} catch (SQLException e)
{
throw new OpenAS2Exception("Failed to start TCP server", e);
}
}
}

public void stop()
{
// Stopping the TCP server will stop the database so only do one of them
if (server != null)
{
server.stop();
}
else
{
try
{
shutdown(connectString);
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
destroyConnectionPool();
}
}

public void destroyConnectionPool()
{
if (cp == null)
{
return;
}
cp.dispose();
cp = null;
}

public Connection getConnection() throws SQLException, OpenAS2Exception
{
// Check that a connection pool is running
if (cp == null)
{
throw new OpenAS2Exception("Connection pool not initialized.");
}
return cp.getConnection();
}

public boolean shutdown(String connectString) throws SQLException, OpenAS2Exception
{
// Wait briefly if there are active connections
int waitCount = 0;
try
{
while (cp != null && cp.getActiveConnections() > 0 && waitCount < 10)
{
TimeUnit.MILLISECONDS.sleep(100);
waitCount++;
}
} catch (InterruptedException e)
{
// Do nothing
}
Connection c = getConnection();
Statement st = c.createStatement();

boolean result = st.execute("SHUTDOWN");
c.close();
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ public void buildMessageData(Message msg, InputStream ip, String filename) throw
try
{
//byte[] data = IOUtilOld.getFileBytes(file);
String contentType = getParameter(PARAM_MIMETYPE, false);
// Allow Content-Type to be overridden at partnership level or as property
String contentType = msg.getPartnership().getAttributeOrProperty(Partnership.PA_CONTENT_TYPE, null);
if (contentType == null) contentType = getParameter(PARAM_MIMETYPE, false);
if (contentType == null)
{
contentType = "application/octet-stream";
Expand Down
Loading

0 comments on commit c0309bd

Please sign in to comment.