⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 submitregistryentry.java

📁 java web services how to program
💻 JAVA
字号:
// Fig. 10.7: SubmitRegistryEntry.java
// Registers Deitel book title service in a UDDI registry.

package com.deitel.jws1.jaxr;

// JAXR core packages
import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;

// java core packages
import java.util.*;
import java.net.PasswordAuthentication;

public class SubmitRegistryEntry {

   // capability interface for querying XML registry
   private BusinessQueryManager queryManager;

   // capability interface for adding, updating, removing entries
   private BusinessLifeCycleManager lifeCycleManager;
   
   // default constructor
   public SubmitRegistryEntry() throws Exception
   {
      // create login password pair
      String userName = "username";
      String password = "password";
      
      // create XMLRegistry manager instance
      XMLRegistryManager registryManager =
         new XMLRegistryManager( userName, password );

      // obtain business query 
      queryManager =
         registryManager.getBusinessQueryManager();
      
      // obtain business life cycle manager reference
      lifeCycleManager =
         registryManager.getBusinessLifeCycleManager();
      
   } // end constructor 
   
   // create Organization object Deitel & Associates
   private Organization createOrganization() 
      throws JAXRException
   {
      // create organization
      Organization organization = 
         lifeCycleManager.createOrganization( 
            "Deitel & Associates" );
      
      // create description string
      InternationalString description =
         lifeCycleManager.createInternationalString(
            "Content providers for Deitel(tm) " +
            "How to Program series and the Deitel " +
            "Developer Series" );     
      
      // set description
      organization.setDescription( description );
      
      // create contact information
      User contact = lifeCycleManager.createUser();
      
      // set contact name
      PersonName name = lifeCycleManager.createPersonName(
         "Kyle Lomeli" );
      
      contact.setPersonName( name );
      
      // set contact phone number
      TelephoneNumber phoneNumber =
         lifeCycleManager.createTelephoneNumber();
      
      phoneNumber.setNumber( "(123) 456-7890" );
      
      Collection phoneNumberList = new ArrayList();
      phoneNumberList.add( phoneNumber );
      
      contact.setTelephoneNumbers( phoneNumberList );
      
      // set contact email addresses
      EmailAddress emailAddress1 =
         lifeCycleManager.createEmailAddress( 
            "deitel@deitel.com" );
      
      EmailAddress emailAddress2 =
         lifeCycleManager.createEmailAddress(
            "Kyle.Lomeli@deitel.net" );
      
      Collection emailAddressList = new ArrayList();
      emailAddressList.add( emailAddress1 );
      emailAddressList.add( emailAddress2 );
      
      contact.setEmailAddresses( emailAddressList );
      
      // set contact information in organization
      organization.setPrimaryContact( contact );
      
      return organization;
      
   } // end method createOrganization

   // create service with appropriate bindings
   private Service createService() throws JAXRException
   {
      // create service
      Service service = lifeCycleManager.createService( 
         "Book Title Service" );
      
      // create service description
      InternationalString description =
         lifeCycleManager.createInternationalString(
            "Provides titles of Deitel books " +
            "corresponding to given ISBN number." );
      
      // set description
      service.setDescription( description );
      
      // create service binding
      ServiceBinding serviceBinding =
         lifeCycleManager.createServiceBinding();
      
      // create service binding description
      InternationalString bindingDescription =
         lifeCycleManager.createInternationalString(
            "Web service BookTitle is deployed on " +
            "an Axis Web services platform. " +
            "Platform set up for moderate use." );
      
      // set description
      serviceBinding.setDescription( bindingDescription );
      
      // set URI for service
      serviceBinding.setAccessURI(
         "http://www.deitel.com:8080/axis/BookTitle" );
                
      // contains location of WSDL document
      SpecificationLink specificationLink =
         lifeCycleManager.createSpecificationLink();

      // create Concept for WSDL link
      // null maps the element to tModel 
      Concept wsdlConcept = 
         lifeCycleManager.createConcept( 
            null, "wsdlSpec", "wsdlSpec" );

      // define key for wsdl concept
      Key wsdlKey = lifeCycleManager.createKey( 
         "uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4" );

      // set concept key
      wsdlConcept.setKey( wsdlKey );

      // set Concept to specification link
      specificationLink.setSpecificationObject( 
         wsdlConcept );

      // define WSDL URL
      String wsdlURL = 
         "http://www.deitel.com:8080/axis/BookTitle?wsdl";
         
      String wsdlDescription = 
         "WSDL for Web service BookTitle";
      
      // create link to wsdl document
      ExternalLink wsdlURI = 
         lifeCycleManager.createExternalLink(
            wsdlURL, wsdlDescription );
      
      // add reference to WSDL file to specification link
      specificationLink.addExternalLink( wsdlURI );
      
      // add reference to WSDL file to concept
      wsdlConcept.addExternalLink( wsdlURI );      

      // add WSDL URL to service binding
      serviceBinding.addSpecificationLink( 
         specificationLink );
      
      // create ArrayList of service bindings
      Collection bindingList = new ArrayList();
      bindingList.add( serviceBinding );
      
      // add service binding Collection to service
      service.addServiceBindings( bindingList );
      
      return service;
   } // end method createService

