+

Search Tips   |   Advanced Search

Edit applications

We can edit deployed applications through the console, wsadmin.sh, or by programming. Use this example to edit a deployed application through programming.

This task assumes a basic familiarity with MBean programming. For information on MBean programming, see MBean Java (API) documentation. In this information center, click Reference > Mbean interfaces.

Before we can edit an application on WebSphere Application Server, install the application.

Perform the following tasks to edit the deployed application.

  1. Connect to WebSphere Application Server.

  2. Create the application management proxy.

  3. Get information about an installed application.

  4. Manipulate task data as necessary.

  5. Save changes for the installed application.


Results

After you successfully run the code, the application is edited.


Example

The following example shows how to edit an application, based on the previous steps.

import java.lang.*;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
import com.ibm.websphere.management.application.*;
import com.ibm.websphere.management.application.client.*;
import com.ibm.websphere.management.*;

import javax.management.*;

public class aa {

    public static void main (String [] args) {

        try {
             
  // Connect to WebSphere Application Server.
  String host = "localhost";
  String port = "8880";
  String target = "WebSphere:cell=cellName,node=nodeName,server=server1";

  Properties config = new Properties();
  config.put (AdminClient.CONNECTOR_HOST, host);
  config.put (AdminClient.CONNECTOR_PORT, port);
  config.put (AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
  System.out.println ("Config: " + config);
     AdminClient _soapClient = AdminClientFactory.createAdminClient(config);
  
  // Create the application management proxy, AppManagement.
  AppManagement proxy = AppManagementProxy. getJMXProxyForClient (_soapClient);

  String appName = "MyApp";
// Get information for an application with name appName:
// Pass Locale information as the preference.
Hashtable prefs = new Hashtable();
 prefs.put(AppConstants.APPDEPL_LOCALE, Locale.getDefault()); 
Vector allTasks =  appMgmt.getApplicationInfo (appName, prefs, null); 

// Manipulate task data as necessary.
if (task.getName().equals ("MapRolesToUsers") && !task. isTaskDisabled()) 
{ 
       // find out column index for role and user column 
       // refer to the previous table to find the column names        int roleColumn = -1;
       int userColumn = -1;
       String[] colNames = task.getColumnNames();
       for (int i=0; i < colNames.length; i++)
       { 
            if (colNames[i].equals ("role"))
             roleColumn = i;
            else if (colNames[i].equals ("role.user"))
               userColumn = i; 
       } 
            
       // iterate over task data starting at row 1 as row0 is       // column names        String[][]data = task.getTaskData();
       for (int i=1; i < data.length; i++)
       {
            if (data[i][roleColumn].equals ("Role1")) 
            {
             data[i][userColumn]="User1|User2";
               break;
            }
       } 
       
       // now that the task data is changed, save it back
       task.setTaskData (data);
} 

// Save changes back into the installed application:
// Set information for an application with name appName. 
// Pass Locale information as the preference.
prefs = new Hashtable();
prefs.put(AppConstants.APPDEPL_LOCALE, Locale.getDefault());
appMgmt.setApplicationInfo (appName, prefs, null, allTasks);

        }
        catch (Exception e) {
            e.printStackTrace();
        }

    }

}


Related tasks

  • Install an application through programming
  • Uninstall an application through programming
  • Add to, updating, or deleting part of an application through programming
  • Preparing a module and adding it to an existing application through programming
  • Preparing and updating a module through programming
  • Delete a module through programming
  • Add a file through programming
  • Update a file through programming
  • Delete a file through programming