List of usage examples for org.springframework.beans FatalBeanException FatalBeanException
public FatalBeanException(String msg)
From source file:org.bytesoft.bytejta.supports.spring.TransactionEndpointPostProcessor.java
public void initializeCoordinator(ConfigurableListableBeanFactory beanFactory, BeanDefinition protocolDef, String compensableBeanId) throws BeansException { MutablePropertyValues mpv = protocolDef.getPropertyValues(); PropertyValue pv = mpv.getPropertyValue("port"); if (pv == null || pv.getValue() == null) { throw new FatalBeanException("Attribute 'port' of <dubbo:protocol ... /> is null."); }/* ww w .j a v a 2s. c om*/ String host = CommonUtils.getInetAddress(); String port = String.valueOf(pv.getValue()); String identifier = String.format("%s:%s", host, port); BeanDefinition beanDef = beanFactory.getBeanDefinition(compensableBeanId); beanDef.getPropertyValues().addPropertyValue("identifier", identifier); }
From source file:com.apporiented.spring.override.AbstractGenericBeanDefinitionParser.java
public final BeanDefinition parse(Element element, ParserContext parserContext) { if (!enabled) { throw new FatalBeanException("Support for " + element.getTagName() + " has been disabled. Please add the required jar files " + "to your classpath."); }//www . ja v a2 s. co m AbstractBeanDefinition definition = parseInternal(element, parserContext); if (!parserContext.isNested()) { try { String id = resolveId(element, definition, parserContext); if (!StringUtils.hasText(id)) { parserContext.getReaderContext().error("Id is required for element '" + element.getLocalName() + "' when used as a top-level tag", element); } String[] aliases = resolveAliases(element, definition, parserContext); BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases); if (decorator != null) { holder = decorator.decorate(element, holder, parserContext); } registerBeanDefinition(holder, parserContext.getRegistry()); if (shouldFireEvents()) { BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder); postProcessComponentDefinition(componentDefinition); parserContext.registerComponent(componentDefinition); } } catch (BeanDefinitionStoreException ex) { parserContext.getReaderContext().error(ex.getMessage(), element); return null; } } else if (decorator != null) { BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, ""); decorator.decorate(element, holder, parserContext); } return definition; }
From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractX509CredentialBeanDefinitionParser.java
/** * Parses the certificates from the credential configuration. * /*ww w. j ava2 s .com*/ * @param configChildren children of the credential element * @param builder credential build */ protected void parseCertificates(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) { List<Element> certElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "Certificate")); if (certElems == null || certElems.isEmpty()) { return; } log.debug("Parsing x509 credential certificates"); ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>(); byte[] encodedCert; Collection<X509Certificate> decodedCerts; for (Element certElem : certElems) { encodedCert = getEncodedCertificate(DatatypeHelper.safeTrimOrNullString(certElem.getTextContent())); if (encodedCert == null) { continue; } boolean isEntityCert = false; Attr entityCertAttr = certElem.getAttributeNodeNS(null, "entityCertificate"); if (entityCertAttr != null) { isEntityCert = XMLHelper.getAttributeValueAsBoolean(entityCertAttr); } if (isEntityCert) { log.debug("Element config flag found indicating entity certificate"); } try { decodedCerts = X509Util.decodeCertificate(encodedCert); certs.addAll(decodedCerts); if (isEntityCert) { if (decodedCerts.size() == 1) { builder.addPropertyValue("entityCertificate", decodedCerts.iterator().next()); } else { throw new FatalBeanException( "Config element indicated an entityCertificate, but multiple certs where decoded"); } } } catch (CertificateException e) { throw new FatalBeanException("Unable to create X509 credential, unable to parse certificates", e); } } builder.addPropertyValue("certificates", certs); }
From source file:org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.java
public void initZookeeperAddressIfNecessary(ConfigurableListableBeanFactory beanFactory) throws BeansException { String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); if (com.alibaba.dubbo.config.RegistryConfig.class.getName().equals(beanDef.getBeanClassName())) { MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue protpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_PROTOCOL); PropertyValue addrpv = mpv.getPropertyValue(KEY_DUBBO_REGISTRY_ADDRESS); String protocol = null; String address = null; if (addrpv == null) { throw new FatalBeanException("zookeeper address cannot be null!"); // should never happen } else if (protpv == null) { String value = String.valueOf(addrpv.getValue()); try { URL url = new URL(null, value, this); protocol = url.getProtocol(); address = url.getAuthority(); } catch (Exception ex) { throw new FatalBeanException("Unsupported format!"); }/*from w ww . java2s. c o m*/ } else { protocol = String.valueOf(protpv.getValue()); String value = StringUtils.trimToEmpty(String.valueOf(addrpv.getValue())); int index = value.indexOf(protocol); if (index == -1) { address = value; } else if (index == 0) { String str = StringUtils.trimToEmpty(value.substring(protocol.length())); if (str.startsWith("://")) { address = StringUtils.trimToEmpty(str.substring(3)); } else { throw new FatalBeanException("Unsupported format!"); } } else { throw new FatalBeanException("Unsupported format!"); } } if (KEY_DUBBO_REGISTRY_ZOOKEEPER.equalsIgnoreCase(protocol) == false) { throw new FatalBeanException("Unsupported protocol!"); } String addrKey = "zookeeperAddr"; String[] watcherBeanArray = beanFactory .getBeanNamesForType(org.bytesoft.bytetcc.supports.zk.TransactionCuratorClient.class); BeanDefinition watcherBeanDef = beanFactory.getBeanDefinition(watcherBeanArray[0]); MutablePropertyValues warcherMpv = watcherBeanDef.getPropertyValues(); PropertyValue warcherPv = warcherMpv.getPropertyValue(addrKey); if (warcherPv == null) { warcherMpv.addPropertyValue(new PropertyValue(addrKey, address)); } else { warcherMpv.removePropertyValue(addrKey); warcherMpv.addPropertyValue(new PropertyValue(addrKey, address)); } } } }
From source file:org.bytesoft.bytetcc.supports.dubbo.CompensableDubboConfigValidator.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); final Map<String, Class<?>> beanClassMap = new HashMap<String, Class<?>>(); final Map<String, BeanDefinition> serviceMap = new HashMap<String, BeanDefinition>(); final Map<String, BeanDefinition> references = new HashMap<String, BeanDefinition>(); String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); Class<?> beanClass = null; try {/*from ww w .j a v a 2 s . c o m*/ beanClass = cl.loadClass(beanClassName); beanClassMap.put(beanName, beanClass); } catch (Exception ex) { continue; } if (com.alibaba.dubbo.config.spring.ServiceBean.class.equals(beanClass)) { serviceMap.put(beanName, beanDef); } else if (com.alibaba.dubbo.config.spring.ReferenceBean.class.equals(beanClass)) { references.put(beanName, beanDef); } } for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); String beanKey = entry.getKey(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue ref = mpv.getPropertyValue("ref"); PropertyValue filter = mpv.getPropertyValue("filter"); PropertyValue group = mpv.getPropertyValue("group"); if (ref == null || ref.getValue() == null || RuntimeBeanReference.class.equals(ref.getValue().getClass()) == false) { continue; } RuntimeBeanReference beanRef = (RuntimeBeanReference) ref.getValue(); Class<?> refClass = beanClassMap.get(beanRef.getBeanName()); if (refClass.getAnnotation(Compensable.class) == null) { continue; } if (group == null || group.getValue() == null || KEY_GROUP_COMPENSABLE.equals(group.getValue()) == false) { logger.warn("The value of attr 'group'(beanId= {}) should be 'org.bytesoft.bytetcc'.", beanKey); continue; } else if (filter == null || filter.getValue() == null || KEY_FILTER_COMPENSABLE.equals(filter.getValue()) == false) { logger.warn("The value of attr 'filter'(beanId= {}) should be 'compensable'.", beanKey); continue; } PropertyValue timeoutPv = mpv.getPropertyValue(KEY_TIMEOUT); Object value = timeoutPv == null ? null : timeoutPv.getValue(); if (String.valueOf(Integer.MAX_VALUE).equals(value) == false) { throw new FatalBeanException(String.format("Timeout value(beanId= %s) must be %s." // , beanKey, Integer.MAX_VALUE)); } } for (Iterator<Map.Entry<String, BeanDefinition>> itr = references.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); String beanKey = entry.getKey(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue filter = mpv.getPropertyValue("filter"); PropertyValue group = mpv.getPropertyValue("group"); if (group == null || group.getValue() == null || KEY_GROUP_COMPENSABLE.equals(group.getValue()) == false) { logger.warn("The value of attr 'group'(beanId= {}) should be 'org.bytesoft.bytetcc'.", beanKey); continue; } else if (filter == null || filter.getValue() == null || KEY_FILTER_COMPENSABLE.equals(filter.getValue()) == false) { logger.warn("The value of attr 'filter'(beanId= {}) should be 'compensable'.", beanKey); continue; } PropertyValue timeoutPv = mpv.getPropertyValue(KEY_TIMEOUT); Object value = timeoutPv == null ? null : timeoutPv.getValue(); if (String.valueOf(Integer.MAX_VALUE).equals(value) == false) { throw new FatalBeanException( String.format("The value of attribute 'timeout' (beanId= %s) must be %s." // , beanKey, Integer.MAX_VALUE)); } } }
From source file:org.bytesoft.bytetcc.supports.dubbo.DubboConfigPostProcessor.java
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); List<BeanDefinition> appNameList = new ArrayList<BeanDefinition>(); List<BeanDefinition> providerList = new ArrayList<BeanDefinition>(); List<BeanDefinition> consumerList = new ArrayList<BeanDefinition>(); List<BeanDefinition> protocolList = new ArrayList<BeanDefinition>(); List<BeanDefinition> registryList = new ArrayList<BeanDefinition>(); Map<String, BeanDefinition> serviceMap = new HashMap<String, BeanDefinition>(); Map<String, BeanDefinition> referenceMap = new HashMap<String, BeanDefinition>(); Map<String, Class<?>> clazzMap = new HashMap<String, Class<?>>(); Map<String, BeanDefinition> compensableMap = new HashMap<String, BeanDefinition>(); String[] beanNameArray = beanFactory.getBeanDefinitionNames(); for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); Class<?> beanClass = null; try {//from w w w . ja v a 2 s . co m beanClass = cl.loadClass(beanClassName); } catch (Exception ex) { logger.warn("Cannot load class {}, beanId= {}!", beanClassName, beanName, ex); continue; } clazzMap.put(beanClassName, beanClass); if (beanClass.getAnnotation(Compensable.class) != null) { compensableMap.put(beanName, beanDef); } } for (int i = 0; i < beanNameArray.length; i++) { String beanName = beanNameArray[i]; BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName); String beanClassName = beanDef.getBeanClassName(); Class<?> beanClass = clazzMap.get(beanClassName); if (com.alibaba.dubbo.config.ApplicationConfig.class.equals(beanClass)) { appNameList.add(beanDef); } else if (com.alibaba.dubbo.config.ProtocolConfig.class.equals(beanClass)) { protocolList.add(beanDef); } else if (com.alibaba.dubbo.config.RegistryConfig.class.equals(beanClass)) { registryList.add(beanDef); } else if (com.alibaba.dubbo.config.ProviderConfig.class.equals(beanClass)) { providerList.add(beanDef); } else if (com.alibaba.dubbo.config.ConsumerConfig.class.equals(beanClass)) { consumerList.add(beanDef); } else if (com.alibaba.dubbo.config.spring.ServiceBean.class.equals(beanClass)) { MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue ref = mpv.getPropertyValue("ref"); RuntimeBeanReference beanRef = (RuntimeBeanReference) ref.getValue(); String refBeanName = beanRef.getBeanName(); if (compensableMap.containsKey(refBeanName) == false) { continue; } serviceMap.put(beanName, beanDef); } else if (com.alibaba.dubbo.config.spring.ReferenceBean.class.equals(beanClass)) { MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue group = mpv.getPropertyValue("group"); if (group == null || group.getValue() == null || "org.bytesoft.bytetcc".equals(group.getValue()) == false) { continue; } referenceMap.put(beanName, beanDef); } } Set<BeanDefinition> providerSet = new HashSet<BeanDefinition>(); Set<BeanDefinition> protocolSet = new HashSet<BeanDefinition>(); for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); BeanDefinition beanDef = entry.getValue(); MutablePropertyValues mpv = beanDef.getPropertyValues(); PropertyValue provider = mpv.getPropertyValue("provider"); PropertyValue protocol = mpv.getPropertyValue("protocol"); String providerValue = provider == null ? null : String.valueOf(provider.getValue()); if (providerValue == null) { if (providerList.size() > 0) { providerSet.add(providerList.get(0)); } } else if ("N/A".equals(providerValue) == false) { String[] keyArray = providerValue.split("\\s*,\\s*"); for (int j = 0; j < keyArray.length; j++) { String key = keyArray[j]; BeanDefinition def = beanFactory.getBeanDefinition(key); providerSet.add(def); } } String protocolValue = protocol == null ? null : String.valueOf(protocol.getValue()); if (protocolValue == null) { if (protocolList.size() > 0) { protocolSet.add(protocolList.get(0)); } } else if ("N/A".equals(protocolValue) == false) { String[] keyArray = protocolValue.split("\\s*,\\s*"); for (int i = 0; i < keyArray.length; i++) { String key = keyArray[i]; BeanDefinition def = beanFactory.getBeanDefinition(key); protocolSet.add(def); } } } ApplicationConfigValidator appConfigValidator = new ApplicationConfigValidator(); appConfigValidator.setDefinitionList(appNameList); appConfigValidator.validate(); if (protocolList.size() == 0) { throw new FatalBeanException("There is no protocol config specified!"); } for (Iterator<BeanDefinition> itr = protocolSet.iterator(); itr.hasNext();) { BeanDefinition beanDef = itr.next(); ProtocolConfigValidator validator = new ProtocolConfigValidator(); validator.setBeanDefinition(beanDef); validator.validate(); } for (Iterator<BeanDefinition> itr = providerSet.iterator(); itr.hasNext();) { BeanDefinition beanDef = itr.next(); ProviderConfigValidator validator = new ProviderConfigValidator(); validator.setBeanDefinition(beanDef); validator.validate(); } for (Iterator<Map.Entry<String, BeanDefinition>> itr = serviceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); ServiceConfigValidator validator = new ServiceConfigValidator(); validator.setBeanName(entry.getKey()); validator.setBeanDefinition(entry.getValue()); validator.validate(); // retries, loadbalance, cluster, filter, group } for (Iterator<Map.Entry<String, BeanDefinition>> itr = referenceMap.entrySet().iterator(); itr.hasNext();) { Map.Entry<String, BeanDefinition> entry = itr.next(); ReferenceConfigValidator validator = new ReferenceConfigValidator(); validator.setBeanName(entry.getKey()); validator.setBeanDefinition(entry.getValue()); validator.validate(); // retries, loadbalance, cluster, filter } }
From source file:org.bytesoft.bytetcc.supports.spring.CompensableAnnotationValidator.java
private void validateDeclaredRemotingException(Method method, Class<?> clazz) throws IllegalStateException { Class<?>[] exceptionTypeArray = method.getExceptionTypes(); boolean located = false; for (int i = 0; i < exceptionTypeArray.length; i++) { Class<?> exceptionType = exceptionTypeArray[i]; if (RemotingException.class.isAssignableFrom(exceptionType)) { located = true;// w ww.j a v a 2 s . co m break; } } if (located) { throw new FatalBeanException(String.format( "The method(%s) shouldn't be declared to throw a remote exception: org.bytesoft.compensable.RemotingException!", method)); } }
From source file:org.echocat.jomon.spring.BeanPostConfigurer.java
@Nullable protected BeanAndPropertyName getBeanAndPropertyNameOf(@Nonnull String key) throws BeansException { final String[] parts = key.split("[#|@]"); if (parts.length != 2) { throw new FatalBeanException( "The property key '" + key + "' is invalid. The syntax is: <beanName>#<propertyName>"); }//from w w w . j a v a 2 s . c o m final PropertyValueType propertyValueType = key.contains("#") ? value : reference; return new BeanAndPropertyName(parts[0], parts[1], propertyValueType); }
From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.PluginConfigurationServiceDefault.java
public void initialize() { PluginConfigurationServiceDefault.logger.info("Initializing the advanced shared build number plugin."); this.configLock.writeLock().lock(); PluginConfigurationServiceDefault.logger.debug(""); try {/*from ww w . j av a2s.com*/ if (!this.xsdFile.exists() || !this.xsdFile.canRead()) this.copyXsdFileToDestination(); this.loadDefaultConfigFileHeader(); if (!this.configFile.exists()) this.copyDefaultConfigFileToDestination(); else if (!this.configFile.canRead() || !this.configFile.canWrite()) throw new FatalBeanException("Existing configuration in place, but not readable and writable"); this.initializeXmlDigesterLoader(); this.loadConfiguration(); this.initializeFileWatcher(); } finally { this.configLock.writeLock().unlock(); } }
From source file:org.obiba.onyx.spring.AnnotatedBeanFinderFactoryBean.java
/** * Injects the set of annotation types.//from w ww .j a v a2 s. com * * @param annotationClasses the set of qualified annotation class names to set. */ @SuppressWarnings("unchecked") public void setAnnotationClasses(Set<String> annotationClasses) { // Filter tabs and new lines for (String annotationClass : annotationClasses) { Class<? extends Annotation> clazz; try { clazz = (Class<? extends Annotation>) Class.forName(cleanString(annotationClass)); this.annotationClasses.add(clazz); } catch (NoClassDefFoundError ignore) { throw new FatalBeanException("The class " + annotationClass + " in the annotatedClasses property of the sessionFactory declaration is not an annotation type."); } catch (ClassCastException e) { throw new FatalBeanException("Could not find annotation class " + annotationClass + " in the annotatedClasses property of the sessionFactory declaration."); } catch (Throwable throwable) { throw new FatalBeanException("Could not add annotation class " + annotationClass + " to the list of annotations in the annotatedClasses property of the sessionFactory declaration: " + throwable); } } }