From f45e5e611f7d990477ede18dfc79a18d926eb347 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 28 Jan 2016 17:43:44 +0100 Subject: [PATCH] Enabled logging of HTTP-requests and -responses Also switched to the performant and mature HttpClient-library from Apache. --- pom.xml | 9 +++++++ .../de/juplo/yourshouter/SocialConfig.java | 26 +++++++++++++++++++ src/main/resources/application.properties | 5 ++++ 3 files changed, 40 insertions(+) diff --git a/pom.xml b/pom.xml index 73ce372..91aaa8b 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,10 @@ NOT_SET NOT_SET NOT_SET + + 60000 + 60000 + ERROR @@ -53,6 +57,11 @@ spring-security-crypto runtime + + + org.apache.httpcomponents + httpclient + diff --git a/src/main/java/de/juplo/yourshouter/SocialConfig.java b/src/main/java/de/juplo/yourshouter/SocialConfig.java index fc136ad..4efa0e2 100644 --- a/src/main/java/de/juplo/yourshouter/SocialConfig.java +++ b/src/main/java/de/juplo/yourshouter/SocialConfig.java @@ -2,12 +2,14 @@ package de.juplo.yourshouter; +import org.apache.http.HttpRequestFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.social.UserIdSource; import org.springframework.core.env.Environment; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.social.config.annotation.ConnectionFactoryConfigurer; import org.springframework.social.config.annotation.EnableSocial; import org.springframework.social.config.annotation.SocialConfigurerAdapter; @@ -188,4 +190,28 @@ public class SocialConfig extends SocialConfigurerAdapter repository.findPrimaryConnection(Facebook.class); return connection != null ? connection.getApi() : null; } + + /** + * Use the HttpClient from Apaches HttpComponents + * for HTTP-requests. + * + * We also configure shorter intervals for the connection timeout and the + * read timeout. + * + * @param env The {@link Environment}, to read additional parameters from. + * @return The alternative implementation of {@link HttpRequestFactory}. + */ + @Bean + public HttpComponentsClientHttpRequestFactory requestFactory(Environment env) + { + HttpComponentsClientHttpRequestFactory factory = + new HttpComponentsClientHttpRequestFactory(); + factory.setConnectTimeout( + Integer.parseInt(env.getProperty("httpclient.timeout.connection")) + ); + factory.setReadTimeout( + Integer.parseInt(env.getProperty("httpclient.timeout.read")) + ); + return factory; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 46ade25..a66df89 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -6,8 +6,13 @@ server.port: 8443 server.ssl.key-store: keystore server.ssl.key-store-password: secret +httpclient.timeout.connection=@httpclient.timeout.connection@ +httpclient.timeout.read=@httpclient.timeout.read@ + spring.thymeleaf.prefix=/thymeleaf/ spring.thymeleaf.cache=false logging.level.org.springframework.social=debug +logging.level.org.apache.http=@httpclient.logging.level@ +logging.level.org.apache.http.wire=ERROR logging.level.de.juplo.yourshouter=info -- 2.20.1