org.springframework.web.client.RestTemplate.getRequestFactory()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.springframework.web.client.RestTemplate.getRequestFactory方法的一些代码示例,展示了RestTemplate.getRequestFactory的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestTemplate.getRequestFactory方法的具体详情如下:
包路径:org.springframework.web.client.RestTemplate
类名称:RestTemplate
方法名:getRequestFactory

RestTemplate.getRequestFactory介绍

暂无

代码示例

代码示例来源: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: ctripcorp/apollo

@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()));
}

代码示例来源:origin: paulc4/microservices-demo

/**
 * The RestTemplate works because it uses a custom request-factory that uses
 * Ribbon to look-up the service to use. This method simply exists to show
 * this.
 */
@PostConstruct
public void demoOnly() {
  // Can't do this in the constructor because the RestTemplate injection
  // happens afterwards.
  logger.warning("The RestTemplate request factory is "
      + restTemplate.getRequestFactory().getClass());
}

代码示例来源:origin: paulc4/microservices-demo

/**
 * The RestTemplate works because it uses a custom request-factory that uses
 * Ribbon to look-up the service to use. This method simply exists to show
 * this.
 */
@PostConstruct
public void demoOnly() {
  // Can't do this in the constructor because the RestTemplate injection
  // happens afterwards.
  logger.warning("The RestTemplate request factory is "
      + restTemplate.getRequestFactory().getClass());
}

代码示例来源:origin: FastBootWeixin/FastBootWeixin

public ClientHttpRequestFactory getRequestFactory() {
  return restTemplate.getRequestFactory();
}

代码示例来源:origin: org.springframework.boot/spring-boot-test

private Class<? extends ClientHttpRequestFactory> getRequestFactoryClass(
    RestTemplate restTemplate) {
  ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
  if (InterceptingClientHttpRequestFactory.class
      .isAssignableFrom(requestFactory.getClass())) {
    Field requestFactoryField = ReflectionUtils.findField(RestTemplate.class,
        "requestFactory");
    ReflectionUtils.makeAccessible(requestFactoryField);
    requestFactory = (ClientHttpRequestFactory) ReflectionUtils
        .getField(requestFactoryField, restTemplate);
  }
  return requestFactory.getClass();
}

代码示例来源:origin: com.sap.cloud.lm.sl/cloudfoundry-client-lib

protected void configureRequestFactory(RestTemplate restTemplate) {
  ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
  if (!(requestFactory instanceof CloudControllerRestClientHttpRequestFactory)) {
    restTemplate.setRequestFactory(new CloudControllerRestClientHttpRequestFactory(requestFactory));
  }
}

代码示例来源:origin: org.cloudfoundry/cloudfoundry-client-lib

protected void configureCloudFoundryRequestFactory(RestTemplate restTemplate) {
  ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
  if (!(requestFactory instanceof CloudFoundryClientHttpRequestFactory)) {
    restTemplate.setRequestFactory(
        new CloudFoundryClientHttpRequestFactory(requestFactory));
  }
}

代码示例来源:origin: com.sap.cloud.lm.sl/cloudfoundry-client-lib

protected ResourceOwnerPasswordAccessTokenProvider createResourceOwnerPasswordAccessTokenProvider() {
  ResourceOwnerPasswordAccessTokenProvider resourceOwnerPasswordAccessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider();
  resourceOwnerPasswordAccessTokenProvider.setRequestFactory(restTemplate.getRequestFactory()); // copy the http proxy along
  return resourceOwnerPasswordAccessTokenProvider;
}

代码示例来源:origin: org.cloudfoundry/cloudfoundry-client-lib

protected ResourceOwnerPasswordAccessTokenProvider createResourceOwnerPasswordAccessTokenProvider() {
  ResourceOwnerPasswordAccessTokenProvider resourceOwnerPasswordAccessTokenProvider = new ResourceOwnerPasswordAccessTokenProvider();
  resourceOwnerPasswordAccessTokenProvider.setRequestFactory(restTemplate.getRequestFactory()); //copy the http proxy along
  return resourceOwnerPasswordAccessTokenProvider;
}

代码示例来源:origin: org.motechproject/motech-http-agent

