Any ADSI-compliant client language can access the ADSI interfaces provided by the IIS Admin Objects, including Visual C++ and VBScript. However, a powerful new feature provided by the Java 2.0 SDK, called J/Direct, adds Java to the list of ADSI-capable languages.
J/Direct is a set of language constructs that are built directly into the Win32 VM for Java that ships with Java 2.0. These new constructs allow Java developers to access any Win32 API from within their Java application – including the ADSI set of functions that are necessary to access the IIS Admin Objects.
This sample demonstrates how to construct a Java class component that can be used to access the IIS metabase through the IIS Admin Objects. The main component class, ServerAdmin, implements methods that allow the component user to start, stop, and check the status of the default FTP server on the local IIS installation, with the ADsPath of IIS://LocalHost/msftpsvc/1. Each of three methods that Server Admin implements – startFtp, stopFtp, and getStatus – use the getObject method provided in the JDirectADSI class, contained in the activeds package.
JDirectADSI accomplishes two tasks. First, it uses J/Direct’s new @dll.import directive to gain access to the DLL, activeds.dll, and one of the methods that that DLL exposes, ADsGetObject. Note that the usage of @dll.import is in many ways similar to the function and feel of Visual Basic’s DECLARE statement.
J/Direct makes it easier to call Win32 API functions, but the JDirectADSI class goes one step further by wrapping the now-exposed ADsGetObject method in the easier-to-use, more Java-like getObject method used by the ServerAdmin methods.
Note Despite this wrapping, however, note that the caller methods, such as startFtp, must cast the return from the getObject call as IADsServiceOperations. As an alternative to this requirement, you could create separate wrappers for distinct, oft-requested types, and have the wrapper explicitly return a value (a pointer) of the appropriate type.
This project is available in the ...\components\java\Samples subdirectory of the IIS samples directory.