Tom Keith

Greenhorn
+ Follow
since Mar 26, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tom Keith

Hi,

The following example will list all applications running. In this case, I have 4 applications.

Invoking WLST script
------------------------
java weblog.WLST listAppStatus.py t3://localhost:7001


listAppStatus.py
------------------

def checkWlsApplicationState(serverURL):

clusterCheck = ""

#target indicates if it a cluster or admin server.
#In this case, AdminServer is the name of my adminserver.
#WLS defeault is myServer

target = ""

try:
connect('weblogic', 'weblogic' ,url=serverURL)
except:
dumpStack()
disconnect()

cd("AppDeployments")
myapps = ls(returnMap='true')

cd("../Servers")
domainName = cmo.getName()

cd("AdminServer")
slcBean = cmo.lookupServerLifeCycleRuntime()
status = slcBean.getState()

cd("../../")
try:
cd("Clusters/" + domainName + "_cluster")
clusterCheck = 0
except:
clusterCheck = 1

if clusterCheck == 0:
print 'Domain ' + domainName + ' is Clustered'
target = domainName + '_cluster'
else:
print 'Domain ' + domainName + ' is Not Clustered'
target = 'AdminServer'

print ''
domainRuntime()

cd("AppRuntimeStateRuntime/AppRuntimeStateRuntime")

print '-------------------------------------------------------------------------------'
print 'Application Name Intended State Current State'
print '-------------------------------------------------------------------------------'

appIndex=0

for applicationName in myapps:

intendedState = cmo.getIntendedState(applicationName, target)
currentState = cmo.getCurrentState(applicationName, target)

if appIndex == 0:
print applicationName + ' ' + intendedState + ' ' + currentState
elif appIndex == 1:
print applicationName + ' ' + intendedState + ' ' + currentState
elif appIndex == 2:
print applicationName + ' ' + intendedState + ' ' + currentState
elif appIndex == 3:
print applicationName + ' ' + intendedState + ' ' + currentState

appIndex = appIndex + 1

print '-------------------------------------------------------------------------------'

disconnect()

#Argument 1 is Admin URL
#For example: t3://localhost:7001

checkWlsApplicationState(sys.argv[1])


# End of WLST


HTH,
Tom
14 years ago
Hi Sanjeev,

Try the following code. This was tested on weblogic 9.1 and should pretty much work on others where you have WLST (WebLogic Scripting Tools) installed.

To run, copy the line inbetween block and save the file as WlsMonitor.py. Then to run it type

java weblogic.WLST WlsMonitor.py

This will create a file called wls_domain_details.html and will email it to the address specified in the code.

This will send details for AdminServer as well as all the running managed servers in the domain.

Hope this helps.



Thanks,
Tom
16 years ago
I tried another way of doing this and the following is the code:

import java.util.Date;
import java.util.TimeZone;
import java.util.Calendar;
import java.util.StringTokenizer;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;
import java.util.ArrayList;

public class TimerTest {

String arr[]={"element1", "element2"};
public static RunTask task = null;
public static int RETRY_COUNT = 4;
ArrayList arraylist = new ArrayList();
Date today, future;

public static void main(String[] args) {
new TimerTest();
}

public TimerTest() {
//Different ways to Add Elements to the arraylist
for(int i=0;i<arr.length;i++) {
arraylist.add(i,arr[i]);
}

String strCode = null;
try {
for(int i = 0;i< arraylist.size();i++) {
strCode = (String)arraylist.get(i);
task = new RunTask(strCode, RETRY_COUNT);
task.start();
System.out.println( "\n["+ Thread.currentThread().getName()+"] Started the thread ->" + task.getName());
System.out.println("Sleeping for 2 seconds...");
Thread.sleep(2000L);
}
}
catch(Exception e) {
}
}
}

