[wsas-java-dev] svn commit r1691 - in
trunk/wsas/java/modules/core/src/org/wso2/wsas: . util
svn at wso2.org
svn at wso2.org
Mon Apr 2 01:31:54 PDT 2007
Author: azeez
Date: Mon Apr 2 01:31:47 2007
New Revision: 1691
Added:
trunk/wsas/java/modules/core/src/org/wso2/wsas/util/Utils.java
Modified:
trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java
Log:
Ability to switch off Admin UI
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/MainServlet.java Mon Apr 2 01:31:47 2007
@@ -201,7 +201,8 @@
((AdminUIServletFilter) servletContext
.getAttribute(AdminUIServletFilter.class.getName()));
adminUIServletFilter.init((Map) configCtx.getProperty(ServerConstants.GENERATED_PAGES),
- configCtx.getContextRoot());
+ configCtx.getContextRoot(),
+ Utils.isAdminConsoleEnabled());
// set redirection
RequestRedirectionFilter requestRedirectionFilter =
@@ -256,29 +257,7 @@
public void startServer() throws ServerException {
try {
init(this.servletConfig);
-
- //Reinitialize all of the servlets, for this puprpose,
- // the servlets should have added themselves
- // as ServletContext attributes in the previous init call
- ServletContext servletContext = servletConfig.getServletContext();
- Enumeration attributeNames = servletContext.getAttributeNames();
- while (attributeNames.hasMoreElements()) {
- Object attrib = servletContext.getAttribute((String) attributeNames.nextElement());
- if (attrib instanceof HttpServlet) {
- ((HttpServlet) attrib).init();
- } else if (attrib instanceof AdminUIServletFilter) {
- AdminUIServletFilter adminUIServletFilter = (AdminUIServletFilter) attrib;
- Map genPages = (Map) serverManager.configContext.
- getProperty(ServerConstants.GENERATED_PAGES);
- adminUIServletFilter.init(genPages,
- serverManager.configContext.getContextRoot());
- } else if (attrib instanceof RequestRedirectionFilter) {
- RequestRedirectionFilter requestRedirectionFilter =
- (RequestRedirectionFilter) servletContext.
- getAttribute(RequestRedirectionFilter.class.getName());
- requestRedirectionFilter.init(serverManager.configContext.getContextRoot());
- }
- }
+ reinitializeServlets(this.servletConfig.getServletContext());
} catch (ServletException e) {
String msg = "Cannot start server";
log.fatal(msg, e);
@@ -346,6 +325,12 @@
// Now we switch to the new Config ctx
serverManager.configContext = configurationContext;
+ // Disable admin services, if needed
+ if (!Utils.isAdminConsoleEnabled()) {
+ serverManager.configContext.getAxisConfiguration().
+ removeServiceGroup(ServerConstants.ADMIN_SERVICE_GROUP);
+ }
+
// Start the ListenerManager
serverManager.startListenerManager();
@@ -353,25 +338,39 @@
servletContext.removeAttribute(ServerConstants.CONFIGURATION_CONTEXT);
servletContext.setAttribute(ServerConstants.CONFIGURATION_CONTEXT,
configurationContext);
-
- // Reinitialize all of the servlets, for this puprpose,
- // the servlets should have added themselves
- // as ServletContext attributes in the previous init call
- Enumeration attributeNames = servletContext.getAttributeNames();
- while (attributeNames.hasMoreElements()) {
- Object attrib = servletContext.getAttribute((String) attributeNames.nextElement());
- if (attrib instanceof HttpServlet) {
- ((HttpServlet) attrib).init();
- }
- }
-
- } catch (ServletException e) {
+ reinitializeServlets(servletContext);
+ } catch (Exception e) {
String msg = "Cannot set ConfigurationContext";
log.fatal(msg, e);
throw new ServerException(msg, e);
}
}
+ private void reinitializeServlets(ServletContext servletContext) throws ServletException {
+ // Reinitialize all of the servlets, for this puprpose,
+ // the servlets should have added themselves
+ // as ServletContext attributes in the previous init call
+ Enumeration attributeNames = servletContext.getAttributeNames();
+ while (attributeNames.hasMoreElements()) {
+ Object attrib = servletContext.getAttribute((String) attributeNames.nextElement());
+ if (attrib instanceof HttpServlet) {
+ ((HttpServlet) attrib).init();
+ } else if (attrib instanceof AdminUIServletFilter) {
+ AdminUIServletFilter adminUIServletFilter = (AdminUIServletFilter) attrib;
+ Map genPages = (Map) serverManager.configContext.
+ getProperty(ServerConstants.GENERATED_PAGES);
+ adminUIServletFilter.init(genPages,
+ serverManager.configContext.getContextRoot(),
+ Utils.isAdminConsoleEnabled());
+ } else if (attrib instanceof RequestRedirectionFilter) {
+ RequestRedirectionFilter requestRedirectionFilter =
+ (RequestRedirectionFilter) servletContext.
+ getAttribute(RequestRedirectionFilter.class.getName());
+ requestRedirectionFilter.init(serverManager.configContext.getContextRoot());
+ }
+ }
+ }
+
public void shutdown() throws ServerException {
cleanupSystem();
}
@@ -393,6 +392,14 @@
log.info("Command listener starting on port ----> " + cmdListenerPort);
}
+ public void destroy() {
+ try {
+ shutdown();
+ } catch (ServerException e) {
+ log.error(e);
+ }
+ }
+
private void cleanupSystem() {
log.info("Cleaning up system...");
new FileManipulator().deleteDir(new File(wso2wsasHome + File.separator +
@@ -406,12 +413,4 @@
}
}
}
-
- public void destroy() {
- try {
- shutdown();
- } catch (ServerException e) {
- log.error(e);
- }
- }
}
Added: trunk/wsas/java/modules/core/src/org/wso2/wsas/util/Utils.java
==============================================================================
--- (empty file)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/util/Utils.java Mon Apr 2 01:31:47 2007
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.wsas.util;
+
+import org.wso2.utils.ServerConfiguration;
+import org.wso2.wsas.ServerConstants;
+import org.apache.axis2.Constants;
+
+/**
+ *
+ */
+public class Utils {
+
+ public static boolean isAdminConsoleEnabled() {
+ boolean enableAdminConsole = true;
+ String enableAdminConsoleProp =
+ ServerConfiguration.getInstance().getFirstProperty("Management.EnableConsole");
+ if (enableAdminConsoleProp != null) {
+ enableAdminConsole = Boolean.valueOf(enableAdminConsoleProp).booleanValue();
+ }
+ return enableAdminConsole;
+ }
+
+ public static String getAxis2Xml() {
+ String axis2XML = ServerConfiguration.getInstance().
+ getFirstProperty("Axis2Config.ConfigurationFile");
+ if (axis2XML == null) {
+ axis2XML = System.getProperty(Constants.AXIS2_CONF);
+ }
+ return axis2XML;
+ }
+
+ public static String getWsasServerXml(){
+ String serverXML = System.getProperty(ServerConstants.WSO2WSAS_SERVER_XML);
+ if (serverXML == null) {
+ System.setProperty(ServerConstants.WSO2WSAS_SERVER_XML,
+ ServerConfiguration.configurationXMLLocation);
+ }
+ return serverXML;
+ }
+
+}
More information about the Wsas-java-dev
mailing list