연결 테스트 서비스

WebSphere® Application Server는 데이터 소스 구성의 유효성을 검증하기 위해 연결 테스트 서비스를 제공합니다. testConnection 조작은 데이터 소스 구성을 인스턴스화하여 연결을 확보한 후 즉시 연결을 닫습니다.

WebSphere 변수와 데이터 소스가 연관된 경우, 변수를 올바르게 구성했는지 확인하려면 "WebSphere 변수 작성, 편집 및 삭제" 주제를 참조하십시오. variable cannot be found 예외는 올바르지 않게 정의된 변수를 통해 호출된 데이터 소스를 사용하려고 했기 때문에 발생합니다.

연결 테스트 서비스 활성화

연결 테스트 서비스를 활성화하는 데는 관리 콘솔, wsadmin 도구 또는 Java™ 독립형 프로그램을 통한 세 가지 방법이 있습니다. 각 프로세스는 동일한 MBean에서 동일한 메소드를 호출합니다.

관리 콘솔

WebSphere Application Server는 단순히 단추를 눌러 관리 콘솔에서 연결을 테스트할 수 있게 합니다(모두 연결 테스트 단추가 있는 데이터 소스 콜렉션, 데이터 소스 설정, 버전 4 데이터 소스 콜렉션 및 버전 4 데이터 소스 설정 페이지). 데이터 소스를 정의하고 저장한 후 이 단추를 클릭하여 데이터 소스 정의의 매개변수가 올바른지 확인할 수 있습니다. 콜렉션 페이지에서 몇 가지 데이터 소스를 선택하고 한꺼번에 모두 테스트할 수 있습니다. 먼저 만족해야 하는 특정 조건이 있음을 주의하십시오. 자세한 정보는 "관리 콘솔로 연결 테스트" 주제를 참조하십시오.

참고: 관리 콘솔에서 Sybase 데이터 소스에 연결하기 위해 연결 테스트를 클릭하면 다음 예외가 발생합니다.
server1 서버의 svtaix24Node01 노드에서 isagent 데이터 소스에 대해
다음 예외와 함께 연결 테스트가 실패했습니다. java.lang.Exception:
java.sql.SQLException: JZ006: Caught IOException: java.net.ConnectException: A 
원격 호스트에서 연결 조작을 거부했습니다.DSRA0010E: SQL State = JZ006,
Error Code = 0
이 예외는 Sybase 데이터 소스 포트 번호가 Sybase 서버에 구성된 포트와 일치하지 않을 때 발생합니다. 기본 포트 번호는 5000입니다. /<sybase 설치 디렉토리>에 있는 인터페이스 파일에서 Sybase 서버의 포트 번호를 확인하십시오.

WsAdmin 도구

wsadmin 도구는 WebSphere Application Server 관리 활동의 전체 범위에 대한 스크립트 인터페이스를 제공합니다. 연결 테스트 기능이 MBean의 메소드로서 구현되고 wsadmin이 MBean 메소드를 호출할 수 있기 때문에, wsadmin을 이용하여 DataSources에 대한 연결을 테스트할 수 있습니다. wsadmin을 통한 데이터 소스 연결 테스트에는 두 가지 옵션이 있습니다.

wsadmin의 AdminControl 오브젝트에는 testConnection 조작이 있어서 데이터 소스 오브젝트의 구성 특성을 테스트할 수 있습니다. 정보는 "wsadmin으로 연결 테스트" 주제를 참조하십시오.

MBean 연산을 호출하여 연결을 테스트할 수 있습니다. 이 기법의 지침으로 "wsadmin으로 데이터 소스 연결 테스트" 주제의 예제를 사용하십시오.

Java 독립형 프로그램

마지막으로, DataSourceCfgHelper MBean에서 testConnection 메소드를 실행하여 연결을 테스트할 수 있습니다. 이 메소드는 구성된 데이터 소스의 구성 ID를 전달할 수 있게 합니다. Java 프로그램은 실행 중인 JMX(Java Management Extensions) 서버에 연결하여 MBean에 액세스합니다. Application Server의 기본 설치에서, 대개 포트 8880의 애플리케이션 서버에서 실행 중인 JMX 서버에 연결합니다.

