| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Install.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">jUDDI Core Services</a> > <a href="index.source.html" class="el_package">org.apache.juddi.config</a> > <span class="el_source">Install.java</span></div><h1>Install.java</h1><pre class="source lang-java linenums">/* |
| * Copyright 2001-2008 The Apache Software Foundation. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| */ |
| package org.apache.juddi.config; |
| |
| import java.io.File; |
| import java.io.IOException; |
| import java.io.InputStream; |
| import java.io.StringReader; |
| import java.net.URI; |
| import java.net.URISyntaxException; |
| import java.net.URL; |
| import java.text.SimpleDateFormat; |
| import java.util.ArrayList; |
| import java.util.Date; |
| import java.util.Enumeration; |
| import java.util.List; |
| import java.util.StringTokenizer; |
| import java.util.UUID; |
| import java.util.jar.JarEntry; |
| import java.util.jar.JarFile; |
| import java.util.logging.Level; |
| import java.util.logging.Logger; |
| |
| import javax.persistence.EntityManager; |
| import javax.persistence.EntityTransaction; |
| import javax.xml.bind.JAXB; |
| import javax.xml.bind.JAXBContext; |
| import javax.xml.bind.JAXBElement; |
| import javax.xml.bind.JAXBException; |
| import javax.xml.bind.Unmarshaller; |
| import javax.xml.stream.XMLInputFactory; |
| import javax.xml.stream.XMLStreamException; |
| import javax.xml.stream.XMLStreamReader; |
| import javax.xml.transform.stream.StreamSource; |
| |
| import org.apache.commons.configuration.Configuration; |
| import org.apache.commons.configuration.ConfigurationException; |
| import org.apache.commons.logging.Log; |
| import org.apache.commons.logging.LogFactory; |
| import org.apache.juddi.ClassUtil; |
| import org.apache.juddi.api.impl.AuthenticatedService; |
| import org.apache.juddi.api.impl.UDDIInquiryImpl; |
| import org.apache.juddi.api.impl.UDDIPublicationImpl; |
| import org.apache.juddi.keygen.KeyGenerator; |
| import org.apache.juddi.mapping.MappingApiToModel; |
| import org.apache.juddi.mapping.MappingModelToApi; |
| import org.apache.juddi.model.ReplicationConfiguration; |
| import org.apache.juddi.model.UddiEntityPublisher; |
| import org.apache.juddi.replication.ReplicationNotifier; |
| import org.apache.juddi.v3.client.cryptor.XmlUtils; |
| import org.apache.juddi.v3.error.ErrorMessage; |
| import org.apache.juddi.v3.error.FatalErrorException; |
| import org.apache.juddi.v3.error.InvalidKeyPassedException; |
| import org.apache.juddi.v3.error.KeyUnavailableException; |
| import org.apache.juddi.v3.error.ValueNotAllowedException; |
| import org.apache.juddi.validation.ValidatePublish; |
| import org.apache.juddi.validation.ValidateReplication; |
| import org.apache.juddi.validation.ValidateUDDIKey; |
| import org.uddi.api_v3.SaveBusiness; |
| import org.uddi.api_v3.SaveTModel; |
| import org.uddi.api_v3.TModel; |
| import org.uddi.repl_v3.Operator; |
| import org.uddi.v3_service.DispositionReportFaultMessage; |
| |
| /** |
| * This class is called when jUDDI starts up |
| * |
| * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a> |
| * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a> |
| * @see org.apache.juddi.servlets.RegistryServlet |
| */ |
| <span class="nc" id="L86">public class Install {</span> |
| |
| public static final String FILE_BUSINESSENTITY = "_BusinessEntity.xml"; |
| public static final String FILE_PUBLISHER = "_Publisher.xml"; |
| public static final String FILE_TMODELKEYGEN = "_tModelKeyGen.xml"; |
| public static final String FILE_TMODELS = "_tModels.xml"; |
| |
| public static final String FILE_PERSISTENCE = "persistence.xml"; |
| public static final String JUDDI_INSTALL_DATA_DIR = "juddi_install_data/"; |
| public static final String JUDDI_CUSTOM_INSTALL_DATA_DIR = "juddi_custom_install_data/"; |
| public static final String FILE_REPLICATION_CONFIG = "_replicationConfiguration.xml"; |
| <span class="fc" id="L97"> public static final Log log = LogFactory.getLog(Install.class);</span> |
| |
| protected static void install(Configuration config) throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException, XMLStreamException { |
| |
| <span class="fc" id="L101"> EntityManager em = PersistenceManager.getEntityManager();</span> |
| <span class="fc" id="L102"> EntityTransaction tx = em.getTransaction();</span> |
| |
| <span class="fc" id="L104"> UddiEntityPublisher rootPublisher = null;</span> |
| |
| try { |
| <span class="fc" id="L107"> tx.begin();</span> |
| <span class="fc" id="L108"> boolean seedAlways = config.getBoolean("juddi.seed.always", false);</span> |
| <span class="fc" id="L109"> boolean alreadyInstalled = alreadyInstalled(config);</span> |
| <span class="pc bpc" id="L110" title="2 of 4 branches missed."> if (!seedAlways && alreadyInstalled) {</span> |
| <span class="nc" id="L111"> throw new FatalErrorException(new ErrorMessage("errors.install.AlreadyInstalled"));</span> |
| } |
| |
| <span class="fc" id="L114"> String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);</span> |
| <span class="fc" id="L115"> String fileRootTModelKeygen = rootPublisherStr + FILE_TMODELKEYGEN;</span> |
| <span class="fc" id="L116"> TModel rootTModelKeyGen = (TModel) buildInstallEntity(fileRootTModelKeygen, "org.uddi.api_v3", config);</span> |
| <span class="fc" id="L117"> String fileRootBusinessEntity = rootPublisherStr + FILE_BUSINESSENTITY;</span> |
| <span class="fc" id="L118"> org.uddi.api_v3.BusinessEntity rootBusinessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity(fileRootBusinessEntity, "org.uddi.api_v3", config);</span> |
| |
| <span class="fc" id="L120"> String rootPartition = getRootPartition(rootTModelKeyGen);</span> |
| //JUDDI-645 |
| <span class="fc" id="L122"> String nodeId = config.getString(Property.JUDDI_NODE_ID, getNodeId(rootBusinessEntity.getBusinessKey(), rootPartition));</span> |
| //getNodeId(rootBusinessEntity.getBusinessKey(), rootPartition); |
| <span class="fc" id="L124"> String rootbizkey = getNodeId(rootBusinessEntity.getBusinessKey(), rootPartition);</span> |
| <span class="fc" id="L125"> String fileRootPublisher = rootPublisherStr + FILE_PUBLISHER;</span> |
| <span class="fc" id="L126"> String fileReplicationConfig = rootPublisherStr + FILE_REPLICATION_CONFIG;</span> |
| <span class="fc" id="L127"> org.uddi.repl_v3.ReplicationConfiguration replicationCfg = (org.uddi.repl_v3.ReplicationConfiguration) buildInstallEntityAlt(fileReplicationConfig, org.uddi.repl_v3.ReplicationConfiguration.class, config);</span> |
| <span class="pc bpc" id="L128" title="1 of 2 branches missed."> if (!alreadyInstalled) {</span> |
| <span class="fc" id="L129"> log.info("Loading the root Publisher from file " + fileRootPublisher);</span> |
| |
| <span class="fc" id="L131"> rootPublisher = installPublisher(em, fileRootPublisher, config);</span> |
| <span class="fc" id="L132"> installRootPublisherKeyGen(em, rootTModelKeyGen, rootPartition, rootPublisher, nodeId);</span> |
| <span class="fc" id="L133"> rootBusinessEntity.setBusinessKey(rootbizkey);</span> |
| <span class="fc" id="L134"> installBusinessEntity(true, em, rootBusinessEntity, rootPublisher, rootPartition, config, nodeId);</span> |
| <span class="fc" id="L135"> installReplicationConfiguration(em, replicationCfg, config, nodeId);</span> |
| } else { |
| <span class="nc" id="L137"> log.debug("juddi.seed.always reapplies all seed files except for the root data.");</span> |
| } |
| |
| <span class="fc" id="L140"> List<String> juddiPublishers = getPublishers(config);</span> |
| <span class="fc bfc" id="L141" title="All 2 branches covered."> for (String publisherStr : juddiPublishers) {</span> |
| <span class="fc" id="L142"> String filePublisher = publisherStr + FILE_PUBLISHER;</span> |
| <span class="fc" id="L143"> String fileTModelKeygen = publisherStr + FILE_TMODELKEYGEN;</span> |
| <span class="fc" id="L144"> TModel tModelKeyGen = (TModel) buildInstallEntity(fileTModelKeygen, "org.uddi.api_v3", config);</span> |
| <span class="fc" id="L145"> String fileBusinessEntity = publisherStr + FILE_BUSINESSENTITY;</span> |
| <span class="fc" id="L146"> org.uddi.api_v3.BusinessEntity businessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity(fileBusinessEntity, "org.uddi.api_v3", config);</span> |
| <span class="fc" id="L147"> UddiEntityPublisher publisher = installPublisher(em, filePublisher, config);</span> |
| <span class="pc bpc" id="L148" title="1 of 2 branches missed."> if (publisher == null) {</span> |
| <span class="nc" id="L149"> throw new ConfigurationException("File " + filePublisher + " not found.");</span> |
| } else { |
| <span class="pc bpc" id="L151" title="1 of 2 branches missed."> if (tModelKeyGen != null) {</span> |
| <span class="nc" id="L152"> installPublisherKeyGen(em, tModelKeyGen, publisher, nodeId);</span> |
| } |
| <span class="pc bpc" id="L154" title="1 of 2 branches missed."> if (businessEntity != null) {</span> |
| <span class="nc" id="L155"> installBusinessEntity(false, em, businessEntity, publisher, null, config, nodeId);</span> |
| } |
| <span class="fc" id="L157"> String fileTModels = publisherStr + FILE_TMODELS;</span> |
| <span class="fc" id="L158"> installSaveTModel(em, fileTModels, publisher, nodeId, config);</span> |
| } |
| <span class="fc" id="L160"> }</span> |
| |
| <span class="fc" id="L162"> tx.commit();</span> |
| <span class="nc" id="L163"> } catch (DispositionReportFaultMessage dr) {</span> |
| <span class="nc" id="L164"> log.error(dr.getMessage(), dr);</span> |
| <span class="nc" id="L165"> tx.rollback();</span> |
| <span class="nc" id="L166"> throw dr;</span> |
| <span class="nc" id="L167"> } catch (JAXBException je) {</span> |
| <span class="nc" id="L168"> log.error(je.getMessage(), je);</span> |
| <span class="nc" id="L169"> tx.rollback();</span> |
| <span class="nc" id="L170"> throw je;</span> |
| <span class="nc" id="L171"> } catch (IOException ie) {</span> |
| <span class="nc" id="L172"> log.error(ie.getMessage(), ie);</span> |
| <span class="nc" id="L173"> tx.rollback();</span> |
| <span class="nc" id="L174"> throw ie;</span> |
| <span class="nc" id="L175"> } catch (XMLStreamException ex) {</span> |
| <span class="nc" id="L176"> log.error(ex.getMessage(), ex);</span> |
| <span class="nc" id="L177"> tx.rollback();</span> |
| <span class="nc" id="L178"> throw ex;</span> |
| } finally { |
| <span class="pc bpc" id="L180" title="3 of 4 branches missed."> if (tx.isActive()) {</span> |
| <span class="nc" id="L181"> tx.rollback();</span> |
| } |
| <span class="pc" id="L183"> em.close();</span> |
| <span class="fc" id="L184"> }</span> |
| <span class="fc" id="L185"> }</span> |
| |
| protected static void uninstall() { |
| // Close the open emf, open a new one with Persistence.create...(String, Map) and overwrite the property that handles the table |
| // generation. The persistence.xml file will have to be read in to determine which property |
| // to overwrite. The property will be specific to the provider. |
| // Hibernate: <property name="hibernate.hbm2ddl.auto" value="update"/> ->use "create-drop" or just "drop"? |
| // OpenJPA: openjpa.jdbc.SynchronizeMappings=buildSchema(SchemaAction='add,deleteTableContents') |
| // etc...(find more) |
| // Then close this emf. Question: is the original emf reusable or will closing it cause problems? |
| |
| <span class="nc" id="L196"> }</span> |
| |
| /** |
| * Checks if there is a database with a root publisher. If it is not |
| * found an |
| * |
| * @param config |
| * @return true if it finds a database with the root publisher in it. |
| * @throws ConfigurationException |
| */ |
| protected static boolean alreadyInstalled(Configuration config) throws ConfigurationException { |
| |
| <span class="fc" id="L208"> String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);</span> |
| <span class="fc" id="L209"> log.info("Checking if jUDDI is seeded by searching for root publisher " + rootPublisherStr);</span> |
| <span class="fc" id="L210"> org.apache.juddi.model.Publisher publisher = null;</span> |
| <span class="fc" id="L211"> int numberOfTries = 0;</span> |
| <span class="pc bpc" id="L212" title="1 of 2 branches missed."> while (numberOfTries++ < 100) {</span> |
| <span class="fc" id="L213"> EntityManager em = PersistenceManager.getEntityManager();</span> |
| <span class="fc" id="L214"> EntityTransaction tx = em.getTransaction();</span> |
| try { |
| <span class="fc" id="L216"> tx.begin();</span> |
| <span class="fc" id="L217"> publisher = em.find(org.apache.juddi.model.Publisher.class, rootPublisherStr);</span> |
| <span class="fc" id="L218"> tx.commit();</span> |
| } finally { |
| <span class="pc bpc" id="L220" title="3 of 4 branches missed."> if (tx.isActive()) {</span> |
| <span class="nc" id="L221"> tx.rollback();</span> |
| } |
| <span class="pc" id="L223"> em.close();</span> |
| <span class="fc" id="L224"> }</span> |
| <span class="fc bfc" id="L225" title="All 2 branches covered."> if (publisher != null) {</span> |
| <span class="fc" id="L226"> return true;</span> |
| } |
| |
| <span class="pc bpc" id="L229" title="1 of 2 branches missed."> if (config.getBoolean(Property.JUDDI_LOAD_INSTALL_DATA, Property.DEFAULT_LOAD_INSTALL_DATA)) {</span> |
| <span class="fc" id="L230"> log.debug("Install data not yet installed.");</span> |
| <span class="fc" id="L231"> return false;</span> |
| } else { |
| try { |
| <span class="nc" id="L234"> log.info("Install data not yet installed.");</span> |
| <span class="nc" id="L235"> log.info("Going to sleep and retry...");</span> |
| <span class="nc" id="L236"> Thread.sleep(1000l);</span> |
| <span class="nc" id="L237"> } catch (InterruptedException e) {</span> |
| <span class="nc" id="L238"> log.error(e.getMessage(), e);</span> |
| <span class="nc" id="L239"> }</span> |
| } |
| <span class="nc" id="L241"> }</span> |
| <span class="nc" id="L242"> throw new ConfigurationException("Could not load the Root node data. Please check for errors.");</span> |
| } |
| |
| protected static String getRootPartition(TModel rootTModelKeyGen) throws JAXBException, IOException, DispositionReportFaultMessage { |
| <span class="fc" id="L246"> String result = rootTModelKeyGen.getTModelKey().substring(0, rootTModelKeyGen.getTModelKey().lastIndexOf(KeyGenerator.PARTITION_SEPARATOR));</span> |
| |
| <span class="pc bpc" id="L248" title="2 of 4 branches missed."> if (result == null || result.length() == 0) {</span> |
| <span class="nc" id="L249"> throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.MalformedKey", result));</span> |
| } |
| |
| // Must validate the root partition. The first component should be a domain key and the any following |
| // tokens should be a valid KSS. |
| <span class="fc" id="L254"> result = result.trim();</span> |
| <span class="pc bpc" id="L255" title="2 of 4 branches missed."> if (result.endsWith(KeyGenerator.PARTITION_SEPARATOR) || result.startsWith(KeyGenerator.PARTITION_SEPARATOR)) {</span> |
| <span class="nc" id="L256"> throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.MalformedKey", result));</span> |
| } |
| |
| <span class="fc" id="L259"> StringTokenizer tokenizer = new StringTokenizer(result.toLowerCase(), KeyGenerator.PARTITION_SEPARATOR);</span> |
| <span class="fc bfc" id="L260" title="All 2 branches covered."> for (int count = 0; tokenizer.hasMoreTokens(); count++) {</span> |
| <span class="fc" id="L261"> String nextToken = tokenizer.nextToken();</span> |
| |
| <span class="fc bfc" id="L263" title="All 2 branches covered."> if (count == 0) {</span> |
| <span class="pc bpc" id="L264" title="1 of 2 branches missed."> if (!ValidateUDDIKey.isValidDomainKey(nextToken)) {</span> |
| <span class="nc" id="L265"> throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.MalformedKey", result));</span> |
| } |
| } else { |
| <span class="pc bpc" id="L268" title="1 of 2 branches missed."> if (!ValidateUDDIKey.isValidKSS(nextToken)) {</span> |
| <span class="nc" id="L269"> throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.MalformedKey", result));</span> |
| } |
| } |
| } |
| |
| <span class="fc" id="L274"> return result;</span> |
| } |
| |
| protected static String getNodeId(String userNodeId, String rootPartition) throws DispositionReportFaultMessage { |
| |
| <span class="fc" id="L279"> String result = userNodeId;</span> |
| <span class="pc bpc" id="L280" title="2 of 4 branches missed."> if (result == null || result.length() == 0) {</span> |
| <span class="nc" id="L281"> result = rootPartition + KeyGenerator.PARTITION_SEPARATOR + UUID.randomUUID();</span> |
| } else { |
| <span class="fc" id="L283"> ValidateUDDIKey.validateUDDIv3Key(result);</span> |
| <span class="fc" id="L284"> String keyPartition = result.substring(0, result.lastIndexOf(KeyGenerator.PARTITION_SEPARATOR));</span> |
| <span class="pc bpc" id="L285" title="1 of 2 branches missed."> if (!rootPartition.equalsIgnoreCase(keyPartition)) {</span> |
| <span class="nc" id="L286"> throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", userNodeId));</span> |
| } |
| } |
| <span class="fc" id="L289"> return result;</span> |
| } |
| |
| private static String installBusinessEntity(boolean isRoot, EntityManager em, org.uddi.api_v3.BusinessEntity rootBusinessEntity, |
| UddiEntityPublisher rootPublisher, String rootPartition, Configuration config, String nodeId) |
| throws JAXBException, DispositionReportFaultMessage, IOException { |
| |
| <span class="pc bpc" id="L296" title="1 of 2 branches missed."> if (isRoot) {</span> |
| <span class="fc" id="L297"> validateRootBusinessEntity(rootBusinessEntity, rootPublisher, rootPartition, config);</span> |
| } |
| |
| <span class="fc" id="L300"> org.apache.juddi.model.BusinessEntity modelBusinessEntity = new org.apache.juddi.model.BusinessEntity();</span> |
| <span class="fc" id="L301"> MappingApiToModel.mapBusinessEntity(rootBusinessEntity, modelBusinessEntity);</span> |
| |
| <span class="fc" id="L303"> modelBusinessEntity.setAuthorizedName(rootPublisher.getAuthorizedName());</span> |
| <span class="fc" id="L304"> modelBusinessEntity.setNodeId(nodeId);</span> |
| <span class="fc" id="L305"> Date now = new Date();</span> |
| <span class="fc" id="L306"> modelBusinessEntity.setCreated(now);</span> |
| <span class="fc" id="L307"> modelBusinessEntity.setModified(now);</span> |
| <span class="fc" id="L308"> modelBusinessEntity.setModifiedIncludingChildren(now);</span> |
| //JUDDI-645 |
| //modelBusinessEntity.setNodeId(modelBusinessEntity.getEntityKey()); |
| <span class="fc" id="L311"> modelBusinessEntity.setNodeId(config.getString(Property.JUDDI_NODE_ID, modelBusinessEntity.getEntityKey()));</span> |
| |
| <span class="fc bfc" id="L313" title="All 2 branches covered."> for (org.apache.juddi.model.BusinessService service : modelBusinessEntity.getBusinessServices()) {</span> |
| <span class="fc" id="L314"> service.setAuthorizedName(rootPublisher.getAuthorizedName());</span> |
| <span class="fc" id="L315"> service.setNodeId(modelBusinessEntity.getNodeId());</span> |
| <span class="fc" id="L316"> service.setCreated(now);</span> |
| <span class="fc" id="L317"> service.setModified(now);</span> |
| <span class="fc" id="L318"> service.setModifiedIncludingChildren(now);</span> |
| //JUDDI-645 |
| //service.setNodeId(config.getString(Property.JUDDI_NODE_ID,modelBusinessEntity.getEntityKey())); |
| //service.setNodeId(modelBusinessEntity.getEntityKey()); |
| |
| <span class="fc bfc" id="L323" title="All 2 branches covered."> for (org.apache.juddi.model.BindingTemplate binding : service.getBindingTemplates()) {</span> |
| <span class="fc" id="L324"> binding.setAuthorizedName(rootPublisher.getAuthorizedName());</span> |
| <span class="fc" id="L325"> binding.setNodeId(nodeId);</span> |
| <span class="fc" id="L326"> binding.setCreated(now);</span> |
| <span class="fc" id="L327"> binding.setModified(now);</span> |
| <span class="fc" id="L328"> binding.setModifiedIncludingChildren(now);</span> |
| //binding.setNodeId(modelBusinessEntity.getEntityKey()); |
| //binding.setNodeId(config.getString(Property.JUDDI_NODE_ID,modelBusinessEntity.getEntityKey())); |
| //JUDDI-645 |
| |
| <span class="fc" id="L333"> }</span> |
| <span class="fc" id="L334"> }</span> |
| |
| <span class="fc" id="L336"> em.persist(modelBusinessEntity);</span> |
| <span class="fc" id="L337"> SaveBusiness sb = new SaveBusiness();</span> |
| <span class="fc" id="L338"> sb.getBusinessEntity().add(rootBusinessEntity);</span> |
| <span class="fc" id="L339"> ReplicationNotifier.enqueue(UDDIPublicationImpl.getChangeRecord(modelBusinessEntity, rootBusinessEntity, modelBusinessEntity.getNodeId()));</span> |
| |
| <span class="fc" id="L341"> return modelBusinessEntity.getEntityKey();</span> |
| |
| } |
| |
| // A watered down version of ValidatePublish's validateBusinessEntity, designed for the specific condition that this is run upon the initial |
| // jUDDI install. |
| private static void validateRootBusinessEntity(org.uddi.api_v3.BusinessEntity businessEntity, UddiEntityPublisher rootPublisher, |
| String rootPartition, Configuration config) |
| throws DispositionReportFaultMessage { |
| |
| // A supplied businessService can't be null |
| <span class="pc bpc" id="L352" title="1 of 2 branches missed."> if (businessEntity == null) {</span> |
| <span class="nc" id="L353"> throw new ValueNotAllowedException(new ErrorMessage("errors.businessentity.NullInput"));</span> |
| } |
| |
| // The business key should already be set to the previously calculated and validated nodeId. This validation is unnecessary but kept for |
| // symmetry with the other entity validations. |
| <span class="fc" id="L358"> String entityKey = businessEntity.getBusinessKey();</span> |
| <span class="pc bpc" id="L359" title="2 of 4 branches missed."> if (entityKey == null || entityKey.length() == 0) {</span> |
| <span class="nc" id="L360"> entityKey = rootPartition + KeyGenerator.PARTITION_SEPARATOR + UUID.randomUUID();</span> |
| <span class="nc" id="L361"> businessEntity.setBusinessKey(entityKey);</span> |
| } else { |
| // Per section 4.4: keys must be case-folded |
| <span class="fc" id="L364"> entityKey = entityKey.toLowerCase();</span> |
| <span class="fc" id="L365"> businessEntity.setBusinessKey(entityKey);</span> |
| |
| <span class="fc" id="L367"> ValidateUDDIKey.validateUDDIv3Key(entityKey);</span> |
| <span class="fc" id="L368"> String keyPartition = entityKey.substring(0, entityKey.lastIndexOf(KeyGenerator.PARTITION_SEPARATOR));</span> |
| <span class="pc bpc" id="L369" title="1 of 2 branches missed."> if (!rootPartition.equalsIgnoreCase(keyPartition)) {</span> |
| <span class="nc" id="L370"> throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));</span> |
| } |
| } |
| |
| <span class="fc" id="L374"> ValidatePublish validatePublish = new ValidatePublish(rootPublisher, config.getString(Property.JUDDI_NODE_ID));</span> |
| |
| <span class="fc" id="L376"> validatePublish.validateNames(businessEntity.getName());</span> |
| <span class="fc" id="L377"> validatePublish.validateDiscoveryUrls(businessEntity.getDiscoveryURLs());</span> |
| <span class="fc" id="L378"> validatePublish.validateContacts(businessEntity.getContacts(), config);</span> |
| <span class="fc" id="L379"> validatePublish.validateCategoryBag(businessEntity.getCategoryBag(), config, true);</span> |
| <span class="fc" id="L380"> validatePublish.validateIdentifierBag(businessEntity.getIdentifierBag(), config, true);</span> |
| |
| <span class="fc" id="L382"> org.uddi.api_v3.BusinessServices businessServices = businessEntity.getBusinessServices();</span> |
| <span class="pc bpc" id="L383" title="1 of 2 branches missed."> if (businessServices != null) {</span> |
| <span class="fc" id="L384"> List<org.uddi.api_v3.BusinessService> businessServiceList = businessServices.getBusinessService();</span> |
| <span class="pc bpc" id="L385" title="2 of 4 branches missed."> if (businessServiceList == null || businessServiceList.size() == 0) {</span> |
| <span class="nc" id="L386"> throw new ValueNotAllowedException(new ErrorMessage("errors.businessservices.NoInput"));</span> |
| } |
| |
| <span class="fc bfc" id="L389" title="All 2 branches covered."> for (org.uddi.api_v3.BusinessService businessService : businessServiceList) {</span> |
| <span class="fc" id="L390"> validateRootBusinessService(businessService, businessEntity, rootPublisher, rootPartition, config);</span> |
| <span class="fc" id="L391"> }</span> |
| } |
| |
| <span class="fc" id="L394"> }</span> |
| |
| // A watered down version of ValidatePublish's validateBusinessService, designed for the specific condition that this is run upon the initial |
| // jUDDI install. |
| private static void validateRootBusinessService(org.uddi.api_v3.BusinessService businessService, org.uddi.api_v3.BusinessEntity parent, |
| UddiEntityPublisher rootPublisher, String rootPartition, Configuration config) |
| throws DispositionReportFaultMessage { |
| |
| // A supplied businessService can't be null |
| <span class="pc bpc" id="L403" title="1 of 2 branches missed."> if (businessService == null) {</span> |
| <span class="nc" id="L404"> throw new ValueNotAllowedException(new ErrorMessage("errors.businessservice.NullInput"));</span> |
| } |
| |
| // A business key doesn't have to be provided, but if it is, it should match the parent business's key |
| <span class="fc" id="L408"> String parentKey = businessService.getBusinessKey();</span> |
| <span class="pc bpc" id="L409" title="2 of 4 branches missed."> if (parentKey != null && parentKey.length() > 0) {</span> |
| <span class="pc bpc" id="L410" title="1 of 2 branches missed."> if (!parentKey.equalsIgnoreCase(parent.getBusinessKey())) {</span> |
| <span class="nc" id="L411"> throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentBusinessNotFound", parentKey + " " + businessService.getBusinessKey() + " " + businessService.getBusinessKey().length() + " " + parentKey.length()));</span> |
| } |
| } |
| |
| // Retrieve the service's passed key |
| <span class="fc" id="L416"> String entityKey = businessService.getServiceKey();</span> |
| <span class="pc bpc" id="L417" title="2 of 4 branches missed."> if (entityKey == null || entityKey.length() == 0) {</span> |
| <span class="nc" id="L418"> entityKey = rootPartition + KeyGenerator.PARTITION_SEPARATOR + UUID.randomUUID();</span> |
| <span class="nc" id="L419"> businessService.setServiceKey(entityKey);</span> |
| } else { |
| // Per section 4.4: keys must be case-folded |
| <span class="fc" id="L422"> entityKey = entityKey.toLowerCase();</span> |
| <span class="fc" id="L423"> businessService.setServiceKey(entityKey);</span> |
| |
| <span class="fc" id="L425"> ValidateUDDIKey.validateUDDIv3Key(entityKey);</span> |
| <span class="fc" id="L426"> String keyPartition = entityKey.substring(0, entityKey.lastIndexOf(KeyGenerator.PARTITION_SEPARATOR));</span> |
| <span class="pc bpc" id="L427" title="1 of 2 branches missed."> if (!rootPartition.equalsIgnoreCase(keyPartition)) {</span> |
| <span class="nc" id="L428"> throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));</span> |
| } |
| } |
| |
| <span class="fc" id="L432"> ValidatePublish validatePublish = new ValidatePublish(rootPublisher, config.getString(Property.JUDDI_NODE_ID));</span> |
| |
| <span class="fc" id="L434"> validatePublish.validateNames(businessService.getName());</span> |
| <span class="fc" id="L435"> validatePublish.validateCategoryBag(businessService.getCategoryBag(), config, true);</span> |
| |
| <span class="fc" id="L437"> org.uddi.api_v3.BindingTemplates bindingTemplates = businessService.getBindingTemplates();</span> |
| <span class="pc bpc" id="L438" title="1 of 2 branches missed."> if (bindingTemplates != null) {</span> |
| <span class="fc" id="L439"> List<org.uddi.api_v3.BindingTemplate> bindingTemplateList = bindingTemplates.getBindingTemplate();</span> |
| <span class="pc bpc" id="L440" title="2 of 4 branches missed."> if (bindingTemplateList == null || bindingTemplateList.size() == 0) {</span> |
| <span class="nc" id="L441"> throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplates.NoInput"));</span> |
| } |
| |
| <span class="fc bfc" id="L444" title="All 2 branches covered."> for (org.uddi.api_v3.BindingTemplate bindingTemplate : bindingTemplateList) {</span> |
| <span class="fc" id="L445"> validateRootBindingTemplate(bindingTemplate, businessService, rootPublisher, rootPartition, config);</span> |
| <span class="fc" id="L446"> }</span> |
| } |
| <span class="fc" id="L448"> }</span> |
| |
| // A watered down version of ValidatePublish's validatBindingTemplate, designed for the specific condition that this is run upon the initial |
| // jUDDI install. |
| private static void validateRootBindingTemplate(org.uddi.api_v3.BindingTemplate bindingTemplate, org.uddi.api_v3.BusinessService parent, |
| UddiEntityPublisher rootPublisher, String rootPartition, Configuration config) |
| throws DispositionReportFaultMessage { |
| |
| // A supplied businessService can't be null |
| <span class="pc bpc" id="L457" title="1 of 2 branches missed."> if (bindingTemplate == null) {</span> |
| <span class="nc" id="L458"> throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplate.NullInput"));</span> |
| } |
| |
| // A service key doesn't have to be provided, but if it is, it should match the parent service's key |
| <span class="fc" id="L462"> String parentKey = bindingTemplate.getServiceKey();</span> |
| <span class="pc bpc" id="L463" title="2 of 4 branches missed."> if (parentKey != null && parentKey.length() > 0) {</span> |
| <span class="pc bpc" id="L464" title="1 of 2 branches missed."> if (!parentKey.equalsIgnoreCase(parent.getServiceKey())) {</span> |
| <span class="nc" id="L465"> throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentServiceNotFound", parentKey));</span> |
| } |
| } |
| |
| // Retrieve the service's passed key |
| <span class="fc" id="L470"> String entityKey = bindingTemplate.getBindingKey();</span> |
| <span class="pc bpc" id="L471" title="2 of 4 branches missed."> if (entityKey == null || entityKey.length() == 0) {</span> |
| <span class="nc" id="L472"> entityKey = rootPartition + KeyGenerator.PARTITION_SEPARATOR + UUID.randomUUID();</span> |
| <span class="nc" id="L473"> bindingTemplate.setBindingKey(entityKey);</span> |
| } else { |
| // Per section 4.4: keys must be case-folded |
| <span class="fc" id="L476"> entityKey = entityKey.toLowerCase();</span> |
| <span class="fc" id="L477"> bindingTemplate.setBindingKey(entityKey);</span> |
| |
| <span class="fc" id="L479"> ValidateUDDIKey.validateUDDIv3Key(entityKey);</span> |
| <span class="fc" id="L480"> String keyPartition = entityKey.substring(0, entityKey.lastIndexOf(KeyGenerator.PARTITION_SEPARATOR));</span> |
| <span class="pc bpc" id="L481" title="1 of 2 branches missed."> if (!rootPartition.equalsIgnoreCase(keyPartition)) {</span> |
| <span class="nc" id="L482"> throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));</span> |
| } |
| } |
| |
| <span class="fc" id="L486"> ValidatePublish validatePublish = new ValidatePublish(rootPublisher, config.getString(Property.JUDDI_NODE_ID));</span> |
| |
| <span class="fc" id="L488"> validatePublish.validateCategoryBag(bindingTemplate.getCategoryBag(), config, true);</span> |
| <span class="fc" id="L489"> validatePublish.validateTModelInstanceDetails(bindingTemplate.getTModelInstanceDetails(), config, true);</span> |
| |
| <span class="fc" id="L491"> }</span> |
| |
| private static void installTModels(EntityManager em, List<org.uddi.api_v3.TModel> apiTModelList, UddiEntityPublisher publisher, String nodeId) throws DispositionReportFaultMessage { |
| <span class="pc bpc" id="L494" title="1 of 2 branches missed."> if (apiTModelList != null) {</span> |
| <span class="fc bfc" id="L495" title="All 2 branches covered."> for (org.uddi.api_v3.TModel apiTModel : apiTModelList) {</span> |
| <span class="fc" id="L496"> String tModelKey = apiTModel.getTModelKey();</span> |
| |
| <span class="fc bfc" id="L498" title="All 2 branches covered."> if (tModelKey.toUpperCase().endsWith(KeyGenerator.KEYGENERATOR_SUFFIX.toUpperCase())) {</span> |
| <span class="fc" id="L499"> installPublisherKeyGen(em, apiTModel, publisher, nodeId);</span> |
| } else { |
| <span class="fc" id="L501"> org.apache.juddi.model.Tmodel modelTModel = new org.apache.juddi.model.Tmodel();</span> |
| <span class="fc" id="L502"> apiTModel.setTModelKey(apiTModel.getTModelKey().toLowerCase());</span> |
| |
| <span class="fc" id="L504"> MappingApiToModel.mapTModel(apiTModel, modelTModel);</span> |
| |
| <span class="fc" id="L506"> modelTModel.setAuthorizedName(publisher.getAuthorizedName());</span> |
| |
| <span class="fc" id="L508"> Date now = new Date();</span> |
| <span class="fc" id="L509"> modelTModel.setCreated(now);</span> |
| <span class="fc" id="L510"> modelTModel.setModified(now);</span> |
| <span class="fc" id="L511"> modelTModel.setModifiedIncludingChildren(now);</span> |
| <span class="fc" id="L512"> modelTModel.setNodeId(nodeId);</span> |
| |
| <span class="fc" id="L514"> em.persist(modelTModel);</span> |
| |
| <span class="fc" id="L516"> SaveTModel stm = new SaveTModel();</span> |
| <span class="fc" id="L517"> stm.getTModel().add(apiTModel);</span> |
| <span class="fc" id="L518"> ReplicationNotifier.enqueue(UDDIPublicationImpl.getChangeRecord(modelTModel, apiTModel, nodeId));</span> |
| } |
| |
| <span class="fc" id="L521"> }</span> |
| } |
| |
| <span class="fc" id="L524"> }</span> |
| |
| private static void installRootPublisherKeyGen(EntityManager em, TModel rootTModelKeyGen, String rootPartition, UddiEntityPublisher publisher, String nodeId) |
| throws DispositionReportFaultMessage { |
| |
| <span class="fc" id="L529"> rootTModelKeyGen.setTModelKey(rootPartition + KeyGenerator.PARTITION_SEPARATOR + KeyGenerator.KEYGENERATOR_SUFFIX);</span> |
| |
| <span class="fc" id="L531"> installPublisherKeyGen(em, rootTModelKeyGen, publisher, nodeId);</span> |
| <span class="fc" id="L532"> }</span> |
| |
| private static void installPublisherKeyGen(EntityManager em, TModel apiTModel, UddiEntityPublisher publisher, String nodeId) throws DispositionReportFaultMessage { |
| |
| <span class="fc" id="L536"> org.apache.juddi.model.Tmodel modelTModel = new org.apache.juddi.model.Tmodel();</span> |
| <span class="fc" id="L537"> MappingApiToModel.mapTModel(apiTModel, modelTModel);</span> |
| |
| <span class="fc" id="L539"> modelTModel.setAuthorizedName(publisher.getAuthorizedName());</span> |
| |
| <span class="fc" id="L541"> Date now = new Date();</span> |
| <span class="fc" id="L542"> modelTModel.setCreated(now);</span> |
| <span class="fc" id="L543"> modelTModel.setModified(now);</span> |
| <span class="fc" id="L544"> modelTModel.setModifiedIncludingChildren(now);</span> |
| <span class="fc" id="L545"> modelTModel.setNodeId(nodeId);</span> |
| |
| <span class="fc" id="L547"> em.persist(modelTModel);</span> |
| |
| <span class="fc" id="L549"> }</span> |
| |
| private static List<String> getPublishers(Configuration config) throws ConfigurationException { |
| <span class="fc" id="L552"> List<String> publishers = new ArrayList<String>();</span> |
| <span class="fc" id="L553"> String basePath = JUDDI_CUSTOM_INSTALL_DATA_DIR;</span> |
| <span class="fc" id="L554"> URL url = ClassUtil.getResource(JUDDI_CUSTOM_INSTALL_DATA_DIR, Install.class);</span> |
| <span class="pc bpc" id="L555" title="1 of 2 branches missed."> if (url == null) {</span> |
| <span class="fc" id="L556"> url = ClassUtil.getResource(JUDDI_INSTALL_DATA_DIR, Install.class);</span> |
| <span class="fc" id="L557"> basePath = JUDDI_INSTALL_DATA_DIR;</span> |
| } |
| |
| <span class="fc" id="L560"> String path = null;</span> |
| |
| try { |
| <span class="fc" id="L563"> path = url.toURI().getSchemeSpecificPart();</span> |
| <span class="nc" id="L564"> } catch (URISyntaxException e) {</span> |
| <span class="nc" id="L565"> throw new ConfigurationException(e);</span> |
| <span class="fc" id="L566"> }</span> |
| |
| <span class="fc" id="L568"> File dir = new File(path);</span> |
| <span class="fc" id="L569"> String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);</span> |
| <span class="pc bpc" id="L570" title="1 of 2 branches missed."> if (dir.exists()) {</span> |
| <span class="fc" id="L571"> log.debug("Discovering the Publisher XML data files in directory: " + path);</span> |
| <span class="fc" id="L572"> File[] files = dir.listFiles(new PublisherFileFilter());</span> |
| <span class="pc bpc" id="L573" title="1 of 2 branches missed."> if (files!=null)</span> |
| <span class="fc bfc" id="L574" title="All 2 branches covered."> for (File f : files) {</span> |
| <span class="fc" id="L575"> String publisher = f.getName().substring(0, f.getName().indexOf(FILE_PUBLISHER));</span> |
| <span class="fc bfc" id="L576" title="All 2 branches covered."> if (!rootPublisherStr.equalsIgnoreCase(publisher)) {</span> |
| <span class="fc" id="L577"> publishers.add(publisher);</span> |
| } |
| } |
| <span class="fc" id="L580"> } else {</span> |
| <span class="nc" id="L581"> String[] paths = {};</span> |
| <span class="nc" id="L582"> Enumeration<JarEntry> en = null;</span> |
| <span class="nc" id="L583"> JarFile jf = null;</span> |
| try { |
| |
| <span class="nc bnc" id="L586" title="All 2 branches missed."> if (path.indexOf("!") > 0) {</span> |
| <span class="nc" id="L587"> paths = path.split("!");</span> |
| <span class="nc" id="L588"> jf = new JarFile(new File(new URI(paths[0])));</span> |
| <span class="nc" id="L589"> en = jf.entries();</span> |
| } else { |
| // Handle Windows / jboss-5.1.0 case |
| <span class="nc bnc" id="L592" title="All 2 branches missed."> if (path.indexOf(".jar") > 0) {</span> |
| <span class="nc" id="L593"> paths = path.split(".jar");</span> |
| <span class="nc" id="L594"> paths[0] = paths[0] + ".jar";</span> |
| <span class="nc" id="L595"> File temp = new File(paths[0]);</span> |
| <span class="nc bnc" id="L596" title="All 2 branches missed."> if (temp.exists()) {</span> |
| <span class="nc" id="L597"> jf = new JarFile(temp);</span> |
| <span class="nc" id="L598"> en = jf.entries();</span> |
| } |
| } |
| } |
| <span class="nc bnc" id="L602" title="All 2 branches missed."> if (paths.length > 0) {</span> |
| <span class="nc" id="L603"> log.debug("Discovering the Publisher XML data files in jar: " + paths[0]);</span> |
| <span class="nc bnc" id="L604" title="All 4 branches missed."> while (en != null && en.hasMoreElements()) {</span> |
| <span class="nc" id="L605"> String name = en.nextElement().getName();</span> |
| <span class="nc bnc" id="L606" title="All 2 branches missed."> if (name.endsWith(FILE_PUBLISHER)) {</span> |
| <span class="nc" id="L607"> log.debug("Found publisher file=" + name);</span> |
| <span class="nc" id="L608"> String publisher = name.substring(basePath.length(), name.indexOf(FILE_PUBLISHER));</span> |
| <span class="nc bnc" id="L609" title="All 2 branches missed."> if (!rootPublisherStr.equalsIgnoreCase(publisher)) {</span> |
| <span class="nc" id="L610"> publishers.add(publisher);</span> |
| } |
| } |
| <span class="nc" id="L613"> }</span> |
| } else { |
| <span class="nc" id="L615"> log.info("No custom configuration files where found in " + path);</span> |
| } |
| <span class="nc bnc" id="L617" title="All 2 branches missed."> if (jf != null) {</span> |
| <span class="nc" id="L618"> jf.close();</span> |
| } |
| |
| <span class="nc" id="L621"> } catch (IOException e) {</span> |
| <span class="nc" id="L622"> throw new ConfigurationException(e);</span> |
| <span class="nc" id="L623"> } catch (URISyntaxException e) {</span> |
| <span class="nc" id="L624"> throw new ConfigurationException(e);</span> |
| <span class="nc" id="L625"> }</span> |
| } |
| <span class="fc" id="L627"> return publishers;</span> |
| } |
| |
| private static Object buildInstallEntityAlt(final String fileName, Class outputtype, Configuration config) throws JAXBException, IOException, ConfigurationException { |
| <span class="fc" id="L631"> InputStream resourceStream = null;</span> |
| |
| // First try the custom install directory |
| <span class="fc" id="L634"> URL url = ClassUtil.getResource(JUDDI_CUSTOM_INSTALL_DATA_DIR + fileName, Install.class);</span> |
| <span class="pc bpc" id="L635" title="1 of 2 branches missed."> if (url != null) {</span> |
| <span class="nc" id="L636"> resourceStream = url.openStream();</span> |
| } |
| |
| // If the custom install directory doesn't exist, then use the standard install directory where the resource is guaranteed to exist. |
| <span class="pc bpc" id="L640" title="1 of 2 branches missed."> if (resourceStream == null) {</span> |
| <span class="fc" id="L641"> url = ClassUtil.getResource(JUDDI_INSTALL_DATA_DIR + fileName, Install.class);</span> |
| <span class="pc bpc" id="L642" title="1 of 2 branches missed."> if (url != null) {</span> |
| <span class="fc" id="L643"> resourceStream = url.openStream();</span> |
| } |
| // If file still does not exist then return null; |
| <span class="pc bpc" id="L646" title="2 of 4 branches missed."> if (url == null || resourceStream == null) {</span> |
| <span class="nc bnc" id="L647" title="All 2 branches missed."> if (fileName.endsWith(FILE_PUBLISHER)) {</span> |
| <span class="nc" id="L648"> throw new ConfigurationException("Could not locate " + JUDDI_INSTALL_DATA_DIR + fileName);</span> |
| } else { |
| <span class="nc" id="L650"> log.debug("Could not locate: " + url);</span> |
| } |
| <span class="nc" id="L652"> return null;</span> |
| } |
| } |
| <span class="fc" id="L655"> log.info("Loading the content of file: " + url);</span> |
| <span class="fc" id="L656"> StringBuilder xml = new StringBuilder();</span> |
| <span class="fc" id="L657"> byte[] b = new byte[4096];</span> |
| <span class="fc bfc" id="L658" title="All 2 branches covered."> for (int n; (n = resourceStream.read(b)) != -1;) {</span> |
| <span class="fc" id="L659"> xml.append(new String(b, 0, n, AuthenticatedService.UTF8));</span> |
| } |
| <span class="fc" id="L661"> log.debug("inserting: " + xml.toString());</span> |
| <span class="fc" id="L662"> StringReader reader = new StringReader(xml.toString());</span> |
| |
| <span class="fc" id="L664"> Object obj= XmlUtils.unmarshal(reader, outputtype);</span> |
| <span class="fc" id="L665"> reader.close();</span> |
| <span class="fc" id="L666"> return obj;</span> |
| } |
| |
| private static Object buildInstallEntity(final String fileName, String packageName, Configuration config) throws JAXBException, IOException, ConfigurationException, XMLStreamException { |
| <span class="fc" id="L670"> InputStream resourceStream = null;</span> |
| |
| // First try the custom install directory |
| <span class="fc" id="L673"> URL url = ClassUtil.getResource(JUDDI_CUSTOM_INSTALL_DATA_DIR + fileName, Install.class);</span> |
| <span class="pc bpc" id="L674" title="1 of 2 branches missed."> if (url != null) {</span> |
| <span class="nc" id="L675"> resourceStream = url.openStream();</span> |
| } |
| |
| // If the custom install directory doesn't exist, then use the standard install directory where the resource is guaranteed to exist. |
| <span class="pc bpc" id="L679" title="1 of 2 branches missed."> if (resourceStream == null) {</span> |
| <span class="fc" id="L680"> url = ClassUtil.getResource(JUDDI_INSTALL_DATA_DIR + fileName, Install.class);</span> |
| <span class="fc bfc" id="L681" title="All 2 branches covered."> if (url != null) {</span> |
| <span class="fc" id="L682"> resourceStream = url.openStream();</span> |
| } |
| // If file still does not exist then return null; |
| <span class="pc bpc" id="L685" title="1 of 4 branches missed."> if (url == null || resourceStream == null) {</span> |
| <span class="pc bpc" id="L686" title="1 of 2 branches missed."> if (fileName.endsWith(FILE_PUBLISHER)) {</span> |
| <span class="nc" id="L687"> throw new ConfigurationException("Could not locate " + JUDDI_INSTALL_DATA_DIR + fileName);</span> |
| } else { |
| <span class="fc" id="L689"> log.debug("Could not locate: " + url);</span> |
| } |
| <span class="fc" id="L691"> return null;</span> |
| } |
| } |
| <span class="fc" id="L694"> log.info("Loading the content of file: " + url);</span> |
| <span class="fc" id="L695"> StringBuilder xml = new StringBuilder();</span> |
| <span class="fc" id="L696"> byte[] b = new byte[4096];</span> |
| <span class="fc bfc" id="L697" title="All 2 branches covered."> for (int n; (n = resourceStream.read(b)) != -1;) {</span> |
| <span class="fc" id="L698"> xml.append(new String(b, 0, n, AuthenticatedService.UTF8));</span> |
| } |
| <span class="fc" id="L700"> log.debug("inserting: " + xml.toString());</span> |
| <span class="fc" id="L701"> StringReader reader = new StringReader(xml.toString());</span> |
| |
| <span class="fc" id="L703"> Object obj= XmlUtils.unmarshal(reader, packageName);</span> |
| <span class="fc" id="L704"> reader.close();</span> |
| <span class="fc" id="L705"> return obj;</span> |
| } |
| |
| /** |
| * Public convenience method that allows one to retrieve the node |
| * business entity (perhaps to display during an install process, or |
| * even to initiate the install process). |
| * |
| * @param businessKey |
| * @return BusinessEntity Object |
| * @throws DispositionReportFaultMessage |
| */ |
| public static org.uddi.api_v3.BusinessEntity getNodeBusinessEntity(String businessKey) throws DispositionReportFaultMessage { |
| <span class="nc" id="L718"> UDDIInquiryImpl inquiry = new UDDIInquiryImpl();</span> |
| |
| <span class="nc" id="L720"> org.uddi.api_v3.GetBusinessDetail gbd = new org.uddi.api_v3.GetBusinessDetail();</span> |
| <span class="nc" id="L721"> gbd.getBusinessKey().add(businessKey);</span> |
| |
| <span class="nc" id="L723"> org.uddi.api_v3.BusinessDetail bd = inquiry.getBusinessDetail(gbd);</span> |
| <span class="nc bnc" id="L724" title="All 2 branches missed."> if (bd != null) {</span> |
| <span class="nc" id="L725"> List<org.uddi.api_v3.BusinessEntity> beList = bd.getBusinessEntity();</span> |
| <span class="nc bnc" id="L726" title="All 4 branches missed."> if (beList != null && beList.size() > 0) {</span> |
| <span class="nc" id="L727"> return beList.get(0);</span> |
| } |
| } |
| |
| <span class="nc" id="L731"> return new org.uddi.api_v3.BusinessEntity();</span> |
| } |
| |
| /** |
| * Public convenience method that allows one to install additional |
| * TModels via a SaveTModel structure. |
| * |
| * @param em - the entity manager to a juddi model |
| * @param fileName - name of SaveTModel xml file |
| * @param publisher - the publisher structure that owns the tModels |
| * @param nodeId - the node id of the custodial node |
| * @throws JAXBException |
| * @throws DispositionReportFaultMessage |
| * @throws IOException |
| * @throws ConfigurationException |
| */ |
| public static void installSaveTModel(EntityManager em, String fileName, UddiEntityPublisher publisher, String nodeId, Configuration config) |
| throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException, XMLStreamException { |
| |
| <span class="fc" id="L750"> SaveTModel apiSaveTModel = (SaveTModel) buildInstallEntity(fileName, "org.uddi.api_v3", config);</span> |
| <span class="pc bpc" id="L751" title="1 of 2 branches missed."> if (apiSaveTModel != null) {</span> |
| <span class="fc" id="L752"> installTModels(em, apiSaveTModel.getTModel(), publisher, nodeId);</span> |
| } |
| <span class="fc" id="L754"> }</span> |
| |
| /** |
| * Public convenience method that allows one to install additional |
| * Publishers via a Publisher structure. |
| * |
| * @param em - the entity manager to the juddi model |
| * @param fileName - name of Publisher xml file |
| * @return UddiEntityPublisher object, can be any UDDIEntity |
| * @throws JAXBException |
| * @throws DispositionReportFaultMessage |
| * @throws IOException |
| * @throws ConfigurationException |
| */ |
| public static UddiEntityPublisher installPublisher(EntityManager em, String fileName, Configuration config) |
| throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException, XMLStreamException { |
| |
| <span class="fc" id="L771"> org.apache.juddi.api_v3.Publisher apiPub = (org.apache.juddi.api_v3.Publisher) buildInstallEntity(fileName, "org.apache.juddi.api_v3", config);</span> |
| <span class="pc bpc" id="L772" title="1 of 2 branches missed."> if (apiPub == null) {</span> |
| <span class="nc" id="L773"> return null;</span> |
| } |
| <span class="fc" id="L775"> org.apache.juddi.model.Publisher modelPub = new org.apache.juddi.model.Publisher();</span> |
| <span class="fc" id="L776"> MappingApiToModel.mapPublisher(apiPub, modelPub);</span> |
| <span class="fc" id="L777"> em.persist(modelPub);</span> |
| <span class="fc" id="L778"> return modelPub;</span> |
| } |
| |
| public static org.uddi.repl_v3.ReplicationConfiguration applyReplicationTokenChanges(org.uddi.repl_v3.ReplicationConfiguration replicationCfg, Configuration config, String thisnode) { |
| <span class="fc" id="L782"> log.info("replacing tokens on repl config");</span> |
| <span class="pc bpc" id="L783" title="1 of 2 branches missed."> if (replicationCfg == null) {</span> |
| <span class="nc" id="L784"> return null;</span> |
| } |
| //apply any token replacements |
| <span class="fc bfc" id="L787" title="All 2 branches covered."> for (Operator op : replicationCfg.getOperator()) {</span> |
| <span class="fc" id="L788"> op.setOperatorNodeID(op.getOperatorNodeID().replace("${juddi.nodeId}", thisnode));</span> |
| <span class="fc" id="L789"> op.setSoapReplicationURL(op.getSoapReplicationURL().replace("${juddi.server.baseurlsecure}", config.getString("juddi.server.baseurlsecure")));</span> |
| <span class="fc" id="L790"> op.setSoapReplicationURL(op.getSoapReplicationURL().replace("${juddi.server.baseurl}", config.getString("juddi.server.baseurl")));</span> |
| <span class="fc" id="L791"> }</span> |
| <span class="pc bpc" id="L792" title="1 of 2 branches missed."> if (replicationCfg.getCommunicationGraph() != null) {</span> |
| <span class="fc bfc" id="L793" title="All 2 branches covered."> for (int i = 0; i < replicationCfg.getCommunicationGraph().getNode().size(); i++) {</span> |
| <span class="fc" id="L794"> replicationCfg.getCommunicationGraph().getNode().set(i, replicationCfg.getCommunicationGraph().getNode().get(i).replace("${juddi.nodeId}", thisnode));</span> |
| |
| } |
| <span class="pc bpc" id="L797" title="1 of 2 branches missed."> for (int i = 0; i < replicationCfg.getCommunicationGraph().getEdge().size(); i++) {</span> |
| <span class="nc" id="L798"> replicationCfg.getCommunicationGraph().getEdge().get(i).setMessageSender(replicationCfg.getCommunicationGraph().getEdge().get(i).getMessageSender().replace("${juddi.nodeId}", thisnode));</span> |
| <span class="nc" id="L799"> replicationCfg.getCommunicationGraph().getEdge().get(i).setMessageReceiver(replicationCfg.getCommunicationGraph().getEdge().get(i).getMessageReceiver().replace("${juddi.nodeId}", thisnode));</span> |
| <span class="nc bnc" id="L800" title="All 2 branches missed."> for (int k = 0; k < replicationCfg.getCommunicationGraph().getEdge().get(i).getMessageReceiverAlternate().size(); k++) {</span> |
| <span class="nc" id="L801"> replicationCfg.getCommunicationGraph().getEdge().get(i).getMessageReceiverAlternate().set(k, replicationCfg.getCommunicationGraph().getEdge().get(i).getMessageReceiverAlternate().get(k).replace("${juddi.nodeId}", thisnode));</span> |
| } |
| } |
| } |
| |
| <span class="fc bfc" id="L806" title="All 2 branches covered."> for (Operator op : replicationCfg.getOperator()) {</span> |
| <span class="fc" id="L807"> op.setOperatorNodeID(op.getOperatorNodeID().replace("${juddi.nodeId}", thisnode));</span> |
| <span class="fc" id="L808"> }</span> |
| <span class="fc" id="L809"> log.info("replacing tokens on repl config, done");</span> |
| <span class="fc" id="L810"> return replicationCfg;</span> |
| } |
| |
| private static void installReplicationConfiguration(EntityManager em, org.uddi.repl_v3.ReplicationConfiguration replicationCfg, Configuration config, String thisnode) throws DispositionReportFaultMessage, ConfigurationException { |
| <span class="fc" id="L814"> replicationCfg = applyReplicationTokenChanges(replicationCfg, config, thisnode);</span> |
| <span class="fc" id="L815"> new ValidateReplication(null, thisnode).validateSetReplicationNodes(replicationCfg, em, thisnode, config);</span> |
| |
| <span class="fc" id="L817"> SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmZ");</span> |
| <span class="fc" id="L818"> replicationCfg.setTimeOfConfigurationUpdate(sdf.format(new Date()));</span> |
| |
| <span class="fc" id="L820"> org.apache.juddi.model.ReplicationConfiguration model = new ReplicationConfiguration();</span> |
| |
| <span class="fc" id="L822"> MappingApiToModel.mapReplicationConfiguration(replicationCfg, model, em);</span> |
| |
| <span class="fc" id="L824"> model.setSerialNumber(System.currentTimeMillis());</span> |
| |
| <span class="fc" id="L826"> org.apache.juddi.model.ReplicationConfiguration oldstuff = null;</span> |
| // logger.info(publisher.getAuthorizedName() + " is setting the replication config from " + getRequestorsIPAddress());// + " " + sw.toString()); |
| try { |
| <span class="nc" id="L829"> oldstuff = (ReplicationConfiguration) em.createQuery("select c FROM ReplicationConfiguration c order by c.serialNumber desc").getSingleResult();</span> |
| <span class="fc" id="L830"> } catch (Exception ex) {</span> |
| <span class="nc" id="L831"> }</span> |
| <span class="pc bpc" id="L832" title="1 of 2 branches missed."> if (oldstuff != null) {</span> |
| <span class="nc" id="L833"> em.remove(oldstuff);</span> |
| } |
| <span class="fc" id="L835"> em.persist(model);</span> |
| <span class="fc" id="L836"> }</span> |
| |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html> |