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);
}
}
}
}
}
}
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);
}
}
}
}
}
}
File operations in Java Read file, write into file, Append file
File operations involved majorly are reading it , writing into a file and appending it.
Reading from a File :
try {
BufferedReader in = new BufferedReader(new FileReader("infilename"));
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
} catch (IOException e) {
}
BufferedReader in = new BufferedReader(new FileReader("infilename"));
String str;
while ((str = in.readLine()) != null) {
process(str);
}
in.close();
} catch (IOException e) {
}
Writing into a File :
try {
BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
out.write("aString");
out.close();
} catch (IOException e) {
}
Appending to a File :
try {
BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
out.write("aString");
out.close();
} catch (IOException e) {
}
Thursday, August 02, 2012
//
Labels:
Java
//
2
comments
//
Running batch scripts through java and wait for it to complete which internally calls java processes.
The below example show how can we wait for the script to complete running.
public static void main(String[] args) throws InterruptedException,
IOException {
System.out.println("Starting ");
Runtime runtime = Runtime.getRuntime();
String[] command = { "cmd.exe", "/C", "start /WAIT",
"C:\\Users\\IBM_ADMIN\\Desktop\\BVT31\\BVT31\\xFAST.bat",
"--cf", "IE_Configurations.properties", "--tc",
"scripts\\testCases" };
Process p = runtime
.exec(command, null, new File(tipBVTScriptsPath));
p.waitFor();
System.out.println(p.exitValue());
}
String[] command = { "cmd.exe", "/C", "start /WAIT",....
Start /WAIT is the main thing to be understood here which will wait for the launched batch script in the separate window to get completed.
Once all the actions in the batch are completed the window remains open.
Hence the main important point here is to have "exit" statement as the last statement in the batch script which runs as process.
The below example show how can we wait for the script to complete running.
public static void main(String[] args) throws InterruptedException,
IOException {
System.out.println("Starting ");
Runtime runtime = Runtime.getRuntime();
String[] command = { "cmd.exe", "/C", "start /WAIT",
"C:\\Users\\IBM_ADMIN\\Desktop\\BVT31\\BVT31\\xFAST.bat",
"--cf", "IE_Configurations.properties", "--tc",
"scripts\\testCases" };
Process p = runtime
.exec(command, null, new File(tipBVTScriptsPath));
p.waitFor();
System.out.println(p.exitValue());
}
Start /WAIT is the main thing to be understood here which will wait for the launched batch script in the separate window to get completed.
Once all the actions in the batch are completed the window remains open.
Hence the main important point here is to have "exit" statement as the last statement in the batch script which runs as process.
//
Labels:
Java
//
0
comments
//
Running batch script using JAVA and storing output in a log file.
Batch script to be run will take input parameters / arguments.The below simple Java code will help to run a batch file (bat script) and store the output of batch run in to a file. The batch script to be run from the java takes few parameters as inputs.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
public class ApplicabilityCheck {
public static void main(String[] args) {
try {
System.out.println("ESS BVT");
String cfgprefix = "server1";
InetAddress hostname = InetAddress.getLocalHost();
String host = hostname.getCanonicalHostName();
String httpsPort = "16311";
String truststorepassword = "krishna";
String basicauthuser = "krishna";
String basicauthpassword = "krishna";
String essCleintPath = "C:\\Krish\\My Docs\\Foundation services install\\ESS - 15183\\ESSAuthnClientApp\\MyApp\\bin";
String essOutputDir = "C:\\Krish\\My Docs\\Foundation services install\\ESS - 15183\\ESSAuthnClientApp";
String passString = "succeeded";
File tokenOutFile = new File("ESS_Token_Out");
File essOutputFile = new File(essOutputDir + "\\ESS_OUTPUT.log");
File iosdpTrustStoreFile = new File(essCleintPath + "\\16311.jks");
File runExampleFile = new File(essCleintPath+ "\\runExampleApp.bat");
if (iosdpTrustStoreFile.exists() && runExampleFile.exists()) {
System.out.println("File:- "
+ iosdpTrustStoreFile.getAbsolutePath() + " Exists");
String setupExampleString = "setupExampleApp.bat -cfgprefix "
+ cfgprefix + " -host " + host + " -port " + httpsPort
+ " -protocol https -truststorelocation \""
+ iosdpTrustStoreFile.getAbsolutePath()
+ "\" -truststorepassword " + truststorepassword
+ " -basicauthuser " + basicauthuser
+ " -basicauthpassword " + basicauthpassword;
System.out.println(setupExampleString);
String runExampleAppString = "\""
+ runExampleFile.getAbsolutePath() + "\" " + cfgprefix
+ " -tokenOutFile " + tokenOutFile.getName() + " -uname "
+ basicauthuser + " -pword " + basicauthpassword;
System.out.println(runExampleAppString);
/* Now running the Run Example */
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(runExampleAppString, null, new File(essCleintPath));
String line;
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedWriter w = new BufferedWriter(new FileWriter(essOutputFile));
while ((line = r.readLine()) != null) {
if(line.contains(passString)) System.out.println("ESS installed");
w.write(line);
}
r.close();
w.close();
} else
System.out.println("Trust Store JKS file is not available");
} catch (Exception e) {
System.out.println(e);
}
}
}
References:
[1]
Krishna Weds Sudha - Marriage Live recorded video.
Thursday, March 22, 2012
// //
1 comments
//
How to invoke p(j)ython script through ANT scripts do deploy WAR files on to Webshere. ?
The below is a simple ant script invoking python files which will deploy and un-deploy the given J2EE Apps in running Websphere server profile. 1. The ant script will invoke python files.
2. Ant script's target pathconvert will convert the property values containg back slashes in a file path to forward slashes.
3. Ant script target timestamp will print the time stamp along with message in the given log file. Takes care of new line character using 
 at the end of message ...
Ant Script to call jython scripts which will deploy and undeploy provided J2E WAR file.
Below is the Ant script.
hi
<project name="DeployFSAdmin" default="install" basedir=".">
<description>
Silent Deployment of WAR files
</description>
<property name="FSAdminLog" value="c:/FSAdmin_install.log" />
<target id="install" name="install" depends="pathconvert">
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Starting Server now" />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\startServer.bat" output="${FSAdminLog}" append="true">
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Starting FS Admin App Deployment now" />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\wsadmin.bat" output="${FSAdminLog}" append="true">
<arg value="-lang" />
<arg value="jython" />
<arg value="-username" />
<arg value="krishna" />
<arg value="-password" />
<arg value="krishna" />
<arg value="-f" />
<arg value="${deployFile}" />
<arg value="${updatedWARFile}" />
<arg value="FSAdminApp" />
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="FS Admin App Deployment completed" />
</antcall>
</target>
<target id="unistall" name="uninstall">
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Starting Server now." />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\startServer.bat" output="${FSAdminLog}" append="true">
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Un-Deployment of FS Admin in progress..." />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\wsadmin.bat" output="${FSAdminLog}" append="true">
<arg value="-lang" />
<arg value="jython" />
<arg value="-username" />
<arg value="krishna" />
<arg value="-password" />
<arg value="krishna" />
<arg value="-f" />
<arg value="${undeployFile}" />
<arg value="FSAdminApp" />
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Undeployment of FASApp completed" />
</antcall>
</target>
<!-- The target "pathconvert" is to convert all the windows back slahes into forward slashes-->
<target id="pathconvert" name="pathconvert">
<tempfile property="temp.file" />
<echo message="${warfile}" file="${temp.file}" />
<loadfile srcfile="${temp.file}" property="updatedWARFile">
<filterchain>
<replaceregex pattern="\\" replace="/" flags="g" />
</filterchain>
</loadfile>
<delete file="${temp.file}" />
</target>
<!-- To print the time stamp along with message in a log file -->
<target name="timestamp">
<tstamp>
<format property="logtime" pattern="yyyy.MM.dd ':' HH:mm:ss z" />
</tstamp>
<!-- New line charecter uasage 
 -->
<echo file="${LogFile}" message="
${logtime} : ${Message}.
" append="true" />
</target>
</project>
Below is the Deploying Python file.<project name="DeployFSAdmin" default="install" basedir=".">
<description>
Silent Deployment of WAR files
</description>
<property name="FSAdminLog" value="c:/FSAdmin_install.log" />
<target id="install" name="install" depends="pathconvert">
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Starting Server now" />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\startServer.bat" output="${FSAdminLog}" append="true">
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Starting FS Admin App Deployment now" />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\wsadmin.bat" output="${FSAdminLog}" append="true">
<arg value="-lang" />
<arg value="jython" />
<arg value="-username" />
<arg value="krishna" />
<arg value="-password" />
<arg value="krishna" />
<arg value="-f" />
<arg value="${deployFile}" />
<arg value="${updatedWARFile}" />
<arg value="FSAdminApp" />
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="FS Admin App Deployment completed" />
</antcall>
</target>
<target id="unistall" name="uninstall">
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Starting Server now." />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\startServer.bat" output="${FSAdminLog}" append="true">
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Un-Deployment of FS Admin in progress..." />
</antcall>
<exec executable="C:\\Program Files\\IBM\\WebSphere\\AppServer\\profiles\\AppSrv01\\bin\\wsadmin.bat" output="${FSAdminLog}" append="true">
<arg value="-lang" />
<arg value="jython" />
<arg value="-username" />
<arg value="krishna" />
<arg value="-password" />
<arg value="krishna" />
<arg value="-f" />
<arg value="${undeployFile}" />
<arg value="FSAdminApp" />
<arg value="server1" />
</exec>
<antcall target="timestamp">
<param name="LogFile" value="${FSAdminLog}" />
<param name="Message" value="Undeployment of FASApp completed" />
</antcall>
</target>
<!-- The target "pathconvert" is to convert all the windows back slahes into forward slashes-->
<target id="pathconvert" name="pathconvert">
<tempfile property="temp.file" />
<echo message="${warfile}" file="${temp.file}" />
<loadfile srcfile="${temp.file}" property="updatedWARFile">
<filterchain>
<replaceregex pattern="\\" replace="/" flags="g" />
</filterchain>
</loadfile>
<delete file="${temp.file}" />
</target>
<!-- To print the time stamp along with message in a log file -->
<target name="timestamp">
<tstamp>
<format property="logtime" pattern="yyyy.MM.dd ':' HH:mm:ss z" />
</tstamp>
<!-- New line charecter uasage 
 -->
<echo file="${LogFile}" message="
${logtime} : ${Message}.
" append="true" />
</target>
</project>
hi
'''
Created on Jan 18, 2012
@author: krishna
'''
import sys
#--------------------------------------------------------------
# Install an application onto this server
#--------------------------------------------------------------
def install(serverName, nodeName, app, appName=None):
print "Installing the application"
appOptions = "[-server " + serverName + " -node " + nodeName
if len(appName) != 0:
appOptions = appOptions + " -appname " + appName +" -contextroot " + appName
appOptions = appOptions + " -defaultbinding.virtual.host default_host -usedefaultbindings]"
print "Server Options: " + appOptions
AdminApp.install(app, appOptions)
#--------------------------------------------------------------
# Save all changes and stop the server
#--------------------------------------------------------------
print "Now saving all the configurations"
AdminConfig.save()
print "Now stoping the server"
AdminControl.stopServer(serverName, nodeName)
#-----------------------------------------------------------------
# Main
#-----------------------------------------------------------------
if (len(sys.argv) != 3):
print "This script requires 3 parameters:, , "
print "e.g.: argsDeployWARfile.py C:/Krish/SimpleJ2E_1.0.0.war SimpleJ2E server1"
else:
application = sys.argv[0]
appName = sys.argv[1]
print "application: " + application
print "app name: " + appName
nodeName = AdminControl.getNode()
print nodeName
serverName = sys.argv[2]
print serverName
install(serverName, nodeName, application, appName)
Below is the un-deploying Python file.'''
Created on Jan 18, 2012
@author: krishna
'''
import sys
#--------------------------------------------------------------
# Install an application onto this server
#--------------------------------------------------------------
def install(serverName, nodeName, app, appName=None):
print "Installing the application"
appOptions = "[-server " + serverName + " -node " + nodeName
if len(appName) != 0:
appOptions = appOptions + " -appname " + appName +" -contextroot " + appName
appOptions = appOptions + " -defaultbinding.virtual.host default_host -usedefaultbindings]"
print "Server Options: " + appOptions
AdminApp.install(app, appOptions)
#--------------------------------------------------------------
# Save all changes and stop the server
#--------------------------------------------------------------
print "Now saving all the configurations"
AdminConfig.save()
print "Now stoping the server"
AdminControl.stopServer(serverName, nodeName)
#-----------------------------------------------------------------
# Main
#-----------------------------------------------------------------
if (len(sys.argv) != 3):
print "This script requires 3 parameters:
print "e.g.: argsDeployWARfile.py C:/Krish/SimpleJ2E_1.0.0.war SimpleJ2E server1"
else:
application = sys.argv[0]
appName = sys.argv[1]
print "application: " + application
print "app name: " + appName
nodeName = AdminControl.getNode()
print nodeName
serverName = sys.argv[2]
print serverName
install(serverName, nodeName, application, appName)
hi
'''
Created on Jan 18, 2012
@author: krishna
'''
#-----------------------------------------------------------------
# Main
#-----------------------------------------------------------------
if (len(sys.argv) != 2):
print "This script requires 1 parameters:, "
print "e.g.: undeployWAR.py SimpleJ2E server1"
else:
appName = sys.argv[0]
print "application name: " + appName
serverName = sys.argv[1]
print "Server Name: " + serverName
nodeName = AdminControl.getNode()
AdminApp.uninstall (appName)
print "Now saving all the configurations"
AdminConfig.save()
print "Now stopping the server"
AdminControl.stopServer(serverName, nodeName)
'''
Created on Jan 18, 2012
@author: krishna
'''
#-----------------------------------------------------------------
# Main
#-----------------------------------------------------------------
if (len(sys.argv) != 2):
print "This script requires 1 parameters:
print "e.g.: undeployWAR.py SimpleJ2E server1"
else:
appName = sys.argv[0]
print "application name: " + appName
serverName = sys.argv[1]
print "Server Name: " + serverName
nodeName = AdminControl.getNode()
AdminApp.uninstall (appName)
print "Now saving all the configurations"
AdminConfig.save()
print "Now stopping the server"
AdminControl.stopServer(serverName, nodeName)
Popular Posts
-
The best solution to know about these init levels is to understand the " man init " command output on Unix. There are basically 8...
-
How to Unlock BSNL 3G data card to use it with Airtel and Vodafone Model no : LW272 ? How to unlock BSNL 3G data card( Model no : LW272 )us...
-
How to transfer bike registration from one State to other (Karnataka to Andhra)?? Most of us having two wheelers purchased and registered in...
-
ఓం శ్రీ స్వామియే శరణం ఆయ్యప్ప!! Related posts : Trip to Sabarimala - Part 1 Trip to Sabarimala - Part 2 Ayappa Deeksha required things...
-
Following are some of interesting blogs I found till now ...please comment to add your blog here. Blogs in English : http://nitawriter.word...
Popular posts
- Airtel and vodafone GPRS settings for pocket PC phones
- Andhra 2 America
- Ayyappa Deeksha required things
- Blogs I watch !
- Captions for your bike
- DB2 FAQs
- Deepavali Vs The Goddes of sleep
- ETV - Dhee D2 D3
- Evolution of smoking in India Women
- How to make credit card payments?
- init 0, init 1, init 2 ..
- Java-J2EE interview preparation
- mCheck Application jar or jad download
- My SQL FAQs
- My Travelogues
- Old is blod - New is italic
- Online pay methids for credit cards
- Oracle FAQs
- Pilgrimages
- Smoking in Indian Women
- Technology Vs Humans
- Twitter feeds for all Telugu stars on single page.
- Unix best practices
- Unix FAQs