Thursday, February 12, 2009

Badly-coded PeopleCode Fails Invocation of User-defined methods Through Web Services

I wrote a user-defined method in a PeopleSoft component interface (i.e. USER_PROFILE) which was exposed as a web services. But when I called this method from a web service client, I received below error:

The key UserID was not found in the request. (158,16017) PT_INTEGRATION.CIDefinition.OnExecute Name:setKeys PCPC:16560 Statement:306Called from:PT_INTEGRATION.CIDefinition.OnExecute Name:invokeUserDefinedFunction Statement:97Called from:PT_INTEGRATION.CIDefinition.OnExecute Name:OnEvent Statement:34

By using PeopleCode debugging, I traced the error to method setKeys of PT_INTEGRATION:CIDefinition and concluded it is the badly-coded PeopleCode that has resulted in the error.

Let's investigate the PeopleCode(partial) of method setKeys:


/* set the keys */
For &i = 1 To &ciKeyCollection.Count

&currentKey = &ciKeyCollection.item(&i);
&keyNotFound = True;

/* is there a corresponding element in the input XML? */

For &j = 1 To &rootNode.ChildNodeCount
/* NOTE: This is the bad code that causes the error! */
If (Upper(&rootNode.GetChildNode(&j).LocalName) = &currentKey.name) Then

/* the key is present in the XML */
&keyNotFound = False;

Local string &keyValue = &rootNode.GetChildNode(&j).NodeValue;

If (&keyValue = "") Then
throw CreateException(&ibMsgSetNumber, &emsgKeyValueNotInRequest, "No value found for the key %1 in the request.", &currentKey.name);
End-If;

/* set the key data */
&ciInstance.SetPropertyByName(&currentKey.name, &keyValue);

End-If;
End-For;

If (&keyNotFound) Then
throw CreateException(&ibMsgSetNumber, &emsgKeyNotInRequest, "The key %1 was not found in the request.", &currentKey.name);
End-If;

End-For;

The logic of method setKeys is clear: it tries to search the SOAP request for the component interface search key values and sets key values if the search succeeds, or throws an exception if it fails. For example, the search key of component interface USER_PROFILE 'UserId', method setKeys should be able to extract key value 'TESTUSER1' from SOAP request


<Method__CompIntfc__USER_PROFILE>
<UserID>TESTUSER1</UserID>
...
</Method__CompIntfc__USER_PROFILE>


However, things don't go as expected because of the following statement:


If (Upper(&rootNode.GetChildNode(&j).LocalName) = &currentKey.name) Then


This If-Then statement tries to compare a SOAP node with a search key name. You may have noticed the SOAP node name (&rootNode.GetChildNode(&j).LocalName) is formatted to upper case while the search key name (&currentKey.name) is not. It seems that the programmer assumed that the search key name was always upper case and so required no formatting, but how could he/she made such an arbitary assumption?

For component interface USER_PROFILE which I was working with, since the search key name happens to be 'UserId' instead of 'USERID', above comparison always gives a 'false' and the codes setting key values will never be executed, that is the reason why I saw error "The key %1 was not found in the request."

The resolution is simple, after modifying above statement as


If (Upper(&rootNode.GetChildNode(&j).LocalName) = Upper(&currentKey.name)) Then


the web service has executed properly.

Alternatively, the code can also be


If (&rootNode.GetChildNode(&j).LocalName = &currentKey.name) Then


but it is less safe obviously.

This code persists until PeopleTools rel 8.49.08. Hopefully Oracle will correct it in later release.

Tuesday, February 10, 2009

Scripts Listing Processes and Memory Usage of PeopleSoft Application Server and Process Scheduler

Sometimes I want to list all processes belonging to a PeopleSoft app/process domain. Although PSADMIN does provide some options for this purpose, none can satisfy me fully. For example:

./psadmin -c sstatus -d DOMAIN

- No JSH and WSH, also no PID (process id, which is important to me)

./psadmin -c pslist -d DOMAIN

- Shows PID, but no BBL, JSH and WSH

./psadmin -p status -d DBNAME

- No PID

Besides, I am also interested in the memory usage each process, but PSADMIN doesn't provide this kind of information too.

Therefore, I wrote 2 scripts in order to self-help. One is a shell script (view) runnable at Solaris. The other one is a VB script (view) runnable at Windows. A bat file (view) is provided as a wrapper to make the VB script run on and output to DOS commandline, it must reside at the same directory as the VB script.

Both scripts have similar syntax:

