Search in sources :

Example 76 with RestTemplate

use of org.springframework.web.client.RestTemplate in project steve by RWTH-i5-IDSG.

the class GithubReleaseCheckService method init.

@PostConstruct
private void init() {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(API_TIMEOUT_IN_MILLIS);
    factory.setConnectTimeout(API_TIMEOUT_IN_MILLIS);
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy());
    restTemplate = new RestTemplate(Collections.singletonList(new MappingJackson2HttpMessageConverter(mapper)));
    restTemplate.setRequestFactory(factory);
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) PropertyNamingStrategy(com.fasterxml.jackson.databind.PropertyNamingStrategy) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PostConstruct(javax.annotation.PostConstruct)

Example 77 with RestTemplate

use of org.springframework.web.client.RestTemplate in project lavagna by digitalfondue.

the class ApiHooksService method executeScript.

private static boolean executeScript(String name, CompiledScript script, Map<String, Object> scope) {
    try {
        ScriptContext newContext = new SimpleScriptContext();
        Bindings engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
        engineScope.putAll(scope);
        engineScope.put("log", LOG);
        engineScope.put("GSON", Json.GSON);
        engineScope.put("restTemplate", new RestTemplate());
        script.eval(newContext);
        return true;
    } catch (ScriptException ex) {
        LOG.warn("Error while executing script " + name, ex);
        return false;
    }
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate)

Example 78 with RestTemplate

use of org.springframework.web.client.RestTemplate in project selenium_java by sergueik.

the class TestSteps method checkHomePage.

@Then("Home page is accessible")
public void checkHomePage() throws IOException {
    String baseUrl = System.getProperty("docker.url");
    RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject(baseUrl, String.class);
    assertThat("Default 'Hello World!' string expected", result, is("Hello World!"));
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) Then(org.jbehave.core.annotations.Then)

Example 79 with RestTemplate

use of org.springframework.web.client.RestTemplate in project tutorials by eugenp.

the class ApiClient method buildRestTemplate.

/**
 * Build the RestTemplate used to make HTTP requests.
 * @return RestTemplate
 */
protected RestTemplate buildRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    // This allows us to read the response more than once - Necessary for debugging.
    restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory)

Example 80 with RestTemplate

use of org.springframework.web.client.RestTemplate in project tutorials by eugenp.

the class RestTemplateBasicLiveTest method givenResourceUrl_whenSendGetForRequestEntity_thenBodyCorrect.

@Test
public void givenResourceUrl_whenSendGetForRequestEntity_thenBodyCorrect() throws IOException {
    final RestTemplate template = new RestTemplate();
    final ResponseEntity<String> response = template.getForEntity(fooResourceUrl + "/1", String.class);
    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode root = mapper.readTree(response.getBody());
    final JsonNode name = root.path("name");
    assertThat(name.asText(), notNullValue());
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)519 Test (org.junit.Test)135 Test (org.junit.jupiter.api.Test)78 HttpHeaders (org.springframework.http.HttpHeaders)77 HttpEntity (org.springframework.http.HttpEntity)76 URI (java.net.URI)73 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)45 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)44 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)40 IOException (java.io.IOException)36 Bean (org.springframework.context.annotation.Bean)35 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)32 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)27 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)27 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)22 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)22 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)22