이 호출의 리턴값은 0, 양의 숫자 또는 예외입니다. 0은 작업이 경고 없이 성공적으로 완료했음을 표시합니다. 양의 숫자는 해당 번호의 경고와 함께 작업이 성공적으로 완료되었음을 표시합니다. 예외는 연결 테스트가 실패했음을 표시합니다.

참고: 예제: testConnection(ConfigID)를 사용하여 연결 테스트

다음 예제 코드는 데이터 소스 인스턴스 및 관련 연결 인스턴스를 작성하고 데이터베이스 연결성을 사용할 수 있도록 테스트합니다.

이 프로그램은 JMX를 사용하여 실행 중인 서버에 연결하고 DataSourceCfgHelper MBean에서 testConnection 메소드를 호출합니다. 주석 행의 ND는 다음 코드가 WebSphere Application Server WebSphere Application Server, Network Deployment에 적용됨을 나타냅니다. 주석 행의 Base는 다음 코드가 WebSphere Application Server에 적용됨을 나타냅니다.

/**
 * Description
 * Resource adapter test program to make sure that the MBean interfaces work.
 * Following interfaces are tested
 * 
 *  ---  testConnection()
 * 
 * 
 * We need following to run
 * C:\src>java -Djava.ext.dirs=C:\WebSphere\AppServer\lib;C:\WebSphere\AppServer\java\jre\lib\ext testDSGUI
 * must include jre for log.jar and mail.jar, else get class not found exception
 * 
 * 
 */

import java.util.Iterator;
import java.util.Locale;
import java.util.Properties; 
import java.util.Set;

import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeOperationsException;

import com.ibm.websphere.management.AdminClient;
import com.ibm.websphere.management.AdminClientFactory;
import com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException;

public class testDSGUI {

//Use port 8880 for a Base installation or port 8879 for ND installation
String port = "8880";
// String port = "8879";
String host = "localhost";
final static boolean verbose = true;

// eg a configuration ID for DataSource declared at the node level for Base
private static final String resURI = "cells/cat/nodes/cat|resources.xml#DataSource_1";

// eg a 4.0 DataSource declared at the node level for Base
//    private static final String resURI = "cells/cat/nodes/cat|resources.xml#WAS40DataSource_1";

// eg Apache Derby DataSource declared at the server level for Base
//private static final String resURI = "cells/cat/nodes/cat/servers/server1/resources.xml#DataSource_6";

// eg node level DataSource for ND
//private static final String resURI = "cells/catNetwork/nodes/cat|resources.xml#DataSource_1";

// eg server level DataSource for ND
//private static final String resURI = "cells/catNetwork/nodes/cat/servers/server1|resources.xml#DataSource_4";

// eg cell level DataSource for ND
//private static final String resURI = "cells/catNetwork|resources.xml#DataSource_1";

