From: Kai Moritz Date: Tue, 29 Oct 2019 08:49:28 +0000 (+0100) Subject: WIP: Spring-Upgrade auf 2.2.0 X-Git-Tag: wip-webclient~49 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=171128614996b92879ada06ff6d2c13b93fad60d;p=facebook-errors WIP: Spring-Upgrade auf 2.2.0 --- diff --git a/pom.xml b/pom.xml index 3a8720d..705cb06 100644 --- a/pom.xml +++ b/pom.xml @@ -58,8 +58,6 @@ https://oss.sonatype.org/content/repositories/snapshots/ - 2.0.3.RELEASE - @@ -79,12 +77,6 @@ spring-boot-autoconfigure true - - org.springframework.social - spring-social-facebook - ${spring-social-facebook.version} - true - diff --git a/src/main/java/de/juplo/facebook/errors/FacebookErrorsSpringSocialAutoConfiguration.java b/src/main/java/de/juplo/facebook/errors/FacebookErrorsSpringSocialAutoConfiguration.java deleted file mode 100644 index 49a3101..0000000 --- a/src/main/java/de/juplo/facebook/errors/FacebookErrorsSpringSocialAutoConfiguration.java +++ /dev/null @@ -1,123 +0,0 @@ -package de.juplo.facebook.errors; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration; -import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.social.facebook.api.Facebook; -import org.springframework.social.facebook.api.impl.FacebookTemplate; -import org.springframework.web.client.ResponseErrorHandler; -import org.springframework.web.client.RestTemplate; - - - -/** - * Automatic configuration for Srping-Social-Facebook - * - * @author Kai Moritz - */ -@Configuration -@ConditionalOnClass(value = FacebookTemplate.class) -@AutoConfigureAfter({ - WebMvcAutoConfiguration.class, - FacebookAutoConfiguration.class - }) -public class FacebookErrorsSpringSocialAutoConfiguration -{ - private static final Logger LOG = - LoggerFactory.getLogger(FacebookErrorsSpringSocialAutoConfiguration.class); - - - @Bean - static public BeanPostProcessor errorHandlerInjectorSpringSocial() - { - LOG.info("Configuring GraphApiErrorHandler for handling error-messages"); - return new BeanPostProcessor() - { - @Override - public Object postProcessBeforeInitialization( - Object bean, - String beanName - ) - throws - BeansException - { - return bean; - } - - @Override - public Object postProcessAfterInitialization( - Object bean, - String beanName - ) - throws - BeansException - { - if (bean instanceof Facebook) - { - try - { - Facebook facebook = (Facebook) bean; - RestTemplate template = (RestTemplate) facebook.restOperations(); - ResponseErrorHandler handler = template.getErrorHandler(); - template.setErrorHandler(new GraphApiErrorHandler(handler)); - // Be sure, that the potential exception is triggered before! - LOG.debug("Injecting GraphApiErrorHandler in {}", facebook); - } - catch (BeanCreationException e) - { - /** - * This exception is called, if the BeanPostProcessor is called - * with a scoped bean, while the according scope is not - * accessible. - * This happens during initialization and can safely be ignored, - * because we only have to inject the handler for beans, that are - * actually usable. - */ - } - } - - return bean; - } - }; - } - - @Bean - static public BeanDefinitionRegistryPostProcessor test() - { - return new BeanDefinitionRegistryPostProcessor() - { - @Override - public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException - { - for(String name : registry.getBeanDefinitionNames()) - { - BeanDefinition bean = registry.getBeanDefinition(name); - LOG.info("{}: {} - {} / {}", name, bean.getBeanClassName(), bean.getFactoryBeanName(), bean); - } - } - - @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException - { - for(String name : factory.getBeanNamesForType(Facebook.class)) - { - BeanDefinition bean = factory.getBeanDefinition(name); - LOG.info("{}{}", name, factory.isFactoryBean(name) ? " (factory)" : ""); - } - } - }; - } -} \ No newline at end of file