activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: AMQ-7486: Log at INFO level on starting standalone broker the http url of the web console
Date Fri, 04 Oct 2013 12:10:37 GMT
Updated Branches:
  refs/heads/trunk 4f19f31a3 -> 84c4b9db5


AMQ-7486: Log at INFO level on starting standalone broker the http url of the web console


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/84c4b9db
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/84c4b9db
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/84c4b9db

Branch: refs/heads/trunk
Commit: 84c4b9db56a08d81639d19a65db79a28f8f319ae
Parents: e889e36
Author: Claus Ibsen <claus.ibsen@gmail.com>
Authored: Fri Oct 4 14:09:48 2013 +0200
Committer: Claus Ibsen <claus.ibsen@gmail.com>
Committed: Fri Oct 4 14:10:28 2013 +0200

----------------------------------------------------------------------
 .../apache/activemq/web/WebConsoleStarter.java  | 44 ++++++++++++--------
 .../java/org/apache/activemq/web/tool/Main.java |  1 +
 .../org/apache/activemq/web/WebConsolePort.java | 41 ++++++++++++++++++
 assembly/src/release/conf/jetty.xml             | 10 ++++-
 4 files changed, 77 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/84c4b9db/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java
----------------------------------------------------------------------
diff --git a/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java
b/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java
index 4fa89f8..d6c5d6d 100644
--- a/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java
+++ b/activemq-web-console/src/main/java/org/apache/activemq/web/WebConsoleStarter.java
@@ -30,8 +30,6 @@ import javax.servlet.ServletContextListener;
 
 /**
  * Starts the WebConsole.
- * 
- * 
  */
 public class WebConsoleStarter implements ServletContextListener {
     
@@ -40,30 +38,28 @@ public class WebConsoleStarter implements ServletContextListener {
     public void contextInitialized(ServletContextEvent event) {
         LOG.debug("Initializing ActiveMQ WebConsole...");
 
+        String webconsoleType = getWebconsoleType();
+
         ServletContext servletContext = event.getServletContext();
-        WebApplicationContext context = createWebapplicationContext(servletContext);
+        WebApplicationContext context = createWebapplicationContext(servletContext, webconsoleType);
 
         initializeWebClient(servletContext, context);
 
-        LOG.info("ActiveMQ WebConsole initialized.");
-    }
-
-    private WebApplicationContext createWebapplicationContext(ServletContext servletContext)
{
-
-        String webconsoleType = System.getProperty("webconsole.type", "embedded");
-
-        // detect osgi
-        try {
-            if (OsgiUtil.isOsgi()) {
-                webconsoleType = "osgi";
+        // for embedded console log what port it uses
+        if ("embedded".equals(webconsoleType)) {
+            // show the url for the web consoles / main page so people can spot it
+            String port = System.getProperty("jetty.port");
+            if (port != null) {
+                LOG.info("ActiveMQ WebConsole available at http://localhost:{}/", port);
             }
-        } catch (NoClassDefFoundError ignore) {
         }
 
+        LOG.debug("ActiveMQ WebConsole initialized.");
+    }
 
+    private WebApplicationContext createWebapplicationContext(ServletContext servletContext,
String webconsoleType) {
         String configuration = "/WEB-INF/webconsole-" + webconsoleType + ".xml";
-
-        LOG.info("Web console type: " + webconsoleType);
+        LOG.debug("Web console type: " + webconsoleType);
 
         XmlWebApplicationContext context = new XmlWebApplicationContext();
         context.setServletContext(servletContext);
@@ -93,6 +89,20 @@ public class WebConsoleStarter implements ServletContextListener {
         // do nothing, since the context is destroyed anyway
     }
 
+    private static String getWebconsoleType() {
+        String webconsoleType = System.getProperty("webconsole.type", "embedded");
+
+        // detect osgi
+        try {
+            if (OsgiUtil.isOsgi()) {
+                webconsoleType = "osgi";
+            }
+        } catch (NoClassDefFoundError ignore) {
+        }
+
+        return webconsoleType;
+    }
+
     static class OsgiUtil {
         static boolean isOsgi() {
             return (FrameworkUtil.getBundle(WebConsoleStarter.class) != null);

http://git-wip-us.apache.org/repos/asf/activemq/blob/84c4b9db/activemq-web-console/src/test/java/org/apache/activemq/web/tool/Main.java
----------------------------------------------------------------------
diff --git a/activemq-web-console/src/test/java/org/apache/activemq/web/tool/Main.java b/activemq-web-console/src/test/java/org/apache/activemq/web/tool/Main.java
index 1eb6583..7a419c3 100644
--- a/activemq-web-console/src/test/java/org/apache/activemq/web/tool/Main.java
+++ b/activemq-web-console/src/test/java/org/apache/activemq/web/tool/Main.java
@@ -47,6 +47,7 @@ public final class Main {
             port = Integer.parseInt(text);
         }
         System.out.println("Starting Web Server on port: " + port);
+        System.setProperty("jetty.port", "" + port);
         Server server = new Server();
         SelectChannelConnector connector = new SelectChannelConnector();
         connector.setPort(port);

http://git-wip-us.apache.org/repos/asf/activemq/blob/84c4b9db/activemq-web/src/main/java/org/apache/activemq/web/WebConsolePort.java
----------------------------------------------------------------------
diff --git a/activemq-web/src/main/java/org/apache/activemq/web/WebConsolePort.java b/activemq-web/src/main/java/org/apache/activemq/web/WebConsolePort.java
new file mode 100644
index 0000000..47691d7
--- /dev/null
+++ b/activemq-web/src/main/java/org/apache/activemq/web/WebConsolePort.java
@@ -0,0 +1,41 @@
+/**
+ * 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.activemq.web;
+
+/**
+ * Bean to initialize the port number we use for embedded Jetty server for the web consoles.
+ */
+public class WebConsolePort {
+
+    public static final int DEFAULT_PORT = 8161;
+
+    private int port = DEFAULT_PORT;
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public void start() {
+        // you may set a JVM system property for the jetty.port
+        String port = System.getProperty("jetty.port", "" + this.port);
+        System.setProperty("jetty.port", port);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/84c4b9db/assembly/src/release/conf/jetty.xml
----------------------------------------------------------------------
diff --git a/assembly/src/release/conf/jetty.xml b/assembly/src/release/conf/jetty.xml
index 718efbd..f55b0c6 100644
--- a/assembly/src/release/conf/jetty.xml
+++ b/assembly/src/release/conf/jetty.xml
@@ -111,13 +111,19 @@
     <bean id="contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
     </bean>
 
-    <bean id="Server" class="org.eclipse.jetty.server.Server" init-method="start"
+    <bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
+             <!-- the default port number for the web console -->
+        <property name="port" value="8161"/>
+    </bean>
+
+    <bean id="Server" depends-on="jettyPort" class="org.eclipse.jetty.server.Server" init-method="start"
         destroy-method="stop">
 
         <property name="connectors">
             <list>
                 <bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
-                    <property name="port" value="8161" />
+                     <!-- see the jettyPort bean -->
+                    <property name="port" value="#{systemProperties['jetty.port']}" />
                 </bean>
                 <!--
                     Enable this connector if you wish to use https with web console


Mime
View raw message