tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject svn commit: r1528597 - in /tomee/tomee/trunk/server/openejb-cxf/src: main/java/org/apache/openejb/server/cxf/CxfWsContainer.java main/java/org/apache/openejb/server/cxf/pojo/PojoWsContainer.java test/java/org/apache/openejb/server/cxf/WsJMXTest.java
Date Wed, 02 Oct 2013 19:14:23 GMT
Author: jlmonteiro
Date: Wed Oct  2 19:14:22 2013
New Revision: 1528597

URL: http://svn.apache.org/r1528597
Log:
OPENEJB-2040 OPENEJB-2041 Publish JMX information for JAX-RS and JAX-WS

Added:
    tomee/tomee/trunk/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WsJMXTest.java
  (with props)
Modified:
    tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
    tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoWsContainer.java

Modified: tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java?rev=1528597&r1=1528596&r2=1528597&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
(original)
+++ tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/CxfWsContainer.java
Wed Oct  2 19:14:22 2013
@@ -20,14 +20,21 @@ package org.apache.openejb.server.cxf;
 import org.apache.cxf.Bus;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.apache.cxf.transport.http.HTTPTransportFactory;
+import org.apache.openejb.api.internal.Internal;
+import org.apache.openejb.api.jmx.Description;
+import org.apache.openejb.api.jmx.MBean;
 import org.apache.openejb.assembler.classic.util.ServiceConfiguration;
 import org.apache.openejb.core.webservices.PortData;
+import org.apache.openejb.monitoring.LocalMBeanServer;
+import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.server.cxf.transport.HttpTransportFactory;
 import org.apache.openejb.server.cxf.transport.util.CxfUtil;
 import org.apache.openejb.server.httpd.HttpListener;
 import org.apache.openejb.server.httpd.HttpRequest;
 import org.apache.openejb.server.httpd.HttpResponse;
 
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -38,12 +45,14 @@ public abstract class CxfWsContainer imp
     protected CxfEndpoint endpoint;
     protected final HTTPTransportFactory httpTransportFactory;
     protected final ServiceConfiguration serviceConfiguration;
+    private ObjectName jmxName;
+
 
     public CxfWsContainer(final Bus bus, final PortData port, final ServiceConfiguration
config) {
         this.bus = bus;
         this.port = port;
         this.serviceConfiguration = config;
-        
+
         final List<String> ids = new ArrayList<String>();
         ids.add("http://schemas.xmlsoap.org/wsdl/soap/");
 
@@ -55,19 +64,25 @@ public abstract class CxfWsContainer imp
         endpoint = createEndpoint();
         endpoint.publish("http://nopath");
         destination = (AbstractHTTPDestination) endpoint.getServer().getDestination();
+
+        // register an MBean for this endpoint
+        this.jmxName = registerMBean();
     }
 
     protected abstract CxfEndpoint createEndpoint();
+    protected abstract ObjectName registerMBean();
 
     public void destroy() {
+        unregisterMBean();
+
         if (endpoint != null) {
             endpoint.stop();
             endpoint = null;
         }
-        // if (destination != null) {
-        //    destination.shutdown();
-        //    destination = null;
-        // }
+    }
+
+    private void unregisterMBean() {
+        LocalMBeanServer.unregisterSilently(jmxName);
     }
 
     @Override
@@ -82,4 +97,5 @@ public abstract class CxfWsContainer imp
             }
         }
     }
+
 }

Modified: tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoWsContainer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoWsContainer.java?rev=1528597&r1=1528596&r2=1528597&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoWsContainer.java
(original)
+++ tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoWsContainer.java
Wed Oct  2 19:14:22 2013
@@ -18,11 +18,24 @@
 package org.apache.openejb.server.cxf.pojo;
 
 import org.apache.cxf.Bus;
+import org.apache.openejb.api.internal.Internal;
+import org.apache.openejb.api.jmx.Description;
+import org.apache.openejb.api.jmx.MBean;
+import org.apache.openejb.api.jmx.ManagedAttribute;
+import org.apache.openejb.api.jmx.ManagedOperation;
 import org.apache.openejb.assembler.classic.util.ServiceConfiguration;
+import org.apache.openejb.core.webservices.HandlerChainData;
+import org.apache.openejb.core.webservices.HandlerData;
 import org.apache.openejb.core.webservices.PortData;
