[507] | 1 | package gov.hhs.fha.nhinc.connectmgr.uddi;
|
---|
| 2 |
|
---|
| 3 | import gov.hhs.fha.nhinc.connectmgr.data.CMBindingDescriptions;
|
---|
| 4 | import java.util.HashSet;
|
---|
| 5 | import java.util.List;
|
---|
| 6 | import java.util.ArrayList;
|
---|
| 7 |
|
---|
| 8 | import javax.xml.bind.JAXBElement;
|
---|
| 9 |
|
---|
| 10 | import javax.xml.ws.BindingProvider;
|
---|
| 11 |
|
---|
| 12 | import org.uddi.api_v3.BusinessList;
|
---|
| 13 | import org.uddi.api_v3.BusinessInfos;
|
---|
| 14 | import org.uddi.api_v3.BusinessInfo;
|
---|
| 15 | import org.uddi.api_v3.BusinessService;
|
---|
| 16 | import org.uddi.api_v3.ServiceInfo;
|
---|
| 17 | import org.uddi.api_v3.FindBusiness;
|
---|
| 18 | import org.uddi.api_v3.Name;
|
---|
| 19 | import org.uddi.api_v3.GetBusinessDetail;
|
---|
| 20 | import org.uddi.api_v3.BusinessDetail;
|
---|
| 21 | import org.uddi.api_v3.GetServiceDetail;
|
---|
| 22 | import org.uddi.api_v3.ServiceDetail;
|
---|
| 23 | import org.uddi.api_v3.Description;
|
---|
| 24 | import org.uddi.api_v3.BusinessEntity;
|
---|
| 25 | import org.uddi.api_v3.KeyedReference;
|
---|
| 26 | import org.uddi.api_v3.BindingTemplate;
|
---|
| 27 | import org.uddi.v3_service.UDDIService;
|
---|
| 28 | import org.uddi.v3_service.UDDIInquiryPortType;
|
---|
| 29 |
|
---|
| 30 | import org.apache.commons.logging.Log;
|
---|
| 31 | import org.apache.commons.logging.LogFactory;
|
---|
| 32 |
|
---|
| 33 | import gov.hhs.fha.nhinc.properties.PropertyAccessor;
|
---|
| 34 |
|
---|
| 35 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessEntities;
|
---|
| 36 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessEntity;
|
---|
| 37 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessNames;
|
---|
| 38 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessDescriptions;
|
---|
| 39 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessServices;
|
---|
| 40 | import gov.hhs.fha.nhinc.connectmgr.data.CMBusinessService;
|
---|
| 41 | import gov.hhs.fha.nhinc.connectmgr.data.CMBindingNames;
|
---|
| 42 | import gov.hhs.fha.nhinc.connectmgr.data.CMBindingTemplate;
|
---|
| 43 | import gov.hhs.fha.nhinc.connectmgr.data.CMBindingTemplates;
|
---|
| 44 | import gov.hhs.fha.nhinc.connectmgr.data.CMUDDIConnectionInfo;
|
---|
| 45 | import gov.hhs.fha.nhinc.connectmgr.data.CMUDDIConnectionInfoXML;
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * This class is used to retrieve the connection information from the UDDI server.
|
---|
| 49 | *
|
---|
| 50 | * @author Les Westberg
|
---|
| 51 | */
|
---|
| 52 | public class UDDIAccessor
|
---|
| 53 | {
|
---|
| 54 |
|
---|
| 55 | private static Log log = LogFactory.getLog(UDDIAccessor.class);
|
---|
| 56 | private static String GATEWAY_PROPFILE_NAME = "gateway";
|
---|
| 57 | private static String UDDI_INQUIRY_ENDPOINT_URL = "UDDIInquiryEndpointURL";
|
---|
| 58 | private static String UDDI_BUSINESSES_TO_IGNORE = "UDDIBusinessesToIgnore";
|
---|
| 59 | private static String HOME_COMMUNITY_ID_KEY = "uddi:nhin:nhie:homecommunityid";
|
---|
| 60 | private static String UNIFORM_SERVICE_NAME_KEY = "uddi:nhin:service:uniformservicename";
|
---|
| 61 | private static String SERVICE_VERSION_KEY = "uddi:nhin:service:versionofservice";
|
---|
| 62 |
|
---|
| 63 | // URL for the UDDI Server.
|
---|
| 64 | private String m_sUDDIInquiryEndpointURL = "";
|
---|
| 65 |
|
---|
| 66 | // These are business entities that the UDDI will send us that we should ignore.
|
---|
| 67 | // These are configured in the gateway.properties file and will be used to eliminate
|
---|
| 68 | // some of the entries we get back from the UDDI server.
|
---|
| 69 | //------------------------------------------------------------------------------------
|
---|
| 70 | private HashSet<String> m_hBusinessToIgnore = new HashSet<String>();
|
---|
| 71 |
|
---|
| 72 | private boolean m_bPropsLoaded = false; // True if the props have been loaded.
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | /**
|
---|
| 76 | * This method loads information from the gateway.properties file that are
|
---|
| 77 | * pertinent to this class.
|
---|
| 78 | */
|
---|
| 79 | private void loadProperties()
|
---|
| 80 | throws UDDIAccessorException
|
---|
| 81 | {
|
---|
| 82 | if (!m_bPropsLoaded)
|
---|
| 83 | {
|
---|
| 84 | try
|
---|
| 85 | {
|
---|
| 86 | String sValue = PropertyAccessor.getProperty(GATEWAY_PROPFILE_NAME, UDDI_INQUIRY_ENDPOINT_URL);
|
---|
| 87 | if ((sValue != null) && (sValue.length() > 0))
|
---|
| 88 | {
|
---|
| 89 | m_sUDDIInquiryEndpointURL = sValue;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | sValue = PropertyAccessor.getProperty(GATEWAY_PROPFILE_NAME, UDDI_BUSINESSES_TO_IGNORE);
|
---|
| 93 | if ((sValue != null) && (sValue.length() > 0))
|
---|
| 94 | {
|
---|
| 95 | String saBusiness[] = sValue.split(";");
|
---|
| 96 | if ((saBusiness != null) && (saBusiness.length > 0))
|
---|
| 97 | {
|
---|
| 98 | for (int i = 0; i < saBusiness.length; i++)
|
---|
| 99 | {
|
---|
| 100 | m_hBusinessToIgnore.add(saBusiness[i]);
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | m_bPropsLoaded = true;
|
---|
| 106 |
|
---|
| 107 | }
|
---|
| 108 | catch (Exception e)
|
---|
| 109 | {
|
---|
| 110 | String sErrorMessage = "Failed to retrieve properties from " + GATEWAY_PROPFILE_NAME +
|
---|
| 111 | ".properties file. Error: " + e.getMessage();
|
---|
| 112 | log.error(sErrorMessage, e);
|
---|
| 113 | throw new UDDIAccessorException(sErrorMessage, e);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | // If we do not have the endpoint URL, then we have a problem.
|
---|
| 117 | //-------------------------------------------------------------
|
---|
| 118 | if ((m_sUDDIInquiryEndpointURL == null) || (m_sUDDIInquiryEndpointURL.length() <= 0))
|
---|
| 119 | {
|
---|
| 120 | log.error("Failed to retrieve property: '" + UDDI_INQUIRY_ENDPOINT_URL + "' from " +
|
---|
| 121 | GATEWAY_PROPFILE_NAME + ".properties file. UDDI server cannot be accessed.");
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | /**
|
---|
| 127 | * This method retrieves the port for the UDDI server with the correct endpoint.
|
---|
| 128 | *
|
---|
| 129 | * @return
|
---|
| 130 | */
|
---|
| 131 | private UDDIInquiryPortType getUDDIInquiryWebService()
|
---|
| 132 | throws UDDIAccessorException
|
---|
| 133 | {
|
---|
| 134 | UDDIInquiryPortType oPort = null;
|
---|
| 135 |
|
---|
| 136 | try
|
---|
| 137 | {
|
---|
| 138 | UDDIService oService = new UDDIService();
|
---|
| 139 | oPort = oService.getUDDIInquiryPort();
|
---|
| 140 |
|
---|
| 141 | // Need to load in the correct UDDI endpoint URL address.
|
---|
| 142 | //--------------------------------------------------------
|
---|
| 143 | ((BindingProvider)oPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, m_sUDDIInquiryEndpointURL);
|
---|
| 144 | }
|
---|
| 145 | catch (Exception e)
|
---|
| 146 | {
|
---|
| 147 | String sErrorMessage = "Failed to retrieve the UDDI Inquiry Web Service port. Error: " + e.getMessage();
|
---|
| 148 | log.error(sErrorMessage, e);
|
---|
| 149 | throw new UDDIAccessorException(sErrorMessage, e);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | return oPort;
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * This method craetes a business entity by extracting the information from
|
---|
| 158 | * a business info object.
|
---|
| 159 | *
|
---|
| 160 | * @param oBusInfo The business information that contains the information.
|
---|
| 161 | * @return The translated information.
|
---|
| 162 | */
|
---|
| 163 | private CMBusinessEntity businessEntityFromBusinesInfo(BusinessInfo oBusInfo)
|
---|
| 164 | {
|
---|
| 165 | CMBusinessEntity oEntity = new CMBusinessEntity();
|
---|
| 166 | boolean bHaveData = false;
|
---|
| 167 |
|
---|
| 168 | if (oBusInfo != null)
|
---|
| 169 | {
|
---|
| 170 | // Business Key
|
---|
| 171 | //-------------
|
---|
| 172 | if ((oBusInfo.getBusinessKey() != null) && (oBusInfo.getBusinessKey().length() > 0))
|
---|
| 173 | {
|
---|
| 174 | oEntity.setBusinessKey(oBusInfo.getBusinessKey());
|
---|
| 175 | bHaveData = true;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | // Names
|
---|
| 179 | //------
|
---|
| 180 | if ((oBusInfo.getName() != null) &&
|
---|
| 181 | (oBusInfo.getName().size() > 0))
|
---|
| 182 | {
|
---|
| 183 | CMBusinessNames oNames = new CMBusinessNames();
|
---|
| 184 | oEntity.setNames(oNames);
|
---|
| 185 | for (Name oUDDIName : oBusInfo.getName())
|
---|
| 186 | {
|
---|
| 187 | if ((oUDDIName.getValue() != null) && (oUDDIName.getValue().length() > 0))
|
---|
| 188 | {
|
---|
| 189 | oNames.getBusinessName().add(oUDDIName.getValue());
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 | bHaveData = true;
|
---|
| 193 | } // if ((oBusInfo.getName() != null) && ...
|
---|
| 194 |
|
---|
| 195 | // Description
|
---|
| 196 | //------------
|
---|
| 197 | if ((oBusInfo.getDescription() != null) &&
|
---|
| 198 | (oBusInfo.getDescription().size() > 0))
|
---|
| 199 | {
|
---|
| 200 | CMBusinessDescriptions oDescripts = new CMBusinessDescriptions();
|
---|
| 201 | oEntity.setDescriptions(oDescripts);
|
---|
| 202 | for (Description oUDDIDescript : oBusInfo.getDescription())
|
---|
| 203 | {
|
---|
| 204 | if ((oUDDIDescript.getValue() != null) && (oUDDIDescript.getValue().length() > 0))
|
---|
| 205 | {
|
---|
| 206 | oDescripts.getBusinessDescription().add(oUDDIDescript.getValue());
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 | bHaveData = true;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
| 212 | // Set up for the services. - This pass will only put in the service key.
|
---|
| 213 | // We will have to do another retrieval to get the rest of the service information.
|
---|
| 214 | //------------------------------------------------------------------------
|
---|
| 215 | if ((oBusInfo.getServiceInfos() != null) &&
|
---|
| 216 | (oBusInfo.getServiceInfos().getServiceInfo() != null) &&
|
---|
| 217 | (oBusInfo.getServiceInfos().getServiceInfo().size() > 0))
|
---|
| 218 | {
|
---|
| 219 | CMBusinessServices oServices = new CMBusinessServices();
|
---|
| 220 | for (ServiceInfo oUDDIService : oBusInfo.getServiceInfos().getServiceInfo())
|
---|
| 221 | {
|
---|
| 222 | boolean bHaveServiceData = false;
|
---|
| 223 | CMBusinessService oService = new CMBusinessService();
|
---|
| 224 |
|
---|
| 225 | // Service Key
|
---|
| 226 | //------------
|
---|
| 227 | if ((oUDDIService.getServiceKey() != null) && (oUDDIService.getServiceKey().length() > 0))
|
---|
| 228 | {
|
---|
| 229 | oService.setServiceKey(oUDDIService.getServiceKey());
|
---|
| 230 | bHaveServiceData = true;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | oService.setInternalWebService(false); // If it is in UDDI - it is not internal
|
---|
| 234 |
|
---|
| 235 | // Service Name - We will pick this up on the detail.
|
---|
| 236 | //---------------------------------------------------
|
---|
| 237 |
|
---|
| 238 |
|
---|
| 239 | if (bHaveServiceData)
|
---|
| 240 | {
|
---|
| 241 | oServices.getBusinessService().add(oService);
|
---|
| 242 | bHaveData = true;
|
---|
| 243 | }
|
---|
| 244 | } // for (ServiceInfo oUDDIService : oBusInfo.getServiceInfos().getServiceInfo())
|
---|
| 245 |
|
---|
| 246 | if (oServices.getBusinessService().size() > 0)
|
---|
| 247 | {
|
---|
| 248 | oEntity.setBusinessServices(oServices);
|
---|
| 249 | }
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | if (bHaveData)
|
---|
| 254 | {
|
---|
| 255 | return oEntity;
|
---|
| 256 | }
|
---|
| 257 | else
|
---|
| 258 | {
|
---|
| 259 | return null;
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | /**
|
---|
| 264 | * This method extracts the business key from the business info object.
|
---|
| 265 | *
|
---|
| 266 | * @param oBusInfo The business information object containing the data.
|
---|
| 267 | * @return The key that was extracted.
|
---|
| 268 | */
|
---|
| 269 | private String extractBusinessKey(BusinessInfo oBusInfo)
|
---|
| 270 | {
|
---|
| 271 | String sKey = "";
|
---|
| 272 |
|
---|
| 273 | if ((oBusInfo != null) &&
|
---|
| 274 | (oBusInfo.getBusinessKey() != null) &&
|
---|
| 275 | (oBusInfo.getBusinessKey().length() > 0))
|
---|
| 276 | {
|
---|
| 277 | sKey = oBusInfo.getBusinessKey();
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | return sKey;
|
---|
| 281 |
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 |
|
---|
| 285 |
|
---|
| 286 | /**
|
---|
| 287 | * This method retrieves the business entities from the UDDI server.
|
---|
| 288 | * It does not retrieve the services or bindings. They are retrieved
|
---|
| 289 | * on other calls. This only retrieves the business information.
|
---|
| 290 | *
|
---|
| 291 | * @return the BusinessEntities retrieved from the UDDI server.
|
---|
| 292 | * @throws UDDIAccessorException
|
---|
| 293 | */
|
---|
| 294 | private CMBusinessEntities retrieveBusinessesInfoFromUDDI()
|
---|
| 295 | throws UDDIAccessorException
|
---|
| 296 | {
|
---|
| 297 | CMBusinessEntities oEntities = new CMBusinessEntities();
|
---|
| 298 |
|
---|
| 299 | if (log.isDebugEnabled())
|
---|
| 300 | {
|
---|
| 301 | log.debug("Retrieving business entities from UDDI using find_business web service call.");
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | BusinessList oBusinessList = null;
|
---|
| 305 |
|
---|
| 306 | try
|
---|
| 307 | {
|
---|
| 308 | UDDIInquiryPortType oPort = getUDDIInquiryWebService();
|
---|
| 309 |
|
---|
| 310 | // Make the call...
|
---|
| 311 | //-----------------
|
---|
| 312 | FindBusiness oSearchParams = new FindBusiness();
|
---|
| 313 | oSearchParams.setMaxRows(100);
|
---|
| 314 | oBusinessList = oPort.findBusiness(oSearchParams);
|
---|
| 315 |
|
---|
| 316 | }
|
---|
| 317 | catch (Exception e)
|
---|
| 318 | {
|
---|
| 319 | String sErrorMessage = "Failed to call 'find_business' web service on the NHIN UDDI server. Errro: " +
|
---|
| 320 | e.getMessage();
|
---|
| 321 | log.error(sErrorMessage, e);
|
---|
| 322 | throw new UDDIAccessorException(sErrorMessage, e);
|
---|
| 323 | }
|
---|
| 324 |
|
---|
| 325 | // Now lets go through what we have...
|
---|
| 326 | //------------------------------------
|
---|
| 327 | if ((oBusinessList != null) &&
|
---|
| 328 | (oBusinessList.getBusinessInfos() != null) &&
|
---|
| 329 | (oBusinessList.getBusinessInfos().getBusinessInfo() != null) &&
|
---|
| 330 | (oBusinessList.getBusinessInfos().getBusinessInfo().size() > 0))
|
---|
| 331 | {
|
---|
| 332 | for (BusinessInfo oBusInfo : oBusinessList.getBusinessInfos().getBusinessInfo())
|
---|
| 333 | {
|
---|
| 334 | String sKey = extractBusinessKey(oBusInfo);
|
---|
| 335 |
|
---|
| 336 | if (!m_hBusinessToIgnore.contains(sKey))
|
---|
| 337 | {
|
---|
| 338 | // Make sure this is not one of the ones we need to filter out...
|
---|
| 339 | //----------------------------------------------------------------
|
---|
| 340 | CMBusinessEntity oEntity = null;
|
---|
| 341 | oEntity = businessEntityFromBusinesInfo(oBusInfo);
|
---|
| 342 | if (oEntity != null)
|
---|
| 343 | {
|
---|
| 344 | oEntities.getBusinessEntity().add(oEntity);
|
---|
| 345 | }
|
---|
| 346 | }
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
| 350 | return oEntities;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | /**
|
---|
| 354 | * This method returns the business with the specified
|
---|
| 355 | * business key. If it does not exist in the list, then null is returned.
|
---|
| 356 | *
|
---|
| 357 | * @param oEntities The list of businesses to search.
|
---|
| 358 | * @param sBusinessKey The business key to look for.
|
---|
| 359 | * @return The item from the list that matches the business key.
|
---|
| 360 | */
|
---|
| 361 | private CMBusinessEntity findSpecificBusiness(List<CMBusinessEntity> oaEntities, String sBusinessKey)
|
---|
| 362 | {
|
---|
| 363 | CMBusinessEntity oEntity = null;
|
---|
| 364 |
|
---|
| 365 | if ((oaEntities != null) &&
|
---|
| 366 | (oaEntities.size() > 0))
|
---|
| 367 | {
|
---|
| 368 | for (CMBusinessEntity oTempEntity : oaEntities)
|
---|
| 369 | {
|
---|
| 370 | if ((oTempEntity.getBusinessKey() != null) &&
|
---|
| 371 | (oTempEntity.getBusinessKey().equals(sBusinessKey)))
|
---|
| 372 | {
|
---|
| 373 | oEntity = oTempEntity;
|
---|
| 374 | break; // We found it - get out of the loop...
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | return oEntity;
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 | /**
|
---|
| 383 | * This method returns the service with the specified business key and service key.
|
---|
| 384 | * If it does not exist in the list, then null is returned.
|
---|
| 385 | *
|
---|
| 386 | * @param oEntities The list of businesses to search.
|
---|
| 387 | * @param sBusinessKey The business key for the business entity.
|
---|
| 388 | * @param sServiceKey The service key to look for.
|
---|
| 389 | * @return The item from the list that matches the business key.
|
---|
| 390 | */
|
---|
| 391 | private CMBusinessService findSpecificService(List<CMBusinessEntity> oaEntities,
|
---|
| 392 | String sBusinessKey, String sServiceKey)
|
---|
| 393 | {
|
---|
| 394 | CMBusinessService oService = null;
|
---|
| 395 |
|
---|
| 396 | CMBusinessEntity oEntity = findSpecificBusiness(oaEntities, sBusinessKey);
|
---|
| 397 |
|
---|
| 398 | if ((oEntity != null) &&
|
---|
| 399 | (oEntity.getBusinessServices() != null) &&
|
---|
| 400 | (oEntity.getBusinessServices().getBusinessService() != null) &&
|
---|
| 401 | (oEntity.getBusinessServices().getBusinessService().size() > 0))
|
---|
| 402 | {
|
---|
| 403 | for (CMBusinessService oTempService : oEntity.getBusinessServices().getBusinessService())
|
---|
| 404 | {
|
---|
| 405 | if ((oTempService.getServiceKey() != null) &&
|
---|
| 406 | (oTempService.getServiceKey().equals(sServiceKey)))
|
---|
| 407 | {
|
---|
| 408 | oService = oTempService;
|
---|
| 409 | break; // We found it - get out of the loop...
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | return oService;
|
---|
| 415 | }
|
---|
| 416 |
|
---|
| 417 | /**
|
---|
| 418 | * This method looks through the set of keyed reference objects for the one that is specified.
|
---|
| 419 | * Once it finds it, it extracts the keyValue and returns it.
|
---|
| 420 | *
|
---|
| 421 | * @param oaKeys The keys to be searched.
|
---|
| 422 | * @param sDesiredKey The key to look for.
|
---|
| 423 | * @return The value assocaited with that key.
|
---|
| 424 | */
|
---|
| 425 | private String findAndGetValueFromKeyedReference(List<KeyedReference> oaKeys, String sDesiredKey)
|
---|
| 426 | {
|
---|
| 427 | String sValue = "";
|
---|
| 428 |
|
---|
| 429 | if ((oaKeys == null) ||
|
---|
| 430 | (oaKeys.size() <= 0))
|
---|
| 431 | {
|
---|
| 432 | return "";
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | for (KeyedReference oKey : oaKeys)
|
---|
| 436 | {
|
---|
| 437 | if ((oKey.getTModelKey() != null) &&
|
---|
| 438 | (oKey.getTModelKey().equals(sDesiredKey)) &&
|
---|
| 439 | (oKey.getKeyValue() != null))
|
---|
| 440 | {
|
---|
| 441 | sValue = oKey.getKeyValue();
|
---|
| 442 | break; // We found what we wanted - get out of the loop
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | return sValue;
|
---|
| 447 | }
|
---|
| 448 |
|
---|
| 449 | /**
|
---|
| 450 | * This method takes in a list of JAXBElements and searches for a KeyedReference where
|
---|
| 451 | * the key is the one specified. If one is found, it will return the value for it.
|
---|
| 452 | *
|
---|
| 453 | * @param oaElement The list of JAXB elements.
|
---|
| 454 | * @param sKey The key to search for.
|
---|
| 455 | * @return The value associated with that key.
|
---|
| 456 | */
|
---|
| 457 | private String findAndGetValueFromJAXBElementKeyedReference (List<JAXBElement<?>> oaElement, String sKey)
|
---|
| 458 | {
|
---|
| 459 | String sValue = "";
|
---|
| 460 |
|
---|
| 461 | if ((oaElement == null) ||
|
---|
| 462 | (oaElement.size() <= 0))
|
---|
| 463 | {
|
---|
| 464 | return "";
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | for (JAXBElement oElement : oaElement)
|
---|
| 468 | {
|
---|
| 469 | if ((oElement.getDeclaredType() != null) &&
|
---|
| 470 | (oElement.getDeclaredType().getCanonicalName() != null) &&
|
---|
| 471 | (oElement.getDeclaredType().getCanonicalName().equals("org.uddi.api_v3.KeyedReference")))
|
---|
| 472 | {
|
---|
| 473 | KeyedReference oKeyRef = (KeyedReference) oElement.getValue();
|
---|
| 474 |
|
---|
| 475 | if ((oKeyRef != null) &&
|
---|
| 476 | (oKeyRef.getTModelKey() != null) &&
|
---|
| 477 | (oKeyRef.getTModelKey().equals(sKey)) &&
|
---|
| 478 | (oKeyRef.getKeyValue() != null))
|
---|
| 479 | {
|
---|
| 480 | sValue = oKeyRef.getKeyValue();
|
---|
| 481 | }
|
---|
| 482 | }
|
---|
| 483 | }
|
---|
| 484 |
|
---|
| 485 | return sValue;
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | /**
|
---|
| 489 | * This method loops through the business entities and fills in any pertinent
|
---|
| 490 | * detailed information by calling the UDDI server get_businessDetail function. Note
|
---|
| 491 | * that this information was not available in the find_business. In order to get it
|
---|
| 492 | * we have to do separate call.
|
---|
| 493 | *
|
---|
| 494 | * @param oEntities The businesses to retrieve the detail and the object where the
|
---|
| 495 | * details will be placed.
|
---|
| 496 | */
|
---|
| 497 | private void retrieveDetailedBusinessInfoFromUDDI(CMBusinessEntities oEntities)
|
---|
| 498 | throws UDDIAccessorException
|
---|
| 499 | {
|
---|
| 500 | if ((oEntities == null) ||
|
---|
| 501 | (oEntities.getBusinessEntity() == null) ||
|
---|
| 502 | (oEntities.getBusinessEntity().size() <= 0))
|
---|
| 503 | {
|
---|
| 504 | return; // we are done there is nothing to retrieve.
|
---|
| 505 | }
|
---|
| 506 |
|
---|
| 507 | BusinessDetail oResult = null;
|
---|
| 508 |
|
---|
| 509 | try
|
---|
| 510 | {
|
---|
| 511 | GetBusinessDetail oSearchParams = new GetBusinessDetail();
|
---|
| 512 |
|
---|
| 513 | // Load up the list of keys to retrieve the details of...
|
---|
| 514 | //--------------------------------------------------------
|
---|
| 515 | for (CMBusinessEntity oEntity : oEntities.getBusinessEntity())
|
---|
| 516 | {
|
---|
| 517 | if ((oEntity.getBusinessKey() != null) && (oEntity.getBusinessKey().length() > 0))
|
---|
| 518 | {
|
---|
| 519 | oSearchParams.getBusinessKey().add(oEntity.getBusinessKey());
|
---|
| 520 | }
|
---|
| 521 | } // for (CMBusinessEntity oEntity : oEntities.getBusinessEntity())
|
---|
| 522 |
|
---|
| 523 | UDDIInquiryPortType oPort = getUDDIInquiryWebService();
|
---|
| 524 | oResult = oPort.getBusinessDetail(oSearchParams);
|
---|
| 525 | }
|
---|
| 526 | catch (Exception e)
|
---|
| 527 | {
|
---|
| 528 | String sErrorMessage = "Failed to call UDDI web service get_businessDetail method. Error: " + e.getMessage();
|
---|
| 529 | log.error(sErrorMessage, e);
|
---|
| 530 | throw new UDDIAccessorException(sErrorMessage, e);
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | // Now let's process the results...
|
---|
| 534 | //---------------------------------
|
---|
| 535 | if ((oResult != null) &&
|
---|
| 536 | (oResult.getBusinessEntity() != null) &&
|
---|
| 537 | (oResult.getBusinessEntity().size() > 0))
|
---|
| 538 | {
|
---|
| 539 | // Now put the returned information back into our structure.
|
---|
| 540 | //-----------------------------------------------------------
|
---|
| 541 | for (BusinessEntity oUDDIEntity : oResult.getBusinessEntity())
|
---|
| 542 | {
|
---|
| 543 | if ((oUDDIEntity.getBusinessKey() != null) && (oUDDIEntity.getBusinessKey().length() > 0))
|
---|
| 544 | {
|
---|
| 545 | CMBusinessEntity oEntity = findSpecificBusiness(oEntities.getBusinessEntity(), oUDDIEntity.getBusinessKey());
|
---|
| 546 |
|
---|
| 547 | if (oEntity != null)
|
---|
| 548 | {
|
---|
| 549 | // Home community ID
|
---|
| 550 | //------------------
|
---|
| 551 | if ((oUDDIEntity.getIdentifierBag() != null) &&
|
---|
| 552 | (oUDDIEntity.getIdentifierBag().getKeyedReference() != null) &&
|
---|
| 553 | (oUDDIEntity.getIdentifierBag().getKeyedReference().size() > 0))
|
---|
| 554 | {
|
---|
| 555 | String sValue = findAndGetValueFromKeyedReference(oUDDIEntity.getIdentifierBag().getKeyedReference(),
|
---|
| 556 | HOME_COMMUNITY_ID_KEY);
|
---|
| 557 | if ((sValue != null) && (sValue.length() > 0))
|
---|
| 558 | {
|
---|
| 559 | if (sValue.startsWith("urn:oid:"))
|
---|
| 560 | {
|
---|
| 561 | sValue = sValue.substring("urn:oid:".length());
|
---|
| 562 | }
|
---|
| 563 | oEntity.setHomeCommunityId(sValue);
|
---|
| 564 | }
|
---|
| 565 | } // if ((oUDDIEntity.getIdentifierBag() != null) && ...
|
---|
| 566 | } // if (oEntity != nulll)
|
---|
| 567 | } // if ((oUDDIEntity.getBusinessKey() != null) && (oUDDIEntity.getBusinessKey().length() > 0))
|
---|
| 568 | } // for (BusinessEntity oUDDIEntity : oResult.getBusinessEntity())
|
---|
| 569 |
|
---|
| 570 | } // if ((oResult != null) &&
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | /**
|
---|
| 574 | * This method retrieves the service information from the UDDI server for
|
---|
| 575 | * each of the business entities.
|
---|
| 576 | *
|
---|
| 577 | * @param oEntities The business entities for which services should be retrieved. The
|
---|
| 578 | * information is placed in the appropriate location in this object.
|
---|
| 579 | * @throws UDDIAccessorException
|
---|
| 580 | */
|
---|
| 581 | private void retrieveDetailedServiceInfoFromUDDI(CMBusinessEntities oEntities)
|
---|
| 582 | throws UDDIAccessorException
|
---|
| 583 | {
|
---|
| 584 | if ((oEntities == null) ||
|
---|
| 585 | (oEntities.getBusinessEntity() == null) ||
|
---|
| 586 | (oEntities.getBusinessEntity().size() <= 0))
|
---|
| 587 | {
|
---|
| 588 | return; // we are done there is nothing to retrieve.
|
---|
| 589 | }
|
---|
| 590 |
|
---|
| 591 | ServiceDetail oResult = null;
|
---|
| 592 |
|
---|
| 593 | try
|
---|
| 594 | {
|
---|
| 595 | GetServiceDetail oSearchParams = new GetServiceDetail();
|
---|
| 596 |
|
---|
| 597 | // Load up the list of service keys to retrieve the details of...
|
---|
| 598 | //--------------------------------------------------------
|
---|
| 599 | for (CMBusinessEntity oEntity : oEntities.getBusinessEntity())
|
---|
| 600 | {
|
---|
| 601 | if ((oEntity.getBusinessServices() != null) &&
|
---|
| 602 | (oEntity.getBusinessServices().getBusinessService() != null) &&
|
---|
| 603 | (oEntity.getBusinessServices().getBusinessService().size() > 0))
|
---|
| 604 | {
|
---|
| 605 | for (CMBusinessService oService : oEntity.getBusinessServices().getBusinessService())
|
---|
| 606 | {
|
---|
| 607 | if ((oService.getServiceKey() != null) && (oService.getServiceKey().length() > 0))
|
---|
| 608 | {
|
---|
| 609 | oSearchParams.getServiceKey().add(oService.getServiceKey());
|
---|
| 610 | }
|
---|
| 611 | } // for (CMBusinessService oService : oEntity.getBusinessServices().getBusinessService())
|
---|
| 612 | } // if ((oEntity.getBusinessServices() != null) && ...
|
---|
| 613 | } // for (CMBusinessEntity oEntity : oEntities.getBusinessEntity())
|
---|
| 614 |
|
---|
| 615 | UDDIInquiryPortType oPort = getUDDIInquiryWebService();
|
---|
| 616 | oResult = oPort.getServiceDetail(oSearchParams);
|
---|
| 617 | }
|
---|
| 618 | catch (Exception e)
|
---|
| 619 | {
|
---|
| 620 | String sErrorMessage = "Failed to call UDDI web service get_serviceDetail method. Error: " + e.getMessage();
|
---|
| 621 | log.error(sErrorMessage, e);
|
---|
| 622 | throw new UDDIAccessorException(sErrorMessage, e);
|
---|
| 623 | }
|
---|
| 624 |
|
---|
| 625 | // Now let's process the results...
|
---|
| 626 | //---------------------------------
|
---|
| 627 | if ((oResult != null) &&
|
---|
| 628 | (oResult.getBusinessService() != null) &&
|
---|
| 629 | (oResult.getBusinessService().size() > 0))
|
---|
| 630 | {
|
---|
| 631 | // Now put the returned information back into our structure.
|
---|
| 632 | //-----------------------------------------------------------
|
---|
| 633 | for (BusinessService oUDDIService : oResult.getBusinessService())
|
---|
| 634 | {
|
---|
| 635 | if ((oUDDIService.getServiceKey() != null) &&
|
---|
| 636 | (oUDDIService.getServiceKey().length() > 0) &&
|
---|
| 637 | (oUDDIService.getBusinessKey() != null) &&
|
---|
| 638 | (oUDDIService.getBusinessKey().length() > 0))
|
---|
| 639 | {
|
---|
| 640 | CMBusinessService oService = findSpecificService(oEntities.getBusinessEntity(),
|
---|
| 641 | oUDDIService.getBusinessKey(),
|
---|
| 642 | oUDDIService.getServiceKey());
|
---|
| 643 |
|
---|
| 644 | if (oService != null)
|
---|
| 645 | {
|
---|
| 646 | // Binding Service Name
|
---|
| 647 | //----------------------
|
---|
| 648 | if ((oUDDIService.getName() != null) &&
|
---|
| 649 | (oUDDIService.getName().size() > 0))
|
---|
| 650 | {
|
---|
| 651 | CMBindingNames oNames = new CMBindingNames();
|
---|
| 652 | oService.setNames(oNames);
|
---|
| 653 |
|
---|
| 654 | for (Name oUDDIName : oUDDIService.getName())
|
---|
| 655 | {
|
---|
| 656 | if ((oUDDIName.getValue() != null) && (oUDDIName.getValue().length() > 0))
|
---|
| 657 | {
|
---|
| 658 | oService.getNames().getName().add(oUDDIName.getValue());
|
---|
| 659 | }
|
---|
| 660 | }
|
---|
| 661 | } // if ((oUDDIService.getName() != null) &&
|
---|
| 662 |
|
---|
| 663 | // Binding Descriptions
|
---|
| 664 | //---------------------
|
---|
| 665 | if ((oUDDIService.getDescription() != null) &&
|
---|
| 666 | (oUDDIService.getDescription().size() > 0))
|
---|
| 667 | {
|
---|
| 668 | CMBindingDescriptions oDescripts = new CMBindingDescriptions();
|
---|
| 669 | oService.setDescriptions(oDescripts);
|
---|
| 670 |
|
---|
| 671 | for (Description oUDDIDescript : oUDDIService.getDescription())
|
---|
| 672 | {
|
---|
| 673 | if ((oUDDIDescript.getValue() != null) && (oUDDIDescript.getValue().length() > 0))
|
---|
| 674 | {
|
---|
| 675 | oService.getDescriptions().getDescription().add(oUDDIDescript.getValue());
|
---|
| 676 | }
|
---|
| 677 | }
|
---|
| 678 | } // if ((oUDDIService.getDescription() != null) && ...
|
---|
| 679 |
|
---|
| 680 | // Uniform Service Name & Service Version
|
---|
| 681 | //----------------------------------------
|
---|
| 682 | if ((oUDDIService.getCategoryBag() != null) &&
|
---|
| 683 | (oUDDIService.getCategoryBag().getContent() != null) &&
|
---|
| 684 | (oUDDIService.getCategoryBag().getContent().size() > 0))
|
---|
| 685 | {
|
---|
| 686 | // Uniform Service Name
|
---|
| 687 | //---------------------
|
---|
| 688 | String sValue = findAndGetValueFromJAXBElementKeyedReference(oUDDIService.getCategoryBag().getContent(),
|
---|
| 689 | UNIFORM_SERVICE_NAME_KEY);
|
---|
| 690 | if (sValue != null)
|
---|
| 691 | {
|
---|
| 692 | oService.setUniformServiceName(sValue);
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | // Service Version
|
---|
| 696 | //----------------
|
---|
| 697 | sValue = findAndGetValueFromJAXBElementKeyedReference(oUDDIService.getCategoryBag().getContent(),
|
---|
| 698 | SERVICE_VERSION_KEY);
|
---|
| 699 | if (sValue != null)
|
---|
| 700 | {
|
---|
| 701 | oService.setServiceVersion(sValue);
|
---|
| 702 | }
|
---|
| 703 | } // if ((oUDDIService.getCategoryBag() != null) && ...
|
---|
| 704 |
|
---|
| 705 | // Binding Template Information
|
---|
| 706 | //-----------------------------
|
---|
| 707 | if ((oUDDIService.getBindingTemplates() != null) &&
|
---|
| 708 | (oUDDIService.getBindingTemplates().getBindingTemplate() != null) &&
|
---|
| 709 | (oUDDIService.getBindingTemplates().getBindingTemplate().size() > 0))
|
---|
| 710 | {
|
---|
| 711 | CMBindingTemplates oTemplates = new CMBindingTemplates();
|
---|
| 712 | for (BindingTemplate oUDDITemplate : oUDDIService.getBindingTemplates().getBindingTemplate())
|
---|
| 713 | {
|
---|
| 714 | CMBindingTemplate oTemplate = new CMBindingTemplate();
|
---|
| 715 | boolean bHaveData = false;
|
---|
| 716 |
|
---|
| 717 | // Endpoint URL
|
---|
| 718 | //--------------
|
---|
| 719 | if ((oUDDITemplate.getAccessPoint() != null) &&
|
---|
| 720 | (oUDDITemplate.getAccessPoint().getValue() != null) &&
|
---|
| 721 | (oUDDITemplate.getAccessPoint().getValue().length() > 0))
|
---|
| 722 | {
|
---|
| 723 | oTemplate.setEndpointURL(oUDDITemplate.getAccessPoint().getValue());
|
---|
| 724 | bHaveData = true;
|
---|
| 725 | }
|
---|
| 726 |
|
---|
| 727 | if (bHaveData)
|
---|
| 728 | {
|
---|
| 729 | oTemplates.getBindingTemplate().add(oTemplate);
|
---|
| 730 | }
|
---|
| 731 | }
|
---|
| 732 |
|
---|
| 733 | if ((oTemplates.getBindingTemplate() != null) &&
|
---|
| 734 | (oTemplates.getBindingTemplate().size() > 0))
|
---|
| 735 | {
|
---|
| 736 | oService.setBindingTemplates(oTemplates);
|
---|
| 737 | }
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 | } // if (oService != null)
|
---|
| 741 | } // if ((oUDDIService.getServiceKey() != null) && ...
|
---|
| 742 | } // for (BusinessService oUDDIService : oResult.getBusinessService())
|
---|
| 743 |
|
---|
| 744 | } // if ((oResult != null) &&
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | /**
|
---|
| 748 | * This method is used to retrieve the data from the UDDI server. The
|
---|
| 749 | * data is returned in the form of CMBusinessEntities.
|
---|
| 750 | *
|
---|
| 751 | * @return The Business Entities that were retrieved from the UDDI server.
|
---|
| 752 | *
|
---|
| 753 | */
|
---|
| 754 | public CMBusinessEntities retrieveFromUDDIServer()
|
---|
| 755 | throws UDDIAccessorException
|
---|
| 756 | {
|
---|
| 757 | CMBusinessEntities oEntities = new CMBusinessEntities();
|
---|
| 758 |
|
---|
| 759 | loadProperties();
|
---|
| 760 |
|
---|
| 761 |
|
---|
| 762 | // If we are failing to load the properties or if we do not
|
---|
| 763 | // have the endpoint URL - there is nothing to do...
|
---|
| 764 | //-----------------------------------------------------------
|
---|
| 765 | if ((!m_bPropsLoaded) || (m_sUDDIInquiryEndpointURL == null) ||
|
---|
| 766 | (m_sUDDIInquiryEndpointURL.length() <= 0))
|
---|
| 767 | {
|
---|
| 768 | return null;
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | // First step is to retrieve the high level business information...
|
---|
| 772 | //------------------------------------------------------------------
|
---|
| 773 | oEntities = retrieveBusinessesInfoFromUDDI();
|
---|
| 774 |
|
---|
| 775 | // Now lets retrieve the detailed business & service information for
|
---|
| 776 | // these businesses.
|
---|
| 777 | //--------------------------------------------------------------------------
|
---|
| 778 | if (oEntities != null)
|
---|
| 779 | {
|
---|
| 780 | retrieveDetailedBusinessInfoFromUDDI(oEntities);
|
---|
| 781 | retrieveDetailedServiceInfoFromUDDI(oEntities);
|
---|
| 782 | }
|
---|
| 783 |
|
---|
| 784 |
|
---|
| 785 | return oEntities;
|
---|
| 786 | }
|
---|
| 787 |
|
---|
| 788 | /**
|
---|
| 789 | * Main method.
|
---|
| 790 | *
|
---|
| 791 | * @param args
|
---|
| 792 | */
|
---|
| 793 | public static void main (String args[])
|
---|
| 794 | {
|
---|
| 795 | UDDIAccessor oAccessor = new UDDIAccessor();
|
---|
| 796 |
|
---|
| 797 | CMBusinessEntities oEntities = null;
|
---|
| 798 |
|
---|
| 799 | try
|
---|
| 800 | {
|
---|
| 801 | oEntities = oAccessor.retrieveFromUDDIServer();
|
---|
| 802 |
|
---|
| 803 | if (oEntities != null)
|
---|
| 804 | {
|
---|
| 805 | CMUDDIConnectionInfo oUDDIConnectionInfo = new CMUDDIConnectionInfo();
|
---|
| 806 | oUDDIConnectionInfo.setBusinessEntities(oEntities);
|
---|
| 807 |
|
---|
| 808 | String sXML = CMUDDIConnectionInfoXML.serialize(oUDDIConnectionInfo);
|
---|
| 809 | System.out.println(sXML);
|
---|
| 810 | }
|
---|
| 811 | }
|
---|
| 812 | catch (Exception e)
|
---|
| 813 | {
|
---|
| 814 | System.out.println("An unexpected exception occurred: " + e.getMessage());
|
---|
| 815 | e.printStackTrace();
|
---|
| 816 | }
|
---|
| 817 |
|
---|
| 818 |
|
---|
| 819 |
|
---|
| 820 | System.out.println("");
|
---|
| 821 | System.out.println("We are done.");
|
---|
| 822 | }
|
---|
| 823 | }
|
---|