org.springframework.http.client.BufferingClientHttpRequestFactory Java Examples
The following examples show how to use
org.springframework.http.client.BufferingClientHttpRequestFactory.
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: MockRestServiceServer.java From java-technology-stack with MIT License | 6 votes |
@Override public MockRestServiceServer build(RequestExpectationManager manager) { MockRestServiceServer server = new MockRestServiceServer(manager); MockClientHttpRequestFactory factory = server.new MockClientHttpRequestFactory(); if (this.restTemplate != null) { if (this.bufferContent) { this.restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); } else { this.restTemplate.setRequestFactory(factory); } } if (this.asyncRestTemplate != null) { this.asyncRestTemplate.setAsyncRequestFactory(factory); } return server; }
Example #2
Source File: ApiClient.java From openapi-generator with Apache License 2.0 | 6 votes |
/** * Build the RestTemplate used to make HTTP requests. * @return RestTemplate */ protected RestTemplate buildRestTemplate() { List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(new MappingJackson2HttpMessageConverter()); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); xmlMapper.registerModule(new JsonNullableModule()); messageConverters.add(new MappingJackson2XmlHttpMessageConverter(xmlMapper)); RestTemplate restTemplate = new RestTemplate(messageConverters); for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ if(converter instanceof AbstractJackson2HttpMessageConverter){ ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); ThreeTenModule module = new ThreeTenModule(); module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); mapper.registerModule(module); mapper.registerModule(new JsonNullableModule()); } } // This allows us to read the response more than once - Necessary for debugging. restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory())); return restTemplate; }
Example #3
Source File: ApiClient.java From openapi-generator with Apache License 2.0 | 6 votes |
/** * Build the RestTemplate used to make HTTP requests. * @return RestTemplate */ protected RestTemplate buildRestTemplate() { RestTemplate restTemplate = new RestTemplate(); for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ if(converter instanceof AbstractJackson2HttpMessageConverter){ ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); ThreeTenModule module = new ThreeTenModule(); module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); mapper.registerModule(module); mapper.registerModule(new JsonNullableModule()); } } // This allows us to read the response more than once - Necessary for debugging. restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory())); return restTemplate; }
Example #4
Source File: AllureRestTemplateTest.java From allure-java with Apache License 2.0 | 6 votes |
protected final AllureResults execute() { final RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); restTemplate.setInterceptors(Collections.singletonList(new AllureRestTemplate())); final WireMockServer server = new WireMockServer(WireMockConfiguration.options().dynamicPort()); return runWithinTestContext(() -> { server.start(); WireMock.configureFor(server.port()); WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/hello")).willReturn(WireMock.aResponse().withBody("some body"))); try { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<JsonNode> entity = new HttpEntity<>(headers); ResponseEntity<String> result = restTemplate.exchange(server.url("/hello"), HttpMethod.GET, entity, String.class); Assertions.assertEquals(result.getStatusCode(), HttpStatus.OK); } finally { server.stop(); } }); }
Example #5
Source File: AbstractIT.java From bowman with Apache License 2.0 | 6 votes |
protected AbstractIT() { baseUri = URI.create(System.getProperty("baseUrl", "http://localhost:8080")); clientFactory = Configuration.builder() .setBaseUri(baseUri) .setClientHttpRequestFactory(new BufferingClientHttpRequestFactory( new HttpComponentsClientHttpRequestFactory())) .setRestTemplateConfigurer(new RestTemplateConfigurer() { @Override public void configure(RestTemplate restTemplate) { restTemplate.getInterceptors().addAll(asList( new LoggingClientHttpRequestInterceptor(), createdEntityRecordingInterceptor )); } }) .build() .buildClientFactory(); }
Example #6
Source File: ApiClient.java From tutorials with MIT License | 6 votes |
/** * Build the RestTemplate used to make HTTP requests. * @return RestTemplate */ protected RestTemplate buildRestTemplate() { RestTemplate restTemplate = new RestTemplate(); for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ if(converter instanceof AbstractJackson2HttpMessageConverter){ ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); ThreeTenModule module = new ThreeTenModule(); module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); mapper.registerModule(module); mapper.registerModule(new JsonNullableModule()); } } // This allows us to read the response more than once - Necessary for debugging. restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory())); return restTemplate; }
Example #7
Source File: MockRestServiceServer.java From spring-analysis-note with MIT License | 5 votes |
@Override public MockRestServiceServer build(RequestExpectationManager manager) { MockRestServiceServer server = new MockRestServiceServer(manager); MockClientHttpRequestFactory factory = server.new MockClientHttpRequestFactory(); if (this.restTemplate != null) { if (this.bufferContent) { this.restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); } else { this.restTemplate.setRequestFactory(factory); } } if (this.asyncRestTemplate != null) { this.asyncRestTemplate.setAsyncRequestFactory(factory); } return server; }
Example #8
Source File: RequestCompressionPluginTest.java From riptide with MIT License | 5 votes |
@Override public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) { return Stream.of( new SimpleClientHttpRequestFactory(), // new Netty4ClientHttpRequestFactory(), # broken, see #823 new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()), new ApacheClientHttpRequestFactory(HttpClients.createDefault(), Mode.BUFFERING), new ApacheClientHttpRequestFactory(HttpClients.createDefault(), Mode.STREAMING) ).map(Arguments::of); }
Example #9
Source File: ApiClient.java From tutorials with MIT License | 5 votes |
/** * 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; }