상세 컨텐츠

본문 제목

Chapter 4 UDDI - 4

프로그래밍/웹서비스

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

본문


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.BusinessQueryManager;
import javax.xml.registry.Connection;
import javax.xml.registry.ConnectionFactory;
import javax.xml.registry.FindQualifier;
import javax.xml.registry.JAXRException;
import javax.xml.registry.RegistryService;
import javax.xml.registry.infomodel.ExternalLink;
import javax.xml.registry.infomodel.InternationalString;
import javax.xml.registry.infomodel.Organization;
import javax.xml.registry.infomodel.RegistryObject;
import javax.xml.registry.infomodel.Service;
import javax.xml.registry.infomodel.ServiceBinding;
import javax.xml.registry.infomodel.SpecificationLink;
 
 
public class uddiFindWebService {
 
    public void exec()
    throws JAXRException {
 
                                   // RegistryService 객체 생성
                                   RegistryService rs =
            getConnection().getRegistryService();
 
                                   // 인쿼리 작업을 위해서 BusinessQueryManager 객체 생성
                                   BusinessQueryManager bqm =
            rs.getBusinessQueryManager();
 
                                   // 검색된 결과를 소팅하기 위해 Collection 객체 생성
                                   Collection  findQualifiers = new ArrayList();
                                   findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
 
        // 회사 이름으로 찾기 위해 Collenction 객체 생성
        Collection namePatterns = new ArrayList();
        namePatterns.add("%test%");
       
        // 회사 이름으로 찾기
        BulkResponse response =
            bqm.findOrganizations(findQualifiers, namePatterns, null, null, null, null);
   
                                   // 검색된 모든 회사(Organization) 얻어냄
                                   Collection orgCollection = response.getCollection();
                                   Iterator orgIterator = orgCollection.iterator();
 
        while (orgIterator.hasNext()) {
            // 한개의 회사(Organization) 뽑아
            Organization org = (Organization) orgIterator.next();
            // businessService 엘리먼트 내용에 대한 정보 얻기
            System.out.println("n---businessService 엘리먼트 내용에 대한 정보 얻기---");
            // 서비스 정보 얻기
            Collection serviceCollection = org.getServices();
            Iterator serviceIterator = serviceCollection.iterator();
 
            printWSList(serviceIterator);
        }
    }          
 
    /**
     * 서비스 리스트 출력
     * @param serviceIterator
     * @throws javax.xml.registry.JAXRException
     */
    void printWSList(Iterator serviceIterator)
    throws JAXRException {
        while (serviceIterator.hasNext()) {
            Service service = (Service)serviceIterator.next();
            InternationalString localeServiceName = service.getName();
            InternationalString localeServiceDesc = service.getDescription();
            String strServiceName = localeServiceName.getValue(Locale.ENGLISH);
            String strServiceDesc = localeServiceDesc.getValue(Locale.ENGLISH);
            System.out.println(" 서비스 이름: " + strServiceName);
            System.out.println(" 서비스 설명: " + strServiceDesc);
            System.out.println("n---bindingTemplate 엘리먼트 내용에 대한 정보 얻기---");
            Collection serviceBindingCollection = service.getServiceBindings();
            Iterator serviceBindingIterator = serviceBindingCollection.iterator();
            printWSBindingList(serviceBindingIterator);
        }
    }
 
    /**
     * 서비스 바인딩 리스트 출력
     * @param serviceBindingIterator
     * @throws javax.xml.registry.JAXRException
     */
    void printWSBindingList(Iterator serviceBindingIterator)
    throws JAXRException {
        while (serviceBindingIterator.hasNext()) {
            ServiceBinding serviceBinding = (ServiceBinding)serviceBindingIterator.next();
            String strAccessPointURL = serviceBinding.getAccessURI();
            InternationalString localeAccssPointDesc = serviceBinding.getDescription();
            String strAccessPointDesc = localeAccssPointDesc.getValue(Locale.ENGLISH);
            System.out.println(" 서비스 종점 URL: " + strAccessPointURL);
            System.out.println(" 서비스 종점 설명: " + strAccessPointDesc);
            Collection specificaionLinksCollection = serviceBinding.getSpecificationLinks();
            Iterator specificaionLinksIterator = specificaionLinksCollection.iterator();
            printTmodeList(specificaionLinksIterator);
        }
    }
 
    /**
     * tModeList 출력
     * @param specificaionLinksIterator
     * @throws javax.xml.registry.JAXRException
     */
    void printTmodeList(Iterator specificaionLinksIterator)
    throws JAXRException {
        while (specificaionLinksIterator.hasNext()) {
            SpecificationLink specificationLink = (SpecificationLink)specificaionLinksIterator.next();
            System.out.println("n---참조하는 tModel 엘리먼트 내용에 대한 정보 얻기---");
            RegistryObject registryObject = specificationLink.getSpecificationObject();
            InternationalString localeTModelName = registryObject.getName();
            String strTModelName = localeTModelName.getValue();
            System.out.println("tModel 이름: " + strTModelName);
            InternationalString localeRegistryObject = registryObject.getDescription();
            String strTModelDesc = localeRegistryObject.getValue(Locale.ENGLISH);
            System.out.println("tModel 설명: " + strTModelDesc);
            System.out.println("n---overviewDoc 엘리먼트 내용에 대한 정보 얻기---");
            Collection externalLinksCollection = registryObject.getExternalLinks();
            Iterator externalLinksIterator = externalLinksCollection.iterator();
            printWSDLList(externalLinksIterator);
        }
    }
 