   // create classification based on business role
   private Classification createBusinessClassification()
      throws JAXRException
   {       
      // create classification scheme
      ClassificationScheme classificationScheme =
         queryManager.findClassificationSchemeByName(
            null, "ntis-gov:naics" );
      
      // create classification
      Classification classification = 
         lifeCycleManager.createClassification(
            classificationScheme,
            "Educational Support Services",
            "61171" );
      
      return classification;
      
   } // end method createBusinessClassification

   // create classification based on business location
   private Classification createLocationClassification() 
      throws JAXRException
   {
      // create classification scheme
      ClassificationScheme classificationScheme =
         queryManager.findClassificationSchemeByName(
            null, "iso-ch:3166:1999" );
      
      // create concept
      Classification classification =
         lifeCycleManager.createClassification(
            classificationScheme, "UNITED STATES", "US" );
      
      return classification;
  
   } // end method createLocationClassification

   // construct and initialize an organization
   // to submit to registry
   public Organization getOrganization()
      throws JAXRException
   {
      // create organization
      Organization organization = createOrganization();
      
      // create service descriptor object
      Service service = createService();
      
      Collection serviceList = new ArrayList();
      serviceList.add( service );
      
      // set service descriptor
      organization.addServices( serviceList );
      
      // create business classifications
      Classification businessClassification =
         createBusinessClassification();
      
      Classification locationClassification =
         createLocationClassification();
      
      Collection classificationList = new ArrayList();
      classificationList.add( businessClassification );
      classificationList.add( locationClassification );
      
      // set business classification
      organization.setClassifications( classificationList );
      
      return organization;
      
   } // end method getOrganization

   // save organization object in registry
   public Organization register( Organization organization )
      throws JAXRException
   {
      // create Collection of organizations
      Collection organizationList = new ArrayList();
      organizationList.add( organization );
      
      // submit organization
      BulkResponse bulkResponse = 
         lifeCycleManager.saveOrganizations( organizationList );
      
      // obtain submission keys
      Collection keyCollection = 
         bulkResponse.getCollection();

      // ensure Collection not null
      if ( keyCollection != null ) {

         Iterator keys = keyCollection.iterator();
         
         // assign key if exists
         if ( keys.hasNext() ) {
            Key assignedKey = ( Key )keys.next();
            organization.setKey( assignedKey );
         }
      } // end if

      // ensure no exceptions occurred
      Collection exceptionCollection = 
         bulkResponse.getExceptions();

      if ( exceptionCollection != null ) {
         
         // display exceptions
         Iterator exceptions = 
            exceptionCollection.iterator();
         
         while ( exceptions.hasNext() ) {
            JAXRException exception =
               ( JAXRException )exceptions.next();
            
            exception.printStackTrace();
         }
      } // end if
      
      return organization;
      
   } // end method register
   
   // entry point for class ServiceRegister
   public static void main( String[] args ) 
   {
      try {
         
         SubmitRegistryEntry serviceRegister =
            new SubmitRegistryEntry();
         
         // create Deitel organization
         Organization deitelOrganization =
            serviceRegister.getOrganization();
                  
         // register organization
         deitelOrganization =
            serviceRegister.register( deitelOrganization );
         
         // obtain key if submission successful
         Key assignedKey = deitelOrganization.getKey();
         
         // print results if key exists
         if ( assignedKey != null ) {
         
            System.out.println( "Submission successful!" );
            System.out.println( "Service registered with key: " +
                assignedKey.getId() );
         } // end if
         
      } // end try
      
      catch ( Exception exception ) {
         exception.printStackTrace();
      }
   } // end method main
   
} // end class SubmitRegistryEntry

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -