本文整理了Java中org.springframework.web.client.RestTemplate.setRequestFactory
方法的一些代码示例,展示了RestTemplate.setRequestFactory
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestTemplate.setRequestFactory
方法的具体详情如下:
包路径:org.springframework.web.client.RestTemplate
类名称:RestTemplate
方法名:setRequestFactory
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new instance of the {@link RestTemplate} based on the given {@link ClientHttpRequestFactory}.
* @param requestFactory the HTTP request factory to use
* @see org.springframework.http.client.SimpleClientHttpRequestFactory
* @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory
*/
public RestTemplate(ClientHttpRequestFactory requestFactory) {
this();
setRequestFactory(requestFactory);
}
代码示例来源:origin: org.springframework/spring-web
/**
* Create a new instance of the {@link RestTemplate} based on the given {@link ClientHttpRequestFactory}.
* @param requestFactory the HTTP request factory to use
* @see org.springframework.http.client.SimpleClientHttpRequestFactory
* @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory
*/
public RestTemplate(ClientHttpRequestFactory requestFactory) {
this();
setRequestFactory(requestFactory);
}
代码示例来源:origin: eugenp/tutorials
/**
* 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;
}
代码示例来源:origin: spring-projects/spring-framework
@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;
}
}
代码示例来源:origin: liuyangming/ByteTCC
@org.springframework.context.annotation.Bean
public SpringBootBeanRegistry springBootBeanRegistry(@Autowired ClientHttpRequestFactory requestFactory) {
SpringBootBeanRegistry springBootBeanRegistry = SpringBootBeanRegistry.getInstance();
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(requestFactory);
springBootBeanRegistry.setRestTemplate(restTemplate);
return springBootBeanRegistry;
}
代码示例来源:origin: liuyangming/ByteTCC
@org.springframework.context.annotation.Bean("compensableRestTemplate")
public RestTemplate transactionTemplate(@Autowired ClientHttpRequestFactory requestFactory) {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(requestFactory);
SpringCloudBeanRegistry registry = SpringCloudBeanRegistry.getInstance();
registry.setRestTemplate(restTemplate);
return restTemplate;
}
代码示例来源:origin: liuyangming/ByteTCC
@org.springframework.context.annotation.Bean
public SpringBootBeanRegistry springBootBeanRegistry(@Autowired ClientHttpRequestFactory requestFactory) {
SpringBootBeanRegistry springBootBeanRegistry = SpringBootBeanRegistry.getInstance();
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(requestFactory);
springBootBeanRegistry.setRestTemplate(restTemplate);
return springBootBeanRegistry;
}
代码示例来源:origin: stackoverflow.com
RestTemplate rt = new RestTemplate();
//set interceptors/requestFactory
ClientHttpRequestInterceptor ri = new LoggingRequestInterceptor();
List<ClientHttpRequestInterceptor> ris = new ArrayList<ClientHttpRequestInterceptor>();
ris.add(ri);
rt.setInterceptors(ris);
rt.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
代码示例来源:origin: liuyangming/ByteTCC
@org.springframework.context.annotation.Bean("compensableRestTemplate")
@org.springframework.cloud.client.loadbalancer.LoadBalanced
public RestTemplate transactionTemplate(@Autowired ClientHttpRequestFactory requestFactory) {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(requestFactory);
SpringCloudBeanRegistry registry = SpringCloudBeanRegistry.getInstance();
registry.setRestTemplate(restTemplate);
return restTemplate;
}
代码示例来源:origin: cloudfoundry/uaa
public RestAuthenticationManager() {
RestTemplate restTemplate = new RestTemplate();
// The default java.net client doesn't allow you to handle 4xx responses
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
protected boolean hasError(HttpStatus statusCode) {
return statusCode.series() == HttpStatus.Series.SERVER_ERROR;
}
});
this.restTemplate = restTemplate;
}
代码示例来源:origin: ctripcorp/apollo
public void afterPropertiesSet() throws UnsupportedEncodingException {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
restTemplate = new RestTemplate(httpMessageConverters.getConverters());
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory(httpClient);
requestFactory.setConnectTimeout(portalConfig.connectTimeout());
requestFactory.setReadTimeout(portalConfig.readTimeout());
restTemplate.setRequestFactory(requestFactory);
}
代码示例来源:origin: spring-io/initializr
@Bean
RestTemplateCustomizer mockMvcCustomizer(BeanFactory beanFactory) {
return (template) -> template.setRequestFactory(
beanFactory.getBean(MockMvcClientHttpRequestFactory.class));
}
代码示例来源:origin: spring-projects/spring-security-oauth
@Override
public void setRequestFactory(ClientHttpRequestFactory requestFactory) {
if (!(requestFactory instanceof OAuthClientHttpRequestFactory)) {
requestFactory = new OAuthClientHttpRequestFactory(requestFactory, getResource(), getSupport());
}
super.setRequestFactory(requestFactory);
}
代码示例来源:origin: org.springframework.boot/spring-boot
private void configureRequestFactory(RestTemplate restTemplate) {
ClientHttpRequestFactory requestFactory = null;
if (this.requestFactorySupplier != null) {
requestFactory = this.requestFactorySupplier.get();
}
else if (this.detectRequestFactory) {
requestFactory = new ClientHttpRequestFactorySupplier().get();
}
if (requestFactory != null) {
if (this.requestFactoryCustomizer != null) {
this.requestFactoryCustomizer.accept(requestFactory);
}
restTemplate.setRequestFactory(requestFactory);
}
}
代码示例来源:origin: spring-projects/spring-security-oauth
protected RestOperations getRestTemplate() {
if (restTemplate == null) {
synchronized (this) {
if (restTemplate == null) {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(getResponseErrorHandler());
restTemplate.setRequestFactory(requestFactory);
restTemplate.setInterceptors(interceptors);
this.restTemplate = restTemplate;
}
}
}
if (messageConverters == null) {
setMessageConverters(new RestTemplate().getMessageConverters());
}
return restTemplate;
}
代码示例来源:origin: stackoverflow.com
final InputStream fis = new FileInputStream(new File("c:\\autoexec.bat")); // or whatever
final RequestCallback requestCallback = new RequestCallback() {
@Override
public void doWithRequest(final ClientHttpRequest request) throws IOException {
request.getHeaders().add("Content-type", "application/octet-stream");
IOUtils.copy(fis, request.getBody());
}
};
final RestTemplate restTemplate = new RestTemplate();
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);
restTemplate.setRequestFactory(requestFactory);
final HttpMessageConverterExtractor<String> responseExtractor =
new HttpMessageConverterExtractor<String>(String.class, restTemplate.getMessageConverters());
restTemplate.execute("http://localhost:4000", HttpMethod.POST, requestCallback, responseExtractor);
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setup() {
requestFactory = mock(ClientHttpRequestFactory.class);
request = mock(ClientHttpRequest.class);
response = mock(ClientHttpResponse.class);
errorHandler = mock(ResponseErrorHandler.class);
converter = mock(HttpMessageConverter.class);
template = new RestTemplate(Collections.singletonList(converter));
template.setRequestFactory(requestFactory);
template.setErrorHandler(errorHandler);
}
代码示例来源:origin: cloudfoundry/uaa
public RestTemplate createRestTemplate() {
RestTemplate client = new RestTemplate();
client.setRequestFactory(new StatelessRequestFactory());
client.setErrorHandler(new ResponseErrorHandler() {
// Pass errors through in response entity for status code analysis
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
@Override
public void handleError(ClientHttpResponse response) throws IOException {
}
});
return client;
}
代码示例来源:origin: cloudfoundry/uaa
public static RestTemplate getClientCredentialsTemplate(ClientCredentialsResourceDetails details) {
RestTemplate client = new OAuth2RestTemplate(details);
client.setRequestFactory(new StatelessRequestFactory());
client.setErrorHandler(new OAuth2ErrorHandler(details) {
// Pass errors through in response entity for status code analysis
@Override
public boolean hasError(ClientHttpResponse response) throws IOException {
return false;
}
@Override
public void handleError(ClientHttpResponse response) throws IOException {
}
});
return client;
}
代码示例来源:origin: cloudfoundry/uaa
@Before
public void setUp() throws Exception {
((RestTemplate)restOperations).setRequestFactory(new IntegrationTestUtils.StatelessRequestFactory());
ClientCredentialsResourceDetails clientCredentials =
getClientCredentialsResource(new String[] {"scim.write"}, testAccounts.getAdminClientId(), testAccounts.getAdminClientSecret());
client = IntegrationTestUtils.getClientCredentialsTemplate(clientCredentials);
user = createUser(new RandomValueStringGenerator().generate(), "openiduser", "openidlast", "test@openid,com",true);
}
内容来源于网络,如有侵权,请联系作者删除!