    /**
     * WSDL 문서 정보 출력
     * @param externalLinksIterator
     * @throws javax.xml.registry.JAXRException
     */
    void printWSDLList(Iterator externalLinksIterator)
    throws JAXRException {
        while (externalLinksIterator.hasNext()) {
            ExternalLink externalLink = (ExternalLink)externalLinksIterator.next();
            String strWSDLURL = externalLink.getExternalURI();
            System.out.println("WSDL 문서 URL: " + strWSDLURL);
            InternationalString localeWSDLDesc = externalLink.getDescription();
            String strWSDLDesc = localeWSDLDesc.getValue(Locale.ENGLISH);
            System.out.println("WSDL 문서 설명: " + strWSDLDesc);
        }
    }
 
    /**
     * Connection 객체를 생산하는 ConnectionFactory 객체 생성
     * JAXR 프로바이더의 연결을 위한 Connection 객체 생성
     * @return Connection
     * @throws javax.xml.registry.JAXRException
     */
    Connection getConnection()
    throws JAXRException {
        ConnectionFactory factory = ConnectionFactory.newInstance();
        factory.setProperties(setProperty());
        Connection connection = factory.createConnection();
        return connection;
    }
 
    /**
     * JAXR 프로바이더와 연결하기 위한 정보 셋팅
     * @return 프로퍼티
     */
    Properties setProperty() {
        Properties props = new Properties();
        props.setProperty("javax.xml.registry.queryManagerURL",
                          "http://uddi.microsoft.com/inquire");
        return props;
    }
 
    public static void main(String[] args) {
        uddiFindWebService uddiClient = new uddiFindWebService();
        try {
            uddiClient.exec();
        } catch (JAXRException e) {
            e.printStackTrace(); 
        }
    }
}
 
결과
---businessService 엘리먼트 내용에 대한 정보 얻기---
웹 서비스 이름: null
웹 서비스 설명: null
---bindingTemplate 엘리먼트 내용에 대한 정보 얻기---
웹 서비스 종점 URL: CMS
웹 서비스 종점 설명: null
---참조하는 tModel 엘리먼트 내용에 대한 정보 얻기---
tModel 이름: UDDI_tModel
tModel 설명: null
---overviewDoc 엘리먼트 내용에 대한 정보 얻기---
WSDL 문서 URL: http://203.247.150.218/CMS/webServiceProductInfo/wsProductInfo.asmx
WSDL 문서 설명: null
 
 
회사가 제공하는 웹 서비스 이름 및 설명은 UDDI 레지스트리에 저장되어 있는 <businessEntity> 엘리먼트의 자손 엘리먼트인 <businessService> 엘리먼트의 컨텐트에 있다. 웹 서비스 이름 및 설명을 얻기 위해서는 <businessService> 엘리먼트에 대한 JAXR 정보 모델인 Service 객체를 얻어야 한다.
 
웹 서비스 종점 URL 및 설명은 UDDI 레지스트리에 저장되어 있는 <businessService> 엘리먼트의 자손 엘리먼트인 <bindingTemplate> 엘리먼트의 컨텐트이다. 웹 서비스 종점 URL 및 설명을 얻기 위해서는 <bindingTemplate> 엘리먼트에 대한 JAXR 정보모델인 ServiceBinding 객체를 얻어야 한다.
 
<businessEntity> 엘리먼트가 참조하는 tModel Key 정보는 UDDI 레지스트리에 저장되어 있는 <bindingTemplate> 엘리먼트의 자손 엘리먼트인 <tModelInstanceInfo> 엘리먼트의 속성인 tModelKey의 속성값에 있다. <businessEntity> 엘리먼트가 참조하는 tModel Key 정보를 얻기 위해서는 <tModelInstanceInfo> 엘리먼트에 대한 JAXR 정보 모델인 SpecificationLink 객체를 얻어야 한다.
 
회사가 제공하는 웹 서비스에 대한 테크니컬 명세가 기술되어 있는 WSDL 문서 URL 및 설명은 UDDI 레지스트리에 저장되어 있는 <tModel> 엘리먼트의 자손 엘리먼트 <overviewDoc> 엘리먼트의 컨텐트이다. WSDL 문서 URL 및 설명은 얻기 위해서는 <overviewDoc> 엘리먼트에 대한 JAXR 정보 모델인 ExternalLink 객체를 얻어야 한다.

 

관련글 더보기