Search in sources :

Example 36 with BeansException

use of org.springframework.beans.BeansException in project leopard by tanhaichao.

the class LeopardHandlerMapping method initApplicationContext.

@Override
protected void initApplicationContext() throws BeansException {
    // 修改拦截器排序
    try {
        Field field = AbstractHandlerMapping.class.getDeclaredField("interceptors");
        field.setAccessible(true);
        @SuppressWarnings("unchecked") List<Object> interceptors = (List<Object>) field.get(this);
        AnnotationAwareOrderComparator.sort(interceptors);
    // System.out.println("interceptors:" + interceptors);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    super.initApplicationContext();
}
Also used : Field(java.lang.reflect.Field) List(java.util.List) BeansException(org.springframework.beans.BeansException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 37 with BeansException

use of org.springframework.beans.BeansException in project leopard by tanhaichao.

the class LeopardHandlerMapping method initApplicationContext.

@Override
protected void initApplicationContext(ApplicationContext context) throws BeansException {
    try {
        Redis redis = (Redis) context.getBean("sessionRedis");
        StoreRedisImpl.setRedis(redis);
    } catch (NoSuchBeanDefinitionException e) {
        logger.warn("没有配置sessionRedis,不启用分布式session.");
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    super.initApplicationContext(context);
    requestMappingInfoBuilder = new RequestMappingInfoBuilderImpl(context);
}
Also used : Redis(io.leopard.redis.Redis) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) BeansException(org.springframework.beans.BeansException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) RequestMappingInfoBuilderImpl(io.leopard.vhost.RequestMappingInfoBuilderImpl)

Example 38 with BeansException

use of org.springframework.beans.BeansException in project dubbo-faker by moyada.

the class MethodHandleProxy method getProxy.

public MethodProxy getProxy(MethodInvokeDO invokeInfo) {
    // , int poolSize) {
    MethodProxy proxy;
    log.info("init method proxy info.");
    // 检测是否已存在
    Integer id = invokeInfo.getId();
    SoftReference<MethodProxy> ref = proxyMap.get(id);
    if (null != ref) {
        proxy = ref.get();
        if (null != proxy) {
            // && proxy.getService().length == poolSize) {
            return proxy;
        }
    }
    // 获取参数类型
    Class<?>[] paramTypes;
    String[] argsType = invokeInfo.getParamType().split(",");
    int length = argsType.length;
    if (0 == length) {
        paramTypes = new Class[0];
    } else {
        paramTypes = new Class[length];
        for (int index = 0; index < length; index++) {
            try {
                paramTypes[index] = ReflectUtil.getClassType(argsType[index]);
            } catch (ClassNotFoundException e) {
                throw new InitializeInvokerException("获取参数类型失败: " + argsType[index]);
            }
        }
    }
    // 获取方法具柄
    MethodHandle methodHandle = handle.fetchHandleInfo(invokeInfo.getClassName(), invokeInfo.getMethodName(), invokeInfo.getReturnType(), paramTypes);
    // 获取接口
    Class classType;
    try {
        classType = ReflectUtil.getClassType(invokeInfo.getClassName());
    } catch (ClassNotFoundException e) {
        throw new InitializeInvokerException("获取结果失败: " + invokeInfo.getClassName());
    }
    // 获取接口实例
    Object serviceAssembly;
    // Object[] serviceAssembly = new Object[poolSize];
    try {
        serviceAssembly = beanHolder.getBean(classType);
    // for (int index = 0; index < poolSize; index++) {
    // serviceAssembly[index] = beanHelper.getBean(classType);
    // }
    } catch (BeansException e) {
        throw new RpcException("获取接口实例失败: " + invokeInfo.getClassName() + ".", e);
    }
    // for (Object service : serviceAssembly) {
    try {
        methodHandle.invoke(serviceAssembly, null);
    } catch (Throwable throwable) {
    }
    // }
    proxy = new MethodProxy();
    proxy.setParamTypes(paramTypes);
    proxy.setMethodHandle(methodHandle);
    proxy.setService(serviceAssembly);
    // 缓存调用代理
    ref = new SoftReference<>(proxy);
    proxyMap.put(id, ref);
    return proxy;
}
Also used : InitializeInvokerException(cn.moyada.dubbo.faker.core.exception.InitializeInvokerException) RpcException(com.alibaba.dubbo.rpc.RpcException) MethodProxy(cn.moyada.dubbo.faker.core.model.MethodProxy) MethodHandle(java.lang.invoke.MethodHandle) BeansException(org.springframework.beans.BeansException)

Example 39 with BeansException

use of org.springframework.beans.BeansException in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapter method doUpdateNode.

/**
 * <p>doUpdate</p>
 *
 * @param nodeId a int.
 * @param retry a boolean.
 * @throws org.opennms.netmgt.provision.ProvisioningAdapterException if any.
 */
@Override
public void doUpdateNode(final int nodeId) throws ProvisioningAdapterException {
    LOG.debug("doUpdate: updating nodeid: {}", nodeId);
    final OnmsNode node = m_nodeDao.get(nodeId);
    Assert.notNull(node, "doUpdate: failed to return node for given nodeId:" + nodeId);
    final InetAddress ipaddress = m_template.execute(new TransactionCallback<InetAddress>() {

        @Override
        public InetAddress doInTransaction(final TransactionStatus arg0) {
            return getIpForNode(node);
        }
    });
    final String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
    final SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);
    final OnmsAssetRecord asset = node.getAssetRecord();
    m_config.getReadLock().lock();
    try {
        for (AssetField field : m_config.getAssetFieldsForAddress(ipaddress, node.getSysObjectId())) {
            try {
                String value = fetchSnmpAssetString(m_locationAwareSnmpClient, agentConfig, locationName, field.getMibObjs(), field.getFormatString());
                LOG.debug("doUpdate: Setting asset field \" {} \" to value: {}", value, field.getName());
                // Use Spring bean-accessor classes to set the field value
                BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(asset);
                try {
                    wrapper.setPropertyValue(field.getName(), value);
                } catch (BeansException e) {
                    LOG.warn("doUpdate: Could not set property \" {} \" on asset object: {}", field.getName(), e.getMessage(), e);
                }
            } catch (Throwable t) {
                // This exception is thrown if the SNMP operation fails or an incorrect number of
                // parameters is returned by the agent or because of a misconfiguration.
                LOG.warn("doUpdate: Could not set value for asset field \" {} \": {}", field.getName(), t.getMessage(), t);
            }
        }
    } finally {
        m_config.getReadLock().unlock();
    }
    node.setAssetRecord(asset);
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) AssetField(org.opennms.netmgt.config.snmpAsset.adapter.AssetField) TransactionStatus(org.springframework.transaction.TransactionStatus) InetAddress(java.net.InetAddress) BeansException(org.springframework.beans.BeansException)

Example 40 with BeansException

use of org.springframework.beans.BeansException in project opennms by OpenNMS.

the class DefaultPluginRegistry method getPluginInstance.

/**
 * {@inheritDoc}
 */
@Override
public <T> T getPluginInstance(Class<T> pluginClass, PluginConfig pluginConfig) {
    T pluginInstance = beanWithNameOfType(pluginConfig.getPluginClass(), pluginClass);
    if (pluginInstance == null) {
        return null;
    }
    Map<String, String> parameters = new HashMap<String, String>(pluginConfig.getParameterMap());
    BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(pluginInstance);
    try {
        wrapper.setPropertyValues(parameters);
    } catch (BeansException e) {
        error(e, "Could not set properties on report definition: {}", e.getMessage());
    }
    return pluginInstance;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) HashMap(java.util.HashMap) BeansException(org.springframework.beans.BeansException)

Aggregations

BeansException (org.springframework.beans.BeansException)73 Test (org.junit.Test)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 BeanWrapper (org.springframework.beans.BeanWrapper)11 ApplicationContext (org.springframework.context.ApplicationContext)11 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)9 BeanCreationException (org.springframework.beans.factory.BeanCreationException)8 MalformedURLException (java.net.MalformedURLException)7 ArrayList (java.util.ArrayList)7 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)7 Map (java.util.Map)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5 IOException (java.io.IOException)4 Method (java.lang.reflect.Method)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)4 UrlResource (org.springframework.core.io.UrlResource)4 File (java.io.File)3