mx4j/src/examples/mx4j/examples/tools/remote/soap Client.java,NONE,1.1 Server.java,NONE,1.1

Simone Bordet <[email protected]>
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/examples/mx4j/examples/tools/remote/soap
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30759/src/examples/mx4j/examples/tools/remote/soap

Added Files:
	Client.java Server.java 
Log Message:
Example for using the SOAPConnector

--- NEW FILE: Client.java ---
/*
 * Copyright (C) MX4J.
 * 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.soap;

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 SOAPConnectorServer.
 * MX4J's implementation of the SOAP provider requires Axis 1.1, that in turn requires
 * a servlet container to run. The default servlet container used is Jetty 4.2.x.
 * To run this example, you need the following jars:
 * <ul>
 * <li>MX4J 2.x</li>
 * <ul>
 * <li>mx4j.jar</li>
 * <li>mx4j-remote.jar</li>
 * <li>mx4j-tools.jar</li>
 * <li>mx4j-examples.jar</li>
 * </ul>
 * <li>Axis 1.1</li>
 * <ul>
 * <li>axis.jar</li>
 * <li>jaxrpc.jar</li>
 * <li>commons-logging.jar</li>
 * <li>commons-discovery.jar</li>
 * <li>saaj.jar</li>
 * <li>wsdl4j.jar</li>
 * </ul>
 * </ul>
 *
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @version $Revision: 1.1 $
 */
public class Client
{
   public static void main(String[] args) throws Exception
   {
      // This JMXServiceURL works only if the SOAPConnectorServer is in-VM with
      // the SOAPConnector. If this is not the case, set the correct host name.
      JMXServiceURL address = new JMXServiceURL("soap", null, 8080, "/jmxconnector");

      // 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) MX4J.
 * 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.soap;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;

/**
 * This example shows how to setup a JSR 160 connector server that uses SOAP as
 * communication protocol with the client.
 * MX4J's implementation of the SOAP provider requires Axis 1.1, that in turn requires
 * a servlet container to run. The default servlet container used is Jetty 4.2.x.
 * Incoming connections from a client will be accepted by Jetty, handed to the
 * Axis servlet that interpretes the SOAP invocation, and passed to MX4J's
 * SOAPConnectorServer implementation, and finally routed the MBeanServer.
 * Remote notifications are delivered transparently.
 * To run this example, you need the following jars:
 * <ul>
 * <li>MX4J 2.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</li>
 * <ul>
 * <li>org.mortbay.jetty.jar</li>
 * <li>servlet.jar</li>
 * </ul>
 * <li>Axis 1.1</li>
 * <ul>
 * <li>axis.jar</li>
 * <li>jaxrpc.jar</li>
 * <li>commons-logging.jar</li>
 * <li>commons-discovery.jar</li>
 * <li>saaj.jar</li>
 * <li>wsdl4j.jar</li>
 * </ul>
 * </ul>
 *
 * @author <a href="mailto:[email protected]">Simone Bordet</a>
 * @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("soap", null, 8080, "/jmxconnector");

      // Create and start the SOAPConnectorServer
      // Jetty will listen on port 8080
      JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
      connectorServer.start();

      System.out.println("Server up and running");
   }
}



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.