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://username:
[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://username:
[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
Collected Tech Tips: SOAP Control API examples