From cdadb42c5ca51cf6db5be33d0d841dac16885625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Wed, 25 Sep 2024 20:01:54 +0200 Subject: [PATCH 01/19] Removed useless constant PS (pathSeparatorChar) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../admin/launcher/GFLauncherConstants.java | 2 +- .../admin/launcher/GFLauncherNativeHelper.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherConstants.java b/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherConstants.java index 88611631605..a697d79fa75 100644 --- a/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherConstants.java +++ b/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherConstants.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -26,7 +27,6 @@ class GFLauncherConstants { static final String JAVA_NATIVE_SYSPROP_NAME = "java.library.path"; static final String NEWLINE = System.getProperty("line.separator"); static final String LIBDIR = "lib"; - static final String PS = java.io.File.pathSeparator; static final String SPARC = "sparc"; static final String SPARCV9 = "sparcv9"; static final String X86 = "x86"; diff --git a/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherNativeHelper.java b/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherNativeHelper.java index fa5763354f9..559ad70f3f2 100644 --- a/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherNativeHelper.java +++ b/nucleus/admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncherNativeHelper.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -25,11 +26,11 @@ import static com.sun.enterprise.admin.launcher.GFLauncherConstants.AMD64; import static com.sun.enterprise.admin.launcher.GFLauncherConstants.JAVA_NATIVE_SYSPROP_NAME; import static com.sun.enterprise.admin.launcher.GFLauncherConstants.LIBDIR; -import static com.sun.enterprise.admin.launcher.GFLauncherConstants.PS; import static com.sun.enterprise.admin.launcher.GFLauncherConstants.SPARC; import static com.sun.enterprise.admin.launcher.GFLauncherConstants.SPARCV9; import static com.sun.enterprise.admin.launcher.GFLauncherConstants.X86; import static com.sun.enterprise.universal.io.SmartFile.sanitize; +import static java.io.File.pathSeparatorChar; /** * The platform-specific code is ugly. That's why it is concentrated here. @@ -73,11 +74,11 @@ List getCommands() { // don't worry about extra PS's --> no problem-o // don't worry about duplicates -- SmartFile will get rid of them... StringBuilder sb = new StringBuilder(); - sb.append(prefixFileString).append(PS); - sb.append(libFileString).append(PS); - sb.append(lib64FileString).append(PS); - sb.append(stockNativePathsString).append(PS); - sb.append(profilerFileString).append(PS); + sb.append(prefixFileString).append(pathSeparatorChar); + sb.append(libFileString).append(pathSeparatorChar); + sb.append(lib64FileString).append(pathSeparatorChar); + sb.append(stockNativePathsString).append(pathSeparatorChar); + sb.append(profilerFileString).append(pathSeparatorChar); sb.append(suffixFileString); // this looks dumb but there is a lot of potential cleaning going on here From 62aacbafa69b72865460289a720d8e75758492e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 11:23:47 +0200 Subject: [PATCH 02/19] CarHandler - log stacktrace too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../org/glassfish/appclient/server/core/CarHandler.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java index 8856301bb52..1138835bf87 100644 --- a/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java +++ b/appserver/appclient/server/core/src/main/java/org/glassfish/appclient/server/core/CarHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -74,9 +74,9 @@ public String getVersionIdentifier(ReadableArchive archive) { GFCarXMLParser gfXMLParser = new GFCarXMLParser(); versionIdentifier = gfXMLParser.extractVersionIdentifierValue(archive); } catch (IOException e) { - LOG.log(Level.SEVERE, e.getMessage()); + LOG.log(Level.SEVERE, e.getMessage(), e); } catch (XMLStreamException e) { - LOG.log(Level.SEVERE, e.getMessage()); + LOG.log(Level.SEVERE, e.getMessage(), e); } return versionIdentifier; From 83448cb92ccb141c8e8b2aa81c428da83b9212aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 12:36:39 +0200 Subject: [PATCH 03/19] EjbJarHandler - log stacktraces, don't log exception message twice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../glassfish/ejb/deployment/EjbJarHandler.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java index 79790d7bdb4..1365a43ae98 100644 --- a/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java +++ b/appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/EjbJarHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -91,9 +91,9 @@ public String getVersionIdentifier(ReadableArchive archive) { GFEjbJarXMLParser gfXMLParser = new GFEjbJarXMLParser(archive); versionIdentifier = gfXMLParser.extractVersionIdentifierValue(archive); } catch (XMLStreamException e) { - LOG.log(Level.SEVERE, e.getMessage()); + LOG.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { - LOG.log(Level.SEVERE, e.getMessage()); + LOG.log(Level.SEVERE, e.getMessage(), e); } return versionIdentifier; } @@ -145,17 +145,13 @@ public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext co } try { - final DeploymentContext dc = context; - final ClassLoader cl = cloader; - - AccessController.doPrivileged( - new PermsArchiveDelegate.SetPermissionsAction(SMGlobalPolicyUtil.CommponentType.ejb, dc, cl)); + AccessController.doPrivileged(new PermsArchiveDelegate.SetPermissionsAction( + SMGlobalPolicyUtil.CommponentType.ejb, context, cloader)); } catch (PrivilegedActionException e) { throw new SecurityException(e.getException()); } } catch (Exception e) { - LOG.log(Level.SEVERE, e.getMessage()); throw new RuntimeException(e); } return cloader; From a99c02cb1799a437681b529ac1c26d3f67fbdb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 13:12:56 +0200 Subject: [PATCH 04/19] JavaEEDeployer should use StringBuilder instead of StringBuffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../glassfish/javaee/core/deployment/JavaEEDeployer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appserver/deployment/jakartaee-core/src/main/java/org/glassfish/javaee/core/deployment/JavaEEDeployer.java b/appserver/deployment/jakartaee-core/src/main/java/org/glassfish/javaee/core/deployment/JavaEEDeployer.java index 94d46adcf65..d4530eaa75c 100644 --- a/appserver/deployment/jakartaee-core/src/main/java/org/glassfish/javaee/core/deployment/JavaEEDeployer.java +++ b/appserver/deployment/jakartaee-core/src/main/java/org/glassfish/javaee/core/deployment/JavaEEDeployer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Contributors to the Eclipse Foundation + * Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation * Copyright (c) 2008, 2022 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -137,13 +137,13 @@ protected String getModuleClassPath(DeploymentContext ctx) { * @return The instance classpath */ protected String getCommonClassPath() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); File libDir = env.getLibPath(); String libDirPath = libDir.getAbsolutePath(); // Append domain_root/lib/classes - sb.append(libDirPath + File.separator + "classes"); + sb.append(libDirPath).append(File.separator).append("classes"); sb.append(File.pathSeparator); // Append domain_root/lib/[*.jar|*.zip] @@ -151,7 +151,7 @@ protected String getCommonClassPath() { if (files != null) { for (String file : files) { if (file.endsWith(".jar") || file.endsWith(".zip")) { - sb.append(libDirPath + File.separator + file); + sb.append(libDirPath).append(File.separator).append(file); sb.append(File.pathSeparator); } } From f6c61223ef34f9cf4ebfb9dd983490a55d474b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 13:46:55 +0200 Subject: [PATCH 05/19] The AutoProcessor class doesn't exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- appserver/extras/embedded/common/bootstrap/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appserver/extras/embedded/common/bootstrap/pom.xml b/appserver/extras/embedded/common/bootstrap/pom.xml index 80f9740b943..bc1b2064cfa 100644 --- a/appserver/extras/embedded/common/bootstrap/pom.xml +++ b/appserver/extras/embedded/common/bootstrap/pom.xml @@ -81,8 +81,7 @@ jar false ${project.build.directory}/classes - **/OSGiFrameworkLauncher**,**/AutoProcessor** - META-INF/** + **/OSGiFrameworkLauncher** From 9869f442b34a18bf59995cdbd44b9804f2b76794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 13:50:47 +0200 Subject: [PATCH 06/19] UberJarOSGiGlassFishRuntimeBuilder vs exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - don't swallow exceptions - don't catch Error instances Signed-off-by: David Matějček --- .../UberJarOSGiGlassFishRuntimeBuilder.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java b/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java index 4e20431c094..fbfe11066f2 100644 --- a/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java +++ b/appserver/extras/embedded/common/bootstrap/src/main/java/org/glassfish/uberjar/bootstrap/UberJarOSGiGlassFishRuntimeBuilder.java @@ -51,6 +51,7 @@ import static com.sun.enterprise.glassfish.bootstrap.cfg.BootstrapKeys.PLATFORM_PROPERTY_KEY; import static com.sun.enterprise.util.io.FileUtils.USER_HOME; import static org.glassfish.embeddable.GlassFishProperties.CONFIG_FILE_URI_PROP_NAME; +import static org.osgi.framework.Constants.BUNDLE_VERSION; import static org.osgi.framework.Constants.FRAMEWORK_STORAGE; import static org.osgi.framework.Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA; @@ -109,8 +110,8 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc URI jar = null; try { jar = uberJarURI != null ? new URI(uberJarURI) : Util.whichJar(GlassFishRuntime.class); - } catch (URISyntaxException ex) { - logger.log(Level.SEVERE, null, ex); + } catch (URISyntaxException e) { + throw new IllegalStateException(e); } // XXX : Commented out by Prasad , we are again looking for instance root here. Why ? @@ -151,7 +152,7 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc String autoStartBundleLocation = "jar:" + jar.toString() + "!/modules/installroot-builder_jar/," + "jar:" + jar.toString() + "!/modules/instanceroot-builder_jar/," + - "jar:" + jar.toString() + "!/modules/kernel_jar/"; // TODO :: was modules/glassfish_jar + "jar:" + jar.toString() + "!/modules/kernel_jar/"; if (isOSGiEnv()) { autoStartBundleLocation = autoStartBundleLocation + @@ -182,8 +183,8 @@ public GlassFishRuntime build(BootstrapProperties bsOptions) throws GlassFishExc autostartBundle.start(Bundle.START_TRANSIENT); logger.log(Level.FINER, "Started autostartBundle {0}", autostartBundle); return getService(GlassFishRuntime.class, context); - } catch (Throwable t) { - throw new GlassFishException(new Exception(t)); + } catch (Exception e) { + throw new GlassFishException(e); } } @@ -201,10 +202,10 @@ private boolean isOSGiEnv() { } public T getService(Class type, BundleContext context) throws Exception { - ServiceTracker tracker = new ServiceTracker(context, type.getName(), null); + ServiceTracker tracker = new ServiceTracker<>(context, type.getName(), null); try { tracker.open(true); - return type.cast(tracker.waitForService(0)); + return tracker.waitForService(0); } finally { // no need to track further tracker.close(); @@ -233,7 +234,7 @@ private String loadVersion() { URL manifestURL = UberJarOSGiGlassFishRuntimeBuilder.class.getResource("/META-INF/MANIFEST.MF"); try (InputStream manifestStream = manifestURL.openStream()) { Manifest manifest = new Manifest(manifestStream); - return manifest.getMainAttributes().getValue(org.osgi.framework.Constants.BUNDLE_VERSION); + return manifest.getMainAttributes().getValue(BUNDLE_VERSION); } catch (IOException e) { throw new IllegalStateException("Could not load version from the manifest file.", e); } From e942fc00c072cfe1574a32a40057afa4fc90b619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 13:58:03 +0200 Subject: [PATCH 07/19] Minor test cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../org/glassfish/main/admin/test/ClusterITest.java | 7 +------ .../glassfish/main/admin/test/OSGiCommandsITest.java | 3 +-- .../main/admin/test/webapp/HttpServerNameITest.java | 11 +++++------ .../main/test/app/connpool/SQLTraceListenerTest.java | 10 +++------- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/ClusterITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/ClusterITest.java index 28ce29e0b7a..2b52632f027 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/ClusterITest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/ClusterITest.java @@ -16,7 +16,6 @@ */ package org.glassfish.main.admin.test; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -79,15 +78,11 @@ public void createClusterTest() { @Test @Order(2) public void deployAppToClusterTest() { - String warFile = getWar().getAbsolutePath(); + String warFile = TestResources.createSimpleWarDeployment(TEST_APP_NAME).getAbsolutePath(); assertThat(ASADMIN.exec("deploy", "--target", CLUSTER_NAME, "--name", TEST_APP_NAME, "--contextroot", TEST_APP_NAME, warFile), asadminOK()); } - private static File getWar() { - return TestResources.createSimpleWarDeployment(TEST_APP_NAME); - } - @Test @Order(3) public void createInstancesTest() { diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/OSGiCommandsITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/OSGiCommandsITest.java index 407938ed90a..10c2a22e9d4 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/OSGiCommandsITest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/OSGiCommandsITest.java @@ -56,7 +56,6 @@ public static void waitOsgiReady() throws Exception { if (!result.isError()) { return; } - Thread.sleep(1000); } } @@ -127,7 +126,7 @@ public void osgiShell() throws IOException { private String newCmdSession() throws Exception { List value = runCmd("osgi", "--session", "new"); if (value.size() != 1) { - throw new Exception("Unexpected output: \n " + value); + throw new AssertionError("Unexpected output: \n " + value); } return value.get(0); } diff --git a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/webapp/HttpServerNameITest.java b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/webapp/HttpServerNameITest.java index 6000e5d90b5..fbb5d159afd 100644 --- a/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/webapp/HttpServerNameITest.java +++ b/appserver/tests/admin/tests/src/test/java/org/glassfish/main/admin/test/webapp/HttpServerNameITest.java @@ -13,9 +13,9 @@ * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ + package org.glassfish.main.admin.test.webapp; -import java.io.IOException; import java.net.HttpURLConnection; import java.util.concurrent.atomic.AtomicBoolean; @@ -24,7 +24,6 @@ import org.glassfish.main.itest.tools.asadmin.Asadmin; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -33,6 +32,7 @@ import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public class HttpServerNameITest { @@ -43,7 +43,6 @@ public class HttpServerNameITest { private static final AtomicBoolean APP_DEPLOYED = new AtomicBoolean(); - @ParameterizedTest(name = "[{index}] testServerName: {0}") @CsvSource({ "'Plain host name', hostname1, http://hostname1:8080/", "'Plain domain name', my.domain.com, http://my.domain.com:8080/", @@ -53,7 +52,8 @@ public class HttpServerNameITest { "'Secure domain name and port', https://my.domain.com:123, https://my.domain.com:123/", "'Secure domain name and standard port', https://my.domain.com:443, https://my.domain.com/" }) - public void testHostName(String description, String serverName, String expectedUrlPrefix) throws IOException, InterruptedException { + @ParameterizedTest(name = "[{index}] testServerName: {0}") + public void testHostName(String description, String serverName, String expectedUrlPrefix) throws Exception { assertThat(ASADMIN.exec("set", SERVER_NAME_PROPERTY + "=" + serverName), asadminOK()); final HttpURLConnection conn = GlassFishTestEnvironment.openConnection(HTTP_PORT, "/" + TEST_APP_NAME); @@ -73,7 +73,7 @@ static void deploy() { @AfterAll static void undeploy() { - Assumptions.assumeTrue(APP_DEPLOYED.get()); + assumeTrue(APP_DEPLOYED.get()); assertThat(ASADMIN.exec("undeploy", TEST_APP_NAME), asadminOK()); } @@ -81,5 +81,4 @@ static void undeploy() { void cleanup() { ASADMIN.exec("set", SERVER_NAME_PROPERTY + "="); } - } diff --git a/appserver/tests/application/src/test/java/org/glassfish/main/test/app/connpool/SQLTraceListenerTest.java b/appserver/tests/application/src/test/java/org/glassfish/main/test/app/connpool/SQLTraceListenerTest.java index 3f6296eb200..2107cd797d9 100644 --- a/appserver/tests/application/src/test/java/org/glassfish/main/test/app/connpool/SQLTraceListenerTest.java +++ b/appserver/tests/application/src/test/java/org/glassfish/main/test/app/connpool/SQLTraceListenerTest.java @@ -48,14 +48,10 @@ public class SQLTraceListenerTest { private static final System.Logger LOG = System.getLogger(SQLTraceListenerTest.class.getName()); - private static final String RESOURCE_ROOT = "src/main/resources/" + SqlListenerApplication.class.getPackageName().replace(".", "/"); - private static final String LIB_FILE_NAME = "lib.jar"; - private static final String WEBAPP_FILE_NAME = "webapp.war"; private static final String WEBAPP_NAME = "webapp"; - private static final String POOL_NAME = "DerbyPool"; private static final Asadmin ASADMIN = GlassFishTestEnvironment.getAsadmin(); @@ -136,13 +132,13 @@ private static File createSqlTraceListenerLib() throws IOException { return appLib; } - private static File createWebApp() throws IOException { + private static File createWebApp() { WebArchive webArchive = ShrinkWrap.create(WebArchive.class) .addClass(SqlListenerApplication.class) .addClass(SqlListenerEndpoint.class) .addClass(Employee.class) - .addAsResource(new File(RESOURCE_ROOT, "/META-INF/persistence.xml"), "/META-INF/persistence.xml") - .addAsResource(new File(RESOURCE_ROOT, "/META-INF/load.sql"), "/META-INF/load.sql"); + .addAsResource(SqlListenerApplication.class.getPackage(), "/META-INF/persistence.xml", "/META-INF/persistence.xml") + .addAsResource(SqlListenerApplication.class.getPackage(), "/META-INF/load.sql", "/META-INF/load.sql"); LOG.log(INFO, webArchive.toString(true)); From b22b9df8479301132bcb1e2170139e0c8da87628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 14:07:03 +0200 Subject: [PATCH 08/19] Deleted worthless directory placeholders in web-core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../src/main/java/org/apache/catalina/mbeans/.gitkeep_empty_dir | 0 .../src/main/java/org/apache/coyote/http11/.gitkeep_empty_dir | 0 .../main/java/org/apache/tomcat/util/buf/res/.gitkeep_empty_dir | 0 .../java/org/apache/tomcat/util/collections/.gitkeep_empty_dir | 0 .../main/java/org/apache/tomcat/util/compat/.gitkeep_empty_dir | 0 .../main/java/org/apache/tomcat/util/http/res/.gitkeep_empty_dir | 0 .../main/java/org/apache/tomcat/util/net/res/.gitkeep_empty_dir | 0 .../src/main/java/org/apache/tomcat/util/res/.gitkeep_empty_dir | 0 .../java/org/apache/tomcat/util/threads/res/.gitkeep_empty_dir | 0 .../src/main/java/org/glassfish/web/util/.gitkeep_empty_dir | 0 10 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 appserver/web/web-core/src/main/java/org/apache/catalina/mbeans/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/coyote/http11/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/tomcat/util/buf/res/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/tomcat/util/collections/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/tomcat/util/compat/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/tomcat/util/http/res/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/tomcat/util/net/res/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/tomcat/util/res/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/apache/tomcat/util/threads/res/.gitkeep_empty_dir delete mode 100644 appserver/web/web-core/src/main/java/org/glassfish/web/util/.gitkeep_empty_dir diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/mbeans/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/catalina/mbeans/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/coyote/http11/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/coyote/http11/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/tomcat/util/buf/res/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/tomcat/util/buf/res/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/tomcat/util/collections/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/tomcat/util/collections/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/tomcat/util/compat/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/tomcat/util/compat/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/tomcat/util/http/res/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/tomcat/util/http/res/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/tomcat/util/net/res/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/tomcat/util/net/res/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/tomcat/util/res/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/tomcat/util/res/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/apache/tomcat/util/threads/res/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/apache/tomcat/util/threads/res/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/appserver/web/web-core/src/main/java/org/glassfish/web/util/.gitkeep_empty_dir b/appserver/web/web-core/src/main/java/org/glassfish/web/util/.gitkeep_empty_dir deleted file mode 100644 index e69de29bb2d..00000000000 From 8a12f004a77726679c0e618a25750097b64e4212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Sun, 6 Oct 2024 14:22:43 +0200 Subject: [PATCH 09/19] Quick cleanup of JSPCompiler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../org/glassfish/web/jsp/JSPCompiler.java | 112 +++++++----------- 1 file changed, 40 insertions(+), 72 deletions(-) diff --git a/appserver/web/web-glue/src/main/java/org/glassfish/web/jsp/JSPCompiler.java b/appserver/web/web-glue/src/main/java/org/glassfish/web/jsp/JSPCompiler.java index 3b7d44aea21..142d8f56f34 100644 --- a/appserver/web/web-glue/src/main/java/org/glassfish/web/jsp/JSPCompiler.java +++ b/appserver/web/web-glue/src/main/java/org/glassfish/web/jsp/JSPCompiler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Contributors to Eclipse Foundation. + * Copyright (c) 2021, 2024 Contributors to Eclipse Foundation. * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -40,7 +40,6 @@ import java.io.File; import java.util.Enumeration; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.logging.Level; @@ -55,40 +54,37 @@ import org.glassfish.web.deployment.runtime.SunWebAppImpl; import org.glassfish.web.deployment.runtime.WebProperty; +import static java.util.logging.Level.FINE; +import static java.util.logging.Level.INFO; + public final class JSPCompiler { + private static final Logger LOG = LogFacade.getLogger(); + + public static void compile(File inWebDir, File outWebDir, WebBundleDescriptor wbd, ServerContext serverContext) throws DeploymentException { - //to resolve ambiguity - final String amb = null; - compile(inWebDir, outWebDir, wbd, amb, serverContext); + compile(inWebDir, outWebDir, wbd, (String) null, serverContext); } - public static void compile(File inWebDir, File outWebDir, - WebBundleDescriptor wbd, List classpathList, - ServerContext serverContext) - throws DeploymentException { - String classpath = null; - if (classpathList != null) { - classpath = getClasspath(classpathList); - } + + public static void compile(File inWebDir, File outWebDir, WebBundleDescriptor wbd, List classpathList, + ServerContext serverContext) throws DeploymentException { + String classpath = classpathList == null ? null : getClasspath(classpathList); compile(inWebDir, outWebDir, wbd, classpath, serverContext); } - //////////////////////////////////////////////////////////////////////////// - - public static void compile(File inWebDir, File outWebDir, - WebBundleDescriptor wbd, String classpath, - ServerContext serverContext) - throws DeploymentException { + public static void compile(File inWebDir, File outWebDir, WebBundleDescriptor wbd, String classpath, + ServerContext serverContext) throws DeploymentException { + LOG.log(Level.FINEST, "Compiling JSP: in={0}, out={1}, classpath={2}", + new Object[] {inWebDir, outWebDir, classpath}); JspC jspc = new JspC(); - if (classpath != null && classpath.length() >0) { + if (classpath != null && !classpath.isEmpty()) { jspc.setClassPath(classpath); } - // START SJSAS 6311155 String appName = wbd.getApplication().getName(); // so far, this is not segragated per web bundle, all web-bundles will get the @@ -96,7 +92,6 @@ public static void compile(File inWebDir, File outWebDir, String sysClassPath = ASClassLoaderUtil.getModuleClassPath( serverContext.getDefaultServices(), appName, null); jspc.setSystemClassPath(sysClassPath); - // END SJSAS 6311155 verify(inWebDir, outWebDir); @@ -104,7 +99,7 @@ public static void compile(File inWebDir, File outWebDir, jspc.setOutputDir(outWebDir.getAbsolutePath()); jspc.setUriroot(inWebDir.getAbsolutePath()); jspc.setCompile(true); - logger.log(Level.INFO, LogFacade.START_MESSAGE); + LOG.log(INFO, LogFacade.START_MESSAGE); try { jspc.execute(); @@ -121,16 +116,14 @@ public static void compile(File inWebDir, File outWebDir, if(files == null || files.length <= 0) { if (!outWebDir.delete()) { - logger.log(Level.FINE, LogFacade.CANNOT_DELETE_FILE, outWebDir); + LOG.log(FINE, LogFacade.CANNOT_DELETE_FILE, outWebDir); } } - logger.log(Level.INFO, LogFacade.FINISH_MESSAGE); + LOG.log(INFO, LogFacade.FINISH_MESSAGE); } } - //////////////////////////////////////////////////////////////////////////// - private static void verify(File inWebDir, File outWebDir) throws DeploymentException { // inWebDir must exist, outWebDir must either exist or be creatable if (!FileUtils.safeIsDirectory(inWebDir)) { @@ -139,7 +132,7 @@ private static void verify(File inWebDir, File outWebDir) throws DeploymentExcep if (!FileUtils.safeIsDirectory(outWebDir)) { if (!outWebDir.mkdirs()) { - logger.log(Level.FINE, LogFacade.CANNOT_DELETE_FILE, outWebDir); + LOG.log(FINE, LogFacade.CANNOT_DELETE_FILE, outWebDir); } if (!FileUtils.safeIsDirectory(outWebDir)) { @@ -148,9 +141,7 @@ private static void verify(File inWebDir, File outWebDir) throws DeploymentExcep } } - //////////////////////////////////////////////////////////////////////////// - - private static String getClasspath(List paths) { + private static String getClasspath(List paths) { if (paths == null) { return null; } @@ -160,14 +151,12 @@ private static String getClasspath(List paths) { StringBuilder sb = new StringBuilder(); boolean first = true; - for (Iterator it = paths.iterator(); it.hasNext(); ) { - String path = (String)it.next(); + for (String path : paths) { if (first) { first = false; } else { sb.append(File.pathSeparatorChar); } - sb.append(path); } @@ -178,8 +167,6 @@ private static String getClasspath(List paths) { return classpath; } - //////////////////////////////////////////////////////////////////////////// - /** * Configures the given JspC instance with the jsp-config properties * specified in the sun-web.xml of the web module represented by the @@ -196,36 +183,28 @@ private static void configureJspc(JspC jspc, WebBundleDescriptor wbd) { return; } - // START SJSAS 6384538 if (sunWebApp.sizeWebProperty() > 0) { WebProperty[] props = sunWebApp.getWebProperty(); - for (int i = 0; i < props.length; i++) { - String pName = props[i].getAttributeValue("name"); - String pValue = props[i].getAttributeValue("value"); + for (WebProperty prop : props) { + String pName = prop.getValue("name"); + String pValue = prop.getValue("value"); if (pName == null || pValue == null) { throw new IllegalArgumentException( "Missing sun-web-app property name or value"); } if ("enableTldValidation".equals(pName)) { jspc.setIsValidationEnabled( - Boolean.valueOf(pValue).booleanValue()); + Boolean.parseBoolean(pValue)); } } } - // END SJSAS 6384538 - // START SJSAS 6170435 - /* - * Configure JspC with the init params of the JspServlet - */ + // Configure JspC with the init params of the JspServlet Set set = wbd.getWebComponentDescriptors(); if (!set.isEmpty()) { - Iterator iterator = set.iterator(); - while (iterator.hasNext()) { - WebComponentDescriptor webComponentDesc = iterator.next(); + for (WebComponentDescriptor webComponentDesc : set) { if ("jsp".equals(webComponentDesc.getCanonicalName())) { - Enumeration en - = webComponentDesc.getInitializationParameters(); + Enumeration en = webComponentDesc.getInitializationParameters(); if (en != null) { while (en.hasMoreElements()) { InitializationParameter initP = en.nextElement(); @@ -236,19 +215,16 @@ private static void configureJspc(JspC jspc, WebBundleDescriptor wbd) { } } } - // END SJSAS 6170435 - /* - * Configure JspC with jsp-config properties from sun-web.xml, - * which override JspServlet init params of the same name. - */ + // Configure JspC with jsp-config properties from sun-web.xml, + // which override JspServlet init params of the same name. JspConfig jspConfig = sunWebApp.getJspConfig(); if (jspConfig == null) { return; } WebProperty[] props = jspConfig.getWebProperty(); for (int i=0; props!=null && i Date: Sun, 6 Oct 2024 14:43:07 +0200 Subject: [PATCH 10/19] Quick cleanup in WebServiceTesterServlet + removal of IE support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: David Matějček --- .../monitoring/WebServiceTesterServlet.java | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java b/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java index beda1643815..1819865f5b5 100644 --- a/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java +++ b/appserver/webservices/jsr109-impl/src/main/java/org/glassfish/webservices/monitoring/WebServiceTesterServlet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -15,12 +15,6 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -/* - * WebServiceTesterServlet.java - * - * Created on August 6, 2004, 9:14 AM - */ - package org.glassfish.webservices.monitoring; import com.sun.enterprise.deployment.WebServiceEndpoint; @@ -44,6 +38,7 @@ import java.io.PrintWriter; import java.lang.reflect.Method; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; @@ -66,17 +61,22 @@ import org.glassfish.webservices.LogUtils; import org.glassfish.webservices.WebServiceContractImpl; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.glassfish.common.util.HttpParser.getCharsetFromHeader; /** * This servlet is responsible for testing web-services. * - * @author Jerome Dochez + * @author Jerome Dochez 2004 */ public class WebServiceTesterServlet extends HttpServlet { private final WebServiceEndpoint svcEP; private static final Logger logger = LogUtils.getLogger(); - //modules required by wsimport tool + /** + * Modules required by wsimport tool. + * Note that names are not jar file names, but Bundle-SymbolicName header in their manifests! + */ private static final List WSIMPORT_MODULES = Arrays.asList(new String[] { "jakarta.activation-api", "angus-activation", @@ -89,9 +89,8 @@ public class WebServiceTesterServlet extends HttpServlet { private static final Hashtable gsiClasses = new Hashtable<>(); private static final Hashtable ports = new Hashtable<>(); - // resources... - private static final LocalStringManagerImpl localStrings = - new LocalStringManagerImpl(WebServiceTesterServlet.class); + private static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl( + WebServiceTesterServlet.class); public static void invoke(HttpServletRequest request, HttpServletResponse response, WebServiceEndpoint endpoint) { @@ -99,7 +98,7 @@ public static void invoke(HttpServletRequest request, try { WebServiceTesterServlet servlet = new WebServiceTesterServlet(endpoint); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(UTF_8.name()); if (request.getMethod().equalsIgnoreCase("GET")) { servlet.doGet(request, response); } else { @@ -185,20 +184,12 @@ public void doGet(HttpServletRequest req, HttpServletResponse res) "Web Service Tester") + ""); - // Microsoft Internet Explorer does not handle