-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve issue#5, Suppress noisy ESAPI messages
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/org/t246osslab/easybuggy/core/listeners/InitializationListener.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,39 @@ | ||
package org.t246osslab.easybuggy.core.listeners; | ||
|
||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import javax.servlet.annotation.WebListener; | ||
|
||
import org.owasp.esapi.ESAPI; | ||
|
||
@WebListener | ||
public class InitializationListener implements ServletContextListener { | ||
public void contextInitialized(ServletContextEvent event) { | ||
|
||
/* | ||
* Suppress noisy messages output by the ESAPI library. For more detail: | ||
* https://stackoverflow.com/questions/45857064/how-to-suppress-messages-output-by-esapi-library | ||
*/ | ||
try { | ||
PrintStream original = System.out; | ||
PrintStream out = new PrintStream(new OutputStream() { | ||
public void write(int b) { | ||
// Do nothing | ||
} | ||
}); | ||
System.setOut(out); | ||
System.setErr(out); | ||
ESAPI.encoder(); | ||
System.setOut(original); | ||
} catch (Exception e) { | ||
// Do nothing | ||
} | ||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent sce) { | ||
} | ||
} |