You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2022/04/04 14:57:16 UTC

[tomee] branch master updated (37fac78dcc -> 0b26e6e5b7)

This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git


    from 37fac78dcc Minor: Regenerated BOMs for 78d1a5701c2d13a592e1c4b559e3be948ea2d633
     new 02ade8d8ab TOMEE-3889 quote objectnames that contain special characters
     new 0b26e6e5b7 TOMEE-3889 quote objectnames that contain special characters

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../arquillian/tests/jms/MDBWithWildcardTest.java  | 113 +++++++++++++++++++++
 .../openejb/assembler/classic/Assembler.java       |   2 +
 .../openejb/monitoring/ObjectNameBuilder.java      |   4 +
 .../ObjectNameBuilderTest.java}                    |  36 +++----
 4 files changed, 134 insertions(+), 21 deletions(-)
 create mode 100755 arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java
 copy container/openejb-core/src/test/java/org/apache/openejb/{testing/AddInnerTest.java => monitoring/ObjectNameBuilderTest.java} (55%)


[tomee] 02/02: TOMEE-3889 quote objectnames that contain special characters

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 0b26e6e5b7ba18ebe0f96e5bf3ea0c8480adc44e
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Mon Apr 4 14:06:21 2022 +0100

    TOMEE-3889 quote objectnames that contain special characters
---
 .../arquillian/tests/jms/MDBWithWildcardTest.java      | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java
index d5617500e0..5bcb308aed 100755
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java
@@ -30,16 +30,16 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import javax.ejb.ActivationConfigProperty;
-import javax.ejb.MessageDriven;
-import javax.jms.Message;
-import javax.jms.MessageListener;
+import jakarta.ejb.ActivationConfigProperty;
+import jakarta.ejb.MessageDriven;
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServlet;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
@@ -86,7 +86,7 @@ public class MDBWithWildcardTest {
     @MessageDriven(
             activationConfig = {
                     @ActivationConfigProperty(propertyName = "destination", propertyValue = "dest.*.event"),
-                    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
+                    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
             }
     )
     public static class WildcardMdb implements MessageListener {


[tomee] 01/02: TOMEE-3889 quote objectnames that contain special characters

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 02ade8d8abf067dbf10947e713ada57906a9e540
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Mon Apr 4 14:06:21 2022 +0100

    TOMEE-3889 quote objectnames that contain special characters
---
 .../arquillian/tests/jms/MDBWithWildcardTest.java  | 113 +++++++++++++++++++++
 .../openejb/assembler/classic/Assembler.java       |   2 +
 .../openejb/monitoring/ObjectNameBuilder.java      |   4 +
 .../openejb/monitoring/ObjectNameBuilderTest.java  |  39 +++++++
 4 files changed, 158 insertions(+)

diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java
new file mode 100755
index 0000000000..d5617500e0
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-jms-tests/src/test/java/org/apache/openejb/arquillian/tests/jms/MDBWithWildcardTest.java
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.openejb.arquillian.tests.jms;
+
+import org.apache.ziplock.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.lang.management.ManagementFactory;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+
+@RunWith(Arquillian.class)
+public class MDBWithWildcardTest {
+
+    @ArquillianResource
+    private URL url;
+
+    @Deployment(testable = false)
+    public static WebArchive getArchive() {
+
+        return ShrinkWrap.create(WebArchive.class, "jsf-jms-test.war")
+                .addClasses(WildcardMdb.class)
+                .setWebXML(new StringAsset(Descriptors.create(WebAppDescriptor.class)
+                        .version("3.0")
+                        .createServlet()
+                            .servletName("jmx")
+                            .servletClass(JmxServlet.class.getName())
+                        .up()
+                        .createServletMapping()
+                            .servletName("jmx")
+                            .urlPattern("/jmx")
+                        .up()
+                        .exportAsString()));
+    }
+
+    @Test
+    public void test() throws Exception {
+        final URL url = new URL(this.url.toExternalForm() + "/jmx");
+        final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+        Assert.assertEquals(200, urlConnection.getResponseCode());
+        final InputStream inputStream = urlConnection.getInputStream();
+        final String result = IO.slurp(inputStream);
+        Assert.assertEquals("dest.*.event", result.trim());
+    }
+
+
+    @MessageDriven(
+            activationConfig = {
+                    @ActivationConfigProperty(propertyName = "destination", propertyValue = "dest.*.event"),
+                    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
+            }
+    )
+    public static class WildcardMdb implements MessageListener {
+        @Override
+        public void onMessage(final Message message) {
+            System.out.println("Message received");
+        }
+    }
+
+    public static class JmxServlet extends HttpServlet {
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+            try {
+                final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
+                final String name = "openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,j2eeType=Resource,name=\"dest.\\*.event\"";
+                final PrintWriter writer = resp.getWriter();
+                writer.println(platformMBeanServer.getAttribute(new ObjectName(name), "physicalName"));
+                writer.flush();
+            } catch (Throwable t) {
+                throw new ServletException(t);
+            }
+        }
+    }
+}
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 86039d5180..2bca743fdb 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -3404,8 +3404,10 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
 
             if (DynamicMBean.class.isInstance(resource)) {
                 server.registerMBean(resource, objectName);
+                logger.debug("Registered JMX name: " + objectName.toString());
             } else {
                 server.registerMBean(new MBeanPojoWrapper(name, resource), objectName);
+                logger.debug("Registered JMX name: " + objectName.toString());
             }
         } catch (final Exception e) {
             logger.error("Unable to register MBean ", e);
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/monitoring/ObjectNameBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/monitoring/ObjectNameBuilder.java
index c1bdb20080..e1321c0d63 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/monitoring/ObjectNameBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/monitoring/ObjectNameBuilder.java
@@ -58,6 +58,10 @@ public class ObjectNameBuilder {
 
                 if (null != sv) {
                     sv = sv.replace(':', '_');
+
+                    if (sv.contains("\"") || sv.contains("*") || sv.contains("\\") || sv.contains(",") || sv.contains("\n") || sv.contains("?")) {
+                        sv = ObjectName.quote(sv);
+                    }
                 }
 
                 sb.append(entry.getKey()).append("=").append(sv).append(",");
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/monitoring/ObjectNameBuilderTest.java b/container/openejb-core/src/test/java/org/apache/openejb/monitoring/ObjectNameBuilderTest.java
new file mode 100644
index 0000000000..1940b4bca5
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/monitoring/ObjectNameBuilderTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.monitoring;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.management.ObjectName;
+
+public class ObjectNameBuilderTest {
+
+    @Test
+    public void testQuoting() throws Exception {
+        final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
+        jmxName.set("J2EEServer", "openejb");
+        jmxName.set("J2EEApplication", null);
+        jmxName.set("j2eeType", "");
+        jmxName.set("name", "test_with_*_in_it");
+
+        final ObjectName objectName = jmxName.build();
+        Assert.assertEquals("openejb.management:J2EEServer=openejb,J2EEApplication=<empty>,j2eeType=<empty>,name=\"test_with_\\*_in_it\"", objectName.toString());
+    }
+
+
+}
\ No newline at end of file