Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- Improvements/fixes log4j2 for all web-containers
- Cleanup make-file
  • Loading branch information
autumoswitzerland committed Nov 8, 2024
1 parent 03e7d9e commit b27793c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
4 changes: 0 additions & 4 deletions cfg/web-jetty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
<param-name>beetRootConfig</param-name>
<param-value>beetroot.cfg</param-value>
</init-param>
<init-param>
<param-name>servletContainer</param-name>
<param-value>jetty</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
Expand Down
6 changes: 6 additions & 0 deletions cfg/weblogic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
<debug-enabled>false</debug-enabled>
</session-descriptor>

<container-descriptor>
<prefer-application-packages>
<package-name>org.apache.logging.log4j.*</package-name>
</prefer-application-packages>
</container-descriptor>

</weblogic-web-app>
Binary file not shown.
18 changes: 12 additions & 6 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
###############################################################################
#
# beetRoot product packager.
# Version: 4.7
# Version: 4.8
#
# Notes:
# -
#
#------------------------------------------------------------------------------
#
# Copyright 2024 autumo GmbH
# Date: 02.07.2024
# Date: 2024-11-08
#
###############################################################################

Expand All @@ -20,6 +20,8 @@

# Vars
VERSION=3.1.2
SLF4J_SIMPLE_VERSION=1.7.36
LOG4J_WEB_VERSION=2.24.1



Expand Down Expand Up @@ -350,12 +352,16 @@ HEX=`hexdump -vn16 -e'4/4 "%08x" 1 "\n"' /dev/urandom`
sed -i '' 's/web_html_ref_pre_url_part=/web_html_ref_pre_url_part=beetroot/' beetroot.cfg
jar --create --file "beetroot.war" *
mv *.war ../
rm -f logging.xml
cd ..


# -- 2. WebLogic
cp ../cfg/weblogic.xml autumo-beetRoot-web-${VERSION}/WEB-INF/weblogic.xml
cp ../cfg/logging-web-weblogic.xml autumo-beetRoot-web-${VERSION}/logging.xml
cp ../cfg/web-weblogic.xml autumo-beetRoot-web-$VERSION/WEB-INF/web.xml
cp ../cfg/logging-web-weblogic.xml autumo-beetRoot-web-${VERSION}/WEB-INF/log4j2.xml
# Enrich logging implementation
(cd autumo-beetRoot-web-$VERSION/WEB-INF/lib && curl -LO https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-web/${LOG4J_WEB_VERSION}/log4j-web-${LOG4J_WEB_VERSION}.jar)
# change port (used for email templates)
sed -i '' 's/ws_port=.*/ws_port=7001/' autumo-beetRoot-web-${VERSION}/beetroot.cfg
# Use Javax for mailing
Expand All @@ -369,16 +375,16 @@ HEX=`hexdump -vn16 -e'4/4 "%08x" 1 "\n"' /dev/urandom`
-x "*/.DS_Store" \
-x "*/__MACOSX"
rm -fR beetroot/
rm -f autumo-beetRoot-web-${VERSION}/WEB-INF/weblogic.xml
rm -f autumo-beetRoot-web-${VERSION}/WEB-INF/lib/log4j-web-*.jar


