List of usage examples for org.apache.commons.configuration ConfigurationException ConfigurationException
public ConfigurationException(Throwable cause)
ConfigurationException
with specified nested Throwable
. From source file:org.apache.juddi.config.Install.java
protected static void install(Configuration config) throws JAXBException, DispositionReportFaultMessage, IOException, ConfigurationException { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); UddiEntityPublisher rootPublisher = null; try {//from www . ja v a 2s . co m tx.begin(); boolean seedAlways = config.getBoolean("juddi.seed.always", false); boolean alreadyInstalled = alreadyInstalled(config); if (!seedAlways && alreadyInstalled) new FatalErrorException(new ErrorMessage("errors.install.AlreadyInstalled")); String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER); String fileRootTModelKeygen = rootPublisherStr + FILE_TMODELKEYGEN; TModel rootTModelKeyGen = (TModel) buildInstallEntity(fileRootTModelKeygen, "org.uddi.api_v3", config); String fileRootBusinessEntity = rootPublisherStr + FILE_BUSINESSENTITY; org.uddi.api_v3.BusinessEntity rootBusinessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity( fileRootBusinessEntity, "org.uddi.api_v3", config); String rootPartition = getRootPartition(rootTModelKeyGen); String nodeId = getNodeId(rootBusinessEntity.getBusinessKey(), rootPartition); String fileRootPublisher = rootPublisherStr + FILE_PUBLISHER; if (!alreadyInstalled) { log.info("Loading the root Publisher from file " + fileRootPublisher); rootPublisher = installPublisher(em, fileRootPublisher, config); installRootPublisherKeyGen(em, rootTModelKeyGen, rootPartition, rootPublisher, nodeId); rootBusinessEntity.setBusinessKey(nodeId); installBusinessEntity(true, em, rootBusinessEntity, rootPublisher, rootPartition, config); } else { log.debug("juddi.seed.always reapplies all seed files except for the root data."); } List<String> juddiPublishers = getPublishers(config); for (String publisherStr : juddiPublishers) { String filePublisher = publisherStr + FILE_PUBLISHER; String fileTModelKeygen = publisherStr + FILE_TMODELKEYGEN; TModel tModelKeyGen = (TModel) buildInstallEntity(fileTModelKeygen, "org.uddi.api_v3", config); String fileBusinessEntity = publisherStr + FILE_BUSINESSENTITY; org.uddi.api_v3.BusinessEntity businessEntity = (org.uddi.api_v3.BusinessEntity) buildInstallEntity( fileBusinessEntity, "org.uddi.api_v3", config); UddiEntityPublisher publisher = installPublisher(em, filePublisher, config); if (publisher == null) { throw new ConfigurationException("File " + filePublisher + " not found."); } else { if (tModelKeyGen != null) installPublisherKeyGen(em, tModelKeyGen, publisher, nodeId); if (businessEntity != null) installBusinessEntity(false, em, businessEntity, publisher, null, config); String fileTModels = publisherStr + FILE_TMODELS; installSaveTModel(em, fileTModels, publisher, nodeId, config); } } tx.commit(); } catch (DispositionReportFaultMessage dr) { log.error(dr.getMessage(), dr); tx.rollback(); throw dr; } catch (JAXBException je) { log.error(je.getMessage(), je); tx.rollback(); throw je; } catch (IOException ie) { log.error(ie.getMessage(), ie); tx.rollback(); throw ie; } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } }
From source file:org.apache.juddi.config.Install.java
/** * Checks if there is a database with a root publisher. If it is not found * an//from w w w . ja v a2s . c o m * * @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 { String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER); org.apache.juddi.model.Publisher publisher = null; int numberOfTries = 0; while (numberOfTries++ < 100) { EntityManager em = PersistenceManager.getEntityManager(); EntityTransaction tx = em.getTransaction(); try { tx.begin(); publisher = em.find(org.apache.juddi.model.Publisher.class, rootPublisherStr); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } em.close(); } if (publisher != null) return true; if (config.getBoolean(Property.JUDDI_LOAD_INSTALL_DATA, Property.DEFAULT_LOAD_INSTALL_DATA)) { log.debug("Install data not yet installed."); return false; } else { try { log.info("Install data not yet installed."); log.info("Going to sleep and retry..."); Thread.sleep(1000l); } catch (InterruptedException e) { log.error(e.getMessage(), e); } } } throw new ConfigurationException("Could not load the Root node data. Please check for errors."); }
From source file:org.apache.juddi.config.Install.java
private static List<String> getPublishers(Configuration config) throws ConfigurationException { List<String> publishers = new ArrayList<String>(); String basePath = JUDDI_CUSTOM_INSTALL_DATA_DIR; URL url = ClassUtil.getResource(JUDDI_CUSTOM_INSTALL_DATA_DIR, Install.class); if (url == null) { url = ClassUtil.getResource(JUDDI_INSTALL_DATA_DIR, Install.class); basePath = JUDDI_INSTALL_DATA_DIR; }//from w w w .jav a2 s . c o m String path = null; if ("vfsfile".equals(url.getProtocol())) { try { path = url.toURI().getPath(); } catch (URISyntaxException e) { throw new ConfigurationException(e); } } else { path = url.getPath(); } File dir = new File(path); String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER); if (dir.exists()) { log.debug("Discovering the Publisher XML data files in directory: " + path); File[] files = dir.listFiles(new PublisherFileFilter()); for (File f : files) { String publisher = f.getName().substring(0, f.getName().indexOf(FILE_PUBLISHER)); if (!rootPublisherStr.equalsIgnoreCase(publisher)) { publishers.add(publisher); } } } else { String[] paths = {}; Enumeration<JarEntry> en = null; try { if (path.indexOf("!") > 0) { paths = path.split("!"); en = new JarFile(new File(new URI(paths[0]))).entries(); } else { // Handle Windows / jboss-5.1.0 case if (path.indexOf(".jar") > 0) { paths = path.split(".jar"); paths[0] = paths[0] + ".jar"; en = new JarFile(new File(paths[0])).entries(); } } if (paths.length > 0) { log.debug("Discovering the Publisher XML data files in jar: " + paths[0]); while (en.hasMoreElements()) { String name = en.nextElement().getName(); if (name.startsWith(basePath) && name.endsWith(FILE_PUBLISHER)) { log.debug("Found publisher file=" + name); String publisher = name.substring(basePath.length(), name.indexOf(FILE_PUBLISHER)); if (!rootPublisherStr.equalsIgnoreCase(publisher)) { publishers.add(publisher); } } } } else { log.info("No custom configuration files where found in " + path); } } catch (IOException e) { throw new ConfigurationException(e); } catch (URISyntaxException e) { throw new ConfigurationException(e); } } return publishers; }
From source file:org.apache.juddi.config.Install.java
private static Object buildInstallEntity(final String fileName, String packageName, Configuration config) throws JAXBException, IOException, ConfigurationException { InputStream resourceStream = null; // First try the custom install directory URL url = ClassUtil.getResource(JUDDI_CUSTOM_INSTALL_DATA_DIR + fileName, Install.class); if (url != null) resourceStream = url.openStream(); // If the custom install directory doesn't exist, then use the standard install directory where the resource is guaranteed to exist. if (resourceStream == null) { url = ClassUtil.getResource(JUDDI_INSTALL_DATA_DIR + fileName, Install.class); if (url != null) { resourceStream = url.openStream(); }//from w ww . j av a2s .co m // If file still does not exist then return null; if (url == null || resourceStream == null) { if (fileName.endsWith(FILE_PUBLISHER)) { throw new ConfigurationException("Could not locate " + JUDDI_INSTALL_DATA_DIR + fileName); } else { log.debug("Could not locate: " + url); } return null; } } log.info("Loading the content of file: " + url); StringBuilder xml = new StringBuilder(); byte[] b = new byte[4096]; for (int n; (n = resourceStream.read(b)) != -1;) { xml.append(new String(b, 0, n)); } log.debug("inserting: " + xml.toString()); StringReader reader = new StringReader(xml.toString()); JAXBContext jc = JAXBContext.newInstance(packageName); Unmarshaller unmarshaller = jc.createUnmarshaller(); Object obj = ((JAXBElement<?>) unmarshaller.unmarshal(new StreamSource(reader))).getValue(); return obj; }
From source file:org.apache.juddi.v3.auth.XMLDocAuthenticator.java
/** * Read user data from the juddi-users file. * //from w ww . j a v a 2 s . c o m * @throws IOException when the file cannot be opened * JAXBException when the content is misformed. * @throws ConfigurationException */ public synchronized void readUserFile() throws JAXBException, IOException, ConfigurationException { userTable = new HashMap<String, User>(); String usersFileName = getFilename(); if (usersFileName == null || usersFileName.length() == 0) throw new ConfigurationException("usersFileName value is null!"); //log.info("Reading jUDDI Users File: " + usersFileName + "..."); URL resource = ClassUtil.getResource(usersFileName, this.getClass()); if (resource != null) log.info("Reading jUDDI Users File: " + usersFileName + "...from " + resource.toExternalForm()); else log.info("Reading jUDDI Users File: " + usersFileName + "..."); InputStream stream = ClassUtil.getResource(usersFileName, this.getClass()).openStream(); JAXBContext jaxbContext = JAXBContext.newInstance(JuddiUsers.class); Unmarshaller unMarshaller = jaxbContext.createUnmarshaller(); JAXBElement<JuddiUsers> element = unMarshaller.unmarshal(new StreamSource(stream), JuddiUsers.class); JuddiUsers users = element.getValue(); for (User user : users.getUser()) { userTable.put(user.getUserid(), user); log.debug("Loading user credentials for user: " + user.getUserid()); } }
From source file:org.apache.juddi.v3.client.config.ClientConfig.java
private Map<String, UDDIClerk> readClerkConfig(Configuration config, Map<String, UDDINode> uddiNodes) throws ConfigurationException { clientName = config.getString("client[@name]"); clientCallbackUrl = config.getString("client[@callbackUrl]"); Map<String, UDDIClerk> clerks = new HashMap<String, UDDIClerk>(); if (config.containsKey("client.clerks.clerk[@name]")) { String[] names = config.getStringArray("client.clerks.clerk[@name]"); log.debug("clerk names=" + names.length); for (int i = 0; i < names.length; i++) { UDDIClerk uddiClerk = new UDDIClerk(); uddiClerk.setManagerName(clientName); uddiClerk.setName(config.getString("client.clerks.clerk(" + i + ")[@name]")); String nodeRef = config.getString("client.clerks.clerk(" + i + ")[@node]"); if (!uddiNodes.containsKey(nodeRef)) throw new ConfigurationException("Could not find Node with name=" + nodeRef); UDDINode uddiNode = uddiNodes.get(nodeRef); uddiClerk.setUDDINode(uddiNode); uddiClerk.setPublisher(config.getString("client.clerks.clerk(" + i + ")[@publisher]")); uddiClerk.setPassword(config.getString("client.clerks.clerk(" + i + ")[@password]")); uddiClerk.setIsPasswordEncrypted( config.getBoolean("client.clerks.clerk(" + i + ")[@isPasswordEncrypted]", false)); uddiClerk.setCryptoProvider(config.getString("client.clerks.clerk(" + i + ")[@cryptoProvider]")); String clerkBusinessKey = config.getString("client.clerks.clerk(" + i + ")[@businessKey]"); String clerkBusinessName = config.getString("client.clerks.clerk(" + i + ")[@businessName]"); String clerkKeyDomain = config.getString("client.clerks.clerk(" + i + ")[@keyDomain]"); String[] classes = config.getStringArray("client.clerks.clerk(" + i + ").class"); uddiClerk.setClassWithAnnotations(classes); int numberOfWslds = config.getStringArray("client.clerks.clerk(" + i + ").wsdl").length; if (numberOfWslds > 0) { UDDIClerk.WSDL[] wsdls = new UDDIClerk.WSDL[numberOfWslds]; for (int w = 0; w < wsdls.length; w++) { UDDIClerk.WSDL wsdl = uddiClerk.new WSDL(); String fileName = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")"); wsdl.setFileName(fileName); String businessKey = config .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessKey]"); String businessName = config .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessName]"); String keyDomain = config .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@keyDomain]"); if (businessKey == null) businessKey = clerkBusinessKey; if (businessKey == null) businessKey = uddiClerk.getUDDINode().getProperties().getProperty("businessKey"); if (businessKey == null) { //use key convention to build the businessKey if (businessName == null) businessName = clerkBusinessName; if (keyDomain == null) keyDomain = clerkKeyDomain; if (keyDomain == null) keyDomain = uddiClerk.getUDDINode().getProperties().getProperty("keyDomain"); if ((businessName == null && !uddiClerk.getUDDINode().getProperties().containsKey("businessName")) || keyDomain == null && !uddiClerk.getUDDINode().getProperties().containsKey("keyDomain")) throw new ConfigurationException("Either the wsdl(" + wsdls[w] + ") or clerk (" + uddiClerk.name + ") elements require a businessKey, or businessName & keyDomain attributes"); else { Properties properties = new Properties(uddiClerk.getUDDINode().getProperties()); if (businessName != null) properties.put("businessName", businessName); if (keyDomain != null) properties.put("keyDomain", keyDomain); businessKey = UDDIKeyConvention.getBusinessKey(properties); }/* w w w . j a v a 2s . c om*/ } if (!businessKey.toLowerCase().startsWith("uddi:") || !businessKey.substring(5).contains(":")) { throw new ConfigurationException("The businessKey " + businessKey + " does not implement a valid UDDI v3 key format."); } wsdl.setBusinessKey(businessKey); if (keyDomain == null) { keyDomain = businessKey.split(":")[1]; } wsdl.setKeyDomain(keyDomain); wsdls[w] = wsdl; } uddiClerk.setWsdls(wsdls); } clerks.put(names[i], uddiClerk); } } return clerks; }
From source file:org.apache.juddi.v3.client.config.ClientConfig.java
private Set<XRegistration> readXRegConfig(Configuration config, Map<String, UDDIClerk> clerks, String entityType) throws ConfigurationException { String[] entityKeys = config.getStringArray("client.clerks.xregister." + entityType + "[@entityKey]"); Set<XRegistration> xRegistrations = new HashSet<XRegistration>(); if (entityKeys.length > 0) log.info("XRegistration " + entityKeys.length + " " + entityType + "Keys"); for (int i = 0; i < entityKeys.length; i++) { XRegistration xRegistration = new XRegistration(); xRegistration.setEntityKey(/* w w w .j a v a 2s . c o m*/ config.getString("client.clerks.xregister." + entityType + "(" + i + ")[@entityKey]")); String fromClerkRef = config .getString("client.clerks.xregister." + entityType + "(" + i + ")[@fromClerk]"); if (!clerks.containsKey(fromClerkRef)) throw new ConfigurationException("Could not find fromClerk with name=" + fromClerkRef); UDDIClerk fromClerk = clerks.get(fromClerkRef); xRegistration.setFromClerk(fromClerk); String toClerkRef = config.getString("client.clerks.xregister." + entityType + "(" + i + ")[@toClerk]"); if (!clerks.containsKey(toClerkRef)) throw new ConfigurationException("Could not find toClerk with name=" + toClerkRef); UDDIClerk toClerk = clerks.get(toClerkRef); xRegistration.setToClerk(toClerk); log.debug(xRegistration); xRegistrations.add(xRegistration); } return xRegistrations; }
From source file:org.apache.juddi.v3.client.config.ClientConfig.java
public UDDINode getHomeNode() throws ConfigurationException { if (uddiNodes == null) throw new ConfigurationException( "The juddi client configuration " + "must contain at least one node element."); if (uddiNodes.values().size() == 1) return uddiNodes.values().iterator().next(); for (UDDINode uddiNode : uddiNodes.values()) { if (uddiNode.isHomeJUDDI()) { return uddiNode; }// w w w .jav a 2 s . c o m } throw new ConfigurationException( "One of the node elements in the client configuration needs to a 'isHomeJUDDI=\"true\"' attribute."); }
From source file:org.apache.juddi.v3.client.config.ClientConfig.java
public UDDINode getUDDINode(String nodeName) throws ConfigurationException { if (!uddiNodes.containsKey(nodeName)) { throw new ConfigurationException( "Node '" + nodeName + "' cannot be found in the config '" + getClientName() + "'"); }//from w w w . ja va2 s .co m return uddiNodes.get(nodeName); }
From source file:org.apache.juddi.v3.client.config.UDDIClerk.java
/** * Finds a service by the key, referencing the specific Node from the * configuration file//from ww w. ja v a 2s. co m * * @param serviceKey * @param node * @return null if not found or error * @throws RemoteException * @throws TransportException * @throws ConfigurationException */ public BusinessService getServiceDetail(String serviceKey, Node node) throws RemoteException, TransportException, ConfigurationException { GetServiceDetail getServiceDetail = new GetServiceDetail(); getServiceDetail.getServiceKey().add(serviceKey); getServiceDetail.setAuthInfo(getAuthToken(node.getSecurityUrl())); try { ServiceDetail sd = getUDDINode().getTransport().getUDDIInquiryService(node.getInquiryUrl()) .getServiceDetail(getServiceDetail); List<BusinessService> businessServiceList = sd.getBusinessService(); if (businessServiceList.size() == 0) { throw new ConfigurationException("Could not find Service with key=" + serviceKey); } return businessServiceList.get(0); } catch (DispositionReportFaultMessage dr) { DispositionReport report = DispositionReportFaultMessage.getDispositionReport(dr); checkForErrorInDispositionReport(report, DispositionReport.E_INVALID_KEY_PASSED, serviceKey); } catch (SOAPFaultException sfe) { DispositionReport report = DispositionReportFaultMessage.getDispositionReport(sfe); checkForErrorInDispositionReport(report, DispositionReport.E_INVALID_KEY_PASSED, serviceKey); } catch (UndeclaredThrowableException ute) { DispositionReport report = DispositionReportFaultMessage.getDispositionReport(ute); checkForErrorInDispositionReport(report, DispositionReport.E_INVALID_KEY_PASSED, serviceKey); } return null; }