How to get Websphere profile port related information ? using java and ANT

How to get Websphere profile port related information ?

There are actually two ways of getting the port related information used by a Websphere profile.

The first and foremost is to read through AboutThisProfile.txt from /logs .

Second one is to understand the serverindex.xml file inside the profile path . 

Sample Path / Location for this file is : C:\Program Files (x86)\IBM\WebSphere\AppServer\profiles\AppSrv01\config\cells\nc9118041010Node01Cell\nodes\nc9118041010Node01\serverindex.xml

Java Class which get this ports info is shown below ... using XML DOM parser code is written. 
Using Java to read serverindex.xml file to get WAS ports information

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 * This class is used to collect different port information for a profile.
 * For example this class have been used in Ant xml file "config/install/abc/abc_config.xml".
 *
 *
 */

public class GetWASProfilePortInfo extends Task
{
    private String profilePath = null;
    private String endpointName = null;
    private String portValue = null;  
  
    public void setProfilePath(String profilePath)
    {
        this.profilePath = profilePath;
    }
  
    public void setEndpointName(String endpointName)
    {
        this.endpointName = endpointName;
    }
  
    public void setPortValue(String portValue)
    {
        if(portValue != "")
        {
            this.portValue = portValue;
        }
    }
  
    public void execute() throws BuildException
    {
        try
        {
            collectPortInfo();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            throw new BuildException(e);
        }
    }
  
    private void collectPortInfo() throws ParserConfigurationException, SAXException, IOException
    {
        ExistingWASProfileInfo profile = new ExistingWASProfileInfo(profilePath);
        String cellName = profile.getCellName();
        String nodeName = profile.getNodeName();
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        char fs = File.separatorChar;
        File serverIndexXML = new File(profilePath + fs + "config" + fs + "cells" + fs + cellName + fs + "nodes" + fs + nodeName + fs + "serverindex.xml");
        Document doc = docBuilder.parse(serverIndexXML);
        Element docElement = doc.getDocumentElement();
        NodeList list = docElement.getElementsByTagName("specialEndpoints");
        int size = list.getLength();
        for(int i=0; i        {
            Node specialEndpointsNode = list.item(i);
            Node endpointNode = specialEndpointsNode.getAttributes().getNamedItem("endPointName");
            String endPointNameFromXML = endpointNode.getNodeValue();
            if(this.endpointName.equals(endPointNameFromXML))
            {
                NodeList childNodes = specialEndpointsNode.getChildNodes();
                int childNodeSize = childNodes.getLength();
                for(int j=0; j                {
                    Node childNode = childNodes.item(j);
                    if(childNode.getNodeName().equals("endPoint"))
                    {
                        Node portNode = childNode.getAttributes().getNamedItem("port");
                        String portValueFromXML = portNode.getNodeValue();
                        getProject().setProperty(portValue, portValueFromXML);
                    }                  
                }
            }
        }
    }
}

Read more

Popular Posts

Enter your email address:

Buffs ...

Tags


Powered by WidgetsForFree