Enabled logging of HTTP-requests and -responses part-07
authorKai Moritz <kai@juplo.de>
Thu, 28 Jan 2016 16:43:44 +0000 (17:43 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 1 Feb 2016 17:53:23 +0000 (18:53 +0100)
Also switched to the performant and mature HttpClient-library from Apache.

pom.xml
src/main/java/de/juplo/yourshouter/SocialConfig.java
src/main/resources/application.properties

diff --git a/pom.xml b/pom.xml
index 73ce372..91aaa8b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <facebook.app.id>NOT_SET</facebook.app.id>
     <facebook.app.secret>NOT_SET</facebook.app.secret>
     <facebook.app.canvas>NOT_SET</facebook.app.canvas>
+    <!-- settings for the Apache Commons Http-Client -->
+    <httpclient.timeout.connection>60000</httpclient.timeout.connection>
+    <httpclient.timeout.read>60000</httpclient.timeout.read>
+    <httpclient.logging.level>ERROR</httpclient.logging.level>
   </properties>
 
   <dependencies>
       <artifactId>spring-security-crypto</artifactId>
       <scope>runtime</scope>
     </dependency>
+    <!-- Httpclient -->
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
index fc136ad..4efa0e2 100644 (file)
@@ -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 <code>HttpClient</code> from Apaches <code>HttpComponents</code>
+   * 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;
+  }
 }
index 46ade25..a66df89 100644 (file)
@@ -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