pl [-f] {-c-p-c -p} [-m [-h]] instance
Options: -f force execution even appserv domain doesn't exsit
      -c print processes of application server
      -p print processes of process scheduler
      -m print memory usage
      -h print memory usage in human readable format (only applicable to solaris version)


Sample output for running shell script:

$ ~/bin/pl -cmh DOMAIN
PID  PROCESS               VSIZE             RSS
---  -------               -----             ---
6431  PSSUBDSP             107.7M           92.5M
6430  PSPUBDSP             345.2M          161.5M
6397  BBL                   10.9M            8.9M
6407  PSSUBHND              99.7M           84.4M
6446  JREPSVR                8.9M            7.0M
6403  PSAPPSRV             514.7M          306.3M
8105  PSWATCHSRV            15.0M           11.9M
6429  PSBRKDSP             107.7M           92.5M
6402  PSAPPSRV             513.8M          297.5M
6442  JSL                   10.4M            8.4M
6401  PSAPPSRV             533.9M          317.6M
19680  PSMONITORSRV         102.4M           87.2M
6440  WSL                    9.4M            7.6M
6405  PSBRKHND             107.7M           92.5M
6406  PSPUBHND              99.9M           84.6M
6404  PSSAMSRV              97.4M           82.3M
6444  JSH                   12.8M           11.0M
6445  JSH                   16.0M           14.3M
6443  JSH                   16.0M           14.3M


Sample output for running VB script:
C:\WINDOWS\system32>pl -c -p -m DOMAIN
PID     Command         VSize   Working Set
---     -------         -----   -----------
5640    BBL             22.3M   5.8M
1764    PSAPPSRV        114.5M  43.1M
1692    PSAPPSRV        324.5M  81.3M
5856    PSAPPSRV        114.0M  42.5M
2448    PSSAMSRV        104.4M  40.4M
7060    PSANALYTICSRV   107.6M  41.0M
6556    PSANALYTICSRV   107.6M  41.0M
6364    PSANALYTICSRV   107.6M  41.0M
3348    PSDBGSRV        101.5M  37.3M
4592    PSRENSRV        79.4M   17.4M
8112    PSMONITORSRV    101.5M  37.6M
3984    WSL(7000)       24.3M   4.6M
4540    JSL(9000)       25.0M   4.6M
5452    JREPSVR         19.9M   3.9M
7292    PSSAMSRV        100.9M  37.2M
740     PSWATCHSRV      25.1M   6.7M

3840    WSH(7001)       23.9M   4.9M
820     JSH(9001)       24.0M   4.7M
6256    JSH(9002)       26.1M   5.5M
3164    JSH(9003)       24.0M   4.7M
6064    JSH(9004)       26.1M   5.0M
7732    JSH(9005)       24.0M   4.7M

PID     Command         VSize   Working Set
---     -------         -----   -----------
5552    BBL             21.7M   2.7M
5572    PSAESRV         109.9M  14.4M
5616    PSAESRV         109.9M  14.4M
5748    PSPRCSRV        130.8M  21.7M
7112    PSAESRV         303.4M  63.0M
7488    PSDSTSRV        282.0M  50.5M
5812    PSMONITORSRV    100.9M  37.6M


Update on 02/Oct/2009: the enhanced version of pl script (for solaris) is available here

Friday, August 29, 2008

Speed Up PeopleSoft Project Comparison And Migration Using Application Designer Command Line Parameters

As a PeopleSoft system/data administrator, project comaprison or migration is the regular work I have been undertaking. The usual procedure of doing this is:

1) Logon to app designer with source DB name, user and password

2) Open a project that you want to work on

3) Compare it with the target DB to which you would need to provide username and password so as to logon.

4) After comparing the project, migrate it to the target DB. At this point you need to type in username and password one more time.

It is OK if you only need to work on one or two projects everyday. But imagine you receive dozens of requests per day, in particular during the implementation period?

Fortunately, we are able to make use of app designer command line parameters to automate above procedures.

I hereby list the most important parameters below:

  • -CT : DB type
  • -CD : source DB name
  • -CO : username for source DB
  • -CP : password for source DB
  • -TD : target DB name
  • -TO : username for target DB
  • -TP : password for target DB
  • -PJM : name of project to compare
  • -PJC : name of project to migrate

There are many other parameters that specify comare, copy or report options. Please refer to PeopleBooks for details.

I wrote 2 bat files: pscmp.bat and pscpy.bat, which invoke app designer (pside.exe) with all kinds of parameters mentioned above. The basic usage is:

