Java Code Examples for org.springframework.web.client.RestTemplate#getRequestFactory()
The following examples show how to use
org.springframework.web.client.RestTemplate#getRequestFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VaultInitializer.java From spring-vault with Apache License 2.0 | 6 votes |
/** * Create a new {@link VaultInitializer} with the given {@link SslConfiguration} and * {@link VaultEndpoint}. * @param sslConfiguration must not be {@literal null}. * @param vaultEndpoint must not be {@literal null}. */ public VaultInitializer(SslConfiguration sslConfiguration, VaultEndpoint vaultEndpoint) { Assert.notNull(sslConfiguration, "SslConfiguration must not be null"); Assert.notNull(vaultEndpoint, "VaultEndpoint must not be null"); RestTemplate restTemplate = TestRestTemplateFactory.create(sslConfiguration); WebClient webClient = TestWebClientFactory.create(sslConfiguration); VaultTemplate vaultTemplate = new VaultTemplate(TestRestTemplateFactory.TEST_VAULT_ENDPOINT, restTemplate.getRequestFactory(), new PreparingSessionManager()); this.token = Settings.token(); this.prepareVault = new PrepareVault(webClient, TestRestTemplateFactory.create(sslConfiguration), vaultTemplate); this.vaultEndpoint = vaultEndpoint; }
Example 2
Source File: PayloadSender.java From Profiles-Blog with MIT License | 6 votes |
@PostConstruct public void initialize() { restTemplate = new RestTemplate(); // Loose JSON serialization defaults ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.setSerializationInclusion(Include.NON_NULL); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper); restTemplate.setMessageConverters(Arrays.asList(converter)); // Timeout settings SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory(); int tenSeconds = 10000; requestFactory.setReadTimeout(tenSeconds); requestFactory.setConnectTimeout(tenSeconds); }
Example 3
Source File: HttpUtils.java From rqueue with Apache License 2.0 | 5 votes |
public static <T> T readUrl(String url, Class<T> clazz) { try { RestTemplate restTemplate = new RestTemplate(); SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory(); rf.setReadTimeout(2 * Constants.ONE_MILLI_INT); rf.setConnectTimeout(2 * Constants.ONE_MILLI_INT); return restTemplate.getForObject(url, clazz); } catch (Exception e) { log.error("GET call failed for {}", url, e); return null; } }
Example 4
Source File: BintraySearchProviderImpl.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void setTimeout(RestTemplate restTemplate, int connectTimeout, int readTimeout) { restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory()); SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate .getRequestFactory(); rf.setReadTimeout(readTimeout); rf.setConnectTimeout(connectTimeout); }
Example 5
Source File: GoogleSearchProviderImpl.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void setTimeout(RestTemplate restTemplate, int connectTimeout, int readTimeout) { restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory()); SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate .getRequestFactory(); rf.setReadTimeout(readTimeout); rf.setConnectTimeout(connectTimeout); }
Example 6
Source File: GradleUpdateHandler.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private static void setTimeout(RestTemplate restTemplate, int connectTimeout, int readTimeout) { restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory()); SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate .getRequestFactory(); rf.setReadTimeout(readTimeout); rf.setConnectTimeout(connectTimeout); }
Example 7
Source File: HttpArtifactoryTests.java From artifactory-resource with Apache License 2.0 | 5 votes |
@Test public void serverDoesNotBuffer() { // gh-50 ArtifactoryServer server = this.artifactory.server("https://example.com", null, null); RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(server, "restTemplate"); SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate .getRequestFactory(); assertThat(ReflectionTestUtils.getField(requestFactory, "bufferRequestBody")).isEqualTo(Boolean.FALSE); assertThat(ReflectionTestUtils.getField(requestFactory, "outputStreaming")).isEqualTo(Boolean.TRUE); }
Example 8
Source File: CtripMQService.java From apollo with Apache License 2.0 | 5 votes |
@PostConstruct public void init() { restTemplate = new RestTemplate(); SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory(); rf.setReadTimeout(portalConfig.readTimeout()); rf.setConnectTimeout(portalConfig.connectTimeout()); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.setSupportedMediaTypes( Arrays.asList(MediaType.APPLICATION_JSON_UTF8, MediaType.APPLICATION_OCTET_STREAM)); restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter())); }
Example 9
Source File: WireMockRestTemplateConfiguration.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnClass(SSLContextBuilder.class) @ConditionalOnProperty(value = "wiremock.rest-template-ssl-enabled", matchIfMissing = true) public RestTemplateCustomizer wiremockRestTemplateCustomizer() { return new RestTemplateCustomizer() { @Override public void customize(RestTemplate restTemplate) { if (restTemplate .getRequestFactory() instanceof HttpComponentsClientHttpRequestFactory) { HttpComponentsClientHttpRequestFactory factory = (HttpComponentsClientHttpRequestFactory) restTemplate .getRequestFactory(); factory.setHttpClient(createSslHttpClient()); } } private HttpClient createSslHttpClient() { try { SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder().loadTrustMaterial(null, TrustSelfSignedStrategy.INSTANCE).build(), NoopHostnameVerifier.INSTANCE); return HttpClients.custom().setSSLSocketFactory(socketFactory) .build(); } catch (Exception ex) { throw new IllegalStateException("Unable to create SSL HttpClient", ex); } } }; }
Example 10
Source File: CloudControllerRestClientFactory.java From cf-java-client-sap with Apache License 2.0 | 4 votes |
private void setAuthorizingRequestFactory(RestTemplate restTemplate, CloudCredentials credentials, OAuthClient oAuthClient) { ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory(); if (!(requestFactory instanceof CloudControllerRestClientHttpRequestFactory)) { restTemplate.setRequestFactory(new CloudControllerRestClientHttpRequestFactory(requestFactory, credentials, oAuthClient)); } }
Example 11
Source File: MockClientHttpRequestFactoryTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Before public void setup() { RestTemplate restTemplate = new RestTemplate(); this.server = MockRestServiceServer.createServer(restTemplate); this.factory = restTemplate.getRequestFactory(); }
Example 12
Source File: RamlRestTemplate.java From raml-tester with Apache License 2.0 | 4 votes |
private RamlRestTemplate(RamlChecker ramlChecker, boolean notSending, ReportStore reportStore, RestTemplate restTemplate) { this(ramlChecker, notSending, reportStore, restTemplate.getRequestFactory()); init(restTemplate); }