cancel
Showing results for 
Search instead for 
Did you mean: 

Tech Tip: Using the SOAP Control API with Java

The following code uses Stingray's Control API to list all the running virtual servers on a cluster. The code is written in Java and uses the Stingray-API.jar library described in this article: Java Interface Library.

 

listVS.java

 

Make sure to edit the endpoint address (https://usernameSmiley Tongue[email protected]:9090/soap) so that the username, password and host match the admin interface for your Stingray.

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://usernameSmiley Tongue[email protected]: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 ){
               System.out.println( vsnames );
            }
         }
      } 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; }
      }
   }
}

 

Running the example

 

To build and run the code, you'll first need to do the following:

 

  • Download axis 1.4 from Index of /dist/ws/axis/1_4. You can unzip the axis-bin package in your working directory, or you can install the jar files permanently (e.g. in the JAVAHOME/jre/lib/ext/ directory).

 

  • Download the JavaMail library; either unzip the package in your working directory, or install the mail.jar file to the JAVAHOME/jre/lib/ext/ directory.  This package provides class implementations that, though not required, will avoid warning about missing classes

 

Compile and run the example as follows:

 

$ javac -cp Stingray-API.jar:axis-1_4/lib/* listVS.java

$ jar -cvfe listVS.jar listVS listVS*.class

$ java -cp Stingray-API.jar:axis-1_4/lib/*:javamail-1.4.7/lib/*:listVS.jar listVS

Main website

Mail servers

Test site

 

If you install the Stingray-API, Apache Axis 1.2 and JavaMail libraries in your system classpath, then you don't need to reference them explicity when you build and run this example.

 

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.

 

Read more

 

Version history
Revision #:
2 of 2
Last update:
‎01-13-2021 05:29:PM
Updated by:
 
Labels (1)
Contributors
Comments

Axis 1.4 (the latest Axis 1.x that exists) has a bug when trying to convert byte arrays to Strings.  This creeps up on certain calls such as Catalog.SSL.Certificates.getRawCertificate.  You will encounter an ArrayStoreException when you invoke it using the Java code generated by Axis if your certificates in Zeus are stored in binary.

To work around this, change the return type to byte[][].  This has to be done in the BindingStub on the setReturnClass call and on the method itself (e.g. getRawCertificates(..)). Change the return type and any relevant casts to byte[][].  Also change the return type on the Port interface class.

One can also change the types to Axis' ArrayDeserializer.ArrayListExtension or just a java.util.List and this will avoid letting Axis try to convert it. Then you can loop through the list yourself and use the values.