상세 컨텐츠

본문 제목

Chapter 4 UDDI - 3

프로그래밍/웹서비스

by 라제폰 2008. 12. 13. 19:38

본문

JAXR을 이용한 UDDI 레지스트리 검색 분류 체계로 회사 정보 찾기
package webservice.uddi;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;
 
import javax.xml.registry.BulkResponse;
import javax.xml.registry.BusinessLifeCycleManager;
import javax.xml.registry.BusinessQueryManager;
import javax.xml.registry.Connection;
import javax.xml.registry.ConnectionFactory;
import javax.xml.registry.JAXRException;
import javax.xml.registry.RegistryService;
import javax.xml.registry.infomodel.Classification;
import javax.xml.registry.infomodel.ClassificationScheme;
import javax.xml.registry.infomodel.InternationalString;
import javax.xml.registry.infomodel.Organization;
 
 
public class uddiFindClassification {
 
    public void exec()
    throws JAXRException {
 
        // RegistryService 객체 생성
        RegistryService rs =
            getConnection().getRegistryService();
       
        // 인쿼리 작업을 위해서 BusinessQueryManager 객체 생성
        BusinessQueryManager bqm =
            rs.getBusinessQueryManager();
       
        // 퍼블리싱 작업을 위해서 BusinessLifeCycleManager 객체 생성
        BusinessLifeCycleManager blcm =
            rs.getBusinessLifeCycleManager();
 
        // classification 하는 역할은 어떤 분류 체계를 사용할 것인가에 대한 정보와
        // 해당 분류 체계에서 어떤 분류 항목에 대해서 찾을 것인가를
        // 지정하기 위해서 사용된다.
        Collection classifications = new ArrayList();
       
        // 사용할 분류 체계를 지정하기 위한 정보 저장
        ClassificationScheme cScheme =
            bqm.findClassificationSchemeByName(null,"uddi-org:iso-ch:3166:1999");
           
        Classification classification =
            blcm.createClassification(cScheme, "Korea, Republic of", "KR");
        classifications.add(classification);
       
        // ---- 분류 체계로 찾기 ----
        BulkResponse response =
            bqm.findOrganizations(null, null, classifications, null, null, null);
   
                                   // 검색된 모든 회사(Organization) 얻어냄
                                   Collection orgCollection = response.getCollection();
                                   Iterator orgIterator = orgCollection.iterator();
 
        while (orgIterator.hasNext()) {
            // 한개의 회사(Organization) 뽑아
            Organization org = (Organization) orgIterator.next();
            // businessEntity 엘리먼트 내용에 대한 정보 얻기
            System.out.println("n---businessEntity 엘리먼트 내용에 대한 정보 얻기---");
            // 회사 이름 설명 얻기
            InternationalString localeOrgName = org.getName();
            InternationalString localeOrgDesc = org.getDescription();
            String strOrgName = localeOrgName.getValue(Locale.ENGLISH);
            String strOrgDesc = localeOrgDesc.getValue(Locale.ENGLISH);
            System.out.println("회사 이름: " + strOrgName);
            System.out.println("회사 설명: " + strOrgDesc);
        }
    }  
   
    /**
     * Connection 객체를 생산하는 ConnectionFactory 객체 생성
     * JAXR 프로바이더의 연결을 위한 Connection 객체 생성
     * @return Connection 객체
     * @throws javax.xml.registry.JAXRException
     */
    private Connection getConnection()
    throws JAXRException {
        ConnectionFactory factory = ConnectionFactory.newInstance();
        factory.setProperties(setProperty());
        Connection connection = factory.createConnection();
        return connection;
    }
 
    /**
     * JAXR 프로바이더와 연결하기 위한 정보 셋팅
     * @return 프로퍼티
     */
    private Properties setProperty() {
        Properties props = new Properties();
        props.setProperty("javax.xml.registry.queryManagerURL", "http://uddi.ibm.com/testregistry/inquiryapi");
        props.setProperty("javax.xml.registry.lifeCycleManagerURL", "https://uddi.ibm.com/testregistry/publishapi");
        return props;
    }
 
    public static void main(String[] args) {
        uddiFindClassification uddiClient = new uddiFindClassification();
        try {
            uddiClient.exec();
        } catch (JAXRException e) {
            e.printStackTrace();
        }
    }
}
 
결과
---businessEntity 엘리먼트 내용에 대한 정보 얻기---
회사 이름: 9works
회사 설명: null
---businessEntity 엘리먼트 내용에 대한 정보 얻기---
회사 이름: ABCD corporation 2
회사 설명: this is a good corporation.
---businessEntity 엘리먼트 내용에 대한 정보 얻기---
회사 이름: BoardersHigh
회사 설명: null
분류 체계명
uddi-org:iso-ch:3166:1999 à 지역적 분류 체계
unspsc-org:unspsc:3-1 à 제품 코드에 의한 분류 체계

참고 : 위 예제를 실행 시키면 결과 출력이 오래 걸립니다. 인내와 끈기를 가지고 기다리십시오. ^^

 


관련글 더보기