You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/10/19 20:13:32 UTC

svn commit: r465711 - in /incubator/servicemix/trunk/servicemix-console: ./ src/main/java/org/apache/servicemix/console/ src/main/resources/ src/webapp/WEB-INF/

Author: gnodet
Date: Thu Oct 19 11:13:30 2006
New Revision: 465711

URL: http://svn.apache.org/viewvc?view=rev&rev=465711
Log:
All parameterization of the console from the web.xml 

Added:
    incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ContextLoaderListener.java
    incubator/servicemix/trunk/servicemix-console/src/main/resources/log4j.xml
Modified:
    incubator/servicemix/trunk/servicemix-console/pom.xml
    incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ServiceMixPortlet.java
    incubator/servicemix/trunk/servicemix-console/src/webapp/WEB-INF/web.xml

Modified: incubator/servicemix/trunk/servicemix-console/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-console/pom.xml?view=diff&rev=465711&r1=465710&r2=465711
==============================================================================
--- incubator/servicemix/trunk/servicemix-console/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-console/pom.xml Thu Oct 19 11:13:30 2006
@@ -104,7 +104,12 @@
         <groupId>org.mortbay.jetty</groupId>
         <artifactId>maven-jetty-plugin</artifactId>
         <configuration>
-          <scanIntervalSeconds>10</scanIntervalSeconds>
+          <connectors>
+            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
+              <port>9090</port>
+              <maxIdleTime>60000</maxIdleTime>
+            </connector>
+          </connectors>          <scanIntervalSeconds>10</scanIntervalSeconds>
           <webAppSourceDirectory>${basedir}/src/webapp</webAppSourceDirectory>
         </configuration>
       </plugin>

Added: incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ContextLoaderListener.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ContextLoaderListener.java?view=auto&rev=465711
==============================================================================
--- incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ContextLoaderListener.java (added)
+++ incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ContextLoaderListener.java Thu Oct 19 11:13:30 2006
@@ -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.servicemix.console;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class ContextLoaderListener implements ServletContextListener {
+
+    private static ServletContext CONTEXT;
+    
+    public static ServletContext getServletContext() {
+        return CONTEXT;
+    }
+    
+    public void contextInitialized(ServletContextEvent context) {
+        CONTEXT = context.getServletContext();
+    }
+
+    public void contextDestroyed(ServletContextEvent context) {
+        CONTEXT = null;
+    }
+    
+}

