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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

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
        catch(Exception e)
            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();
                NodeList childNodes = specialEndpointsNode.getChildNodes();
                int childNodeSize = childNodes.getLength();
                for(int j=0; j                {
                    Node childNode = childNodes.item(j);
                        Node portNode = childNode.getAttributes().getNamedItem("port");
                        String portValueFromXML = portNode.getNodeValue();
                        getProject().setProperty(portValue, portValueFromXML);

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

Post a Comment

Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")

Popular Posts

Enter your email address:

Buffs ...


Powered by WidgetsForFree