-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow unsigned MDN and control of Content-Transfer-Encoding HTTP head…
…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
1 parent
cb13d62
commit c0309bd
Showing
16 changed files
with
510 additions
and
467 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
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
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
251 changes: 126 additions & 125 deletions
251
Server/src/main/java/org/openas2/processor/msgtracking/EmbeddedDBHandler.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 |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
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
Oops, something went wrong.