# -- 3. Jetty
rm -f autumo-beetRoot-web-${VERSION}/WEB-INF/weblogic.xml
cp ../cfg/web-jetty.xml autumo-beetRoot-web-$VERSION/WEB-INF/web.xml
cp ../cfg/jetty-web.xml autumo-beetRoot-web-$VERSION/WEB-INF/jetty-web.xml
# Replace logging implementation!
(cd autumo-beetRoot-web-$VERSION/WEB-INF/lib && curl -LO https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar)
rm autumo-beetRoot-web-$VERSION/WEB-INF/lib/log4j-slf4j-impl-*.jar
rm -f autumo-beetRoot-web-$VERSION/logging.xml
(cd autumo-beetRoot-web-$VERSION/WEB-INF/lib && curl -LO https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/${SLF4J_SIMPLE_VERSION}/slf4j-simple-${SLF4J_SIMPLE_VERSION}.jar)
# no AUTO_SERVER=TRUE switch
sed -i '' 's|db_url=jdbc:h2:.*|db_url=jdbc:h2:[WEB-CONTEXT-PATH]/db/h2/db/beetroot;IFEXISTS=TRUE|' autumo-beetRoot-web-${VERSION}/beetroot.cfg
# Change back mailing implementation
Expand Down
47 changes: 21 additions & 26 deletions src/main/java/ch/autumo/beetroot/AbstractBeetRootServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void init(ServletConfig config) throws ServletException {
final String configFilePath = config.getInitParameter("beetRootConfig");
final String beetRootServiceClass = config.getInitParameter("beetRootServiceClass");


// 1. Read general config
final BeetRootConfigurationManager configMan = BeetRootConfigurationManager.getInstance();
try {
Expand All @@ -67,19 +68,21 @@ public void init(ServletConfig config) throws ServletException {
}



// 2. Logging configuration
final String servletContainer = config.getInitParameter("servletContainer");
if (servletContainer == null || !servletContainer.equals("jetty")) {
// Configure logging
final String logCfgFile = config.getInitParameter("beetRootLogConfig");
final String logCfgFile = config.getInitParameter("beetRootLogConfig");
if (logCfgFile != null && !logCfgFile.isEmpty()) {
// 2.1 Apache Tomcat.
try {
// For environments such as WebLogic, it is important that a logging context has a unique name!
LoggingFactory.getInstance().initialize(webAppRoot + logCfgFile, configMan.getServletName());
} catch (Exception ioex) {
throw new ServletException("Logging configuration initialization failed !", ioex);
}
}
// logCfgFile = null ->
// 2.2 For WebLogic, log4j2-logging will be initialized
// by the log4j-web-jar and the listener defined in web.xml.
// 2.3 Jetty uses simpler logging that can be bridged with slf4j-simple.


// 3. DB connection manager
try {
Expand All @@ -93,8 +96,8 @@ public void init(ServletConfig config) throws ServletException {
}


// Create the beetRoot server running in a passive server mode,
// basically only parsing and sending the body
// 4. Create the beetRoot server running in a passive server mode,
// basically only parsing and sending the body
try {
final Class<?> clz = Class.forName(beetRootServiceClass);
beetRootService = (BeetRootService) clz.getDeclaredConstructor().newInstance();
Expand All @@ -103,6 +106,7 @@ public void init(ServletConfig config) throws ServletException {
throw new ServletException("Couldn't create beetroot service from class '"+beetRootServiceClass+"'!", e);
}


/** Servlet's life-cycle doesn't allow this.
// Finally load user sessions
try {
Expand All @@ -125,18 +129,15 @@ public void destroy() {
}
*/

// clear sessions from memory
// Clear sessions from memory
sessions.clear(); // all we need to do here

// free service resource, etc.
// Free service resource, etc.
beetRootService.destroy();

// release database resources
// Release database resources
BeetRootDatabaseManager.getInstance().release();

// no threads need to be stopped, no streams closed,
// servlet container does it all for us here.,
// just call the standard servlet destroy-method
// No threads need to be stopped, no streams closed,
// servlet-container does it all for us here.
// Just call the standard servlet-destroy-method.
super.destroy();
}

Expand All @@ -157,23 +158,17 @@ protected BeetRootService getBeetRootService() {
* @throws IOException IO Exception
*/
protected BeetRootHTTPSession findOrCreateHttpSession(HttpServletRequest request) throws IOException {

// servlet container session ID
// Servlet-container session ID
final String sessionID = request.getSession().getId();

BeetRootHTTPSession session = null;
if (sessions.containsKey(sessionID))
return sessions.get(sessionID); // found !

// Create a temp file manager that handles the uploads within nano mechanics
// Create a temporary file manager that handles the uploads within NANO-Httpd API
final ITempFileManager tempFileManager = beetRootService.newTempFileManager();

// If there isn't a session yet, create one and deliver the input stream to it for parsing the body
session = new BeetRootHTTPSession(sessionID, tempFileManager, request.getInputStream());

// store it.
// Store it
sessions.put(sessionID, session);

return session;
}

Expand Down

0 comments on commit b27793c

Please sign in to comment.