 public static void main(String[] args) {
  testDSGUI cds = new testDSGUI();
  cds.run(args);
 }

/**
 * This method tests the ResourceMbean.
 * 
 * @param args
 * @exception Exception
 */
 public void run(String[] args) {

  try {

	System.out.println("Connecting to the application server.......");

        /*************************************************************************/
        /**    Initialize the AdminClient                                        */
        /*************************************************************************/	
	Properties adminProps = new Properties();
	adminProps.setProperty(AdminClient.CONNECTOR_TYPE, AdminClient.CONNECTOR_TYPE_SOAP);
	adminProps.setProperty(AdminClient.CONNECTOR_HOST, host);
	adminProps.setProperty(AdminClient.CONNECTOR_PORT, port);
	AdminClient adminClient = null;
	try {
	    adminClient = AdminClientFactory.createAdminClient(adminProps);
	} catch (com.ibm.websphere.management.exception.ConnectorException ce) {
  	    	    System.out.println("NLS: Cannot make a connection to the application server\n");
	    	    ce.printStackTrace();
	    			System.exit(1);
	}

       /*************************************************************************/
       /**    Locate the Mbean                                                  */
       /*************************************************************************/
	ObjectName handle = null;
	try {
                // Send in a locator string
                // eg for a Base installation this is enough
                ObjectName queryName = new ObjectName("WebSphere:type=DataSourceCfgHelper,*");

                // for ND you need to specify which node/process you would like to test from
                // eg run in the server
//ND: ObjectName queryName = new OjectName
								("WebSphere:cell=catNetwork,node=cat,process=server1,type=DataSourceCfgHelper,*");
                // eg run in the node agent
//ND: ObjectName queryName = new ObjectName
								("WebSphere:cell=catNetwork,node=cat,process=nodeagent,type=DataSourceCfgHelper,*");
//ND: eg run in the   Manager
//ND: ObjectName queryName = new ObjectName
						("WebSphere:cell=catNetwork,node=catManager,process=dmgr,type=DataSourceCfgHelper,*");
	Set s = adminClient.queryNames(queryName, null);
	Iterator iter = s.iterator();
			while (iter.hasNext()) {
                // use the first MBean that is found
	 			 	handle = (ObjectName) iter.next();
		System.out.println("Found this ->" + handle);
		}
				if (handle == null) {
			System.out.println("NLS: Did not find this MBean>>" + queryName);
						System.exit(1);
		}
	} catch (MalformedObjectNameException mone) {
		System.out.println("Check the program variable queryName" + mone);
		} catch (com.ibm.websphere.management.exception.ConnectorException ce) {
		System.out.println("Cannot connect to the application server" + ce);
	}

         /*************************************************************************/
         /**           Build parameters to pass to Mbean                          */
         /*************************************************************************/
		String[] signature = { "java.lang.String" };
		Object[] params = { resURI };
	Object result = null;

       	if (verbose) {
				System.out.println("\nTesting connection to the database using" + handle);
	}

	try {
               /*************************************************************************/
               /**  Start to test the connection to the database                        */
               /*************************************************************************/
				result = adminClient.invoke(handle, "testConnection", params, signature);
	} catch (MBeanException mbe) {
				// ****** all user exceptions come in here
		if (verbose) {
						Exception ex = mbe.getTargetException(); // this is the real exception from the Mbean
						System.out.println("\nNLS:Mbean Exception was received contains" + ex);
			            ex.printStackTrace();
						System.exit(1);
		}
	} catch (InstanceNotFoundException infe) {
				System.out.println("Cannot find" + infe);
	} catch (RuntimeMBeanException rme) {
		Exception ex = rme.getTargetException();
		ex.printStackTrace(System.out);
		         throw ex;
	} catch (Exception ex) {
				System.out.println("\nUnexpected Exception occurred:" + ex);
		            ex.printStackTrace();
	}

         /*************************************************************************/
         /**  Process the result. The result will be the number of warnings      */
         /**  issued. A result of 0 indicates a successful connection with       */
         /**  no warnings. */
         /*************************************************************************/

		//A result of 0 indicates a successful connection with no warnings.
		System.out.println("Result=" + result);

  } catch (RuntimeOperationsException roe) {
	Exception ex = roe.getTargetException();
	ex.printStackTrace(System.out);
  } catch (Exception ex) {
		System.out.println("General exception occurred");
	ex.printStackTrace(System.out);
  }
 }
}
팁: 기존 데이터 소스와 동일한 레벨에서 연결 테스트 서비스를 실행하십시오. 예를 들어, 데이터 소스가 서버 레벨에 구성되어 있는 경우 노드 레벨에서 연결 테스트 서비스를 실행하지 마십시오. 연결 테스트 서비스 및 데이터 소스 구성이 다른 레벨에 있는 경우, 로드 실패 예외가 발생할 수 있습니다. 이 경우, 시스템에서 db2profile 스크립트를 소스화하고 환경에 DB2® 기본 라이브러리의 포인터가 포함되어 있는지 확인하십시오. db2profile 스크립트는 DB2 사용자 ID의 루트 디렉토리에 있습니다.

주제 유형을 표시하는 아이콘 개념 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-base-dist&topic=cdat_testcon
파일 이름:cdat_testcon.html