1 25 package olstore.client; 26 27 import java.net.PasswordAuthentication; 28 import java.util.ArrayList; 29 import java.util.Collection; 30 import java.util.HashSet; 31 import java.util.Iterator; 32 import java.util.List; 33 import java.util.Properties; 34 import java.util.Set; 35 36 import javax.xml.registry.BulkResponse; 37 import javax.xml.registry.BusinessQueryManager; 38 import javax.xml.registry.Connection; 39 import javax.xml.registry.ConnectionFactory; 40 import javax.xml.registry.JAXRException; 41 import javax.xml.registry.RegistryService; 42 import javax.xml.registry.infomodel.ExternalLink; 43 import javax.xml.registry.infomodel.Organization; 44 import javax.xml.registry.infomodel.Service; 45 import javax.xml.registry.infomodel.ServiceBinding; 46 import javax.xml.registry.infomodel.SpecificationLink; 47 48 51 public class RegistryConnector { 52 53 54 private Connection connection; 55 56 57 private BusinessQueryManager bqm; 58 59 60 private List specialsWSDLLocations; 61 62 63 private List cartWSDLLocations; 64 65 69 public RegistryConnector() { 70 specialsWSDLLocations = new ArrayList(); 71 cartWSDLLocations = new ArrayList(); 72 } 73 74 79 public void retrieveWSDLLocations() throws Exception { 80 if (cartWSDLLocations.isEmpty() || specialsWSDLLocations.isEmpty()) { 82 try { 83 makeConnection(); 84 findWSDLLocations(); 85 closeConnection(); 86 } catch (JAXRException e) { 87 throw new Exception( 88 "Could not retrieve WSDL locations from the UDDI registry.\n" 89 + e.getMessage()); 90 } 91 } 92 } 93 94 98 public void closeConnection() throws JAXRException { 99 connection.close(); 100 } 101 102 106 public void makeConnection() throws Exception { 107 108 Configure config = new Configure(); 109 110 Properties props = new Properties(); 111 props.setProperty("javax.xml.registry.queryManagerURL", config.getProperty("queryURL")); 112 props.setProperty("javax.xml.registry.lifeCycleManagerURL", config.getProperty("publishURL")); 113 114 try { 115 ConnectionFactory factory = ConnectionFactory.newInstance(); 117 factory.setProperties(props); 118 connection = factory.createConnection(); 119 120 RegistryService rs = connection.getRegistryService(); 122 123 bqm = rs.getBusinessQueryManager(); 125 126 PasswordAuthentication passwdAuth = new PasswordAuthentication( 129 config.getProperty("user"), config.getProperty("pass") 130 .toCharArray()); 131 Set creds = new HashSet(); 132 creds.add(passwdAuth); 133 134 connection.setCredentials(creds); 136 137 connection.setSynchronous(true); 139 140 } catch (Exception e) { 141 if (connection != null) { 143 try { 144 connection.close(); 145 } catch (JAXRException je) { 146 throw je; 147 } 148 } 149 throw e; 150 } 151 } 152 153 157 public void findWSDLLocations() throws JAXRException { 158 159 Collection names = new ArrayList(); 160 String orgName = "Red Hat Olstore"; 161 names.add(orgName); 162 163 BulkResponse br = bqm.findOrganizations(null, names, null, null, null, 164 null); 165 Iterator iter = br.getCollection().iterator(); 166 167 while (iter.hasNext()) { 168 Organization org = (Organization) iter.next(); 169 Iterator serviceIter = org.getServices().iterator(); 170 171 while (serviceIter.hasNext()) { 172 Service service = (Service) serviceIter.next(); 173 174 Collection serviceBindings = service.getServiceBindings(); 176 177 Iterator sbIter = serviceBindings.iterator(); 178 while (sbIter.hasNext()) { 179 ServiceBinding serviceBinding = (ServiceBinding) sbIter 180 .next(); 181 182 Collection specificationLinks = serviceBinding 184 .getSpecificationLinks(); 185 186 Iterator linkIter = specificationLinks.iterator(); 187 while (linkIter.hasNext()) { 188 SpecificationLink specificationLink = (SpecificationLink) linkIter 189 .next(); 190 191 Collection externalLinks = specificationLink 193 .getExternalLinks(); 194 195 Iterator elinkIter = externalLinks.iterator(); 196 while (elinkIter.hasNext()) { 197 ExternalLink externalLink = (ExternalLink) elinkIter.next(); 198 String externalURI = externalLink.getExternalURI(); 199 200 if (service.getName().getValue().equals("Red Hat Olstore - Shopping cart")) { 202 cartWSDLLocations.add(externalURI); 203 } else { 204 specialsWSDLLocations.add(externalURI); 205 } 206 207 } 208 } 209 } 210 } 211 } 212 213 } 214 215 220 public List getCartWSDLLocations() { 221 return cartWSDLLocations; 222 } 223 224 229 public List getSpecialsWSDLLocations() { 230 return specialsWSDLLocations; 231 } 232 } 233 | Popular Tags |