XML's role in WebSphere Application Server
IBM WebSphere Application Server provides XML document structure services with a document parser, document validator, and document generator for server-side XML processing. When you install WebSphere Application Server, the core XML APIs are automatically added to the appropriate class path, letting you serve static XML documents as soon as the product is installed. To serve dynamically-generated XML documents, use the core APIs to develop servlets or Web applications that generate XML documents. For example, the applications might read the document content from a database. Then deploy those components on your application server.
WebSphere Application Server supports the following XML/XSL APIs:
- XML4J Version 3.1 or Xerces Version 1.2.1
- LotusXSL Version 2.0 or Xalan Version 2.0.1
The components of XML for Java provide support for parsing, validating, and generating XML data. The processor implements the base XML, namespace, and DOM W3C recommendations and SAX de facto standard.
WebSphere Application Server supports XML and allows you to configure its resources using XML documents. WebSphere Application Server understands all the XML documents that conform to WebSphere Application Server Configuration Markup Language Syntax. This concept is known as XML Config. XML Config can be a complete replacement for the administrator console of WebSphere Application Server.
One of the strengths of WebSphere Application Server is its flexibility. You can use a simple XML file to configure an instance of the server. XML Config is one of the most powerful administration applications available for WebSphere Application Server because:
- It has full administrative function
- It has a command line interface
- It lets you save configuration changes and apply them later
- It's possible to write applications related to high-level administration and configuration with any desired functions
- You can create a good Web-based interface using the XML Config API provided with WebSphere
- You can use write custom Web-based administration applications to give you flexible remote configuration.
You can use XML Config for many different types of tasks, such as:
- Configuring an instance of WebSphere Application Server with the help of an XML file.
- Easing migration; it is very handy, when you want to configure a server the same way as another server, just to import the XML file to the second server. (For example, you deleted a server and need to configure one similarly to the deleted one with little or no changes.)
- Fine-tuning the application server by just importing an XML file with parameters and their values specified.
- For complicated and sophisticated administration tasks such as cloning.
- Using WebSphere Commerce Suite (WCS) V5.1. For example, you can create an instance of WCS using XML Config.
- Creating customizable Web-based administration applications.
You can use XML Config to import and export configuration data to and from the WebSphere Application Server administration repository. This XML-based approach complements the administration you can do through the WebSphere administrative console. You can use the command line to make multiple changes to the WebSphere Application Server administration repository at one time without going through the repetitive routines on the administration console. You can also use this tool to extract the repository information from a server and import it onto a cloned server.
The XML Config tool provides three fundamental features:
- Full export
- Generates an XML document describing the configuration of the entire administrative domain. In effect, the full export takes a "snapshot" of the administrative repository contents.
- Partial export
- Provides an XML document specifying administrative objects to export from the administrative domain. The objects and their children are exported to an XML document that you specify.
- Import
- Imports a newly created XML document or a document you previously exported and modified. In the XML document, you can add, modify, or remove administrative objects such as servlets and virtual hosts. Your XML document can replace the administrative repository contents partially or entirely.
xmlconfig {( -import <xml date file>) ||
[ ( -export <xml output file> [ -partial <xml data file>] ) }
- adminNodeName <primary node name>
[- nameServiceHost <hostname> [- nodeServicePort <port number>] ]
[- substitute <"key1=value1[;key2=value2[;..]]"> ]
|
The above command line utility has full administrative functions, but it's not possible to do remote configuration. However, the following approach extends the usability of XML Config even over the Internet.
Writing an XML Config application
The xmlconfig.dtd file has XML specifications for XML Config. This file is also used for error and syntax checking of imported XML files.
a) system.root=WAS_HOME (example 'C:/WebSphere/WAServer') b) XMLConfigDTDLocation=XMLConfigDTD_File_Location (example 'C:/WebSphere/WAServer/bin') |
DOCTYPE websphere-sa-config SYSTEM C:/WebSphere/WAServer/bin/xmlconfig.dtd |
In the case of the command line utility, in XMLConfig.sh/.bat the first parameter passed to the Java application is server.root. The DTD file location for WASCML is set through the above-mentioned statement. You can also set the location in your program by using the following statements.
if(System.getProperty("server.root") == null){
try{
System.getProperties().put("server.root","C:/WEBSPH~1/WAServer");
}
catch(Exception e){
System.out.println("Exception to set server.root" + e);
}
}
if(System.getProperty("XMLConfigDTDLocation") == null){
try{
System.getProperties().put("XMLConfigDTDLocation",
"C:/WEBSPH~1/WAServer/bin");
}
catch(Exception e){
System.out.println("Exception to set XMLConfigDTDLocation" + e);
}
}
|
You need to import the following classes from the package com.ibm.websphere.xmlconfig. (This is the same API that's used in the command line utility, provided in the WAS_HOME/bin directory.)
import com.ibm.websphere.xmlconfig.*;import com.ibm.xml.parser.*;import org.w3c.dom.*;
Now instantiate an object of an XML Config class as follows. There are three different constructors available for the class com.ibm.websphere.xmlconfig XMLConfig.
- public XMLConfig(java.lang.String adminNodeName, boolean _advanced) throws javax.naming.NamingException
- public XMLConfig(java.lang.String adminNodeName, boolean _advanced, java.lang.String nameServiceHost, int nameServicePort) throws javax.naming.NamingException
- public XMLConfig(java.util.Hashtable args) throws InvalidArgumentException, javax.naming.NamingException
Set parameter _advanced to true if you are using WebSphere Application Server Advanced Edition, or to false if not.
Below is an example of the third constructor.
Hashtable arg = new Hashtable();
arg.put("-adminNodeName","mahi");
XMLConfig wasObj = new XMLConfig(arg);
String xmlFile = "export.xml"; // File to hold XML returned by
// XMLConfigFile
// Create a file to hold the XML configuration
File xmlConfig = new File(xmlFile);
FileWriter xmlExport = new FileWriter(xmlConfig);
|
You must get the output from the repository as a DOM object and then convert the object into an XML file. The following statements get the output from the repository as a DOM object:
TXDocument wasxml = null;wasxml = was.executeFullExport();
The following statement converts the DOM object output into XML format and puts it in the file mentioned previously:
wasxml.printWithFormat(xmlExport);
The XML Config API gives you the flexibility to easily develop complicated administration and configuration applications. Configuration situations are not always simple. Imagine there is more than one development team working on a single box that has WebSphere Application Server with multiple instances, or sharing a WebSphere Application Server environment. Applications using XML Config can keep developers away from places where they shouldn't wander. Now it's not required for development teams to log on to the server or use the WebSphere Application Server console. The WebSphere Application Server administrator console can be invoked remotely, but it has no security to restrict the resources you can administer. Using the utilities described in this article gives developers a simple Web interface to do everything they need to without accessing the server or the adminstrator console remotely.
XML Config API applications are also useful to write automated migration processes that let developers deploy to production systems. You can use XML Config in complicated situations like cloning for configuration purposes. XML Config programming applications could be extremely useful for ISPs who are into shared Web hosting on WebSphere Application Server.
- Participate in the discussion forum.
- Get the sample code.
- Access the documentation for the IBM Java packages and APIs delivered with WebSphere.
- Get more information about XML Config in the IBM WebSphere Application Server InfoCenter.
- Read Chapter 21 of the WebSphere Application Server Version 3.5 handbook.
Maheshwar is a computer engineer currently working as a WebSphere Consultant in iS3C. He is experienced in 3-tier WCS configuration with Network Dispatcher on AIX, and has worked on MCIS 2.5 systems. Maheshwar is now fascinated by Web services in WebSphere. You can contact him at maheshwarr@is3c.com.
