mx4j/src/examples/mx4j/examples/tools/remote/hessian/ssl Client.java,NONE,1.1 Server.java,NONE,1.1
Simone Bordet <[email protected]> Mon, 21 Feb 2005 11:32:07 +0000
| Newsgroups | gmane.comp.java.mx4j.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/mx4j/mx4j/src/examples/mx4j/examples/tools/remote/hessian/ssl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11065/src/examples/mx4j/examples/tools/remote/hessian/ssl
Added Files:
Client.java Server.java
Log Message:
Examples on how to run the Hessian connector over HTTPS
--- NEW FILE: Client.java ---
/*
* Copyright (C) The MX4J Contributors.
* All rights reserved.
*
* This software is distributed under the terms of the MX4J License version 1.0.
* See the terms of the MX4J License in the documentation provided with this software.
*/
package mx4j.examples.tools.remote.hessian.ssl;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerDelegateMBean;
import javax.management.MBeanServerInvocationHandler;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.management.timer.Timer;
/**
* This example shows how to connect to a Hessian JMXConnectorServer over HTTPS.
* To run this example, you need the following jars:
* <ul>
* <li>MX4J 3.x</li>
* <ul>
* <li>mx4j.jar</li>
* <li>mx4j-remote.jar</li>
* <li>mx4j-tools.jar</li>
* <li>mx4j-examples.jar</li>
* </ul>
* <li>Hessian 3.0.8</li>
* <ul>
* <li>hessian-3.0.8.jar</li>
* </ul>
* </ul>
*
* @version $Revision: 1.1 $
*/
public class Client
{
public static void main(String[] args) throws Exception
{
// Replace the value with the file path of your keystore.
// IMPORTANT: this should NOT be done in production environments, it is shown here just as an example.
System.setProperty("javax.net.ssl.trustStore", "<your-keystore>");
// This JMXServiceURL works only if the connector server is on the same host of
// the connector. If this is not the case, set the correct host name.
JMXServiceURL address = new JMXServiceURL("hessian+ssl", null, 8443, "/hessianssl");
// Connect a JSR 160 JMXConnector to the server side
JMXConnector connector = JMXConnectorFactory.connect(address);
// Retrieve an MBeanServerConnection that represent the MBeanServer
// the remote connector server is bound to
MBeanServerConnection connection = connector.getMBeanServerConnection();
// Call the server side as if it is a local MBeanServer
ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
Object proxy = MBeanServerInvocationHandler.newProxyInstance(connection, delegateName, MBeanServerDelegateMBean.class, true);
MBeanServerDelegateMBean delegate = (MBeanServerDelegateMBean)proxy;
System.out.println(delegate.getImplementationVendor() + " is cool !");
// Register an MBean, and get notifications via the SOAP protocol
connection.addNotificationListener(delegateName, new NotificationListener()
{
public void handleNotification(Notification notification, Object handback)
{
System.out.println("Got the following notification: " + notification);
}
}, null, null);
ObjectName timerName = ObjectName.getInstance("services:type=Timer");
connection.createMBean(Timer.class.getName(), timerName, null);
// Unregistering the MBean to get another notification
connection.unregisterMBean(timerName);
// Allow the unregistration notification to arrive before killing this JVM
Thread.sleep(1000);
connector.close();
}
}
--- NEW FILE: Server.java ---
/*
* Copyright (C) The MX4J Contributors.
* All rights reserved.
*
* This software is distributed under the terms of the MX4J License version 1.0.
* See the terms of the MX4J License in the documentation provided with this software.
*/
package mx4j.examples.tools.remote.hessian.ssl;
import java.util.HashMap;
import java.util.Map;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import mx4j.tools.remote.http.HTTPConnectorServer;
/**
* This example shows how to setup a JSR 160 connector server that uses Caucho's Hessian
* protocol over HTTPS as communication protocol with the client.
* <br />
* MX4J's implementation requires the hessian library version 3.0.8 and
* a servlet container to run. The default servlet container used is Jetty.
* To run this example, you need the following jars:
* <ul>
* <li>MX4J 3.x</li>
* <ul>
* <li>mx4j.jar</li>
* <li>mx4j-remote.jar</li>
* <li>mx4j-tools.jar</li>
* <li>mx4j-examples.jar</li>
* </ul>
* <li>Jetty 4.2.x or later</li>
* <ul>
* <li>org.mortbay.jetty.jar</li>
* <li>servlet.jar</li>
* <li>commons-logging.jar</li>
* </ul>
* <li>Hessian 3.0.8</li>
* <ul>
* <li>hessian-3.0.8.jar</li>
* </ul>
* </ul>
* Furthermore, you need a Jetty configuration file and a keystore
* (see the MX4J documentation on how to create these 2 files).
*
* @version : $Revision: 1.1 $
*/
public class Server
{
public static void main(String[] args) throws Exception
{
// The MBeanServer
MBeanServer server = MBeanServerFactory.createMBeanServer();
// Pass null as the host name to tell JMXServiceURL to default to InetAddress.getLocalHost().getHostName()
JMXServiceURL url = new JMXServiceURL("hessian+ssl", null, 8443, "/hessianssl");
// Replace the value of the configuration with the file path of the configuration file
Map serverEnv = new HashMap();
serverEnv.put(HTTPConnectorServer.WEB_CONTAINER_CONFIGURATION, "<your-web-container-configuration>");
JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, serverEnv, server);
connectorServer.start();
System.out.println("Server up and running " + connectorServer + " on " + url);
}
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click