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: * @(#)TestComponentConfiguration.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package java4ant;
030:
031: import java.util.Map;
032: import java.util.Set;
033: import javax.management.remote.*;
034: import javax.management.*;
035: import javax.management.openmbean.*;
036:
037: /**
038: */
039: public class TestApplicationConfigurationSupport {
040:
041: private MBeanServerConnection mbns;
042: private static final String RESULT_PREFIX = "##### Result of ";
043:
044: private static final String USER = "jmx.user";
045: private static final String PASSWORD = "jmx.password";
046: private static final String PROVIDER = "jmx.provider";
047: private static final String TARGET = "target";
048: private static final String COMPONENT_NAME = "component.name";
049:
050: public TestApplicationConfigurationSupport() {
051: try {
052: initMBeanServerConnection();
053: } catch (Exception ex) {
054: System.out.println(ex.getMessage());
055: }
056: }
057:
058: public void initMBeanServerConnection() throws Exception {
059: java.util.Map<String, String[]> env = new java.util.HashMap();
060: String user = System.getProperty(USER);
061: String pass = System.getProperty(PASSWORD);
062: String[] credentials = new String[] { user, pass };
063: env.put("jmx.remote.credentials", credentials);
064:
065: String jmxProvider = System.getProperty(PROVIDER);
066:
067: JMXConnector connector = JMXConnectorFactory.connect(
068: new JMXServiceURL(jmxProvider), env);
069:
070: mbns = connector.getMBeanServerConnection();
071: }
072:
073: public ObjectName getComponentConfigurationName() throws Exception {
074: String info = "com.sun.jbi:Target="
075: + System.getProperty(TARGET, "domain")
076: + ",ComponentName="
077: + System.getProperty(COMPONENT_NAME)
078: + ",ServiceType=Configuration";
079: return new ObjectName(info);
080: }
081:
082: /**
083: *
084: */
085: public void isAppVarsSupported() throws Exception {
086: Boolean result = (Boolean) mbns.invoke(
087: getComponentConfigurationName(), "isAppVarsSupported",
088: new Object[] {}, new String[] {});
089:
090: System.out.println(RESULT_PREFIX + " isAppVarsSupported = "
091: + result);
092: }
093:
094: /**
095: *
096: */
097: public void isAppConfigSupported() throws Exception {
098: Boolean result = (Boolean) mbns.invoke(
099: getComponentConfigurationName(),
100: "isAppConfigSupported", new Object[] {},
101: new String[] {});
102:
103: System.out.println(RESULT_PREFIX + " isAppConfigSupported = "
104: + result);
105: }
106:
107: /**
108: * Get actual cause
109: */
110: public Throwable getActualCause(Throwable ex) {
111: Throwable cause = ex;
112:
113: do {
114: if (cause == null) {
115: break;
116: }
117: cause = cause.getCause();
118: } while (cause instanceof javax.management.JMException);
119: return cause;
120: }
121:
122: public void printCause(String opName, Throwable ex) {
123: Throwable cause = getActualCause(ex);
124: if (cause != null) {
125: String result = cause.getMessage();
126: result = result.replace("en_US", "en");
127: System.out.println(RESULT_PREFIX + " isAppVarsSupported = "
128: + "Exception : " + result);
129: }
130: }
131:
132: public static void main(String[] params) throws Exception {
133: TestApplicationConfigurationSupport test = new TestApplicationConfigurationSupport();
134: try {
135: test.isAppVarsSupported();
136: } catch (Throwable ex) {
137: test.printCause("isAppVarsSupported", ex);
138: }
139: try {
140: test.isAppConfigSupported();
141: } catch (Exception ex) {
142: test.printCause("isAppConfigSupported", ex);
143: }
144: }
145: }
|