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

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

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

RestTemplate.patchForObject介绍

暂无

代码示例

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

@Test
public void patchForObject() throws URISyntaxException {
  // JDK client does not support the PATCH method
  Assume.assumeThat(this.clientHttpRequestFactory,
      Matchers.not(Matchers.instanceOf(SimpleClientHttpRequestFactory.class)));
  String s = template.patchForObject(baseUrl + "/{method}", helloWorld, String.class, "patch");
  assertEquals("Invalid content", helloWorld, s);
}

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

@Test
public void patchForObject() throws Exception {
  mockTextPlainHttpMessageConverter();
  HttpHeaders requestHeaders = new HttpHeaders();
  mockSentRequest(PATCH, "http://example.com", requestHeaders);
  mockResponseStatus(HttpStatus.OK);
  String expected = "42";
  mockResponseBody("42", MediaType.TEXT_PLAIN);
  String result = template.patchForObject("http://example.com", "Hello World", String.class);
  assertEquals("Invalid POST result", expected, result);
  assertEquals("Invalid Accept header", MediaType.TEXT_PLAIN_VALUE, requestHeaders.getFirst("Accept"));
  verify(response).close();
}

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

@Test
public void patchForObjectNull() throws Exception {
  mockTextPlainHttpMessageConverter();
  HttpHeaders requestHeaders = new HttpHeaders();
  mockSentRequest(PATCH, "http://example.com", requestHeaders);
  mockResponseStatus(HttpStatus.OK);
  HttpHeaders responseHeaders = new HttpHeaders();
  responseHeaders.setContentType(MediaType.TEXT_PLAIN);
  responseHeaders.setContentLength(10);
  given(response.getHeaders()).willReturn(responseHeaders);
  given(response.getBody()).willReturn(StreamUtils.emptyInput());
  String result = template.patchForObject("http://example.com", null, String.class);
  assertNull("Invalid POST result", result);
  assertEquals("Invalid content length", 0, requestHeaders.getContentLength());
  verify(response).close();
}

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

/**
 * Update a resource by PATCHing the given object to the URI template, and returns the
 * representation found in the response.
 * <p>
 * URI Template variables are expanded using the given URI variables, if any.
 * <p>
 * The {@code request} parameter can be a {@link HttpEntity} in order to add
 * additional HTTP headers to the request.
 * @param url the URL
 * @param request the Object to be PATCHed, may be {@code null}
 * @param responseType the type of the return value
 * @param uriVariables the variables to expand the template
 * @param <T> the type of the return value
 * @return the converted object
 * @throws RestClientException on client-side HTTP error
 * @since 1.4.4
 * @see HttpEntity
 */
public <T> T patchForObject(String url, Object request, Class<T> responseType,
    Object... uriVariables) throws RestClientException {
  return this.restTemplate.patchForObject(url, request, responseType, uriVariables);
}

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

/**
 * Update a resource by PATCHing the given object to the URI template, and returns the
 * representation found in the response.
 * <p>
 * URI Template variables are expanded using the given map.
 * <p>
 * The {@code request} parameter can be a {@link HttpEntity} in order to add
 * additional HTTP headers to the request.
 * @param url the URL
 * @param request the Object to be PATCHed, may be {@code null}
 * @param responseType the type of the return value
 * @param uriVariables the variables to expand the template
 * @param <T> the type of the return value
 * @return the converted object
 * @throws RestClientException on client-side HTTP error
 * @since 1.4.4
 * @see HttpEntity
 */
public <T> T patchForObject(String url, Object request, Class<T> responseType,
    Map<String, ?> uriVariables) throws RestClientException {
  return this.restTemplate.patchForObject(url, request, responseType, uriVariables);
}

代码示例来源:origin: uk.co.blackpepper.bowman/bowman-client

public <T> Resource<T> patchForResource(URI uri, Object patch, Class<T> entityType) {
  ObjectNode node;
  node = restTemplate.patchForObject(uri, patch, ObjectNode.class);
  if (node == null) {
    return null;
  }
  JavaType targetType = objectMapper.getTypeFactory().constructParametricType(Resource.class, entityType);
  return objectMapper.convertValue(node, targetType);
}

代码示例来源:origin: BlackPepperSoftware/bowman

public <T> Resource<T> patchForResource(URI uri, Object patch, Class<T> entityType) {
  ObjectNode node;
  node = restTemplate.patchForObject(uri, patch, ObjectNode.class);
  if (node == null) {
    return null;
  }
  JavaType targetType = objectMapper.getTypeFactory().constructParametricType(Resource.class, entityType);
  return objectMapper.convertValue(node, targetType);
}

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

@Override
public void bindDropletToApp(UUID dropletGuid, UUID appGuid) {
  Map<String, Object> bindDropletRequest = new HashMap<>();
  Map<String, Object> dataMap = new HashMap<>();
  dataMap.put("guid", dropletGuid);
  bindDropletRequest.put("data", dataMap);
  getRestTemplate().patchForObject(getUrl("/v3/apps/{appGuid}/relationships/current_droplet"), bindDropletRequest, String.class,
    appGuid);
}

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

/**
 * Update a resource by PATCHing the given object to the URL, and returns the
 * representation found in the response.
 * <p>
 * The {@code request} parameter can be a {@link HttpEntity} in order to add
 * additional HTTP headers to the request.
 * @param url the URL
 * @param request the Object to be POSTed, may be {@code null}
 * @param responseType the type of the return value
 * @param <T> the type of the return value
 * @return the converted object
 * @throws RestClientException on client-side HTTP error
 * @since 1.4.4
 * @see HttpEntity
 */
public <T> T patchForObject(URI url, Object request, Class<T> responseType)
    throws RestClientException {
  return this.restTemplate.patchForObject(applyRootUriIfNecessary(url), request,
      responseType);
}

相关文章

微信公众号

最新文章

更多