From 0871d3297e76e3b4dfd62de2fa5be79ffb75a0ef Mon Sep 17 00:00:00 2001 From: Andrea Gazzarini Date: Thu, 5 Feb 2009 07:22:17 +0000 Subject: QPID-1581 : Source modification for QMan Admin Console git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@741032 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/java/management/client/build.xml | 5 + .../GetResourcePropertyDocumentExample.java | 1 - .../java/org/apache/qpid/management/Messages.java | 3 + .../configuration/BrokerConnectionData.java | 2 +- .../domain/services/ManagementClient.java | 21 ++- .../qpid/management/domain/services/QMan.java | 10 ++ .../qpid/management/web/action/BrokerModel.java | 80 +++++++++ .../web/action/BrokersManagementAction.java | 188 ++++++++++++++++++++ .../qpid/management/web/action/ConsoleAction.java | 117 +++++++++++++ .../qpid/management/web/action/ConsoleModel.java | 158 +++++++++++++++++ .../web/action/JmxPerspectiveAction.java | 189 ++++++++++++++++++++ .../web/action/LoggingConfigurationAction.java | 114 ++++++++++++ .../web/action/ResourcesManagementAction.java | 91 ++++++++++ .../action/WsdmOperationsPerspectiveAction.java | 191 +++++++++++++++++++++ .../action/WsdmPropertiesPerspectiveAction.java | 188 ++++++++++++++++++++ .../web/action/WsdmRmdPerspectiveAction.java | 113 ++++++++++++ .../web/action/WsdmWsdlPerspectiveAction.java | 134 +++++++++++++++ .../wsdm/capabilities/QManAdapterCapability.java | 4 +- .../wsdm/common/ObjectNameIdFactory.java | 4 +- .../client/src/main/java/wsdl/QManWsResource.wsdl | 2 +- 20 files changed, 1608 insertions(+), 7 deletions(-) create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleModel.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/JmxPerspectiveAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/LoggingConfigurationAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ResourcesManagementAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmOperationsPerspectiveAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java create mode 100644 qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java diff --git a/qpid/java/management/client/build.xml b/qpid/java/management/client/build.xml index f1600cad70..287be93a45 100644 --- a/qpid/java/management/client/build.xml +++ b/qpid/java/management/client/build.xml @@ -101,6 +101,11 @@ + + + + + diff --git a/qpid/java/management/client/src/example/org/apache/qpid/management/example/GetResourcePropertyDocumentExample.java b/qpid/java/management/client/src/example/org/apache/qpid/management/example/GetResourcePropertyDocumentExample.java index 838ca2ced7..56ce81358d 100644 --- a/qpid/java/management/client/src/example/org/apache/qpid/management/example/GetResourcePropertyDocumentExample.java +++ b/qpid/java/management/client/src/example/org/apache/qpid/management/example/GetResourcePropertyDocumentExample.java @@ -80,7 +80,6 @@ public class GetResourcePropertyDocumentExample extends AbstractQManExample @SuppressWarnings("unused") Element resourcePropertyDocument = wsResourceClient.getResourcePropertyDocument(); - } /** * Prints out a description of this example. diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java index c0b43d0c29..dbe6d8c64f 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/Messages.java @@ -117,6 +117,9 @@ public interface Messages String QMAN_300003_BROKER_ALREADY_CONNECTED = " : Unable to enlist given broker connection data : QMan is already connected with broker %s"; String QMAN_300004_INVALID_CONFIGURATION_FILE = " : The given configuration file (%s) is not valid (it doesn't exist or cannot be read)"; String QMAN_300005_QEMU_INITIALIZATION_FAILURE = " : Unable to initialize QEmu module and therefore emulation won't be enabled..."; + + String QMAN_300006_OS_MBEAN_FAILURE = " : Unable to retrieve Operating System properties. No values will be displayed for underlying Operation System."; + String QMAN_300007_RUNTIME_MBEAN_FAILURE = " : Unable to retrieve Runtime Environment properties. No values will be displayed."; // ERROR String QMAN_100001_BAD_MAGIC_NUMBER_FAILURE = " : Message processing failure : incoming message contains a bad magic number (%s) and therefore will be discaded."; diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java index be04c67555..b796620747 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/configuration/BrokerConnectionData.java @@ -44,7 +44,7 @@ public class BrokerConnectionData * @param username the username for connecting with the broker. * @param password the password for connecting with the broker. * @param virtualHost the virtual host. - * @param initialPoolCapacity the number of the connection that must be immediately opened. + * @param initialPoolCapacity the number of connections that must be immediately opened. * @param maxPoolCapacity the maximum number of opened connection. * @param maxWaitTimeout the maximum amount of time that a client will wait for obtaining a connection. */ diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java index a3584571f3..ee610b1713 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/ManagementClient.java @@ -37,7 +37,7 @@ import org.apache.qpid.transport.util.Logger; * * @author Andrea Gazzarini */ -final class ManagementClient +public final class ManagementClient { private final static Logger LOGGER = Logger.get(ManagementClient.class); @@ -46,6 +46,8 @@ final class ManagementClient private DomainModel _domainModel; private QpidService _service; + + private final BrokerConnectionData _connectionData; /** * Builds a new ManagementClient with the given identifier and connection data. @@ -55,12 +57,29 @@ final class ManagementClient */ ManagementClient(UUID brokerId,BrokerConnectionData connectionData) { + _connectionData = connectionData; _service = new QpidService(brokerId); _domainModel = new DomainModel(brokerId); _managementQueueName = Configuration.getInstance().getManagementQueueName(); _methodReplyQueueName = Configuration.getInstance().getMethodReplyQueueName(); } + @Override + public String toString() + { + return _connectionData.toString(); + } + + /** + * Returns the connection data associated with this management client. + * + * @return the connection data associated with this management client. + */ + public BrokerConnectionData getBrokerConnectionData() + { + return _connectionData; + } + /** * Establishing initial communication Between Client and Broker. * According to specification : diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java index 0bc684f04c..d124593472 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/domain/services/QMan.java @@ -371,4 +371,14 @@ public class QMan extends NotificationBroadcasterSupport implements DynamicMBean LOGGER.error(exception, Messages.QMAN_100017_UNABLE_TO_CONNECT,brokerId,data); } } + + /** + * Returns the list of management clients currently handled by QMan. + * + * @return the list of management clients currently handled by QMan. + */ + public List getManagementClients() + { + return managementClients; + } } diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java new file mode 100644 index 0000000000..03e772b9b1 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokerModel.java @@ -0,0 +1,80 @@ +/* + * + * 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.qpid.management.web.action; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.management.ObjectName; + +import org.apache.qpid.management.Names; + +public class BrokerModel +{ + private Map> objectsByType = new HashMap>(); + + private String id; + + void addObject(ObjectName name) + { + String packageName = name.getKeyProperty(Names.PACKAGE); + String className = name.getKeyProperty(Names.CLASS); + if (className != null) + { + String fqn = packageName+"."+className; + + List objects = objectsByType.get(fqn); + if (objects == null) + { + objects = new ArrayList(); + objectsByType.put(fqn,objects); + } + objects.add(name); + } + } + + public String getId() + { + return id; + } + + public void setId(String id) + { + this.id = id; + } + + public Set getCategoryNames(){ + return objectsByType.keySet(); + } + + public List getCategory(String name) + { + return objectsByType.get(name); + } + + public int getCategoryCount() + { + return objectsByType.keySet().size(); + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java new file mode 100644 index 0000000000..ae886767e2 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/BrokersManagementAction.java @@ -0,0 +1,188 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.qpid.management.Names; +import org.apache.qpid.management.configuration.BrokerAlreadyConnectedException; +import org.apache.qpid.management.configuration.BrokerConnectionData; +import org.apache.qpid.management.configuration.BrokerConnectionException; +import org.apache.qpid.management.domain.services.ManagementClient; +import org.apache.qpid.management.domain.services.QMan; + +/** + * This controller is responsible to : + * + *
    + *
  • prepare data for the page that is showing all connected brokers.
  • . + * connect QMan with a broker on demand. + *
+ * @author Andrea Gazzarini + */ +public class BrokersManagementAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + + /** + * Retrieves all connected brokers (their connection data) and prepare the model that + * is then forwarded to the appropriate view page. + */ + @SuppressWarnings("unchecked") + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try + { + QMan qman = (QMan)getServletContext().getAttribute(Names.APPLICATION_NAME); + List managementClients = qman.getManagementClients(); + + List brokers = new ArrayList(managementClients.size()); + + if (!managementClients.isEmpty()) + { + for (ManagementClient managementClient : managementClients) + { + brokers.add(managementClient.getBrokerConnectionData()); + } + request.setAttribute("model", brokers); + } + + RequestDispatcher dispatcher = request.getRequestDispatcher("/brokers_management.jsp"); + dispatcher.forward(request,response); + } catch(Exception exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } + + /** + * Connects QMan with a new broker. + */ + @SuppressWarnings("unchecked") + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try + { + QMan qman = (QMan)getServletContext().getAttribute(Names.APPLICATION_NAME); + + String host = request.getParameter("host"); + String portString = request.getParameter("port"); + String virtualHost = request.getParameter("virtualHost"); + String username = request.getParameter("username"); + String password = request.getParameter("password"); + + String initialCapacityString = request.getParameter("initialCapacity"); + String maxCapacityString = request.getParameter("maxCapacity"); + String maxWaitTimeoutString = request.getParameter("maxWaitTimeout"); + + List errors = new LinkedList(); + int port = 0; + int initialPoolCapacity = 0; + int maxPoolCapacity = 0; + long maxWaitTimeout = 0; + + if(host== null || host.trim().length()==0) + { + errors.add("Invalid value for \"host\" attribute. Must be not null."); + } + + if(virtualHost == null || virtualHost.trim().length()==0) + { + errors.add("Invalid value for \"virtualHost\" attribute. Must be not null."); + } + + try{ + port = Integer.parseInt(portString); + } catch(Exception exception) + { + errors.add("Invalid value for \"port\" attribute. Must be not null and must be a number."); + } + + try{ + initialPoolCapacity = Integer.parseInt(initialCapacityString); + } catch(Exception exception) + { + errors.add("Invalid value for \"Initial Pool Capacity\" attribute. Must be not null and must be a number."); + } + + try{ + maxPoolCapacity = Integer.parseInt(maxCapacityString); + } catch(Exception exception) + { + errors.add("Invalid value for \"Max Pool Capacity\" attribute. Must be not null and must be a number."); + } + + try{ + maxWaitTimeout = Long.parseLong(maxWaitTimeoutString); + } catch(Exception exception) + { + errors.add("Invalid value for \"Max Wait Timeout\" attribute. Must be not null and must be a number."); + } + + request.setAttribute("errors", errors); + + if (errors.isEmpty()) + { + qman.addBroker( + host, + port, + username, + password, + virtualHost, + initialPoolCapacity, + maxPoolCapacity, + maxWaitTimeout); + } + doGet(request, response); + }catch(BrokerAlreadyConnectedException exception) + { + request.setAttribute("errorMessage","Supplied data refers to an already connected broker..."); + RequestDispatcher dispatcher = request.getRequestDispatcher("/brokers_management.jsp"); + dispatcher.forward(request,response); + } + catch(BrokerConnectionException exception) + { + request.setAttribute("errorMessage","Unable to connect with the requested broker..."); + RequestDispatcher dispatcher = request.getRequestDispatcher("/brokers_management.jsp"); + dispatcher.forward(request,response); + } catch(Exception exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleAction.java new file mode 100644 index 0000000000..ee098882f1 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleAction.java @@ -0,0 +1,117 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.File; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.OperatingSystemMXBean; +import java.lang.management.RuntimeMXBean; +import java.util.Date; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.qpid.management.Messages; +import org.apache.qpid.management.Names; +import org.apache.qpid.transport.util.Logger; + +/** + * This action is the controller responsible to prepare data for the home + * page (System Overview) of QMan admin console. + * + * @author Andrea Gazzarini + */ +public class ConsoleAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + + private static final Logger LOGGER = Logger.get(ConsoleAction.class); + + private Date _startDate; + + /** + * Initializes this controller. + * Simply it computes the start date of the application. + */ + @Override + public void init() + { + _startDate = new Date(); + } + + /** + * Prepares data for System Overview admin console page and forward that data to that page. + * + * @throws ServletException when this controller is not able to forward to the appropriate view page. + * @throws IOException when this controller is not able to forward to the appropriate view page. + */ + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + ConsoleModel model = new ConsoleModel(); + model.setVersion("1.0"); + model.setVersionName("Sofia"); + model.setStartDate(_startDate); + model.setHost(System.getProperty(Names.ADAPTER_HOST_PROPERTY_NAME, "localhost")); + model.setPort(Integer.parseInt(System.getProperty(Names.ADAPTER_PORT_PROPERTY_NAME, "8080"))); + + try + { + OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean(); + model.setOsName(operatingSystem.getName()); + model.setProcessors(operatingSystem.getAvailableProcessors()); + model.setOsVersion(operatingSystem.getVersion()); + model.setArchName(operatingSystem.getArch()); + } catch(Exception exception) + { + LOGGER.warn(exception,Messages.QMAN_300006_OS_MBEAN_FAILURE); + model.setOsName("N.A."); + model.setProcessors(null); + model.setOsVersion("N.A."); + model.setArchName("N.A."); + } + + try + { + RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); + + String bootClasspath = runtime.getBootClassPath(); + model.setBootClasspath(bootClasspath.split(File.pathSeparator)); + + String classpath = runtime.getClassPath(); + model.setClasspath(classpath.split(File.pathSeparator)); + + model.setInputArguments(runtime.getInputArguments().toArray(new String[]{})); + } catch(Exception exception) + { + LOGGER.warn(exception,Messages.QMAN_300007_RUNTIME_MBEAN_FAILURE); + } + + request.setAttribute("model", model); + + RequestDispatcher dispatcher = request.getRequestDispatcher("/console.jsp"); + dispatcher.forward(request,response); + } +} diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleModel.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleModel.java new file mode 100644 index 0000000000..ac0e1d2bbd --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ConsoleModel.java @@ -0,0 +1,158 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** + * Console Model. + * It is a simple Data Transfer Object encapsulating all information about QMan + * console (System Overview) + * + * @author Andrea Gazzarini + */ +public class ConsoleModel implements Serializable +{ + private static final long serialVersionUID = -7676132151242738376L; + private String _version; + private String _versionName; + private Date _startDate; + private String _host; + private int _port; + + private String _osName; + private String _osVersion; + private String _archName; + private Integer _processors; + + private String [] _bootClasspath; + private String [] _classpath; + private String [] _inputArguments; + private String [] _systemProperties; + + public String getVersion() + { + return _version; + } + public void setVersion(String version) + { + this._version = version; + } + public String getVersionName() + { + return _versionName; + } + public void setVersionName(String versionName) + { + this._versionName = versionName; + } + public Date getStartDate() + { + return _startDate; + } + public void setStartDate(Date startDate) + { + this._startDate = startDate; + } + public String getHost() + { + return _host; + } + public void setHost(String host) + { + this._host = host; + } + public int getPort() + { + return _port; + } + public void setPort(int port) + { + this._port = port; + } + public String getOsName() + { + return _osName; + } + public void setOsName(String osName) + { + this._osName = osName; + } + public String getOsVersion() + { + return _osVersion; + } + public void setOsVersion(String osVersion) + { + this._osVersion = osVersion; + } + public String getArchName() + { + return _archName; + } + public void setArchName(String archName) + { + this._archName = archName; + } + public Integer getProcessors() + { + return _processors; + } + public void setProcessors(Integer processors) + { + this._processors = processors; + } + public List getBootClasspath() + { + return Arrays.asList(_bootClasspath); + } + public void setBootClasspath(String [] bootClasspath) + { + this._bootClasspath = bootClasspath; + } + public String [] getClasspath() + { + return _classpath; + } + public void setClasspath(String [] classpath) + { + this._classpath = classpath; + } + public String [] getInputArguments() + { + return _inputArguments; + } + public void setInputArguments(String [] inputArguments) + { + this._inputArguments = inputArguments; + } + public String [] getSystemProperties() + { + return _systemProperties; + } + public void setSystemProperties(String [] systemProperties) + { + this._systemProperties = systemProperties; + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/JmxPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/JmxPerspectiveAction.java new file mode 100644 index 0000000000..59777cc9c8 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/JmxPerspectiveAction.java @@ -0,0 +1,189 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Properties; +import java.util.Map.Entry; + +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanInfo; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * This controller is responsible to provide a jmx perspective of a specific resource. + * That means that this controller is querying the Platform MBean server in order to + * get metadata for the requested mbean. + * + * After that metadata will be forwarded to the appropriate view page and therefore + * will be shown on the Admin console. + * + * @author Andrea Gazzarini + */ +public class JmxPerspectiveAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + + /** + * Adapter interface for converting objects on html strings. + * + * @author Andrea Gazzarini. + */ + interface JavaToHtmlAdapter + { + /** + * Returns an HTML string representation of the given object. + * + * @param javaObject the object that needs to be converted. + * @return an html string containing value of the given object. + */ + String toHtml(Object javaObject); + } + + /** + * Adapter implementation for Map (and subclasses). + */ + private JavaToHtmlAdapter mapAdapter = new JavaToHtmlAdapter() + { + @SuppressWarnings("unchecked") + public String toHtml(Object javaObject) + { + Map value = (Map) javaObject; + + // Sanity check : if the map is empty or null there's no need to + // do any convertion + if (value == null || value.isEmpty()) + { + return "(empty)"; + } + + StringBuilder builder = new StringBuilder("
    "); + for (Entry entry : value.entrySet()) + { + builder + .append("
  • ") + .append(entry.getKey()) + .append(" = ") + .append(entry.getValue()); + } + builder.append("
"); + return builder.toString(); + } + }; + + private Map _adapters = new HashMap(); + + @Override + public void init() throws ServletException + { + _adapters.put(Map.class.getName(), mapAdapter); + _adapters.put(HashMap.class.getName(),mapAdapter); + _adapters.put(Properties.class.getName(),mapAdapter); + _adapters.put(Hashtable.class.getName(),mapAdapter); + } + + @SuppressWarnings("unchecked") + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String resourceId = null; + try + { + resourceId = request.getParameter("resourceId"); + + ObjectName objectName = new ObjectName(resourceId); + String [] keyProperties = objectName.getKeyPropertyListString().split(","); + + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + + MBeanInfo metadata = server.getMBeanInfo(objectName); + + Map attributes = getAttributes(server, objectName,metadata.getAttributes()); + + request.setAttribute("resourceId", objectName); + request.setAttribute("metadata",metadata); + request.setAttribute("nameAttributes",keyProperties); + request.setAttribute("attributes",attributes); + + RequestDispatcher dispatcher = request.getRequestDispatcher("/jmx_perspective.jsp"); + dispatcher.forward(request,response); + } catch(MalformedObjectNameException exception) + { + request.setAttribute("errorMessage","Malformed Resource ID : supplied value is "+resourceId); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + + } + catch(Exception exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } + + /** + * Starting from an mbean metadata, this method retrieves all the attributes + * from the corresponding MBean Server. + * + * @param server the mbean server where the target mbean is registered. + * @param name the name of the target mbean. + * @param metadata the metadata of mbean. + * @return a map containing all attributes of the given mbean. + * @throws Exception when it's not possible to retrieve attributes. + */ + private Map getAttributes(MBeanServer server, ObjectName name, MBeanAttributeInfo [] metadata) throws Exception + { + Map result = new HashMap(metadata.length); + for (MBeanAttributeInfo attribute : metadata) + { + Object value = server.getAttribute(name, attribute.getName()); + result.put(attribute.getName(),getAdaptedValue(attribute.getType(), value)); + } + return result; + } + + /** + * Converts the given attribute value in a html string format. + * + * @param type the java type of the given attribute value. + * @param value the attribute value. + * @return a html string format of the given value. + */ + private String getAdaptedValue(String type, Object value) + { + JavaToHtmlAdapter adapter = _adapters.get(type); + return (adapter != null) ? adapter.toHtml(value) : String.valueOf(value); + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/LoggingConfigurationAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/LoggingConfigurationAction.java new file mode 100644 index 0000000000..aefd4ca8dd --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/LoggingConfigurationAction.java @@ -0,0 +1,114 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.qpid.qman.debug.WsdlDebugger; +import org.apache.qpid.qman.debug.XmlDebugger; + +/** + * Logging configuration controller. + * Accepts input parameters from admin console and configure the underlying + * logging subsystem at runtime. + * + * @author Andrea Gazzarini + */ +public class LoggingConfigurationAction extends HttpServlet +{ + private static final long serialVersionUID = 633352305870632824L; + + private final static String WSDL_DEBUG_ENABLED_PARAM = "wsdlDebugEnabled"; + private final static String SOAP_DEBUG_ENABLED_PARAM = "soapDebugEnabled"; + private final static String WEB_SERVER_LOG_LEVEL_PARAM = "webServerLogLevel"; + private final static String QMAN_LOG_LEVEL_PARAM = "qmanLogLevel"; + + private final static String WEB_SERVER_PACKAGE = "org.mortbay"; + private final static String QMAN_PACKAGE = "org.qpid.apache.management"; + + /** + * Retrieves current logging configuration and forward those data to the logging configuration view page. + * In this way that page will be able to display the current logging settings. + * + * @param request the http request. + * @param response the http response. + * @throws ServletException when this controller is not able to forward to the appropriate view page. + * @throws IOException when this controller is not able to forward to the appropriate view page. + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + Level messageDebuggerLogLevel = Logger.getLogger(XmlDebugger.class).getEffectiveLevel(); + Level wsdlDebuggerLogLevel = Logger.getLogger(WsdlDebugger.class).getEffectiveLevel(); + Level webServerLogLevel = Logger.getLogger(WEB_SERVER_PACKAGE).getEffectiveLevel(); + Level qmanLogLevel = Logger.getLogger(QMAN_PACKAGE).getEffectiveLevel(); + + request.setAttribute(WSDL_DEBUG_ENABLED_PARAM,wsdlDebuggerLogLevel.equals(Level.DEBUG)); + request.setAttribute(SOAP_DEBUG_ENABLED_PARAM,messageDebuggerLogLevel.equals(Level.DEBUG)); + request.setAttribute(WEB_SERVER_LOG_LEVEL_PARAM,webServerLogLevel); + request.setAttribute(QMAN_LOG_LEVEL_PARAM,qmanLogLevel); + + RequestDispatcher dispatcher = request.getRequestDispatcher("/logging_configuration.jsp"); + dispatcher.forward(request, response); + } + + /** + * Accepts user data coming from admin console and use it for configure the underlying logging + * subsystem. + * + * @param request the http request. + * @param response the http response. + * @throws ServletException when this controller is not able to forward to the appropriate view page. + * @throws IOException when this controller is not able to forward to the appropriate view page. + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + String wsdlDebugEnabled = request.getParameter(WSDL_DEBUG_ENABLED_PARAM); + String soapDebugEnabled = request.getParameter(SOAP_DEBUG_ENABLED_PARAM); + + String qmanLevel = request.getParameter(QMAN_LOG_LEVEL_PARAM); + String serverLevel = request.getParameter(WEB_SERVER_LOG_LEVEL_PARAM); + + Logger.getLogger(WEB_SERVER_PACKAGE).setLevel(Level.toLevel(serverLevel)); + Logger.getLogger(QMAN_PACKAGE).setLevel(Level.toLevel(qmanLevel)); + + Logger.getLogger(WsdlDebugger.class).setLevel( + "on".equals(wsdlDebugEnabled) + ? Level.DEBUG + : Level.INFO); + + Logger.getLogger(XmlDebugger.class).setLevel( + "on".equals(soapDebugEnabled) + ? Level.DEBUG + : Level.INFO); + + doGet(request, response); + } +} + \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ResourcesManagementAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ResourcesManagementAction.java new file mode 100644 index 0000000000..f1a55be6bf --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/ResourcesManagementAction.java @@ -0,0 +1,91 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.List; +import java.util.Set; + +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.qpid.management.Names; +import org.apache.qpid.management.domain.services.ManagementClient; +import org.apache.qpid.management.domain.services.QMan; + +/** + * This controller retrieves from QMan all the registered resources and organize + * that data in a model that is then forwarded to the appropriate view page. + * + * TODO : In the corresponding view page only one broker is displayed. + * A query should be made on QMan mbean in order to retrieve all connected broker and therefore + * a model for each of them should be created. + * In the corresponding weg page there should be a "tab" for each broker. Each tab should show only + * the objects belonging to that broker. + * + * @author Andrea Gazzarini + */ +public class ResourcesManagementAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + + @SuppressWarnings("unchecked") + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try + { + QMan qman = (QMan)getServletContext().getAttribute(Names.APPLICATION_NAME); + List managementClient = qman.getManagementClients(); + + if (!managementClient.isEmpty()) + { + BrokerModel model = new BrokerModel(); + model.setId(managementClient.toString()); + + MBeanServer mxServer = ManagementFactory.getPlatformMBeanServer(); + Set objectNames = mxServer.queryNames(new ObjectName("Q-MAN:*"), null); + for (ObjectName objectName : objectNames) + { + model.addObject(objectName); + } + + request.setAttribute("model", model); + } + + RequestDispatcher dispatcher = request.getRequestDispatcher("/resources_management.jsp"); + dispatcher.forward(request,response); + } catch(MalformedObjectNameException exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } +} diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmOperationsPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmOperationsPerspectiveAction.java new file mode 100644 index 0000000000..ca5b3285b0 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmOperationsPerspectiveAction.java @@ -0,0 +1,191 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.net.URI; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Properties; +import java.util.Map.Entry; + +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanInfo; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.muse.core.proxy.ProxyHandler; +import org.apache.muse.core.proxy.ReflectionProxyHandler; +import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.qpid.management.Names; +import org.w3c.dom.Element; + +/** + * This controller is responsible to retirve operations metadata from a WS-Resource. + * That metadat will be forwarded and used by the corresponding view page. + * + * TODO : This is not really showing WS metadata. Insted JMX metadata is used here. + * + * @author Andrea Gazzarini + * + */ +public class WsdmOperationsPerspectiveAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + + private ProxyHandler proxyHandler; + + interface JavaToHtmlAdapter + { + String toHtml(Object javaObject); + } + + private URI resourceUri; + + private JavaToHtmlAdapter mapAdapter = new JavaToHtmlAdapter() + { + @SuppressWarnings("unchecked") + public String toHtml(Object javaObject) + { + Map value = (Map) javaObject; + + if (value == null || value.isEmpty()) + { + return "(empty)"; + } + + StringBuilder builder = new StringBuilder(); + builder.append("
    "); + for (Entry entry : value.entrySet()) + { + builder + .append("
  • ") + .append(entry.getKey()) + .append(" = ") + .append(entry.getValue()); + } + builder.append("
"); + return builder.toString(); + } + }; + + private Map adapters = new HashMap(); + + @Override + public void init() throws ServletException + { + adapters.put(Map.class.getName(), mapAdapter); + adapters.put(HashMap.class.getName(),mapAdapter); + adapters.put(Properties.class.getName(),mapAdapter); + adapters.put(Hashtable.class.getName(),mapAdapter); + + proxyHandler = new ReflectionProxyHandler(); + proxyHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata"); + proxyHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "GetMetadata", Names.PREFIX)); + proxyHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Dialect", Names.PREFIX)}); + proxyHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata", Names.PREFIX)); + proxyHandler.setReturnType(Element[].class); + } + + @SuppressWarnings("unchecked") + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try + { + String resourceId = request.getParameter("resourceId"); + ObjectName objectName = new ObjectName(resourceId); + String wsdmResourceId = objectName.getKeyProperty(Names.OBJECT_ID); + + EndpointReference resourceEndpointReference = new EndpointReference(getURI(request)); + resourceEndpointReference.addParameter( + Names.RESOURCE_ID_QNAME, + wsdmResourceId); + +// WsResourceClient resourceClient = new WsResourceClient(resourceEndpointReference); +// Element wsdl = ((Element[])resourceClient.invoke(proxyHandler,WSDL_DIALECT))[0]; +// Element rmd = ((Element[])resourceClient.invoke(proxyHandler,RMD_DIALECT))[0]; + + String [] keyProperties = objectName.getKeyPropertyListString().split(","); + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + + MBeanInfo metadata = server.getMBeanInfo(objectName); + + Map attributes = getAttributes(server, objectName,metadata.getAttributes()); + + request.setAttribute("resourceId", resourceId); + request.setAttribute("metadata",metadata); + request.setAttribute("nameAttributes",keyProperties); + request.setAttribute("attributes",attributes); + + RequestDispatcher dispatcher = request.getRequestDispatcher("/wsdm_operations_perspective.jsp"); + dispatcher.forward(request,response); + } catch(Exception exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } + + private URI getURI(HttpServletRequest request) + { + if (resourceUri == null) + { + StringBuilder builder = new StringBuilder(); + builder + .append(request.getProtocol()) + .append("//") + .append(request.getServerName()) + .append(":") + .append(request.getServerPort()) + .append("/qman/services/QManWsResource"); + resourceUri = URI.create(builder.toString()); + } + return resourceUri; + } + + private Map getAttributes(MBeanServer server, ObjectName name, MBeanAttributeInfo [] metadata) throws Exception + { + Map result = new HashMap(metadata.length); + for (MBeanAttributeInfo attribute : metadata) + { + Object value = server.getAttribute(name, attribute.getName()); + result.put(attribute.getName(),getAdaptedValue(attribute.getType(), value)); + } + return result; + } + + private String getAdaptedValue(String type, Object value) + { + JavaToHtmlAdapter adapter = adapters.get(type); + return (adapter != null) ? adapter.toHtml(value) : String.valueOf(value); + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java new file mode 100644 index 0000000000..de479a00d6 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmPropertiesPerspectiveAction.java @@ -0,0 +1,188 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.net.URI; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Properties; +import java.util.Map.Entry; + +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanInfo; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.muse.core.proxy.ProxyHandler; +import org.apache.muse.core.proxy.ReflectionProxyHandler; +import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.muse.ws.resource.remote.WsResourceClient; +import org.apache.qpid.management.Names; +import org.w3c.dom.Element; + +public class WsdmPropertiesPerspectiveAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + private static final Object [] WSDL_DIALECT = new Object[]{"http://schemas.xmlsoap.org/wsdl/"}; + private static final Object [] RMD_DIALECT = new Object[]{"http://docs.oasis-open.org/wsrf/rmd-1"}; + + private ProxyHandler proxyHandler; + + interface JavaToHtmlAdapter + { + String toHtml(Object javaObject); + } + + private URI resourceUri; + + private JavaToHtmlAdapter mapAdapter = new JavaToHtmlAdapter() + { + @SuppressWarnings("unchecked") + public String toHtml(Object javaObject) + { + Map value = (Map) javaObject; + + if (value == null || value.isEmpty()) + { + return "(empty)"; + } + + StringBuilder builder = new StringBuilder(); + builder.append("
    "); + for (Entry entry : value.entrySet()) + { + builder + .append("
  • ") + .append(entry.getKey()) + .append(" = ") + .append(entry.getValue()); + } + builder.append("
"); + return builder.toString(); + } + }; + + private Map adapters = new HashMap(); + + @Override + public void init() throws ServletException + { + adapters.put(Map.class.getName(), mapAdapter); + adapters.put(HashMap.class.getName(),mapAdapter); + adapters.put(Properties.class.getName(),mapAdapter); + adapters.put(Hashtable.class.getName(),mapAdapter); + + proxyHandler = new ReflectionProxyHandler(); + proxyHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata"); + proxyHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "GetMetadata", Names.PREFIX)); + proxyHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Dialect", Names.PREFIX)}); + proxyHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata", Names.PREFIX)); + proxyHandler.setReturnType(Element[].class); + } + + @SuppressWarnings("unchecked") + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try + { + String resourceId = request.getParameter("resourceId"); + ObjectName objectName = new ObjectName(resourceId); + + String wsresourceid = objectName.getKeyProperty(Names.OBJECT_ID); + + EndpointReference resourceEndpointReference = new EndpointReference(getURI(request)); + resourceEndpointReference.addParameter( + Names.RESOURCE_ID_QNAME, + wsresourceid); + +// WsResourceClient resourceClient = new WsResourceClient(resourceEndpointReference); +// Element wsdl = ((Element[])resourceClient.invoke(proxyHandler,WSDL_DIALECT))[0]; +// Element rmd = ((Element[])resourceClient.invoke(proxyHandler,RMD_DIALECT))[0]; + + String [] keyProperties = objectName.getKeyPropertyListString().split(","); + + + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + + MBeanInfo metadata = server.getMBeanInfo(objectName); + + Map attributes = getAttributes(server, objectName,metadata.getAttributes()); + + request.setAttribute("resourceId", resourceId); + request.setAttribute("metadata",metadata); + request.setAttribute("nameAttributes",keyProperties); + request.setAttribute("attributes",attributes); + + RequestDispatcher dispatcher = request.getRequestDispatcher("/wsdm_properties_perspective.jsp"); + dispatcher.forward(request,response); + } catch(Exception exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } + + private URI getURI(HttpServletRequest request) + { + if (resourceUri == null) + { + StringBuilder builder = new StringBuilder(); + builder + .append(request.getProtocol()) + .append("//") + .append(request.getServerName()) + .append(":") + .append(request.getServerPort()) + .append("/qman/services/QManWsResource"); + resourceUri = URI.create(builder.toString()); + } + return resourceUri; + } + + private Map getAttributes(MBeanServer server, ObjectName name, MBeanAttributeInfo [] metadata) throws Exception + { + Map result = new HashMap(metadata.length); + for (MBeanAttributeInfo attribute : metadata) + { + Object value = server.getAttribute(name, attribute.getName()); + result.put(attribute.getName(),getAdaptedValue(attribute.getType(), value)); + } + return result; + } + + private String getAdaptedValue(String type, Object value) + { + JavaToHtmlAdapter adapter = adapters.get(type); + return (adapter != null) ? adapter.toHtml(value) : String.valueOf(value); + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java new file mode 100644 index 0000000000..bafdc06633 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmRmdPerspectiveAction.java @@ -0,0 +1,113 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; +import java.net.URI; + +import javax.management.ObjectName; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.muse.core.proxy.ProxyHandler; +import org.apache.muse.core.proxy.ReflectionProxyHandler; +import org.apache.muse.util.xml.XmlUtils; +import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.muse.ws.resource.remote.WsResourceClient; +import org.apache.qpid.management.Names; +import org.w3c.dom.Element; + +public class WsdmRmdPerspectiveAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + private static final Object [] DIALECT = new Object[]{"http://docs.oasis-open.org/wsrf/rmd-1"}; + + private ProxyHandler proxyHandler; + + private URI resourceUri; + + @Override + public void init() throws ServletException + { + proxyHandler = new ReflectionProxyHandler(); + proxyHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata"); + proxyHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "GetMetadata", Names.PREFIX)); + proxyHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Dialect", Names.PREFIX)}); + proxyHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata", Names.PREFIX)); + proxyHandler.setReturnType(Element[].class); + } + + @SuppressWarnings("unchecked") + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try + { +// String resourceId = request.getParameter("resourceId"); +// ObjectName objectName = new ObjectName(resourceId); +// +// String wsresourceid = objectName.getKeyProperty(Names.OBJECT_ID); +// EndpointReference resourceEndpointReference = new EndpointReference(getURI(request)); +// resourceEndpointReference.addParameter( +// Names.RESOURCE_ID_QNAME, +// wsresourceid); +// +// WsResourceClient resourceClient = new WsResourceClient(resourceEndpointReference); +// Element rmd = ((Element[])resourceClient.invoke(proxyHandler,DIALECT))[0]; +// +// String output = XmlUtils.toString(rmd); +// +// String [] keyProperties = objectName.getKeyPropertyListString().split(","); +// +// request.setAttribute("resourceId", objectName); +// request.setAttribute("nameAttributes",keyProperties); +// request.setAttribute("rmd",output); + RequestDispatcher dispatcher = request.getRequestDispatcher("/tbd.jsp"); + dispatcher.forward(request,response); + } catch(Exception exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } + + private URI getURI(HttpServletRequest request) + { + if (resourceUri == null) + { + StringBuilder builder = new StringBuilder(); + builder + .append("http://") + .append(request.getServerName()) + .append(":") + .append(request.getServerPort()) + .append("/qman/services/QManWsResource"); + resourceUri = URI.create(builder.toString()); + } + return resourceUri; + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java new file mode 100644 index 0000000000..9b47fe95b9 --- /dev/null +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/web/action/WsdmWsdlPerspectiveAction.java @@ -0,0 +1,134 @@ +/* + * + * 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.qpid.management.web.action; + +import java.io.IOException; +import java.net.URI; + +import javax.management.ObjectName; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.muse.core.proxy.ProxyHandler; +import org.apache.muse.core.proxy.ReflectionProxyHandler; +import org.apache.muse.util.xml.XmlUtils; +import org.apache.muse.ws.addressing.EndpointReference; +import org.apache.muse.ws.resource.remote.WsResourceClient; +import org.apache.qpid.management.Names; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class WsdmWsdlPerspectiveAction extends HttpServlet +{ + private static final long serialVersionUID = -2411413147821629363L; + private static final Object [] WSDL_DIALECT = new Object[]{"http://schemas.xmlsoap.org/wsdl/"}; + + private ProxyHandler proxyHandler; + + private URI resourceUri; + + @Override + public void init() throws ServletException + { + proxyHandler = new ReflectionProxyHandler(); + proxyHandler.setAction("http://schemas.xmlsoap.org/ws/2004/09/mex/GetMetadata"); + proxyHandler.setRequestName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "GetMetadata", Names.PREFIX)); + proxyHandler.setRequestParameterNames(new QName[]{new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Dialect", Names.PREFIX)}); + proxyHandler.setResponseName(new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata", Names.PREFIX)); + proxyHandler.setReturnType(Element[].class); + } + + @SuppressWarnings("unchecked") + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + try + { + String resourceId = request.getParameter("resourceId"); + ObjectName objectName = new ObjectName(resourceId); + + String wsresourceid = objectName.getKeyProperty(Names.OBJECT_ID); + EndpointReference resourceEndpointReference = new EndpointReference(getURI(request)); + resourceEndpointReference.addParameter( + Names.RESOURCE_ID_QNAME, + wsresourceid); + + WsResourceClient resourceClient = new WsResourceClient(resourceEndpointReference); + Element wsdl = ((Element[])resourceClient.invoke(proxyHandler,WSDL_DIALECT))[0]; + + NodeList nodelist = wsdl.getChildNodes(); + Element definitions = null; + for (int i = 0; i < nodelist.getLength(); i++) + { + Node node = nodelist.item(i); + switch (node.getNodeType()) + { + case Node.ELEMENT_NODE: + { + Element element = (Element) node; + if (element.getNodeName().indexOf("definitions") != -1) + { + definitions = element; + break; + } + } + } + } + + String output = XmlUtils.toString(definitions); + + String [] keyProperties = objectName.getKeyPropertyListString().split(","); + + request.setAttribute("resourceId", resourceId); + request.setAttribute("nameAttributes",keyProperties); + request.setAttribute("wsdl",output); + RequestDispatcher dispatcher = request.getRequestDispatcher("/wsdm_wsdl_perspective.jsp"); + dispatcher.forward(request,response); + } catch(Exception exception) + { + request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below."); + request.setAttribute("exception",exception); + RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp"); + dispatcher.forward(request,response); + } + } + + private URI getURI(HttpServletRequest request) + { + if (resourceUri == null) + { + StringBuilder builder = new StringBuilder(); + builder + .append("http://") + .append(request.getServerName()) + .append(":") + .append(request.getServerPort()) + .append("/qman/services/QManWsResource"); + resourceUri = URI.create(builder.toString()); + } + return resourceUri; + } +} \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java index dfb526005f..f1e66789cf 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/capabilities/QManAdapterCapability.java @@ -163,14 +163,14 @@ public class QManAdapterCapability extends AbstractCapability EndpointReference endpointPointReference = new EndpointReference(_resourceURI); endpointPointReference.addParameter( Names.RESOURCE_ID_QNAME, - eventSourceName.getCanonicalName()); + eventSourceName.getKeyProperty(Names.OBJECT_ID)); ResourceManager resourceManager = getResource().getResourceManager(); try { Resource resource = resourceManager.getResource(endpointPointReference); resource.shutdown(); - + LOGGER.info( Messages.QMAN_000031_RESOURCE_HAS_BEEN_REMOVED, eventSourceName); diff --git a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java index 83c1209e42..eb7eee9547 100644 --- a/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java +++ b/qpid/java/management/client/src/main/java/org/apache/qpid/management/wsdm/common/ObjectNameIdFactory.java @@ -20,6 +20,7 @@ */ package org.apache.qpid.management.wsdm.common; +import javax.management.ObjectName; import javax.xml.namespace.QName; import org.apache.muse.core.routing.ResourceIdFactory; @@ -54,6 +55,7 @@ public class ObjectNameIdFactory implements ResourceIdFactory */ public String getNextIdentifier() { - return ThreadSessionManager.getInstance().getSession().getObjectName().getCanonicalName(); + ObjectName objectName = ThreadSessionManager.getInstance().getSession().getObjectName(); + return objectName.getKeyProperty(Names.OBJECT_ID); } } \ No newline at end of file diff --git a/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl b/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl index 00139b70d1..f3ad6c6012 100644 --- a/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl +++ b/qpid/java/management/client/src/main/java/wsdl/QManWsResource.wsdl @@ -536,7 +536,7 @@ - + \ No newline at end of file -- cgit v1.2.1