+import org.apache.openejb.monitoring.LocalMBeanServer;
+import org.apache.openejb.monitoring.ObjectNameBuilder;
 import org.apache.openejb.server.cxf.CxfWsContainer;
 
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
 import javax.naming.Context;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 public class PojoWsContainer extends CxfWsContainer {
@@ -44,4 +57,94 @@ public class PojoWsContainer extends Cxf
     protected PojoEndpoint createEndpoint() {
         return new PojoEndpoint(loader, bus, port, context, target, httpTransportFactory,
bindings, serviceConfiguration);
     }
+
+    @Override
+    protected ObjectName registerMBean() {
+        final ObjectName name = new ObjectNameBuilder("openejb.management")
+                .set("j2eeType", "JAX-WS")
+                .set("J2EEServer", "openejb")
+                .set("J2EEApplication", null)
+                .set("EndpointType", "POJO")
+                .set("name", target.getSimpleName())
+                .build();
+
+        final WsServiceMBean mbean = new WsServiceMBean(context, target, port);
+        LocalMBeanServer.registerDynamicWrapperSilently(mbean, name);
+        return name;
+    }
+
+    @MBean
+    @Description("JAX-WS Service information")
+    @Internal
+    public class WsServiceMBean {
+
+        private final Context context;
+        private final Class target;
+        private final PortData port;
+
+        public WsServiceMBean(final Context context, final Class target, final PortData port)
{
+            this.context = context;
+            this.target = target;
+            this.port = port;
+        }
+
+        @ManagedOperation
+        @Description("")
+        public String getWsdl() {
+            return null;
+        }
+
+        @ManagedAttribute
+        @Description("The service port QName")
+        public String getPort() {
+            return port.getPortName().toString();
+        }
+
+        @ManagedAttribute
+        @Description("The service QName")
+        public String getService() {
+            return port.getServiceName().toString();
+        }
+
+        @ManagedAttribute
+        @Description("The handler list")
+        public TabularData getHandlers() {
+            final List<String> names = new ArrayList<String>();
+            final List<String> values = new ArrayList<String>();
+
+            for (final HandlerChainData handlerChainData : port.getHandlerChains()) {
+                for (final HandlerData handlerData : handlerChainData.getHandlers()) {
+                    names.add(handlerChainData.getServiceNamePattern().toString());
+                    values.add(handlerData.getHandlerClass().getName());
+                }
+            }
+
+            return LocalMBeanServer.tabularData(
+                    "handlers", "The list of handlers",
+                    names.toArray(new String[names.size()]), values.toArray(new String[values.size()]));
+        }
+
+        @ManagedAttribute
+        @Description("Is the service secured?")
+        public boolean getSecured() {
+            return port.isSecure();
+        }
+
+        @ManagedAttribute
+        @Description("Is MTOM enabled?")
+        public boolean getMtomEnabled() {
+            return port.isMtomEnabled();
+        }
+
+        @ManagedAttribute
+        @Description("Service configuration properties")
+        public TabularData getProperties() {
+            return LocalMBeanServer.tabularData(
+                    "properties",
+                    "Service configuration properties",
+                    "Service configuration properties",
+                    port.getProperties()
+            );
+        }
+    }
 }

Added: tomee/tomee/trunk/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WsJMXTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WsJMXTest.java?rev=1528597&view=auto
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WsJMXTest.java
(added)
+++ tomee/tomee/trunk/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WsJMXTest.java
Wed Oct  2 19:14:22 2013
@@ -0,0 +1,101 @@
+/*
+ *     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.server.cxf;
+
+import org.apache.openejb.jee.Servlet;
+import org.apache.openejb.jee.ServletMapping;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.monitoring.LocalMBeanServer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.Module;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.jws.WebService;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@EnableServices("jax-ws")
+@RunWith(ApplicationComposer.class)
+public class WsJMXTest {
+    private static ObjectName name;
+
+    @Module
+    @Classes({AnEjbEndpoint.class, AnPojoEndpoint.class})
+    public WebApp war() {
+        final WebApp webapp = new WebApp().contextRoot("app");
+
+        Servlet servlet = new Servlet();
+        servlet.setServletName("toto");
+        servlet.setServletClass(AnPojoEndpoint.class.getName());
+
+        ServletMapping servletMapping = new ServletMapping();
+        servletMapping.setServletName("pojo");
+        servletMapping.getUrlPattern().add("/toto");
+
+        webapp.getServlet().add(servlet);
+        webapp.getServletMapping().add(servletMapping);
+
+        return webapp;
+    }
+
+    @BeforeClass
+    public static void before() throws MalformedObjectNameException {
+        name = new ObjectName("openejb.management:j2eeType=JAX-WS,J2EEServer=openejb,J2EEApplication=<empty>,EndpointType=EJB,name="
+ AnEjbEndpoint.class.getName());
+    }
+
+    @Test
+    public void checkServiceWasDeployed() throws Exception {
+        Thread.currentThread().sleep(10000000000l);
+        assertTrue(LocalMBeanServer.get().isRegistered(name));
+    }
+
+    @AfterClass
+    public static void after() {
+        assertFalse(LocalMBeanServer.get().isRegistered(name));
+    }
+
+    @Singleton
+    @Lock(LockType.READ)
+    @WebService
+    public static class AnEjbEndpoint {
+
+        public String sayHello(final String me) {
+            return "Hello " + me;
+        }
+
+    }
+
+    @WebService
+    public static class AnPojoEndpoint {
+
+        public String sayHi(final String me) {
+            return "Hi " + me;
+        }
+
+    }
+}

Propchange: tomee/tomee/trunk/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/WsJMXTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message