package com.sun.eportal.provider; /* * * Copyright 2002 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * @author: Ramesh Mandava */ import javax.xml.registry.*; import javax.xml.registry.infomodel.*; import java.net.*; import java.util.*; /** * The ProviderController class uses the JAXR API to publish * information about an Organization, Service, etc. in a registry. * The class also deletes an organization from a registry * if the organization key is specified. */ public class ProviderController { Connection connection = null; RegistryService rs = null; BusinessLifeCycleManager lifeCycleManager = null; BusinessQueryManager queryManager = null; //String queryURL = "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi"; //String publishURL = "https://www-3.ibm.com/services/uddi/testregistry/protect/publishapi"; String queryURL = "http://steffi.sfbay.sun.com:8080/registry-server/RegistryServerServlet"; String publishURL = "http://steffi.sfbay.sun.com:8080/registry-server/RegistryServerServlet"; //String userName = "user-name"; // User must supply user name for access to the registry //String password = "user-password"; // User must supply password for access to the registry String userName = "testuser"; String password = "testuser"; String deleteKey=""; // Key of the Organization to be deleted from the registry // To publish, set toPublish to true // To delete, set toDelete to true boolean toPublish = false; boolean toDelete = false; /* String httpProxyHost = ""; String httpProxyPort = ""; String httpsProxyHost = ""; String httpsProxyPort = ""; */ String httpProxyHost = "webcache.sfbay.sun.com"; String httpProxyPort = "8080"; String httpsProxyHost = "webcache.sfbay.sun.com"; String httpsProxyPort = "8080"; public void setHttpProxyHost ( String proxyHost ) { this.httpProxyHost = proxyHost; } public void setHttpProxyPort ( String httpPort ) { this.httpProxyPort = httpPort; } public void setHttpsProxyHost ( String httpsHost ) { this.httpsProxyHost = httpsHost; } public void setHttpsProxyPort ( String httpsPort ) { this.httpsProxyPort = httpsPort; } public String getHttpProxyHost ( ) { return httpProxyHost ; } public String getHttpProxyPort ( ) { return httpProxyPort ; } public String getHttpsProxyHost ( ) { return httpsProxyHost ; } public String getHttpsProxyPort ( ) { return httpsProxyPort ; } public void setToPublish( boolean toPublish ) { this.toPublish = toPublish; this.toDelete = !toPublish; } public void setToDelete( boolean toDelete ) { this.toDelete= toDelete; this.toPublish = !toDelete; } public void setPublishURL ( String publishURL ) { this.publishURL = publishURL; } public String getPublishURL ( ) { return publishURL; } public void setQueryURL ( String queryURL ) { this.queryURL = queryURL; } public String getQueryURL ( ) { return queryURL; } public void setUserName ( String userName ) { this.userName = userName; } public String getUserName ( ) { return userName; } public void setPassword ( String password ) { this.password = password; } public String getPassword ( ) { return password; } public boolean getToPublish( ) { return toPublish; } public boolean getToDelete( ) { return toDelete; } public String getDeleteKey( ) { return deleteKey; } public ProviderController(String userName, String password, String queryURL, String publishURL) { this.queryURL = queryURL; this.publishURL = publishURL; this.userName = userName; this.password = password; this.toPublish = true; } public ProviderController(String userName, String password, String queryURL, String publishURL, String deleteKey ) { this.queryURL = queryURL; this.publishURL = publishURL; this.userName = userName; this.password = password; this.deleteKey = deleteKey; this.toDelete = true; } public ProviderController( String userName, String password ) { this.userName = userName; this.password = password; this.toPublish = true; } public ProviderController( String userName, String password, String deleteKey ) { this.userName = userName; this.password = password; this.deleteKey = deleteKey; this.toDelete = true; } public ProviderController( ) { System.out.println("Default Constructor --" + " used mainly if this is a bean from a JSP"); } public static void usage( ) { System.out.println("Usage:\n java ProviderController \n OR \n"); System.out.println("Usage:\n java ProviderController \n OR \n"); System.out.println("Usage:\n java ProviderController \n OR \n"); System.out.println("java ProviderController "); } /** main method */ public static void main(String[] args) { ProviderController registryController; if ( args.length==2 ) { // Got only userName and password registryController = new ProviderController( args[0], args[1]); } else if ( args.length==3 ) { //Got userName, password, deleteKey registryController = new ProviderController( args[0], args[1], args[2]); } else if ( args.length == 4 ) { //Got userName, password, queryURL, publishURL registryController = new ProviderController( args[0], args[1], args[2], args[3]); } else if ( args.length == 5 ) { //Got userName, password, queryURL, publishURL, deleteKey registryController = new ProviderController( args[0], args[1], args[2], args[3], args[4]); } else { usage(); return; } // Gets connection to the registry. If it returns a non-null value, // assumes that the Connection, Registry Service, Business Query // Manager, Business Lifecycle manager instances are available in the // appropriate variables if ( registryController.getConnection()== null ) { System.out.println("Problems while getting the connection to registry"); return; } if ( registryController.getToPublish( ) ) { String publishedOrgKey=""; System.out.println("Publishing Aerns and Cable organization" ); publishedOrgKey = registryController.publish( "Aerns and Cable" , "One Stop for all Books", "Bhakti Mehta" , "bhakti.mehta@ae.com" , "http://localhost:8080/ancbooks/bookordering" ); System.out.println("Published Organization Key : " + publishedOrgKey ); System.out.println("Publishing Fun Books organization" ); publishedOrgKey = registryController.publish( "Fun Books" , "Best Stop for all Fun Books", "Bhakti Mehta" , "bhakti.mehta@fb.com" , "http://localhost:8080/funbooks/bookordering" ); System.out.println("Published Organization Key : " + publishedOrgKey ); System.out.println("\nYou need to submit this as a parameter for a delete operation"); System.out.println("Publishing PanAmerican Service" ); publishedOrgKey = registryController.publishRetirementService("Pan American Service", "Pan American Retirement Service" , "Scott Mcnealy" , "scott@panamerican.com" , "http://localhost:8080/PanAmericanRS/jaxrpc/RetirementServiceIF"); System.out.println("Published Pan American Organization Key : " + publishedOrgKey ); System.out.println("\nYou need to submit this as a parameter for a delete operation"); System.out.println("Retirement Specialists" ); publishedOrgKey = registryController.publishRetirementService("Retirement Specialists", "Retirement Service Provider" , "Vinay Pai" , "vinay.pai@retirementspecialists.com" , "http://localhost:8080/RetirementSpecialistsRS/jaxrpc/RetirementServiceIF"); System.out.println("Published Retirement Specialists : " + publishedOrgKey ); } else { System.out.println("\nDeleting previously published organization which has key : " + registryController.getDeleteKey( ) ); registryController.delete( registryController.getDeleteKey( ) ); } //Close connection etc registryController.cleanup(); } /** Cleanup : freeing resources */ public void cleanup( ) { if ( connection != null ) { try { connection.close(); } catch ( JAXRException je ) { System.err.println("Error while closing Connection: " + je ); } } } /** * Establishes a connection to a registry. * */ public Connection getConnection() { /** If connection is already made to registry, use that connection only */ if ( connection != null ) { return connection; } try { // Create a connection to the registry // after setting standard JAXR properties such as: // javax.xml.registry.queryManagerURL, // javax.xml.registry.lifeCycleManagerURL ( for doing publish/delete ) // javax.xml.registry.factoryClass ConnectionFactory factory = ConnectionFactory.newInstance(); // Define connection configuration properties Properties props = new Properties(); props.setProperty("javax.xml.registry.queryManagerURL", queryURL); props.setProperty("javax.xml.registry.lifeCycleManagerURL", publishURL); props.setProperty("javax.xml.registry.factoryClass", "com.sun.xml.registry.uddi.ConnectionFactoryImpl"); props.setProperty("javax.xml.registry.http.proxyHost", httpProxyHost ); props.setProperty("javax.xml.registry.http.proxyPort", httpProxyPort ); props.setProperty("javax.xml.registry.https.proxyHost", httpProxyHost ); props.setProperty("javax.xml.registry.https.proxyPort", httpProxyPort ); factory.setProperties(props); System.out.println("Created connection to registry"); connection = factory.createConnection(); rs = connection.getRegistryService(); System.out.println("Getting Business Life Cycle Manager"); lifeCycleManager = rs.getBusinessLifeCycleManager(); System.out.println("Getting Business Query Manager"); queryManager = rs.getBusinessQueryManager(); // Costructing Authorization Token PasswordAuthentication passwdAuth = new PasswordAuthentication(userName, password.toCharArray()); Set credentials = new HashSet(); credentials.add(passwdAuth); System.out.println("setting security credentials on the connection"); connection.setCredentials(credentials); return connection; } catch (Exception e) { e.printStackTrace(); if (connection != null) { try { connection.close(); } catch (JAXRException je) {} } return null; } } /** * Creates an organization, its classification, and its * services, and saves it to the registry. */ public String publishRetirementService( String orgName , String orgDescription, String contact, String email, String endpoint) { try { System.out.println("Publishing to URL -> " + publishURL ); // Create organization //Organization org = lifeCycleManager.createOrganization("Pan American Services"); Organization org = lifeCycleManager.createOrganization(orgName ); InternationalString orgDesc = lifeCycleManager.createInternationalString(orgDescription); //lifeCycleManager.createInternationalString("Number 1 Retirement services provider in USA"); // Setting description about Organization org.setDescription(orgDesc); // Create primary contact, set name User primaryContact = lifeCycleManager.createUser(); PersonName pName = lifeCycleManager.createPersonName(contact); primaryContact.setPersonName(pName); // Set primary contact phone number TelephoneNumber tNum = lifeCycleManager.createTelephoneNumber(); tNum.setNumber("(408)1234567"); Collection phoneNums = new ArrayList(); phoneNums.add(tNum); primaryContact.setTelephoneNumbers(phoneNums); // Set primary contact email address EmailAddress emailAddress = lifeCycleManager.createEmailAddress(email); //lifeCycleManager.createEmailAddress("bhakti.mehta@panamerican.com"); Collection emailAddresses = new ArrayList(); emailAddresses.add(emailAddress); primaryContact.setEmailAddresses(emailAddresses); // Set primary contact for organization org.setPrimaryContact(primaryContact); Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC); // Set classification scheme to NAICS ClassificationScheme cScheme = queryManager.findClassificationSchemeByName(findQualifiers, "ntis-gov:naics"); // Create and add classification Classification classification = (Classification) lifeCycleManager.createClassification(cScheme, "Pension Funds", "52511"); Collection classifications = new ArrayList(); classifications.add(classification); /* System.err.println("Trying to get uddiOrgTypes " ); //Use the well-known ID for tModel with name uddi-org:types ClassificationScheme uddiOrgTypes = (ClassificationScheme)queryManager.getRegistryObject("uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4"); System.err.println("uddiOrgTypes -> " + uddiOrgTypes ); Classification wsdlSpecClassification = lifeCycleManager.createClassification(uddiOrgTypes, "wsdlSpec", "wsdlSpec"); System.err.println("wsdlSpecClassification -> " + wsdlSpecClassification ); classifications.add(wsdlSpecClassification); System.err.println("After adding wsdlSpec Classification to classifications" ); */ org.addClassifications(classifications); /* Collection oelinks = new ArrayList( ); ExternalLink oelink = lifeCycleManager.createExternalLink( "http://www.verticalorganization.com/books/books.wsdl" , "WSDL document describing the book ordering service interface" ); oelinks.add( oelink ); org.addExternalLinks ( oelinks ); System.err.println("After adding Classifications to Org" ); */ // Create services and service Collection services = new ArrayList(); Service service = lifeCycleManager.createService("Retirement Service"); InternationalString is = lifeCycleManager.createInternationalString("Pension Funds and other retirements services"); service.setDescription(is); // Create service bindings Collection serviceBindings = new ArrayList(); ServiceBinding binding = lifeCycleManager.createServiceBinding(); is = lifeCycleManager.createInternationalString("JAXRPC-FCS (SOAP/HTTP ) based binding "); binding.setDescription(is); binding.setAccessURI(endpoint); //binding.setAccessURI("http://localhost:8080/PanAmericanRS/jaxrpc/RetirementServiceIF"); // Create a Concept for the service type here retirement-service Concept myConcept = (Concept) lifeCycleManager.createObject( LifeCycleManager.CONCEPT ); InternationalString conceptName = lifeCycleManager.createInternationalString("retirement-service"); myConcept.setName ( conceptName ); InternationalString conceptDescription = lifeCycleManager.createInternationalString("Retirement Service[401K funds ]"); myConcept.setDescription( conceptDescription ); // Creates an External Link with External URI pointing to WSDL document describing the service. // Assumes that the WSDL document is standardized by vertical organization and that // all providers providing retirement service implement this ExternalLink elink = lifeCycleManager.createExternalLink( "http://www.verticalorganization.com/retirementservice/retirementservice.wsdl" , "WSDL document describing the retirement( pension funds ) service interface" ); myConcept.addExternalLink( elink ); Collection concepts = new ArrayList(); concepts.add( myConcept ); BulkResponse br = lifeCycleManager.saveConcepts( concepts); Collection conceptKeys = br.getCollection(); Iterator iterator = conceptKeys.iterator(); Key myConceptKey = (Key) iterator.next(); Concept retirementServiceConcept = (Concept) lifeCycleManager.createObject(LifeCycleManager.CONCEPT ); retirementServiceConcept.setKey ( myConceptKey ); Collection slinks = new ArrayList(); SpecificationLink slink = lifeCycleManager.createSpecificationLink(); slink.setSpecificationObject ( retirementServiceConcept ); slink.setUsageDescription ( lifeCycleManager.createInternationalString("Retirement Service Usage Description") ); Collection ups = new ArrayList(); ups.add ("param1 as a check"); slink.setUsageParameters( ups); slinks.add( slink ); binding.addSpecificationLinks( slinks ); serviceBindings.add(binding); // Adds service bindings to service service.addServiceBindings(serviceBindings); // Adds service to services services.add(service); // adding services to organization org.addServices(services); // Adds organization and submits it to registry // Retrieves key if successful Collection orgs = new ArrayList(); orgs.add(org); BulkResponse response = lifeCycleManager.saveOrganizations(orgs); Collection exceptions = response.getExceptions(); if (exceptions == null) { System.out.println("PanAmerican Services Organization is saved"); Collection keys = response.getCollection(); Iterator keyIter = keys.iterator(); if (keyIter.hasNext()) { javax.xml.registry.infomodel.Key orgKey = (javax.xml.registry.infomodel.Key) keyIter.next(); String id = orgKey.getId(); System.out.println("Organization key is " + id); org.setKey(orgKey); return id; } } else { Iterator excIter = exceptions.iterator(); Exception exception = null; while (excIter.hasNext()) { exception = (Exception) excIter.next(); System.err.println("Exception on save: " + exception.toString()); } return null; } } catch (Exception e) { e.printStackTrace(); if (connection != null) { try { connection.close(); } catch (JAXRException je) { System.err.println("Connection close failed"); } } } return null; } /** * Creates an organization, its classification, and its * services, and saves it to the registry. */ public String publish( String orgName, String orgDescription,String contact, String emailid, String endpoint) { try { System.out.println("Publishing to URL -> " + publishURL ); // Create organization //Organization org = lifeCycleManager.createOrganization("Aerns and Cable"); Organization org = lifeCycleManager.createOrganization(orgName); InternationalString orgDesc = lifeCycleManager.createInternationalString(orgDescription ); // Setting description about Organization org.setDescription(orgDesc); // Create primary contact, set name User primaryContact = lifeCycleManager.createUser(); PersonName pName = lifeCycleManager.createPersonName(contact ); primaryContact.setPersonName(pName); // Set primary contact phone number TelephoneNumber tNum = lifeCycleManager.createTelephoneNumber(); tNum.setNumber("(877)1111111"); Collection phoneNums = new ArrayList(); phoneNums.add(tNum); primaryContact.setTelephoneNumbers(phoneNums); // Set primary contact email address EmailAddress emailAddress = lifeCycleManager.createEmailAddress(emailid); Collection emailAddresses = new ArrayList(); emailAddresses.add(emailAddress); primaryContact.setEmailAddresses(emailAddresses); // Set primary contact for organization org.setPrimaryContact(primaryContact); Collection findQualifiers = new ArrayList(); findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC); // Set classification scheme to NAICS ClassificationScheme cScheme = queryManager.findClassificationSchemeByName( findQualifiers, "ntis-gov:naics"); // Create and add classification Classification classification = (Classification) lifeCycleManager.createClassification(cScheme, "Book Stores", "451211"); Collection classifications = new ArrayList(); classifications.add(classification); /* System.err.println("Trying to get uddiOrgTypes " ); //Use the well-known ID for tModel with name uddi-org:types ClassificationScheme uddiOrgTypes = (ClassificationScheme)queryManager.getRegistryObject("uuid:C1ACF26D-9672-4404-9D70-39B756E62AB4"); System.err.println("uddiOrgTypes -> " + uddiOrgTypes ); Classification wsdlSpecClassification = lifeCycleManager.createClassification(uddiOrgTypes, "wsdlSpec", "wsdlSpec"); System.err.println("wsdlSpecClassification -> " + wsdlSpecClassification ); classifications.add(wsdlSpecClassification); System.err.println("After adding wsdlSpec Classification to classifications" ); */ org.addClassifications(classifications); Collection oelinks = new ArrayList( ); ExternalLink oelink = lifeCycleManager.createExternalLink( "http://www.verticalorganization.com/books/books.wsdl" , "WSDL document describing the book ordering service interface" ); oelinks.add( oelink ); org.addExternalLinks ( oelinks ); System.err.println("After adding Classifications to Org" ); // Create services and service Collection services = new ArrayList(); Service service = lifeCycleManager.createService("Online Book Ordering"); InternationalString is = lifeCycleManager.createInternationalString("Ordering books online"); service.setDescription(is); // Create service bindings Collection serviceBindings = new ArrayList(); ServiceBinding binding = lifeCycleManager.createServiceBinding(); is = lifeCycleManager.createInternationalString("JAXM-FCS (SOAP/HTTP ) based binding "); binding.setDescription(is); binding.setValidateURI ( false ); binding.setAccessURI( endpoint); // Create a Concept for the service type here book-ordering Concept myConcept = (Concept) lifeCycleManager.createObject( LifeCycleManager.CONCEPT ); InternationalString conceptName = lifeCycleManager.createInternationalString("book-ordering"); myConcept.setName ( conceptName ); InternationalString conceptDescription = lifeCycleManager.createInternationalString("Online Book Ordering service"); myConcept.setDescription( conceptDescription ); // Creates an External Link with External URI pointing to WSDL document describing the service. // Assumes that the WSDL document is standardized by vertical organization and that // all providers providing online book ordering implement this ExternalLink elink = lifeCycleManager.createExternalLink( "http://www.verticalorganization.com/books/books.wsdl" , "WSDL document describing the book ordering service interface" ); elink.setValidateURI ( false ); myConcept.addExternalLink( elink ); Collection concepts = new ArrayList(); concepts.add( myConcept ); BulkResponse br = lifeCycleManager.saveConcepts( concepts); Collection conceptKeys = br.getCollection(); Iterator iterator = conceptKeys.iterator(); Key myConceptKey = (Key) iterator.next(); Concept bookOrderingConcept = (Concept) lifeCycleManager.createObject(LifeCycleManager.CONCEPT ); bookOrderingConcept.setKey ( myConceptKey ); Collection slinks = new ArrayList(); SpecificationLink slink = lifeCycleManager.createSpecificationLink(); slink.setSpecificationObject ( bookOrderingConcept ); slink.setUsageDescription ( lifeCycleManager.createInternationalString("Usage Description" ) ); Collection ups = new ArrayList(); ups.add ("param1 as a check"); slink.setUsageParameters( ups); slinks.add( slink ); binding.addSpecificationLinks( slinks ); serviceBindings.add(binding); // Adds service bindings to service service.addServiceBindings(serviceBindings); // Adds service to services services.add(service); // adding services to organization org.addServices(services); // Adds organization and submits it to registry // Retrieves key if successful Collection orgs = new ArrayList(); orgs.add(org); BulkResponse response = lifeCycleManager.saveOrganizations(orgs); Collection exceptions = response.getExceptions(); if (exceptions == null) { System.out.println("BooksToGo Organization is saved"); Collection keys = response.getCollection(); Iterator keyIter = keys.iterator(); if (keyIter.hasNext()) { javax.xml.registry.infomodel.Key orgKey = (javax.xml.registry.infomodel.Key) keyIter.next(); String id = orgKey.getId(); System.out.println("Organization key is " + id); org.setKey(orgKey); return id; } } else { Iterator excIter = exceptions.iterator(); Exception exception = null; while (excIter.hasNext()) { exception = (Exception) excIter.next(); System.err.println("Exception on save: " + exception.toString()); } return null; } } catch (Exception e) { e.printStackTrace(); if (connection != null) { try { connection.close(); } catch (JAXRException je) { System.err.println("Connection close failed"); } } } return null; } /** * Removes the organization with the specified keyString value. * * @param keyString the Key of the organization as a String */ public void delete( String keyString ) { try { getConnection(); System.out.println("Deleting from URL : " + publishURL ); // Creating Key object with passed id javax.xml.registry.infomodel.Key key = lifeCycleManager.createKey( keyString); delete ( key ); } catch ( JAXRException je ) { je.printStackTrace(); } } /** * Removes the organization with the specified key value. * * @param key the Key of the organization */ public void delete (javax.xml.registry.infomodel.Key key) { try { String id = key.getId(); System.out.println("Deleting organization with id " + id); Collection keys = new ArrayList(); keys.add(key); BulkResponse response = lifeCycleManager.deleteOrganizations(keys); Collection exceptions = response.getExceptions(); if (exceptions == null) { System.out.println("Organization deleted"); Collection retKeys = response.getCollection(); Iterator keyIter = retKeys.iterator(); javax.xml.registry.infomodel.Key orgKey = null; if (keyIter.hasNext()) { orgKey = (javax.xml.registry.infomodel.Key) keyIter.next(); id = orgKey.getId(); System.out.println("Organization key was " + id); } } else { Iterator excIter = exceptions.iterator(); Exception exception = null; while (excIter.hasNext()) { exception = (Exception) excIter.next(); System.err.println("Exception on delete: " + exception.toString()); } } } catch (Exception e) { e.printStackTrace(); } finally { // At end, close connection to registry if (connection != null) { try { connection.close(); } catch (JAXRException je) { System.err.println("Connection close failed"); } } } } }