001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)EventManagementServlet.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029:
030: package deploytest;
031:
032: import java.io.IOException;
033: import java.io.PrintWriter;
034: import java.util.List;
035: import java.util.Map;
036: import java.util.logging.Level;
037: import java.util.logging.Logger;
038:
039: import javax.management.InstanceAlreadyExistsException;
040: import javax.management.InstanceNotFoundException;
041: import javax.management.MBeanRegistrationException;
042: import javax.management.MBeanServer;
043: import javax.management.MBeanServerFactory;
044: import javax.management.MalformedObjectNameException;
045: import javax.management.NotCompliantMBeanException;
046: import javax.management.ObjectName;
047: import javax.management.openmbean.CompositeData;
048: import javax.servlet.ServletException;
049: import javax.servlet.http.HttpServlet;
050: import javax.servlet.http.HttpServletRequest;
051: import javax.servlet.http.HttpServletResponse;
052:
053: public final class TestEventManagementServlet extends HttpServlet {
054:
055: private static final String EVENTMANAGEMENT_CHANNEL_MBEAN_NAME = "EventManagement:name=EventManagementChannelSupportMBean";
056: private static final Logger mLogger;
057: private static boolean isDebugEnabled;
058: static {
059: mLogger = Logger.getLogger(TestEventManagementServlet.class
060: .getName());
061: isDebugEnabled = mLogger.isLoggable(Level.FINEST);
062:
063: }
064: private TestEventManagementSupport mEventManagementSupportMBean;
065: private MBeanServer mMBeanServer;
066:
067: public TestEventManagementServlet() {
068: }
069:
070: public void init() {
071: // init the Support mbean here
072:
073: try {
074: mEventManagementSupportMBean = new TestEventManagementSupport();
075: ObjectName eventManagementSupportObjectName = new ObjectName(
076: EVENTMANAGEMENT_CHANNEL_MBEAN_NAME);
077: // get default MBeanserver
078: List<MBeanServer> mbeanServers = MBeanServerFactory
079: .findMBeanServer(null);
080: // assuming that target application server alway has @ least 1 mbeanserver
081: MBeanServer lMBeanServer = mbeanServers.get(0);
082: if (lMBeanServer
083: .isRegistered(eventManagementSupportObjectName)) {
084: lMBeanServer
085: .unregisterMBean(eventManagementSupportObjectName);
086: }
087: lMBeanServer.registerMBean(mEventManagementSupportMBean,
088: eventManagementSupportObjectName);
089: } catch (MalformedObjectNameException e) {
090: // TODO Auto-generated catch block
091: e.printStackTrace();
092: } catch (InstanceAlreadyExistsException e) {
093: // TODO Auto-generated catch block
094: e.printStackTrace();
095: } catch (MBeanRegistrationException e) {
096: // TODO Auto-generated catch block
097: e.printStackTrace();
098: } catch (NotCompliantMBeanException e) {
099: // TODO Auto-generated catch block
100: e.printStackTrace();
101: } catch (NullPointerException e) {
102: // TODO Auto-generated catch block
103: e.printStackTrace();
104: } catch (Exception e) {
105: // TODO Auto-generated catch block
106: e.printStackTrace();
107: }
108: }
109:
110: public void destroy() {
111: try {
112: ObjectName eventManagementSupportObjectName = new ObjectName(
113: EVENTMANAGEMENT_CHANNEL_MBEAN_NAME);
114: List<MBeanServer> mbeanServers = MBeanServerFactory
115: .findMBeanServer(null);
116: // assuming that target application server alway has @ least 1 mbeanserver
117: MBeanServer lMBeanServer = mbeanServers.get(0);
118: if (lMBeanServer
119: .isRegistered(eventManagementSupportObjectName)) {
120: lMBeanServer
121: .unregisterMBean(eventManagementSupportObjectName);
122: }
123: } catch (MalformedObjectNameException e) {
124: // TODO Auto-generated catch block
125: e.printStackTrace();
126: } catch (InstanceNotFoundException e) {
127: // TODO Auto-generated catch block
128: e.printStackTrace();
129: } catch (MBeanRegistrationException e) {
130: // TODO Auto-generated catch block
131: e.printStackTrace();
132: } catch (NullPointerException e) {
133: // TODO Auto-generated catch block
134: e.printStackTrace();
135: }
136:
137: }
138:
139: public void doGet(HttpServletRequest request,
140: HttpServletResponse response) throws IOException {
141:
142: }
143:
144: }
|