Work with the Portal Scripting Interface

+

Search Tips   |   Advanced Search

 

  1. Prerequisite information
  2. Interactive mode
  3. Script mode
  4. Run scripting commands in a profile

 

Prerequisite information

The Portal Scripting Interface provided by IBM WebSphere Portal is based on the wsadmin scripting tool provided by IBM WAS. Therefore, before you use the Portal Scripting Interface, familiarize yourself with how to use the WebSphere Application Server wsadmin tool.

 

Interactive mode

Use interactive mode to interact directly and dynamically with the portal to perform simple administrative tasks that should only be executed once.

Before initiating a session in interactive mode, verify WebSphere Portal is running.

To run the portal script client...

cd portal_server_root/bin
./wpscript.sh

If WebSphere Application Server security is disabled...

    ./wpscript.sh -port port

If WebSphere Application Server security is enabled...

    ./wpscript.sh -port port -user admin_userid -password admin_password

Basic parameters include...

Parameter Description
-conntype The type of connection that should be established between scripting. Valid connection types include:

The default value is SOAP. This parameter is optional. Use the -conntype NONE option to run in local mode. The result is that the scripting client is not connected to a running server. If the connection type NONE is selected, the scripting beans are inactive and cannot be used for administration, with the exception of the help command.

-port The name of the connection port. The default port is 10033. This parameter is optional.

The port depends on values chosen during installation. We can verify the value that is set for the WpsSoapPort in...

portal_root/config/wpconfig.properties

For machines that are part of a cell managed by a deployment manager, use -port 8879.

-user User ID under which you establish the connection. This parameter can be mandatory, depending on the security configuration.
-password Password for the user ID under which you establish the connection.

Log on to the portal using the following script command:

$Portal login wpsadmin wpsadmin

Issue portal script commands as required.

After completing tasks, close and exit the script processor. All changes that committed are applied to the portal configuration.

For a detailed syntax and description of the scripting commands, refer to...

Command reference for Portal Scripting Interface

For info on using the Portal Scripting client in a clustered environment, refer to...

Work with the Portal Scripting Interface in a cluster

 

Script mode

Use the script mode to apply predefined changes to the configuration of a portal.

The wpscript tool executes a JACL script that contains the administrative operations. The scripting client inherits the JACL processor from wsadmin, so an administrator can exploit the JACL scripting language, in order to write re-usable, extendable administration scripts.

This mode is typically preferred if reproducible administration tasks are created. For example, the administrator can write a JACL script that produces a complete page subtree, and adds individual page layouts and portlets on each page.

Users who have access permission to perform XML configuration interface requests can change configurations of all resources. The Portal Scripting Interface is mostly consistent with the administration model that is exposed by the Portal user interface.

Before using script mode, make sure that WebSphere Portal is running and a portal script file is available. Use the following procedure.

  1. Update the script file with the appropriate credentials, if required.

  2. Use the following command to launch the script processor tool:

        wpscript.sh -port port -f script_file_name.jacl 

    This initializes the interactive script environment of the portal script processor.

  3. Check the output from the script processor to ensure that no errors occurred during the execution of the script.

All changes committed by the script are immediately applied to the portal configuration.

Here is an example of a portal script file called "testme.jacl":

### testme.jacl ###
### Create a simple page (multi-column Layout)           
###                                                                              

### Procedure: create a multi-column page below the page that is currently       
### selected, and place the given portlets into the layout.                      
###                                                                              
### parameters:                                                                  
###                                                                              
###   name              The name of the page                                     
###   portlet_names     A list of portlet names.                                 
###   
### returns:
###                                                                              
###   oid               The id of the page that has been created                 

proc  create_multi_col_page { name portlet_names } {                            

  global Content Layout Portlet                                                

    set thePage [$Content create page $name html]                              

    $Content select $thePage                                                   

    set lyt0 [$Layout create container horizontal select]                      

    foreach pn $portlet_names {                                                
      set pid [$Portlet find portlet cn $pn]                                   
      $Layout create control $pid                                              
    }                                                                          

  return $thePage                                                              
}                                                                              
                                                                               

### main code starts here                                                        
                                                                               

### Set User ID/ pwd for portal Login command                                    
### 
### User ID and passwords should normally not be placed inside a           
### configuration script; better use property files or command line arguments    

set user portaladmin                                                           
set pwd  adminpwd                                                              
$Portal login $user $pwd                                                       
                                                                               

### Determine and select the parent of the page to be created.                   
### In this example, This is the "Home" label.                              

$Content select [$Content find all uniquename "ibm.portal.Home"]                 
                                                                               

# Invoke the page creation procedure. The label of the page is "My test page", 
# portlets to be added are the workd clock portlet, and the welcome portlet.   

set MyNewPage [ create_multi_col_page "wpscript Example " { "World_Clock" "Welcome_to_WebSphere_Portal" } ]
                                                                               
puts "ok, you are done."       

This script creates a new page with the title "wpscript Example", which resides below the "Home" label. WpScript contains two portlets, which are arranged horizontally.

The scripts can receive parametric information externally, by using one of the JACL feature listed below:

A JACL script can access command line arguments with the JACL scripting variables argc (that holds the number of command line arguments) and argv (that holds the command line arguments themselves).

Example: In the testme.jacl portal script file shown above, delete the following statements:

    set user portaladmin                                                           
    set pwd  adminpwd 

...and replace it with the following code...

    if { $argc != 2 }  {
        puts "invocation syntax: wpscript testme.jacl <user> <pwd>"
          exit       }
      set user [lindex $argv 0]
      set pwd [lindex $argv 1]

The security-sensitive user name and password are removed from the JACL script. The modified code expects the user ID and password to be specified as command line arguments, for example:

    wpscript.sh -port port -f testme.jacl portaladmin adminpwd 

 

Run scripting commands in a profile

A profile is a script that runs before the main script, or before entering interactive mode. Profiles can be used to set up environment specific behavior or user specific data. Profiles are specified when invoking wpscript, using the -profile parameter. For example, the login command can be placed in a profile. The following example of a profile, which can be named mylogin.jacl, would look like this:

    # scripting profile 
    # contains log-in procedure on portal with disabled security     if { $argc != 2 }  {
      puts "invocation syntax: wpscript -f testme.jacl -profile mylogin.jacl <user> <pwd>"
        exit     }
    set user [lindex $argv 0]
    set pwd [lindex $argv 1]
    $Portal login $user $pwd 

Remove or comment out the following statements in the testme.jacl script file:

    # scripting profile 
    # contains log-in procedure on portal with disabled security     if { $argc != 2 }  {
      puts "invocation syntax: wpscript testme.jacl <user> <pwd>"
      exitoy     }
    set user [lindex $argv 0]
    set pwd [lindex $argv 1]
    $Portal login $user $pwd 

Then, invoke the mylogin.jacl script, for example, as follows:

    wpscript.sh -port port -profile mylogin.jacl -f testme.jacl portaladmin adminpwd 

The benefit of this change is that the environment-specific login procedure is removed from the administration script. For systems with enabled WebSphere Application Server security, it is as follows:

  
    # scripting profile 
    # contains log-in procedure on portal with enabled security     $Portal login 

 

Related information

 

Parent topic:

Portal Scripting Interface