애플리케이션 편집
관리 콘솔, wsadmin 도구 프로그래밍을 통해 전개된 애플리케이션을 편집할 수 있습니다. 이 예제를 사용하여 프로그래밍을 통해 전개된 애플리케이션을 편집하십시오.
시작하기 전에
WebSphere® Application Server에서 애플리케이션을 편집하려면 먼저 애플리케이션을 설치해야 합니다.
이 태스크 정보
다음 태스크를 수행하여 배치된 애플리케이션을 편집하십시오.
프로시저
- WebSphere Application Server에 연결하십시오.
- 애플리케이션 관리 프록시를 작성하십시오.
- 설치된 애플리케이션에 대한 정보를 가져오십시오.
- 필요에 따라 태스크 데이터를 조작하십시오.
- 설치된 애플리케이션에 대한 변경사항을 저장하십시오.
결과
예
다음 예제에서는 이전 단계를 기반으로 애플리케이션을 편집하는 방법을 보여줍니다.
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();
}
}
}