Modified: incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ServiceMixPortlet.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ServiceMixPortlet.java?view=diff&rev=465711&r1=465710&r2=465711
==============================================================================
--- incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ServiceMixPortlet.java (original)
+++ incubator/servicemix/trunk/servicemix-console/src/main/java/org/apache/servicemix/console/ServiceMixPortlet.java Thu Oct 19 11:13:30 2006
@@ -45,9 +45,12 @@
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
+import javax.servlet.ServletContext;
 
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
 
 public abstract class ServiceMixPortlet extends GenericPortlet {
 
@@ -61,20 +64,29 @@
     private String namingHost = "localhost";
     private String containerName = JBIContainer.DEFAULT_NAME;
     private String jmxDomainName = ManagementContext.DEFAULT_DOMAIN;
+    private String jmxUrl;
     private int namingPort = ManagementContext.DEFAULT_CONNECTOR_PORT;
     private String jndiPath = ManagementContext.DEFAULT_CONNECTOR_PATH;
+    private String username;
+    private String password;
 
     /**
      * Get the JMXServiceURL - built from the protocol used and host names
      * @return the url
      */
-    public JMXServiceURL getServiceURL(){
+    public JMXServiceURL getServiceURL() {
         JMXServiceURL url = null;
-        try {
-            url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + namingHost + ":" + namingPort + jndiPath);
-        }
-        catch (MalformedURLException e) {
-            log.error("error creating serviceURL: ",e);
+        if (url == null) {
+            try {
+                String jmxUrl = this.jmxUrl;
+                if (jmxUrl == null) {
+                    jmxUrl = "service:jmx:rmi:///jndi/rmi://" + namingHost + ":" + namingPort + jndiPath;
+                }
+                url = new JMXServiceURL(jmxUrl);
+            }
+            catch (MalformedURLException e) {
+                log.error("error creating serviceURL: ", e);
+            }
         }
         return url;
     }
@@ -87,7 +99,10 @@
      */
     public JMXConnector getJMXConnector (JMXServiceURL url) throws IOException {
         log.info("Connecting to JBI Container at: " + url);
-        return JMXConnectorFactory.connect(url);
+        String[] credentials = new String[] { username, password };
+        Map environment = new HashMap();
+        environment.put(JMXConnector.CREDENTIALS, credentials);
+        return JMXConnectorFactory.connect(url, environment);
     }
     
     protected void doHelp(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
@@ -116,6 +131,7 @@
             throw e;
         } catch (Exception e) {
             try {
+                log.debug("Error rendering portlet", e);
                 renderRequest.setAttribute("exception", e);
                 errorView.include(renderRequest, renderResponse);
             } finally {
@@ -139,7 +155,7 @@
      * @return the object name
      */
     protected  ObjectName getObjectName (Class systemClass){
-        return ManagementContext.getSystemObjectName(jmxDomainName, containerName, systemClass);
+        return ManagementContext.getSystemObjectName(jmxDomainName, getContainerName(), systemClass);
     }
     
     
@@ -153,6 +169,22 @@
         normalView = pc.getRequestDispatcher("/WEB-INF/view/" + getPortletName() + "/view.jsp");
         helpView = pc.getRequestDispatcher("/WEB-INF/view/" + getPortletName() + "/help.jsp");
         errorView = pc.getRequestDispatcher("/WEB-INF/view/error.jsp");
+
+        jmxUrl = getConfigString("servicemixJmxUrl", jmxUrl);
+        username = getConfigString("servicemixJmxUsername", username);
+        password = getConfigString("servicemixJmxPassword", password);
+        containerName = getConfigString("servicemixContainerName", containerName);
+    }
+    
+    protected String getConfigString(String name, String defValue) {
+        ServletContext ctx = ContextLoaderListener.getServletContext();
+        if (ctx != null) {
+            String v = ctx.getInitParameter(name);
+            if (v != null) {
+                return v;
+            }
+        }
+        return defValue;
     }
 
     public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
@@ -256,4 +288,32 @@
         this.containerName = containerName;
     }
     
+    /**
+     * @return the password
+     */
+    protected String getPassword() {
+        return password;
+    }
+
+    /**
+     * @param password the password to set
+     */
+    protected void setPassword(String password) {
+        this.password = password;
+    }
+
+    /**
+     * @return the username
+     */
+    protected String getUsername() {
+        return username;
+    }
+
+    /**
+     * @param username the username to set
+     */
+    protected void setUsername(String username) {
+        this.username = username;
+    }
+
 }

Added: incubator/servicemix/trunk/servicemix-console/src/main/resources/log4j.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-console/src/main/resources/log4j.xml?view=auto&rev=465711
==============================================================================
--- incubator/servicemix/trunk/servicemix-console/src/main/resources/log4j.xml (added)
+++ incubator/servicemix/trunk/servicemix-console/src/main/resources/log4j.xml Thu Oct 19 11:13:30 2006
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+        <param name="threshold" value="DEBUG"/>
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%-5p - %-30c{1} - %m%n"/>
+        </layout>
+    </appender>
+
+    <root>
+        <level value="DEBUG"/>
+        <appender-ref ref="CONSOLE"/>
+    </root>
+
+</log4j:configuration>
+<!--
+
+Log4J Configuration Quick Reference:
+====================================
+
+Priority order is DEBUG < INFO < WARN < ERROR < FATAL
+
+PatternLayout conversion characters:
+
+%c   Category of the logging event
+%C   Fully qualified class name of the caller
+%d   Date of the logging event  (example: %d{HH:mm:ss,SSS} )
+%F   File name where the logging request was issued (caution: extremely slow)
+%l   Location information of the caller (caution: extremely slow)
+%L   Line number from where the logging request was issued (caution: extremely slow)
+%m   Application-supplied message
+%M   Method name from where the logging request was issued (caution: extremely slow)
+%n   Line separator
+%p   Priority of the logging event
+%r   Number of milliseconds since the start of the application
+%t   Name of the thread that generated the logging event
+%x   Nested diagnotic context associated with the thread
+%%   A single percent sign
+
+Format modifiers examples:
+
+%20c     Left pad with spaces if category is less than 20 characters long
+%-20c    Right pad with spaces if category is less than 20 characters long
+%.30c    Truncate from the beginning if category is more than 30 chars long
+%20.30c  Left pad 20 chars + truncate from beginning if more than 30 chars
+%-20.30c Right pad 20 chars + truncate from beginning if more than 30 chars
+
+Examples:  "%r [%t] %-5p %c %x - %m\n"
+"%-6r [%15.15t] %-5p %30.30c %x - %m\n"
+
+-->

Modified: incubator/servicemix/trunk/servicemix-console/src/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-console/src/webapp/WEB-INF/web.xml?view=diff&rev=465711&r1=465710&r2=465711
==============================================================================
--- incubator/servicemix/trunk/servicemix-console/src/webapp/WEB-INF/web.xml (original)
+++ incubator/servicemix/trunk/servicemix-console/src/webapp/WEB-INF/web.xml Thu Oct 19 11:13:30 2006
@@ -22,13 +22,33 @@
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
          version="2.4">
 
-    <display-name>ServiceMix Console</display-name>
+  <display-name>ServiceMix Console</display-name>
 
-    <servlet>
-        <display-name>Geronimo Console</display-name>
-        <servlet-name>se-console</servlet-name>
-        <servlet-class>org.apache.pluto.portalImpl.Servlet</servlet-class>
-    </servlet>
+  <context-param>
+    <param-name>servicemixJmxUrl</param-name>
+    <param-value>service:jmx:rmi:///jndi/rmi://localhost/JMXConnector</param-value>
+  </context-param>
+  <context-param>
+    <param-name>servicemixJmxUsername</param-name>
+    <param-value>system</param-value>
+  </context-param>
+  <context-param>
+    <param-name>servicemixJmxPassword</param-name>
+    <param-value>manager</param-value>
+  </context-param>
+  <context-param>
+    <param-name>servicemixContainerName</param-name>
+    <param-value>servicemix</param-value>
+  </context-param>
+  <listener>
+    <listener-class>org.apache.servicemix.console.ContextLoaderListener</listener-class>
+  </listener>
+
+  <servlet>
+      <display-name>Geronimo Console</display-name>
+      <servlet-name>se-console</servlet-name>
+      <servlet-class>org.apache.pluto.portalImpl.Servlet</servlet-class>
+  </servlet>
 
   <servlet>
     <description>Portlet Invoker Servlet</description>