@Autowired
public HttpClientEventListener(RestTemplate restTemplate, @Qualifier("httpAgentSettings") SettingsFacade settings) {
  HttpComponentsClientHttpRequestFactory requestFactory = (HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory();
  requestFactory.setConnectTimeout(Integer.parseInt(settings.getProperty(HTTP_CONNECT_TIMEOUT)));
  requestFactory.setReadTimeout(Integer.parseInt(settings.getProperty(HTTP_READ_TIMEOUT)));
  this.restTemplate = restTemplate;
}

代码示例来源:origin: spring-projects/spring-social-twitter

private ClientHttpResponse executeRequest(HttpMethod method, String url, MultiValueMap<String, String> body) throws IOException {
  ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
  ClientHttpRequest request = requestFactory.createRequest(URI.create(url), method);
  OutputStreamWriter writer = new OutputStreamWriter(request.getBody());
  writer.write(createFormUrlEncodedBodyString(body));
  writer.flush();
  request.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);
  return request.execute();
}

代码示例来源:origin: org.springframework.social/spring-social-twitter

private ClientHttpResponse executeRequest(HttpMethod method, String url, MultiValueMap<String, String> body) throws IOException {
  ClientHttpRequestFactory requestFactory = restTemplate.getRequestFactory();
  ClientHttpRequest request = requestFactory.createRequest(URI.create(url), method);
  OutputStreamWriter writer = new OutputStreamWriter(request.getBody());
  writer.write(createFormUrlEncodedBodyString(body));
  writer.flush();
  request.getHeaders().setContentType(MediaType.APPLICATION_FORM_URLENCODED);
  return request.execute();
}

代码示例来源:origin: stackoverflow.com

List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
 interceptors.add( new NetworkInterceptor() );
 SimpleClientHttpRequestFactory s = new SimpleClientHttpRequestFactory();
 s.setReadTimeout(5000);
 s.setConnectTimeout(1000);
 RestTemplate tpl = new RestTemplate(s);//Or however you instantiated it
 tpl.setInterceptors( interceptors );
 ClientHttpRequestFactory c =  tpl.getRequestFactory();

代码示例来源:origin: org.springframework.cloud.stream.app/spring-cloud-starter-stream-source-twitterstream

private ClientHttpRequestFactory getRequestFactory() {
  // InterceptingClientHttpRequestFactory doesn't let us access the underlying object
  DirectFieldAccessor f = new DirectFieldAccessor(twitter.getRestTemplate().getRequestFactory());
  Object requestFactory = f.getPropertyValue("requestFactory");
  return (ClientHttpRequestFactory) requestFactory;
}

代码示例来源:origin: ad-tech-group/openssp

private T connect(final PathBuilder config) throws RestClientException {
  final RestTemplate restTemplate = new RestTemplate(httpMessageConverters);
  final SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
  rf.setReadTimeout(2000);
  rf.setConnectTimeout(2000);
  config.addParam("t", RestfulContext.getToken());
  final ResponseEntity<T> re = restTemplate.getForEntity(config.buildEndpointURI(), dtoType);
  return re.getBody();
}

代码示例来源:origin: org.springframework.social/spring-social-linkedin

private void registerJsonFormatInterceptor() {		
  RestTemplate restTemplate = getRestTemplate();
  if (interceptorsSupported) {
    List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
    interceptors.add(new JsonFormatInterceptor());
  } else {
    // for Spring 3.0.x where interceptors aren't supported
    ClientHttpRequestFactory originalRequestFactory = restTemplate.getRequestFactory();
    JsonFormatHeaderRequestFactory newRequestFactory = new JsonFormatHeaderRequestFactory(originalRequestFactory);
    restTemplate.setRequestFactory(newRequestFactory);
  }
}

代码示例来源:origin: org.zalando.zauth/spring-social-zauth

private void initialize() {
  super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(getRestTemplate().getRequestFactory()));
  // ClientHttpRequestFactory requestFactory =
  // ClientHttpRequestFactorySelector.getRequestFactory();
  // restTemplate = new RestTemplate(requestFactory);
  initSubApis();
}

代码示例来源:origin: org.springframework.social/spring-social-facebook

private void initialize() {
  // Wrap the request factory with a BufferingClientHttpRequestFactory so that the error handler can do repeat reads on the response.getBody()
  super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(getRestTemplate().getRequestFactory()));
  initSubApis();
}

代码示例来源:origin: spring-projects/spring-social-facebook

private void initialize() {
  // Wrap the request factory with a BufferingClientHttpRequestFactory so that the error handler can do repeat reads on the response.getBody()
  super.setRequestFactory(ClientHttpRequestFactorySelector.bufferRequests(getRestTemplate().getRequestFactory()));
  initSubApis();
}

相关文章