List running Virtual Servers using Java

The following code uses ZXTM's Control API to list all the running virtual servers on a cluster. The code is written in Java.


listVS.java

import com.zeus.soap.zxtm._1_0.*;
import java.security.Security;
import java.security.KeyStore;
import java.security.Provider;
import java.security.cert.X509Certificate;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactorySpi;
import javax.net.ssl.X509TrustManager;

public class listVS {

   public static void main( String[] args ) {

      // Install the all-trusting trust manager
      Security.addProvider( new MyProvider() );
      Security.setProperty( "ssl.TrustManagerFactory.algorithm", "TrustAllCertificates");

      try {
         VirtualServerLocator vsl = new VirtualServerLocator();
         vsl.setVirtualServerPortEndpointAddress(
            "https://username:password@host:9090/soap" );
         VirtualServerPort vsp = vsl.getVirtualServerPort();

         String[] vsnames = vsp.getVirtualServerNames();
         boolean[] vsenabled = vsp.getEnabled( vsnames );

         for( int i = 0; i < vsnames.length; i++ ){
            if( vsenabled[i] ){
               System.out.println( vsnames[i] );
            }
         }
      } catch (Exception e) {
         System.out.println( e.toString() );
      }
   }

   /* The following code disables certificate checking.
   * Use the Security.addProvider and Security.setProperty
   * calls to enable it */
   public static class MyProvider extends Provider {

      public MyProvider() {
         super( "MyProvider", 1.0, "Trust certificates" );
         put( "TrustManagerFactory.TrustAllCertificates", MyTrustManagerFactory.class.getName() );
      }

      protected static class MyTrustManagerFactory extends TrustManagerFactorySpi {
         public MyTrustManagerFactory() {}
         protected void engineInit( KeyStore keystore ) {}
         protected void engineInit(
            ManagerFactoryParameters mgrparams ) {}
         protected TrustManager[] engineGetTrustManagers() {
            return new TrustManager[] { new MyX509TrustManager() };
         }
      }

      protected static class MyX509TrustManager implements X509TrustManager {
         public void checkClientTrusted( X509Certificate[] chain, String authType) {}
         public void checkServerTrusted( X509Certificate[] chain, String authType) {}
         public X509Certificate[] getAcceptedIssuers() { return null; }
      }
   }
}

Notes

The bulk of this code disables client certificate checking. Details of the code and surrounding infrastructure are at
http://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html.

Running the example

This code works with the Java 1.5 SDK/JRE. To build and run the code, you'll need to do the following:

  1. Download axis from http://ws.apache.org/axis/. This provides the WSDL-to-Java converter.

    Copy all the .jar files from axis-version/libs/ to the JAVAHOME/jre/lib/ext/ directory, or add them to your CLASSPATH.

  2. Install the Java Activation Framework and JavaMail libraries to avoid
    warnings when the code is run:

    Copy the activation.jar and mail.jar files contained in these packages to the JAVAHOME/jre/lib/ext/ directory, or add them to your CLASSPATH.

  3. In your build directory, convert the required WSDL files into java code as follows:

    $ java org.apache.axis.wsdl.WSDL2Java VirtualServer.wsdl
    
  4. Compile and run the example as follows:

    $ javac listVS.java
    $ java listVS
    Main website
    Mail servers
    Test site
    
Owen Garrett [Zeus Dev Team] 20 October 2005  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com