Skip to content

Commit

Permalink
Merge pull request #6 from andreformento/master
Browse files Browse the repository at this point in the history
Corrige erro de compilação e teste de integração
  • Loading branch information
andreformentoc authored Jul 15, 2017
2 parents b6a510c + a5c4ab0 commit 49da5e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repositories {


dependencies {
compile 'org.springframework.boot:spring-boot-starter'
compile('org.springframework.boot:spring-boot-starter')
compile 'org.springframework.boot:spring-boot-starter-undertow'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-hateoas'
Expand All @@ -33,6 +33,7 @@ dependencies {
compile 'com.google.guava:guava:22.0'
compile 'org.modelmapper:modelmapper:0.7.5'
compile 'commons-io:commons-io:2.5'
compile 'org.apache.httpcomponents:httpclient:4.4.1'

testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'br.com.six2six:fixture-factory:3.1.0'
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/br/com/concrete/mock/ApiApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package br.com.concrete.mock;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
Expand All @@ -15,8 +20,10 @@ public static void main(String[] args) {
}

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
public RestTemplate restTemplate() {
HttpClient httpClient = HttpClientBuilder.create().build();
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
return new RestTemplate(requestFactory);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import br.com.concrete.mock.generic.model.Request;
import br.com.concrete.mock.infra.model.UriConfiguration;
import br.com.concrete.mock.infra.property.ApiProperty;
import java.util.Optional;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,9 +18,6 @@
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Optional;
import java.util.regex.Pattern;

@Component
public class ExternalApi {

Expand Down Expand Up @@ -69,22 +68,9 @@ public Optional<ExternalApiResult> execute(final Request request) {
.concat(parameters);

LOGGER.info("URL => {}", url);
ResponseEntity<String> apiResult = null;
try {
apiResult = restTemplate.exchange(url, HttpMethod.valueOf(request.getMethod().name().toUpperCase()), entity,
String.class);
return Optional.of(new ExternalApiResult(apiResult, uriConfiguration));
} catch (Exception e) {
LOGGER.error("Erro chamada API " + HttpMethod.valueOf(request.getMethod().name().toUpperCase()) + " " + url,
e);

LOGGER.error("Tentando mais uma vez " + HttpMethod.valueOf(request.getMethod().name().toUpperCase()) + " "
+ url);
}
// }

return Optional.empty();

final ResponseEntity<String> apiResult = restTemplate.exchange(url, HttpMethod.valueOf(request.getMethod().name().toUpperCase()), entity,
String.class);
return Optional.of(new ExternalApiResult(apiResult, uriConfiguration));
}

}

0 comments on commit 49da5e1

Please sign in to comment.