Search in sources :

Example 86 with RestTemplate

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

the class ClientConfig method restTemplate.

@Bean
public RestTemplate restTemplate() {
    HttpHost host = new HttpHost("localhost", 8080, "http");
    CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider()).useSystemProperties().build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactoryDigestAuth(host, client);
    return new RestTemplate(requestFactory);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpHost(org.apache.http.HttpHost) HttpComponentsClientHttpRequestFactoryDigestAuth(org.baeldung.client.HttpComponentsClientHttpRequestFactoryDigestAuth) RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) Bean(org.springframework.context.annotation.Bean)

Example 87 with RestTemplate

use of org.springframework.web.client.RestTemplate in project cetc by DiscoverForever.

the class AnalysisTaskResource method deleteAnalysisTask.

/**
 * 删除预警任务
 * @param analysisTaskID
 * @return
 */
public ResponseEntity<String> deleteAnalysisTask(String analysisTaskID) {
    RestTemplate restTemplate = new RestTemplate();
    // todo 替换为CETC的api接口
    // String url = "http://localhost:3000/test";
    String url = "http://192.168.1.168:8099/deepaction/";
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("id", analysisTaskID);
    HttpEntity entity = new HttpEntity(map, headers);
    String res = restTemplate.exchange(url, HttpMethod.DELETE, entity, String.class).getBody();
    return new ResponseEntity<>(res, headers, HttpStatus.OK);
}
Also used : HashMap(java.util.HashMap) RestTemplate(org.springframework.web.client.RestTemplate)

Example 88 with RestTemplate

use of org.springframework.web.client.RestTemplate in project nakadi by zalando.

the class AuthenticationConfig method restTemplate.

@Bean
public RestTemplate restTemplate(final HttpClient httpClient) {
    final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(httpClient);
    final RestTemplate restTemplate = new RestTemplate(requestFactory);
    restTemplate.setErrorHandler(TokenResponseErrorHandler.getDefault());
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) Bean(org.springframework.context.annotation.Bean)

Example 89 with RestTemplate

use of org.springframework.web.client.RestTemplate in project webcert by sklintyg.

the class ConsumerConfig method customRestTemplate.

@Bean
public RestTemplate customRestTemplate() {
    HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
    httpRequestFactory.setConnectionRequestTimeout(requestTimeout);
    httpRequestFactory.setConnectTimeout(connectionTimeout);
    httpRequestFactory.setReadTimeout(readTimeout);
    return new RestTemplate(httpRequestFactory);
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) Bean(org.springframework.context.annotation.Bean)

Example 90 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-integration by spring-projects.

the class HttpDslTests method testHttpProxyFlow.

@Test
public void testHttpProxyFlow() throws Exception {
    RestTemplate mockMvcRestTemplate = new RestTemplate(new MockMvcClientHttpRequestFactory(this.mockMvc));
    new DirectFieldAccessor(this.serviceInternalGatewayHandler).setPropertyValue("restTemplate", mockMvcRestTemplate);
    this.mockMvc.perform(get("/service").with(httpBasic("admin", "admin")).param("name", "foo")).andExpect(content().string("FOO"));
    this.mockMvc.perform(get("/service").with(httpBasic("user", "user")).param("name", "name")).andExpect(status().isForbidden());
}
Also used : MockMvcClientHttpRequestFactory(org.springframework.test.web.client.MockMvcClientHttpRequestFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RestTemplate(org.springframework.web.client.RestTemplate) 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