forked from greenmail-mail-test/greenmail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes greenmail-mail-test#175 : Support verbose mode for GreenMail an…
…d standalone runner
- Loading branch information
Showing
8 changed files
with
117 additions
and
24 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
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 |
---|---|---|
|
@@ -15,14 +15,15 @@ | |
|
||
/** | ||
* Enables GreenMail to run in standalone mode. | ||
* | ||
* <p> | ||
* Example: java -Dgreenmail.smtp -Dgreenmail.users=test1:pwd1 -jar greenmail.jar | ||
* | ||
* @see PropertiesBasedServerSetupBuilder | ||
* @see PropertiesBasedGreenMailConfigurationBuilder | ||
*/ | ||
public class GreenMailStandaloneRunner { | ||
private final Logger log = LoggerFactory.getLogger(GreenMailStandaloneRunner.class); | ||
private GreenMail greenMail; | ||
|
||
/** | ||
* Start and configure GreenMail using given properties. | ||
|
@@ -36,13 +37,32 @@ public void doRun(Properties properties) { | |
printUsage(System.out); | ||
|
||
} else { | ||
GreenMail greenMail = new GreenMail(serverSetup); | ||
greenMail = new GreenMail(serverSetup); | ||
log.info("Starting GreenMail standalone using " + Arrays.toString(serverSetup)); | ||
greenMail.withConfiguration(new PropertiesBasedGreenMailConfigurationBuilder().build(properties)) | ||
.start(); | ||
} | ||
} | ||
|
||
protected static void configureLogging(Properties properties) { | ||
// Init logging: Try standard log4j configuration mechanism before falling back to | ||
// provided logging configuration | ||
String log4jConfig = System.getProperty("log4j.configuration"); | ||
if (null == log4jConfig) { | ||
if (properties.containsKey(PropertiesBasedServerSetupBuilder.GREENMAIL_VERBOSE)) { | ||
DOMConfigurator.configure(GreenMailStandaloneRunner.class.getResource("/log4j-verbose.xml")); | ||
} else { | ||
DOMConfigurator.configure(GreenMailStandaloneRunner.class.getResource("/log4j.xml")); | ||
} | ||
} else { | ||
if (log4jConfig.toLowerCase().endsWith(".xml")) { | ||
DOMConfigurator.configure(log4jConfig); | ||
} else { | ||
PropertyConfigurator.configure(log4jConfig); | ||
} | ||
} | ||
} | ||
|
||
private void printUsage(PrintStream out) { | ||
// Don't use logger | ||
out.println("Usage: java OPTIONS -jar greenmail.jar"); | ||
|
@@ -58,8 +78,9 @@ private void printUsage(PrintStream out) { | |
{"-Dgreenmail.<protocol|all>.port=...", "Specifies port. Requires additional hostname parameter."}, | ||
{"-Dgreenmail.users=<logon:pwd@domain>[,...]", "Specifies mail users, eg foo:[email protected],foo2:[email protected]."}, | ||
{"Note: domain must be DNS resolvable!"}, | ||
{"-Dgreenmail.auth.disabled ","Disables authentication check so that any password works."}, | ||
{"-Dgreenmail.auth.disabled ", "Disables authentication check so that any password works."}, | ||
{"Also automatically provisions previously non-existent users."}, | ||
{"-Dgreenmail.verbose ", "Enables verbose mode, including JavaMail debug output"}, | ||
}; | ||
for (String[] opt : options) { | ||
if (opt.length == 1) { | ||
|
@@ -81,20 +102,13 @@ private void printUsage(PrintStream out) { | |
out.println(" Starts SMTP on 0.0.0.0:3025 and IMAP on 0.0.0.0:3143"); | ||
} | ||
|
||
public static void main(String[] args) { | ||
// Init logging: Try standard log4j configuration mechanism before falling back to | ||
// provided logging configuration | ||
String log4jConfig = System.getProperty("log4j.configuration"); | ||
if (null == log4jConfig) { | ||
DOMConfigurator.configure(GreenMailStandaloneRunner.class.getResource("/log4j.xml")); | ||
} else { | ||
if (log4jConfig.toLowerCase().endsWith(".xml")) { | ||
DOMConfigurator.configure(log4jConfig); | ||
} else { | ||
PropertyConfigurator.configure(log4jConfig); | ||
} | ||
} | ||
GreenMail getGreenMail() { | ||
return greenMail; | ||
} | ||
|
||
new GreenMailStandaloneRunner().doRun(System.getProperties()); | ||
public static void main(String[] args) { | ||
final Properties properties = System.getProperties(); | ||
configureLogging(properties); | ||
new GreenMailStandaloneRunner().doRun(properties); | ||
} | ||
} |
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> | ||
|
||
<!-- | ||
| For more configuration information and examples see the Jakarta Log4j | ||
| website http://jakarta.apache.org/log4j and for the output pattern format | ||
| http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html | ||
--> | ||
|
||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> | ||
|
||
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Target" value="System.out"/> | ||
<param name="Threshold" value="DEBUG"/> | ||
|
||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%-7.7r %-5.5p %25.25c{2}| %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<root> | ||
<level value="DEBUG" /> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
</log4j:configuration> |
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