You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2011/06/20 11:32:19 UTC
svn commit: r1137562 - in /servicemix/smx3/trunk:
distributions/apache-servicemix-web/src/main/webapp/WEB-INF/
web/servicemix-web-console/
web/servicemix-web-console/src/main/java/org/apache/servicemix/web/jmx/
web/servicemix-web-console/src/main/java/...
Author: gertv
Date: Mon Jun 20 09:32:19 2011
New Revision: 1137562
URL: http://svn.apache.org/viewvc?rev=1137562&view=rev
Log:
SM-2096: MBean lookup failures in web console (plus a few more fixes to the console)
Added:
servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/jmx/
servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBean.java
servicemix/smx3/trunk/web/servicemix-web-console/src/test/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/web/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/web/jmx/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBeanTest.java
servicemix/smx3/trunk/web/servicemix-web-console/src/test/resources/
servicemix/smx3/trunk/web/servicemix-web-console/src/test/resources/log4j.properties
Modified:
servicemix/smx3/trunk/distributions/apache-servicemix-web/src/main/webapp/WEB-INF/web.xml
servicemix/smx3/trunk/web/servicemix-web-console/pom.xml
servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/model/ProxyManager.java
servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/applicationContext.xml
servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/jspf/headertags.jspf
Modified: servicemix/smx3/trunk/distributions/apache-servicemix-web/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/distributions/apache-servicemix-web/src/main/webapp/WEB-INF/web.xml?rev=1137562&r1=1137561&r2=1137562&view=diff
==============================================================================
--- servicemix/smx3/trunk/distributions/apache-servicemix-web/src/main/webapp/WEB-INF/web.xml (original)
+++ servicemix/smx3/trunk/distributions/apache-servicemix-web/src/main/webapp/WEB-INF/web.xml Mon Jun 20 09:32:19 2011
@@ -105,9 +105,9 @@
</servlet-mapping>
<servlet>
- <servlet-name>cxf</servlet-name>
- <display-name>cxf</display-name>
<description>Apache CXF Endpoint</description>
+ <display-name>cxf</display-name>
+ <servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFNonSpringServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Modified: servicemix/smx3/trunk/web/servicemix-web-console/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/web/servicemix-web-console/pom.xml?rev=1137562&r1=1137561&r2=1137562&view=diff
==============================================================================
--- servicemix/smx3/trunk/web/servicemix-web-console/pom.xml (original)
+++ servicemix/smx3/trunk/web/servicemix-web-console/pom.xml Mon Jun 20 09:32:19 2011
@@ -158,6 +158,10 @@
<artifactId>spring-aop</artifactId>
<version>${spring-version}</version>
</dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
Added: servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBean.java?rev=1137562&view=auto
==============================================================================
--- servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBean.java (added)
+++ servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBean.java Mon Jun 20 09:32:19 2011
@@ -0,0 +1,100 @@
+/*
+ * 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.servicemix.web.jmx;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.jmx.MBeanServerNotFoundException;
+import org.springframework.jmx.access.MBeanInfoRetrievalException;
+import org.springframework.jmx.access.MBeanProxyFactoryBean;
+
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import java.io.IOException;
+
+/**
+ * Variant of Spring's {@link MBeanProxyFactoryBean} that improves support for WebSphere by automatically
+ * determining the cell/node/process attributes of the MBean ObjectName
+ */
+public class EnhancedMBeanProxyFactoryBean extends MBeanProxyFactoryBean {
+
+ private static final Log LOG = LogFactory.getLog(EnhancedMBeanProxyFactoryBean.class);
+ protected static final String WEBSPHERE = "WebSphere";
+
+ private MBeanServerConnection connection;
+ private String originalName;
+
+ @Override
+ public void afterPropertiesSet() throws MBeanServerNotFoundException, MBeanInfoRetrievalException {
+ try {
+ if (WEBSPHERE.equals(connection.getDefaultDomain())) {
+ doWebSphereConfiguration();
+ }
+ } catch (IOException e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Unable to determine default domain name - assuming it's not WebSphere", e);
+ }
+ }
+ super.afterPropertiesSet();
+ }
+
+ /*
+ * When running in WebSphere, try determining the cell/node/process values and append those to the
+ * JMX MBean object name.
+ */
+ private void doWebSphereConfiguration() {
+ LOG.info("Running on WebSphere - adding cell/node/process information to " + originalName);
+
+ try {
+ String cell = null;
+ String node = null;
+ String process = null;
+
+ for (Object value : connection.queryNames(new ObjectName("WebSphere:name=JVM,*"), null)) {
+ ObjectName objectName = (ObjectName) value;
+ cell = objectName.getKeyProperty("cell");
+ node = objectName.getKeyProperty("node");
+ process = objectName.getKeyProperty("process");
+ }
+
+ String name = String.format("%s,cell=%s,node=%s,process=%s", originalName, cell, node, process);
+ super.setObjectName(name);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Object name has been changed to " + name);
+ }
+ } catch (MalformedObjectNameException e) {
+ throw new MBeanInfoRetrievalException("Unable to determine cell/node/process information while running in WebSphere", e);
+ } catch (IOException e) {
+ throw new MBeanInfoRetrievalException("Unable to determine cell/node/process information while running in WebSphere", e);
+ }
+ }
+
+ // override to capture the MBean server connection
+ @Override
+ public void setServer(MBeanServerConnection connection) {
+ this.connection = connection;
+ super.setServer(connection);
+ }
+
+ // override to capture the original object name
+ @Override
+ public void setObjectName(Object name) throws MalformedObjectNameException {
+ this.originalName = name != null ? name.toString() : null;
+ super.setObjectName(name);
+ }
+}
Modified: servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/model/ProxyManager.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/model/ProxyManager.java?rev=1137562&r1=1137561&r2=1137562&view=diff
==============================================================================
--- servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/model/ProxyManager.java (original)
+++ servicemix/smx3/trunk/web/servicemix-web-console/src/main/java/org/apache/servicemix/web/model/ProxyManager.java Mon Jun 20 09:32:19 2011
@@ -16,16 +16,16 @@
*/
package org.apache.servicemix.web.model;
-import java.lang.ref.Reference;
-import java.lang.ref.SoftReference;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+import org.apache.servicemix.web.jmx.EnhancedMBeanProxyFactoryBean;
+import org.springframework.jmx.access.MBeanProxyFactoryBean;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-
-import org.springframework.jmx.access.MBeanProxyFactoryBean;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
public class ProxyManager {
@@ -41,7 +41,7 @@ public class ProxyManager {
Reference r = proxies.get(name);
T proxy = (r != null) ? (T) r.get() : null;
if (proxy == null) {
- MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean();
+ MBeanProxyFactoryBean factory = new EnhancedMBeanProxyFactoryBean();
factory.setServer(server);
try {
factory.setObjectName(name);
Modified: servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/applicationContext.xml?rev=1137562&r1=1137561&r2=1137562&view=diff
==============================================================================
--- servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/applicationContext.xml (original)
+++ servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/applicationContext.xml Mon Jun 20 09:32:19 2011
@@ -23,7 +23,7 @@
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
- <bean id="jmxProxy" abstract="true" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
+ <bean id="jmxProxy" abstract="true" class="org.apache.servicemix.web.jmx.EnhancedMBeanProxyFactoryBean">
<property name="server" ref="server"/>
<property name="useStrictCasing" value="false" />
<property name="connectOnStartup" value="false" />
Modified: servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/jspf/headertags.jspf
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/jspf/headertags.jspf?rev=1137562&r1=1137561&r2=1137562&view=diff
==============================================================================
--- servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/jspf/headertags.jspf (original)
+++ servicemix/smx3/trunk/web/servicemix-web-console/src/main/webapp/WEB-INF/jspf/headertags.jspf Mon Jun 20 09:32:19 2011
@@ -17,3 +17,4 @@
<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
Added: servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBeanTest.java?rev=1137562&view=auto
==============================================================================
--- servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBeanTest.java (added)
+++ servicemix/smx3/trunk/web/servicemix-web-console/src/test/java/org/apache/servicemix/web/jmx/EnhancedMBeanProxyFactoryBeanTest.java Mon Jun 20 09:32:19 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.servicemix.web.jmx;
+
+import junit.framework.TestCase;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+/**
+ * Test cases for {@link EnhancedMBeanProxyFactoryBean}
+ */
+public class EnhancedMBeanProxyFactoryBeanTest extends TestCase {
+
+ public void testWebSphereAddsCellNodeAndProcess() throws Exception {
+ MBeanServer server = MBeanServerFactory.createMBeanServer(EnhancedMBeanProxyFactoryBean.WEBSPHERE);
+ server.registerMBean(new Mock(), new ObjectName("WebSphere:name=JVM,cell=myCell,process=myProcess,node=myNode"));
+
+ Mock mbean = new Mock();
+ server.registerMBean(mbean, new ObjectName("test:name=MyMockBean,cell=myCell,process=myProcess,node=myNode"));
+
+ EnhancedMBeanProxyFactoryBean bean = new EnhancedMBeanProxyFactoryBean();
+ bean.setServer(server);
+ bean.setObjectName("test:name=MyMockBean");
+ bean.setProxyInterface(MockMBean.class);
+ bean.afterPropertiesSet();
+
+ MockMBean proxy = (MockMBean) bean.getObject();
+ proxy.doSomethingUseful();
+ assertEquals("We should have use the MBean using the object name without the cell/process/node inforamtion",
+ 1, mbean.usefulness);
+ }
+
+ public static interface MockMBean {
+
+ public void doSomethingUseful();
+
+ }
+
+ public static final class Mock implements MockMBean {
+
+ private int usefulness;
+
+ public void doSomethingUseful() {
+ usefulness++;
+ }
+
+ }
+}
Added: servicemix/smx3/trunk/web/servicemix-web-console/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/web/servicemix-web-console/src/test/resources/log4j.properties?rev=1137562&view=auto
==============================================================================
--- servicemix/smx3/trunk/web/servicemix-web-console/src/test/resources/log4j.properties (added)
+++ servicemix/smx3/trunk/web/servicemix-web-console/src/test/resources/log4j.properties Mon Jun 20 09:32:19 2011
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+#
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=DEBUG, stdout
+
+log4j.logger.org.springframework=INFO
+log4j.logger.org.apache.activemq=INFO
+log4j.logger.org.apache.activemq.spring=WARN
+log4j.logger.org.apache.activemq.store.journal=INFO
+log4j.logger.org.activeio.journal=INFO
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/servicemix-test.log
+log4j.appender.out.append=true