KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jmx > access > RemoteMBeanClientInterceptorTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16
17 package org.springframework.jmx.access;
18
19 import java.net.MalformedURLException JavaDoc;
20
21 import javax.management.MBeanServerConnection JavaDoc;
22 import javax.management.remote.JMXConnector JavaDoc;
23 import javax.management.remote.JMXConnectorFactory JavaDoc;
24 import javax.management.remote.JMXConnectorServer JavaDoc;
25 import javax.management.remote.JMXConnectorServerFactory JavaDoc;
26 import javax.management.remote.JMXServiceURL JavaDoc;
27
28 import org.springframework.core.JdkVersion;
29
30 /**
31  * @author Rob Harrop
32  */

33 public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTests {
34
35     private static final String JavaDoc SERVICE_URL = "service:jmx:jmxmp://localhost:9876";
36
37     private JMXConnectorServer JavaDoc connectorServer;
38
39     private JMXConnector JavaDoc connector;
40
41     public void setUp() throws Exception JavaDoc {
42         super.setUp();
43         this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, server);
44         this.connectorServer.start();
45     }
46
47     private JMXServiceURL JavaDoc getServiceUrl() throws MalformedURLException JavaDoc {
48         return new JMXServiceURL JavaDoc(SERVICE_URL);
49     }
50
51     protected MBeanServerConnection JavaDoc getServerConnection() throws Exception JavaDoc {
52         if (JdkVersion.getMajorJavaVersion() < JdkVersion.JAVA_14) {
53             // to avoid NoClassDefFoundError for JSSE
54
return super.getServerConnection();
55         }
56         
57         this.connector = JMXConnectorFactory.connect(getServiceUrl());
58         return this.connector.getMBeanServerConnection();
59     }
60
61     public void tearDown() throws Exception JavaDoc {
62         if (this.connector != null) {
63             this.connector.close();
64         }
65         this.connectorServer.stop();
66         super.tearDown();
67     }
68
69 }
70
Popular Tags