01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.management.web.action;
22
23 import java.io.IOException;
24 import java.lang.management.ManagementFactory;
25 import java.util.List;
26 import java.util.Set;
27
28 import javax.management.MBeanServer;
29 import javax.management.MalformedObjectNameException;
30 import javax.management.ObjectName;
31 import javax.servlet.RequestDispatcher;
32 import javax.servlet.ServletException;
33 import javax.servlet.http.HttpServlet;
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
36
37 import org.apache.qpid.management.Names;
38 import org.apache.qpid.management.domain.services.ManagementClient;
39 import org.apache.qpid.management.domain.services.QMan;
40
41 /**
42 * This controller retrieves from QMan all the registered resources and organize
43 * that data in a model that is then forwarded to the appropriate view page.
44 *
45 * TODO : In the corresponding view page only one broker is displayed.
46 * A query should be made on QMan mbean in order to retrieve all connected broker and therefore
47 * a model for each of them should be created.
48 * In the corresponding weg page there should be a "tab" for each broker. Each tab should show only
49 * the objects belonging to that broker.
50 *
51 * @author Andrea Gazzarini
52 */
53 public class ResourcesManagementAction extends HttpServlet
54 {
55 private static final long serialVersionUID = -2411413147821629363L;
56
57 @SuppressWarnings("unchecked")
58 @Override
59 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
60 {
61 try
62 {
63 QMan qman = (QMan)getServletContext().getAttribute(Names.APPLICATION_NAME);
64 List<ManagementClient> managementClient = qman.getManagementClients();
65
66 if (!managementClient.isEmpty())
67 {
68 BrokerModel model = new BrokerModel();
69 model.setId(managementClient.toString());
70
71 MBeanServer mxServer = ManagementFactory.getPlatformMBeanServer();
72 Set<ObjectName> objectNames = mxServer.queryNames(new ObjectName("Q-MAN:*"), null);
73 for (ObjectName objectName : objectNames)
74 {
75 model.addObject(objectName);
76 }
77
78 request.setAttribute("model", model);
79 }
80
81 RequestDispatcher dispatcher = request.getRequestDispatcher("/resources_management.jsp");
82 dispatcher.forward(request,response);
83 } catch(MalformedObjectNameException exception)
84 {
85 request.setAttribute("errorMessage","Unable to detect the exact cause Please look at the reported stack trace below.");
86 request.setAttribute("exception",exception);
87 RequestDispatcher dispatcher = request.getRequestDispatcher("/error_page.jsp");
88 dispatcher.forward(request,response);
89 }
90 }
91 }
|