class RunTask extends Thread {
String strCode = null;
RunTask task;
int iRetryCount = 0;

public RunTask(String code, int iCount) {
strCode = code;
iRetryCount = iCount;
}

public RunTask(String code, int iCount, RunTask rt) {
strCode = code;
task = rt;
iRetryCount = iCount;
}

public void run() {
try {
iRetryCount--;

if(task != null) {
System.out.println("Sleeping for 30 seconds...");
Thread.sleep(30000);
if(! task.isAlive()) {
System.out.println(Thread.currentThread().getName() + " is dead...");
}
}
// do someting

if(iRetryCount != 0) {
task = new RunTask(strCode, iRetryCount, this);
task.start();

System.out.println( "\n["+ Thread.currentThread().getName()+"] Stopped & terminated." +
"Starting thread ->" + task.getName());
}

Thread.sleep(1000L);
System.out.println(Thread.currentThread().getName() + " sleeping for 1 second...");

}
catch (ThreadDeath e) {
System.out.println(e.getMessage());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}

But, I have a question. I am killing the current Thread and creating another Thread and ask it to sleep for 30 seconds. This is just a simulation. My actual program will wait for 45 minutes.

My questionis, is there any other better way of doing it?

Thanks,
Tom
Hi,

I have a problem in using Timer and TimerTask.

Problem:
I have a arraylist of say 100 codes. I have to loop through the arraylist and start individual process for each code. Then after eaach individual code is done, reschedule it back in 1 hour.

I am able to do the first part, but struck in the second part.

Code snippet:



Can somebody tell me now how to schedule each code again after 1 hour?

Thanks to all in advance.

Thanks,
Tom


[HW: Added code tags]
[ September 16, 2006: Message edited by: Henry Wong ]
All,

Here is a question regarding SSH and FTP using java. One of our clients were using a leased line earlier and they were able to get the files transferred easily. Now due to management decision, our clint will be using internet for transferring files from our system. The decision on our part was to make the server use SFTP protocol.

Is there any way using java to transfer files back and forth from SFTP server?

Note: I looked into Apache Commons, JSch, JScape, enterprisedt, RADFTP etc.

Any help is really appreiciated.

Thanks,
Tom
18 years ago
Can somebody help me out on this please?

Thanks,
Tom
18 years ago
Create a ear file and copy th file to C:\bea\user_projects\domains\<your domain name>\<your server name>\upload directory. The WLS will automatically pick it up in few seconds.

For example
C:\bea\user_projects\domains\mydomain\myserver\upload

Hope this helps.

- Tom
18 years ago
How do I disable Servlet Filters? Is there a config file?

Another question, Can I write my own AA (Authentication & Authoursation) module by overcoming the password display problem? If so how?

Thanks,
Tom
18 years ago
All,

I have a question regarding FORM Based Authentication. How is j_password protected from hacking meaning that if a Servlet Filter is written then the NT password can be read from the request which is not good for users as they do not want theit NT passwords to be seen. Is there any way to protect the password from being seen? Does App servers like WLS/WAS/JRun etc., do it? If so how?

Thanks,
Tom
18 years ago
Hi All,
I created a web service using IBM Site Developer and when this we tried to created the proxy in power builder 9.0, we got the following error:
Generation Errors:
Deployment Error:
No files returned from server for
service_port: 'Pay4WrapperService_Pay4WrapperPort'
Error code: 'Fail to generate proxy for the port '
Proxy was not created.
Currently we had to create a wrapper web service in Weblogic which Powerbuilder is able to recognize and generate proxies. But I was wondering why?
Any body have any idea?
Thanks,
Tom.
20 years ago
Hi Hari,
Hope you are looking for something like the following:
/**
* Method used to replace a source string with the destination string
*
* @param str the sourceString
* @param pattern the pattern to be replaced
* @param replace the string that replaces thepattern string
*
* @return replaced String
*/
public static String replace(String sourceString, String pattern, String replace) {
if (replace == null) {
replace = "";
}
int stringPosition = 0, stringIndex = 0;
StringBuffer result = new StringBuffer((int) sourceString.length() * 2);
while ((stringIndex = sourceString.indexOf(pattern, stringPosition)) >= 0) {
result.append(sourceString.substring(stringPosition, stringIndex));
result.append(replace);
stringPosition = stringIndex + pattern.length();
}
result.append(sourceString.substring(stringPosition));
return result.toString();
}
HTH,
Tom
21 years ago
Hi All,
I have a question regarding database autocommit. It might sound silly. But I just want to clear my doubts.
Consider the following scenarios:
Question 1
-----------
1) Some DML statments followed by some DDL statements (just for argument sake) and no autocommit defined in the java program, How is the transaction commited?
2) Some DML statments and no autocommit defined in the java program, How is the transaction commited?
Question 2
----------
If no commit is specified in the java program, the which one does the commit:
Is it the JDBC driver that prompts the dadabase to commit the transaction (if so does all the JDBC drivers have this property by default?) or does the Datbase does it by itself?
Thanks,
Tom
Hi Bosun,
Number 2 compiles and works fine . I have been using it for quite sometime. I just wanted to know the difference.
Thanks,
Tom
21 years ago
Hi All,
Consider the following String array declarations.
1)
String[] paramString = new String[4];
paramString[0] = "user1";
paramString[1] = "pwd";
paramString[2] = "1";
paramString[3] = "sa";
2)
String[] paramString = new String[4] {"user1", "pwd", "1", "sa"};
3)
String[] paramString = {"user1", "pwd", "1", "sa"};
My assumption is that all of three are same
Is there is any advantage or disadvantage in doing them or is it just a matter of coding style?
Does it have to do anything with Garbage Collection?
Thanks,
Tom
21 years ago
Hi Rohit,
Take a look at the following Method. The method takes a given prices and formats it.

Hope this helps.
Thanks,
Tom
(edited by Cindy to format code)
[ June 13, 2002: Message edited by: Cindy Glass ]
21 years ago