From ae1371b1652708f6db3c5a662be39550f33714ae Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Tue, 27 Sep 2022 09:52:36 -0300 Subject: [PATCH 1/3] Improved exception handling for Masterpage loading error. Fail fast and with detail --- .../com/genexus/webpanels/GXWebPanel.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/java/src/main/java/com/genexus/webpanels/GXWebPanel.java b/java/src/main/java/com/genexus/webpanels/GXWebPanel.java index 82aac6b95..424838932 100644 --- a/java/src/main/java/com/genexus/webpanels/GXWebPanel.java +++ b/java/src/main/java/com/genexus/webpanels/GXWebPanel.java @@ -101,42 +101,38 @@ public void addString(String value) { httpContext.GX_webresponse.addString(value); } + private static String IMPL_CLASS_SUFFIX = "_impl"; + public GXMasterPage createMasterPage(int remoteHandle, String fullClassName) { + if (fullClassName.equals("(none)")) // none Master Page + { + return new NoneMasterPage((HttpContext) this.context.getHttpContext()); + } - String masterPage = this.context.getPreferences().getProperty("MasterPage", ""); if (fullClassName.equals("(default)")) // Is the default { + String masterPage = this.context.getPreferences().getProperty("MasterPage", ""); if (masterPage.isEmpty()) { logger.error("The default master page is not present on the client.cfg file, please add the MasterPage key to the client.cfg."); return null; } String namespace = this.context.getPreferences().getProperty("NAME_SPACE", ""); - fullClassName = namespace.isEmpty() ? masterPage.toLowerCase() + "_impl" : namespace.trim() + "." + masterPage.toLowerCase() + "_impl"; - } - if (fullClassName.equals("(none)")) // none Master Page - { - return new NoneMasterPage((HttpContext) this.context.getHttpContext()); - } - else{ - fullClassName = fullClassName + "_impl"; + fullClassName = namespace.isEmpty() ? masterPage.toLowerCase() + IMPL_CLASS_SUFFIX : namespace.trim() + "." + masterPage.toLowerCase() + IMPL_CLASS_SUFFIX; } + + fullClassName = fullClassName + IMPL_CLASS_SUFFIX; + try { Class masterPageClass = Class.forName(fullClassName); return (GXMasterPage) masterPageClass.getConstructor(new Class[] {int.class, ModelContext.class}).newInstance(remoteHandle, context.copy()); } catch (ClassNotFoundException e) { - logger.error("MasterPage not found: " + fullClassName); - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); + logger.error("MasterPage class not found: " + fullClassName, e); + throw new RuntimeException(e); + } catch (Exception e) { + logger.error("MasterPage could not be loaded: " + fullClassName, e); + throw new RuntimeException(e); } - return null; } @@ -147,11 +143,15 @@ protected Object dyncall(String MethodName) logger.error("DynCall - Method not found: " + MethodName); return null; } + Class[] pars = m.getParameterTypes(); int ParmsCount = pars.length; Object[] convertedparms = new Object[ParmsCount]; - for (int i = 0; i < ParmsCount; i++) + + for (int i = 0; i < ParmsCount; i++) { convertedparms[i] = convertparm(pars, i, WebUtils.decryptParm(httpContext.GetNextPar(), "")); + } + try { return m.invoke(this, convertedparms); @@ -159,8 +159,9 @@ protected Object dyncall(String MethodName) catch (java.lang.Exception e) { logger.error("DynCall - Invoke error " + MethodName, e); - return null; } + + return null; } protected Object convertparm(Class[] pars, int i, Object value) { From 0e6cdd27d7be220661eb288bfb1f6ad7e7ee79a5 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Wed, 28 Sep 2022 09:59:15 -0300 Subject: [PATCH 2/3] "_impl" could be appended twice for Masterpage class name --- java/src/main/java/com/genexus/webpanels/GXWebPanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/main/java/com/genexus/webpanels/GXWebPanel.java b/java/src/main/java/com/genexus/webpanels/GXWebPanel.java index 424838932..a7e706492 100644 --- a/java/src/main/java/com/genexus/webpanels/GXWebPanel.java +++ b/java/src/main/java/com/genexus/webpanels/GXWebPanel.java @@ -118,7 +118,7 @@ public GXMasterPage createMasterPage(int remoteHandle, String fullClassName) { return null; } String namespace = this.context.getPreferences().getProperty("NAME_SPACE", ""); - fullClassName = namespace.isEmpty() ? masterPage.toLowerCase() + IMPL_CLASS_SUFFIX : namespace.trim() + "." + masterPage.toLowerCase() + IMPL_CLASS_SUFFIX; + fullClassName = namespace.isEmpty() ? masterPage.toLowerCase(): namespace.trim() + "." + masterPage.toLowerCase(); } fullClassName = fullClassName + IMPL_CLASS_SUFFIX; From 69f4321b5470c83758da91fb992d8aceee17873d Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Wed, 28 Sep 2022 10:25:09 -0300 Subject: [PATCH 3/3] Removed unused Masterpage none & default. --- .../com/genexus/webpanels/GXWebPanel.java | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/java/src/main/java/com/genexus/webpanels/GXWebPanel.java b/java/src/main/java/com/genexus/webpanels/GXWebPanel.java index a7e706492..d48eb6649 100644 --- a/java/src/main/java/com/genexus/webpanels/GXWebPanel.java +++ b/java/src/main/java/com/genexus/webpanels/GXWebPanel.java @@ -100,29 +100,9 @@ public boolean isAjaxCallMode() public void addString(String value) { httpContext.GX_webresponse.addString(value); } - - private static String IMPL_CLASS_SUFFIX = "_impl"; - + public GXMasterPage createMasterPage(int remoteHandle, String fullClassName) { - if (fullClassName.equals("(none)")) // none Master Page - { - return new NoneMasterPage((HttpContext) this.context.getHttpContext()); - } - - if (fullClassName.equals("(default)")) // Is the default - { - String masterPage = this.context.getPreferences().getProperty("MasterPage", ""); - if (masterPage.isEmpty()) - { - logger.error("The default master page is not present on the client.cfg file, please add the MasterPage key to the client.cfg."); - return null; - } - String namespace = this.context.getPreferences().getProperty("NAME_SPACE", ""); - fullClassName = namespace.isEmpty() ? masterPage.toLowerCase(): namespace.trim() + "." + masterPage.toLowerCase(); - } - - fullClassName = fullClassName + IMPL_CLASS_SUFFIX; - + fullClassName = fullClassName + "_impl"; try { Class masterPageClass = Class.forName(fullClassName); return (GXMasterPage) masterPageClass.getConstructor(new Class[] {int.class, ModelContext.class}).newInstance(remoteHandle, context.copy());