pscmp <project> <source DB> <source user> <source password> <target DB> <target user> <target password>

and

pscpy <project> <source DB> <source user> <source password> <target DB> <target user> <target password>

Further simpification can be achieved by hard-cording some parameters in the batch scripts. And similarly, you are able to write other scripts to build projects, or just in order to logon without typing in username/password.

Two issues:

1) No parameters provided to customize report filter options. So you still need to logon interactively to change them manually.

2) There may be some definitions that are absent on source but in non-absent state in target. Although this kind of definitions are suposed to be removed from target, they are tagged as 'not upgrade' by default because Peoplesoft would leave them for users to make final desicion. So you also need to logon interactively the tag them as 'upgrade' if you really hope to remove them.

Friday, July 18, 2008

A Script Looking For Processes That Open Specific Ports

Question: In Solaris, how to know which process opens a specific port?

There is an easy answer in Linux: lsof. However, Solaris doesn't deliver a similar command. So I need a workround to resolve it: using ps command to get pid of all processes, and use pfiles to find ports opened by those processes and match them with the given ports.

I wrote the following script to manage it.

Example of usage:

pp 9000
pp 9000 9001
pp 9000-9010 9100 9200-9201


#!/usr/bin/bash

# The script lists the process that opens given ports

# function printing usage message
help_msg () {
echo "Usage: pp ... -..."
}

# initialize argument array
aports=""

# function appending a port to $aports
append_arg () {
if echo " $aports " | grep " $1 " > /dev/null
then
return
fi
aports=`echo $aports $1`
}

# verify arguments
if [ $# -eq 0 ]
then
help_msg
exit 1
fi

# process arguments
for arg in $*
do
if echo $arg | grep "^[0-9]*$" > /dev/null
then
#process single port
append_arg $arg
elif echo $arg | grep "^[0-9]*-[0-9]*" > /dev/null
then
# process port range (-)
n1=`echo $arg | cut -d "-" -f1`
n2=`echo $arg | cut -d "-" -f2`
if [ $n1 -le $n2 ]
then
until [ $n1 -gt $n2 ]
do
append_arg $n1
n1=$((n1 + 1))
done
else
echo "Invalid port:" $arg
fi
else
echo "Invalid port: " $arg
fi
done

# loop arguments
for port in $aports
do
echo "Port: $port"
found=false

# find processes
for pid in `ps -ef -o pid | tail +2`
do
for pport in `/usr/proc/bin/pfiles $pid 2>/dev/null | grep "sockname:" | cut -d: -f 3`
do
if [ $pport -eq $port ]
then
found=true
echo "Process: $pid"
# echo "Command: " `ps -ef -o pid -o args | grep ^\ *$pid | cut -b7-`
echo "Command: " `pargs -l $pid`
#echo $pports
echo
break
fi
done
done

if ! $found
then
echo "Not found"
echo
fi
done

Thursday, July 10, 2008

How To Map A HTTPS-only Web Folder To A Drive

Question: In Windows XP/2003, how to map a web folder which allows for only HTTPS connections to a drive?

Windows web folder is Microsoft's implementation of WebDAV (Web Distributed Authoring and Versioning). Two WebDAV clients: Web Folders and WebDAV Mini Redirector are integrated and preinstalled with Windows. Based on them, there are usually 2 methods to access a web folder in Windows:

1) Use 'Add Network Place' in 'My Network Places',

This always works regardless of the connection type (HTTP or HTTPS). However, you can't map a web folder opened this way to a drive.

2) Use 'net use' at command line, as shown below:
net use x: http://domain-name/path-to-web-folder

The web folder is mapped to a drive, but this method only works for HTTP connection because of the limitations of WebDAV Mini Redirector:
  • No support for HTTPS, i.e. no support for secure connections, unless you are using Vista as a client.

  • No support for declared ports (http://myserver.com:8080/dav/) i.e. your WebDAV server must be using port 80, the default port.

  • No support for LOCK and UNLOCK commands, i.e. no locking if, for example, two users try to access (open) the same Word document.

Therefore, if a web folder supports only HTTPS connections, and you issue command:

net use x: https://domain-name/path-to-web-folder

you are given an error message something like 'Sysytem error 67 has occurred. The network name cannot be found.'

A software called WebDrive does feature a function mapping a HTTPS web folder to a drive, but it is not free, unfortunately.

Good news is we can do it free, with the help of stunnel - a universal SSL wrapper.

Stunnel is a program that allows you to encrypt arbitrary TCP connections inside SSL available on both Unix and Windows. And it is licensed under GPL. We use it here as a proxy that encrypts a HTTP request to a HTTPS one and submits to WebDAV server. The details are below:

1) Download stunnel Win32 binary from here and install it. The latest release is 4.25.

