From a830caca39dedbc738a7dbac37ba9c36bc9339a5 Mon Sep 17 00:00:00 2001 From: eugenp Date: Thu, 25 Jul 2013 19:05:28 +0300 Subject: [PATCH] timeout work --- spring-security-rest-template/pom.xml | 487 +++++++++--------- .../web/controller/FooController.java | 6 + .../src/main/resources/logback.xml | 2 + .../baeldung/client/RawClientLiveTest.java | 29 +- 4 files changed, 278 insertions(+), 246 deletions(-) diff --git a/spring-security-rest-template/pom.xml b/spring-security-rest-template/pom.xml index f657b318b1..2176778c97 100644 --- a/spring-security-rest-template/pom.xml +++ b/spring-security-rest-template/pom.xml @@ -1,275 +1,294 @@ - - 4.0.0 - org.baeldung - spring-security-rest-template - 0.1-SNAPSHOT + + 4.0.0 + org.baeldung + spring-security-rest-template + 0.1-SNAPSHOT - spring-security-rest-template - war + spring-security-rest-template + war - + - + - - org.springframework.security - spring-security-web - ${org.springframework.security.version} - - - org.springframework.security - spring-security-config - ${org.springframework.security.version} - + + org.springframework.security + spring-security-web + ${org.springframework.security.version} + + + org.springframework.security + spring-security-config + ${org.springframework.security.version} + - + - - org.springframework - spring-core - ${org.springframework.version} - - - org.springframework - spring-context - ${org.springframework.version} - - - org.springframework - spring-jdbc - ${org.springframework.version} - - - org.springframework - spring-beans - ${org.springframework.version} - - - org.springframework - spring-aop - ${org.springframework.version} - - - org.springframework - spring-tx - ${org.springframework.version} - - - org.springframework - spring-expression - ${org.springframework.version} - + + org.springframework + spring-core + ${org.springframework.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-context + ${org.springframework.version} + + + org.springframework + spring-jdbc + ${org.springframework.version} + + + org.springframework + spring-beans + ${org.springframework.version} + + + org.springframework + spring-aop + ${org.springframework.version} + + + org.springframework + spring-tx + ${org.springframework.version} + + + org.springframework + spring-expression + ${org.springframework.version} + - - org.springframework - spring-web - ${org.springframework.version} - - - org.springframework - spring-webmvc - ${org.springframework.version} - + + org.springframework + spring-web + ${org.springframework.version} + + + org.springframework + spring-webmvc + ${org.springframework.version} + - - org.springframework - spring-oxm - ${org.springframework.version} - + + org.springframework + spring-oxm + ${org.springframework.version} + - + - - com.fasterxml.jackson.core - jackson-databind - 2.2.2 - + + com.fasterxml.jackson.core + jackson-databind + 2.2.2 + - + + + + + + + + + + + + + + + + org.apache.httpcomponents + httpcore + ${httpcore.version} + + + commons-logging + commons-logging + + + - - org.apache.httpcomponents - httpcore - ${httpcore.version} - - - commons-logging - commons-logging - - - + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + commons-logging + commons-logging + + + - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - commons-logging - commons-logging - - - + - + + javax.servlet + javax.servlet-api + 3.0.1 + provided + - - javax.servlet - javax.servlet-api - 3.0.1 - provided - + + javax.servlet + jstl + 1.2 + runtime + - - javax.servlet - jstl - 1.2 - runtime - + - + + com.google.guava + guava + ${guava.version} + - - com.google.guava - guava - ${guava.version} - + - + + org.springframework + spring-test + ${org.springframework.version} + test + - - org.springframework - spring-test - ${org.springframework.version} - test - + + junit + junit-dep + ${junit.version} + test + - - junit - junit-dep - ${junit.version} - test - + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + - - org.hamcrest - hamcrest-core - ${org.hamcrest.version} - test - - - org.hamcrest - hamcrest-library - ${org.hamcrest.version} - test - + + org.mockito + mockito-core + ${mockito.version} + test + - - org.mockito - mockito-core - ${mockito.version} - test - + - + + spring-security-rest-template + + + src/main/resources + true + + - - spring-security-rest-template - - - src/main/resources - true - - + - + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + true + source + + - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - true - source - - + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*LiveTest.java + + + + + + - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*LiveTest.java - - - - - - + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + jetty8x + embedded + + + + + + + 8082 + + + + - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - true - - jetty8x - embedded - - - - - - - 8082 - - - - + - + - + + + 3.2.3.RELEASE + 3.1.4.RELEASE - - - 3.2.3.RELEASE - 3.1.4.RELEASE + + 4.2.3.Final + 5.1.25 - - 4.2.3.Final - 5.1.25 + + 4.2.4 + 4.2.5 - - 4.2.4 - 4.2.5 + + 1.7.5 + 1.0.11 - - 1.7.5 - 1.0.11 + + 5.0.1.Final - - 5.0.1.Final + + 14.0.1 + 3.1 - - 14.0.1 - 3.1 + + 1.3 + 4.11 + 1.9.5 - - 1.3 - 4.11 - 1.9.5 + 1.8.1 + 1.8.9 - 1.8.1 - 1.8.9 - - - 1.4.3 - 2.15 - + + 1.4.3 + 2.15 + \ No newline at end of file diff --git a/spring-security-rest-template/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-rest-template/src/main/java/org/baeldung/web/controller/FooController.java index b50edb2dcf..9b74c79ca8 100644 --- a/spring-security-rest-template/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-security-rest-template/src/main/java/org/baeldung/web/controller/FooController.java @@ -30,4 +30,10 @@ public class FooController { return new Foo(); } + @RequestMapping(value = "/{id}/unsecured", method = RequestMethod.GET) + @ResponseBody + public Foo findOneUnsecured(@PathVariable("id") final Long id) { + return new Foo(); + } + } diff --git a/spring-security-rest-template/src/main/resources/logback.xml b/spring-security-rest-template/src/main/resources/logback.xml index 1146dade63..90f61a95bc 100644 --- a/spring-security-rest-template/src/main/resources/logback.xml +++ b/spring-security-rest-template/src/main/resources/logback.xml @@ -7,6 +7,8 @@ + + diff --git a/spring-security-rest-template/src/test/java/org/baeldung/client/RawClientLiveTest.java b/spring-security-rest-template/src/test/java/org/baeldung/client/RawClientLiveTest.java index a66be953b9..76668ab41c 100644 --- a/spring-security-rest-template/src/test/java/org/baeldung/client/RawClientLiveTest.java +++ b/spring-security-rest-template/src/test/java/org/baeldung/client/RawClientLiveTest.java @@ -3,38 +3,43 @@ package org.baeldung.client; import java.io.IOException; import org.apache.http.HttpResponse; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; import org.baeldung.client.spring.ClientConfig; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.support.AnnotationConfigContextLoader; -import org.springframework.web.client.RestTemplate; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { ClientConfig.class }, loader = AnnotationConfigContextLoader.class) public class RawClientLiveTest { - @Autowired - private RestTemplate restTemplate; - // tests @Test public final void whenSecuredRestApiIsConsumed_then200OK() throws ClientProtocolException, IOException { - final HttpComponentsClientHttpRequestFactory requestFactory = (HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory(); - final DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient(); - httpClient.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), new UsernamePasswordCredentials("user", "userPass")); + final DefaultHttpClient httpClient = new DefaultHttpClient(); - final HttpResponse response = httpClient.execute(new HttpGet("http://localhost:8080/spring-security-rest-template/api/foos/1")); + final int timeout = 5; // seconds + final HttpParams httpParams = httpClient.getParams(); + // - note: timeout via raw String parameters + // httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout * 1000); + // httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout * 1000); + // httpParams.setParameter("http.connection-manager.timeout", new Long(timeout * 1000)); + // httpParams.setParameter("http.protocol.head-body-timeout", timeout * 1000); + + // - note: timeout via the API + HttpConnectionParams.setConnectionTimeout(httpParams, timeout * 1000); // http.connection.timeout + HttpConnectionParams.setSoTimeout(httpParams, timeout * 1000); // http.socket.timeout + + final HttpResponse response = httpClient.execute(new HttpGet("http://localhost:8080/spring-security-rest-template/api/foos/1/unsecured")); final int statusCode = response.getStatusLine().getStatusCode(); System.out.println(statusCode); } + }