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.servlet;
22
23 import java.util.UUID;
24 import java.util.Map.Entry;
25
26 import javax.servlet.ServletException;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.apache.muse.core.platform.mini.MiniServlet;
31 import org.apache.qpid.management.Messages;
32 import org.apache.qpid.management.Names;
33 import org.apache.qpid.management.configuration.BrokerConnectionData;
34 import org.apache.qpid.management.configuration.Configuration;
35 import org.apache.qpid.management.domain.services.QMan;
36 import org.apache.qpid.transport.util.Logger;
37
38 /**
39 * When QMan is started and a configuration file is given
40 * (via system property) with initial broker connection data(s),
41 * this servlet simply sends connect command(s) to QMan in order
42 * to estabilish the connection(s) to the requested broker(s).
43 *
44 * @author Andrea Gazzarini
45 */
46 public class ConnectQManToBroker extends MiniServlet
47 {
48 private static final long serialVersionUID = 6149614872902682208L;
49 private final static Logger LOGGER = Logger.get(ConnectQManToBroker.class);
50
51 /**
52 * Send one or more initial "connect" command(s) to QMan in order
53 * to estabilish a connection with broker found on the configuration file..
54 * Note that this is done only if that configuration file is given (via system
55 * property) and it is valid.
56 */
57 public void init()
58 {
59 Configuration configuration = Configuration.getInstance();
60 if (configuration.hasOneOrMoreBrokersDefined())
61 {
62 QMan qman = (QMan)getServletContext().getAttribute(Names.APPLICATION_NAME);
63
64 LOGGER.info(Messages.QMAN_000003_CREATING_MANAGEMENT_CLIENTS);
65 for (Entry<UUID, BrokerConnectionData> entry : Configuration.getInstance().getConnectionInfos())
66 {
67 qman.createManagementClient(entry.getKey(), entry.getValue());
68 }
69 } else
70 {
71 LOGGER.info(Messages.QMAN_000022_NO_BROKER_CONFIGURED);
72 }
73 }
74
75 /**
76 * This is a startup module only so an override of the default servlet
77 * behaviour must be done in order to prevent incoming http
78 * requests processing.
79 *
80 * @param request the http request.
81 * @param response the http response.
82 * @throws ServletException each time this method is called.
83 */
84 @Override
85 public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException
86 {
87 throw new ServletException();
88 }
89 }
|