2) Edit stunnel.conf that is located at 'c:\program Files\stunnel\', make the following changes:

client=yes

verify=0

and add the following section to the end of the file:

[psuedo-https]

accept = 80

connect = domain-name:443

TIMEOUTclose = 0

The 'domain-name' above refers to the WebDAV server's domain name or IP address. Save the changes and start stunnel, now you should be able to map the HTTPS web folder to a drive by issuing command:


net use x: http://localhost/path-to-web-folder
Note:

  • This solution has been tested to work on Windows XP Pro SP3 and Windows 2003 EE SP2.
  • Please make sure WebClient service is on, and 'Networking Services' component has been installed with your Windows, otherwise you can't use 'net use' command to connect web folder.
  • If the WebDAV server requires Windows AD authentication, ie you must provide a user id in format of 'domain\user' and password so as to connect, you must logon to the domain first. My attempt to map a drive while logging on as a local user has failed, even I have forced stunnel to launch using a valid domain user id. The reason is not known yet.

Reference:

Tuesday, July 1, 2008

Change Shortcut Key for Firefox Download Manager

Firefox is officially supported by Peoplesoft PIA, and it works fine most of the time. But advanced users may have found they were stuck when trying to invoke system info screen - they hit CTRL-J in FF as they did in IE but saw no system info appeared. Instead, FF popped up a download manager window.

The reason is simple: CTRL-J is being used by FF as a shortcut key for download manager. And unfortunately, FF is not shipping a direct way for user to customize those keys. 'about:config' doesn't enable you to do that.

But there are still ways to tweak it:

1) With add-on. An unofficial FF add-on, 'keyconfig', is available at
http://forums.mozillazine.org/viewtopic.php?t=72994. With that you are free to customize shortcut keys for FF, provided you know how to manually edit FF's user preference file (perfs.js). If you can't or don't want, install one more add-on, 'functions for keyconfig' from http://www.pqrs.org/tekezo/firefox/extensions/functions_for_keyconfig/index.html. This enables you to change keys through UI.

2) Without add-on. Knowing where to get a tool is good, but doing it w/o a tool is cool, right?


Let's look at how FF launches download manager first. Explorer %FIREFOX_HOME%\chrome, find the following 2 files:

  • browser.jar
  • en-US.jar

Unjar browser.jar into %TEMP%, find browser.xul from extracted files and open it in your text editor, you see a line that looks like

  • <menuitem id="menu_openDownloads" label="&downloads.label;" key="key_openDownloads" accesskey="&downloads.accesskey;" command="Tools:Downloads"/>
Note the highlighted 'key' attribute, this obviously defines a shortcut key for download manager menu. Remove it to disable the key.

But what if you only want to change the shortcut key rather than disabling it? Let's look at how "key_openDownloads" is defined. In the same browser.xul, you see

  • <key id="key_openDownloads" key="&downloads.commandkey;" command="Tools:Downloads" modifiers="accel"/>
The highlighted attribute denotes the key value, but how do we know what "&downloads.commandKey;" actually is?

Now extract en-US.jar into %TEMP%, find browser.dtd in which you see

  • <!ENTITY downloads.commandkey "j">
The truth is out there!. Change 'j' to whatever you prefer, but make sure the new key doesn't conflict with other FF shortcuts.

Stuff the modified browser.xul or/and browser.dtd back into the jar files. Open FF and see whether it works.

This tip applies to both FireFox 2 and 3.

Wednesday, October 3, 2007

Troubltshoot Error Occurred When Installing Office 2003 SP3 Into Windows VISTA

I had been trying to install Office 2003 SP3 into my new Thinkpad T61 laptop but kept failing. When trying intallation from Windows Update, it started normally but prompted error on the half way, and never gave a detailed explanation.

I thought it might be Windows Update's fault and so download the separate installer from MS site, but the error persisted, except it gave a detailed error message somethign like 'no sufficient permission to c:\windows\system32\mapisvc.inf'.

I checked the ACL of above mentioned file and found its owner is 'TrustedIntaller', which actually stand for Windows installer service instead of a real group in VISTA. And this file was read-only to the local administrators.

So I made it owned by administrator, and grant write to administrators group. The the SP3 insallation was flying!

Here is the detailed explanation of 'TrustedInstaller'.