Skip to content

Commit ebde820

Browse files
committed
#Fix: Logger initialization fixes. REST, WS Native.
1 parent c99e6cd commit ebde820

File tree

8 files changed

+96
-58
lines changed

8 files changed

+96
-58
lines changed

java/src/main/java/com/genexus/Application.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class Application
2626
static {
2727
Connect.init();
2828
}
29+
2930
public static ILogger logger = LogManager.getLogger(Application.class);
3031

3132
public static boolean usingQueue = false;
@@ -48,7 +49,6 @@ public class Application
4849
private static Object objectLock = new Object();
4950
private static volatile boolean initialized = false;
5051

51-
5252
public static void onExitCleanup()
5353
{
5454
if (toCleanup != null)

java/src/main/java/com/genexus/GxRestService.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
abstract public class GxRestService extends GXWebObjectBase
2424
{
25-
private static final ILogger logger = LogManager.getLogger(GxRestService.class);
25+
private static ILogger logger = null;
2626

2727
protected JSONObject errorJson;
2828
protected boolean error = false;
@@ -59,6 +59,7 @@ public GxRestService()
5959
HttpContext restHttpContext;
6060
public void init(String requestMethod, HttpServletRequest myServletRequest, HttpServletResponse myServletResponse, ServletContext myContext)
6161
{
62+
initLogger(myContext);
6263
try
6364
{
6465
String gxcfg = myContext.getInitParameter("gxcfg");
@@ -83,8 +84,14 @@ public void init(String requestMethod, HttpServletRequest myServletRequest, Http
8384
logger.error("Could not initialize Rest Service", e);
8485
}
8586
}
86-
87-
public void webExecute( )
87+
88+
private void initLogger(ServletContext myContext) {
89+
if (logger == null) {
90+
logger = com.genexus.specific.java.LogManager.initialize(myContext.getRealPath("/"), GxRestService.class);
91+
}
92+
}
93+
94+
public void webExecute( )
8895
{
8996
}
9097

java/src/main/java/com/genexus/specific/java/LogManager.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
package com.genexus.specific.java;
22

33
import com.genexus.common.interfaces.IExtensionLogManager;
4+
import com.genexus.common.interfaces.SpecificImplementation;
45
import com.genexus.diagnostics.core.ILogger;
56

67
public class LogManager implements IExtensionLogManager {
8+
private static boolean initialized;
9+
710
static {
811
configure(".");
912
}
1013

1114
public static void configure(String logBasePath) {
12-
org.apache.logging.log4j.core.lookup.MapLookup.setMainArguments(new String[] {logBasePath});
15+
org.apache.logging.log4j.core.lookup.MapLookup.setMainArguments(new String[]{logBasePath});
1316
//If we do not disable StatusLogger => Log4J throws message logging when log4j.xml is not found
1417
org.apache.logging.log4j.status.StatusLogger.getLogger().setLevel(org.apache.logging.log4j.Level.OFF);
1518
}
19+
public static void initialize(String logBasePath) {
20+
if (!initialized) {
21+
initialized = true;
22+
configure(logBasePath);
23+
if (SpecificImplementation.LogManager == null) {
24+
SpecificImplementation.LogManager = new LogManager();
25+
}
26+
}
27+
}
28+
29+
public static ILogger initialize(String logBasePath, Class<?> clazz) {
30+
initialize(logBasePath);
31+
return SpecificImplementation.LogManager.getLogger(clazz);
32+
}
1633

1734
@Override
1835
public ILogger getLogger(Class<?> clazz) {

java/src/main/java/com/genexus/webpanels/GXObjectUploadServices.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class GXObjectUploadServices extends GXWebObjectStub
1818
{
1919
protected void doExecute(HttpContext context) throws Exception
2020
{
21-
new WebApplicationStartup().init(Application.gxCfg, context);
21+
WebApplicationStartup.init(Application.gxCfg, context);
2222
context.setStream();
2323

2424
try

java/src/main/java/com/genexus/webpanels/GXWebObjectStub.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
import com.genexus.security.GXResult;
1717
import com.genexus.security.GXSecurityProvider;
1818

19-
2019
public abstract class GXWebObjectStub extends HttpServlet
2120
{
22-
public static ILogger logger = LogManager.getLogger(GXWebObjectStub.class);
21+
public static ILogger logger = null;
2322

2423
private static final boolean DEBUG = DebugFlag.DEBUG;
2524

@@ -103,8 +102,8 @@ private void dumpRequestInfo(HttpContext httpContext)
103102

104103
private void callExecute(String method, HttpServletRequest req, HttpServletResponse res) throws ServletException
105104
{
105+
initialize(req, res);
106106
HttpContext httpContext = null;
107-
setResponseBufferSize(res);
108107
try
109108
{
110109
String gxcfg = getServletContext().getInitParameter("gxcfg");
@@ -217,6 +216,13 @@ else if (IntegratedSecurityLevel() == SECURITY_LOW)
217216
}
218217
}
219218

219+
private void initialize(HttpServletRequest req, HttpServletResponse res) {
220+
if (logger == null) {
221+
logger = com.genexus.specific.java.LogManager.initialize(req.getServletContext().getRealPath("/"), GXWebObjectStub.class);
222+
}
223+
setResponseBufferSize(res);
224+
}
225+
220226
private void setResponseBufferSize(HttpServletResponse res) {
221227
Integer bSize = 0;
222228
try {

java/src/main/java/com/genexus/webpanels/ServletEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void contextInitialized(ServletContextEvent event)
8181
{
8282
ServletContext context = event.getServletContext();
8383
String basePath = context.getRealPath("/");
84-
LogManager.configure(basePath);
84+
LogManager.initialize(basePath);
8585
String gxcfg = context.getInitParameter("gxcfg");
8686
if (gxcfg != null)
8787
{

java/src/main/java/com/genexus/webpanels/WebApplicationStartup.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import com.genexus.ApplicationContext;
55
import com.genexus.ModelContext;
66
import com.genexus.internet.HttpContext;
7+
import com.genexus.specific.java.LogManager;
78

8-
public class WebApplicationStartup
9+
public class WebApplicationStartup
910
{
10-
static boolean initialized = false;
11+
private static boolean initialized = false;
1112

12-
public void init(Class baseClass, HttpContext httpContext)
13+
public static void init(Class baseClass, HttpContext httpContext)
1314
{
1415
if (!initialized)
1516
{
@@ -18,7 +19,7 @@ public void init(Class baseClass, HttpContext httpContext)
1819
}
1920

2021

21-
private synchronized void initImpl(Class baseClass, HttpContext httpContext)
22+
private static synchronized void initImpl(Class baseClass, HttpContext httpContext)
2223
{
2324
if (!initialized)
2425
{
@@ -28,7 +29,7 @@ private synchronized void initImpl(Class baseClass, HttpContext httpContext)
2829
appContext.setMsgsToUI(false);
2930
appContext.setServletEngine(true);
3031
appContext.setServletEngineDefaultPath(basePath);
31-
32+
LogManager.initialize(basePath);
3233
Application.init(baseClass, false);
3334
ModelContext.getModelContext(baseClass).setHttpContext(httpContext);
3435
initialized = true;

java/src/main/java/com/genexus/ws/GXHandlerChain.java

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,55 @@
66
import javax.xml.ws.handler.soap.SOAPHandler;
77
import javax.xml.ws.handler.MessageContext;
88
import javax.xml.ws.handler.soap.SOAPMessageContext;
9+
import javax.xml.ws.WebServiceContext;
10+
import javax.annotation.Resource;
11+
import javax.servlet.ServletContext;
12+
913
import com.genexus.diagnostics.core.ILogger;
10-
import com.genexus.diagnostics.core.LogManager;
11-
12-
public class GXHandlerChain implements SOAPHandler<SOAPMessageContext>
13-
{
14-
private static ILogger logger = LogManager.getLogger(GXHandlerChain.class);
15-
public static final String GX_SOAP_BODY = "GXSoapBody";
16-
17-
public Set<QName> getHeaders()
18-
{
19-
return Collections.emptySet();
20-
}
21-
22-
public boolean handleMessage(SOAPMessageContext messageContext)
23-
{
24-
Boolean outboundProperty = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
25-
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();;
26-
try
27-
{
28-
messageContext.getMessage().writeTo(out);
29-
String messageBody = new String(out.toByteArray(), "utf-8");
30-
if (Boolean.FALSE.equals(outboundProperty))
31-
{
32-
messageContext.put(GX_SOAP_BODY, messageBody);
33-
messageContext.setScope(GX_SOAP_BODY, MessageContext.Scope.APPLICATION);
34-
}
35-
36-
logger.debug(messageBody);
37-
}
38-
catch (Exception e)
39-
{
40-
logger.error("Exception in handler: ", e);
41-
}
42-
return true;
43-
}
44-
45-
public boolean handleFault(SOAPMessageContext messageContext)
46-
{
47-
return true;
48-
}
49-
50-
public void close(MessageContext messageContext)
51-
{
52-
}
14+
import com.genexus.specific.java.LogManager;
15+
16+
17+
public class GXHandlerChain implements SOAPHandler<SOAPMessageContext> {
18+
@Resource
19+
private WebServiceContext context;
20+
21+
private static ILogger logger = null;
22+
public static final String GX_SOAP_BODY = "GXSoapBody";
23+
24+
public Set<QName> getHeaders() {
25+
return Collections.emptySet();
26+
}
27+
28+
public boolean handleMessage(SOAPMessageContext messageContext) {
29+
initialize();
30+
Boolean outboundProperty = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
31+
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
32+
;
33+
try {
34+
messageContext.getMessage().writeTo(out);
35+
String messageBody = new String(out.toByteArray(), "utf-8");
36+
if (Boolean.FALSE.equals(outboundProperty)) {
37+
messageContext.put(GX_SOAP_BODY, messageBody);
38+
messageContext.setScope(GX_SOAP_BODY, MessageContext.Scope.APPLICATION);
39+
}
40+
logger.debug(messageBody);
41+
} catch (Exception e) {
42+
logger.error("Exception in handler: ", e);
43+
}
44+
return true;
45+
}
46+
47+
private void initialize() {
48+
if (logger == null) {
49+
ServletContext servletContext = (ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
50+
logger = LogManager.initialize(servletContext.getRealPath("/"), GXHandlerChain.class);
51+
}
52+
}
53+
54+
public boolean handleFault(SOAPMessageContext messageContext) {
55+
return true;
56+
}
57+
58+
public void close(MessageContext messageContext) {
59+
}
5360
}

0 commit comments

Comments
 (0)