-
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.
* Minor changes to messaging for MDN disposition errors. * Use find_java to look for JAVA_HOME * Remove double square brackets for Ubuntu dash compat * Handle cleanup error better. * Cater for unusable or questionable file names * Fix formatting failures * Handle EOF exception gracefully for unreadable pending info files * Refresh the partnership variables just before processing document. * Use find_java for identifying Java * Use the java executable instead of javac as it is not always installed. Use bash shell explicitly to cater for Ubuntu mapping sh to dash * Simplify reconstituting the mime body part. Provide backwards compat for now. * Extract more values to properties in preparation for automated upgrades. * Sample properties file for property driven custom configuration. * Upgrade notes * Updated documentation for 3.4.1 * Add the reject_unsigned_meesages attribute as an example. * New version and updated libraries to latest. * Extract the file splitting functionality to a separate class. Support running it as a thread or as a standalone app from command line * Minor changes to logging to make more sense. * Fix comment. * Version change and update libraries to latest releases. * Merge with upstream * Update mvnw * Fixes to accommodate RestAPI shortcomings with Java 8
- Loading branch information
1 parent
7e2a5cf
commit 641eb93
Showing
10 changed files
with
312 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
import org.openas2.util.FileUtil; | ||
import java.io.File; | ||
|
||
/** | ||
* Class used to add the server's certificate to the KeyStore with your trusted | ||
* certificates. | ||
*/ | ||
public class SplitCsvFile { | ||
|
||
public static final String SOURCE_FILE = "s"; | ||
public static final String OUT_FILENAME_PREFIX = "p"; | ||
public static final String OUTPUT_DIR = "o"; | ||
public static final String MAX_FILE_SIZE = "m"; | ||
public static final String HAS_HEADER_ROW = "h"; | ||
public static final String DEBUG = "d"; | ||
public static final String HELP_OPT = "h"; | ||
|
||
/* | ||
* Options in this format: short-opt, long-opt, has-argument, required, | ||
* description | ||
*/ | ||
public String[][] opts = { | ||
{SOURCE_FILE, "source", "true", "true", "the source file name including path"}, | ||
{MAX_FILE_SIZE, "max_size", "true", "true", "the maximum size of the files"}, | ||
{HAS_HEADER_ROW, "has_header", "false", "false", "if set, the file has a header row that wil be replicated into every file"}, | ||
{OUT_FILENAME_PREFIX, "out_file_prefix", "true", "false", "the prefix for the split file names"}, | ||
{OUTPUT_DIR, "out_dir", "true", "false", "output directory for the split files - defaults to current dir"}, | ||
{DEBUG, "debug", "true", "false", "Enabling debug logging"}, | ||
{HELP_OPT, "help", "false", "false", "print this help"} | ||
}; | ||
|
||
private void usage(Options options) { | ||
String header = "Splits CSV file." + "\nReads the file as a line based file creating new files that will not exceed the specified maximum size."; | ||
String footer = "NOTE: The file is expected to contain lines separated by newline characters."; | ||
|
||
HelpFormatter formatter = new HelpFormatter(); | ||
formatter.printHelp(this.getClass().getName(), header, options, footer, true); | ||
} | ||
|
||
private CommandLine parseCommandLine(String[] args) { | ||
// create the command line parser | ||
CommandLineParser parser = new DefaultParser(); | ||
|
||
// create the Options | ||
Options options = new Options(); | ||
for (String[] opt : opts) { | ||
Option option = Option.builder(opt[0]).longOpt(opt[1]).hasArg("true".equalsIgnoreCase(opt[2])).desc(opt[4]).build(); | ||
option.setRequired("true".equalsIgnoreCase(opt[3])); | ||
options.addOption(option); | ||
} | ||
|
||
// parse the command line arguments | ||
CommandLine line = null; | ||
try { | ||
line = parser.parse(options, args); | ||
} catch (ParseException e) { | ||
System.out.println("Command line parsing error: " + e.getMessage()); | ||
usage(options); | ||
System.exit(-1); | ||
} | ||
return line; | ||
} | ||
|
||
private void process(String[] args) throws Exception { | ||
CommandLine options = parseCommandLine(args); | ||
if (options == null) { | ||
return; | ||
} | ||
String sourceFileName = options.getOptionValue(SOURCE_FILE); | ||
File sourceFile = new File(sourceFileName); | ||
if (!sourceFile.exists()) { | ||
throw new Exception("File does not exist: " + sourceFileName); | ||
} | ||
long maxFileSize = Long.parseLong(options.getOptionValue(MAX_FILE_SIZE)); | ||
String outputDirName = null; | ||
if (options.hasOption(OUTPUT_DIR)) { | ||
outputDirName = options.getOptionValue(OUTPUT_DIR); | ||
} else { | ||
outputDirName = System.getProperty("user.dir"); | ||
} | ||
String prefix = (options.hasOption(OUT_FILENAME_PREFIX)) ? options.getOptionValue(OUT_FILENAME_PREFIX) : ""; | ||
boolean hasHeaderRow = options.hasOption(HAS_HEADER_ROW); | ||
|
||
if (options.hasOption(DEBUG) && "true".equalsIgnoreCase(options.getOptionValue(DEBUG))) { | ||
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); | ||
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); | ||
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "DEBUG"); | ||
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "ERROR"); | ||
} | ||
try { | ||
FileUtil.splitLineBasedFile(sourceFile, outputDirName, maxFileSize, hasHeaderRow, sourceFile.getName(), prefix); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.out.println("Processing error occurred: " + e.getMessage()); | ||
System.exit(-1); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
try { | ||
SplitCsvFile mgr = new SplitCsvFile(); | ||
mgr.process(args); | ||
System.exit(0); | ||
} catch (Exception e) { | ||
System.out.println("Processing error occurred: " + e.getMessage()); | ||
System.exit(-1); | ||
} | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
Server/src/main/java/org/openas2/processor/receiver/FileSplitter.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.openas2.processor.receiver; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.openas2.OpenAS2Exception; | ||
import org.openas2.util.FileUtil; | ||
import org.openas2.util.IOUtil; | ||
|
||
public class FileSplitter implements Runnable { | ||
private File sourceFile; | ||
private String outputDir; | ||
private long maxFileSize; | ||
private boolean containsHeaderRow; | ||
private String newFileBaseName; | ||
private String filenamePrefix; | ||
|
||
private static final Log logger = LogFactory.getLog(FileUtil.class.getSimpleName()); | ||
|
||
public FileSplitter(File sourceFile, String outputDir, long maxFileSize, boolean containsHeaderRow, String newFileBaseName, String filenamePrefix) { | ||
this.sourceFile = sourceFile; | ||
this.outputDir = outputDir; | ||
this.maxFileSize = maxFileSize; | ||
this.containsHeaderRow = containsHeaderRow; | ||
this.newFileBaseName = newFileBaseName; | ||
this.filenamePrefix = filenamePrefix; | ||
} | ||
|
||
public void run(){ | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("File splitter thread invoked for file: " + this.sourceFile.getAbsolutePath()); | ||
} | ||
try { | ||
FileUtil.splitLineBasedFile(this.sourceFile, this.outputDir, this.maxFileSize, this.containsHeaderRow, this.newFileBaseName, this.filenamePrefix); | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("Successfully split the file: " + this.sourceFile.getAbsolutePath()); | ||
} | ||
// Must have been successful so remove the original file | ||
try { | ||
IOUtil.deleteFile(sourceFile); | ||
} catch (IOException e) { | ||
throw new OpenAS2Exception("Failed to delete file after split processing: " + sourceFile.getAbsolutePath(), e); | ||
} | ||
} catch (OpenAS2Exception e) { | ||
logger.error("Failed to successfully split the file: " + this.sourceFile.getAbsolutePath() + " - " + e.getMessage(), e); | ||
} | ||
} | ||
} |
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.