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

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

本文整理了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

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

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

  1. @Test
  2. public void patchForObject() throws Exception {
  3. mockTextPlainHttpMessageConverter();
  4. HttpHeaders requestHeaders = new HttpHeaders();
  5. mockSentRequest(PATCH, "http://example.com", requestHeaders);
  6. mockResponseStatus(HttpStatus.OK);
  7. String expected = "42";
  8. mockResponseBody("42", MediaType.TEXT_PLAIN);
  9. String result = template.patchForObject("http://example.com", "Hello World", String.class);
  10. assertEquals("Invalid POST result", expected, result);
  11. assertEquals("Invalid Accept header", MediaType.TEXT_PLAIN_VALUE, requestHeaders.getFirst("Accept"));
  12. verify(response).close();
  13. }

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

  1. @Test
  2. public void patchForObjectNull() throws Exception {
  3. mockTextPlainHttpMessageConverter();
  4. HttpHeaders requestHeaders = new HttpHeaders();
  5. mockSentRequest(PATCH, "http://example.com", requestHeaders);
  6. mockResponseStatus(HttpStatus.OK);
  7. HttpHeaders responseHeaders = new HttpHeaders();
  8. responseHeaders.setContentType(MediaType.TEXT_PLAIN);
  9. responseHeaders.setContentLength(10);
  10. given(response.getHeaders()).willReturn(responseHeaders);
  11. given(response.getBody()).willReturn(StreamUtils.emptyInput());
  12. String result = template.patchForObject("http://example.com", null, String.class);
  13. assertNull("Invalid POST result", result);
  14. assertEquals("Invalid content length", 0, requestHeaders.getContentLength());
  15. verify(response).close();
  16. }

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

  1. /**
  2. * Update a resource by PATCHing the given object to the URI template, and returns the
  3. * representation found in the response.
  4. * <p>
  5. * URI Template variables are expanded using the given URI variables, if any.
  6. * <p>
  7. * The {@code request} parameter can be a {@link HttpEntity} in order to add
  8. * additional HTTP headers to the request.
  9. * @param url the URL
  10. * @param request the Object to be PATCHed, may be {@code null}
  11. * @param responseType the type of the return value
  12. * @param uriVariables the variables to expand the template
  13. * @param <T> the type of the return value
  14. * @return the converted object
  15. * @throws RestClientException on client-side HTTP error
  16. * @since 1.4.4
  17. * @see HttpEntity
  18. */
  19. public <T> T patchForObject(String url, Object request, Class<T> responseType,
  20. Object... uriVariables) throws RestClientException {
  21. return this.restTemplate.patchForObject(url, request, responseType, uriVariables);
  22. }

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

  1. /**
  2. * Update a resource by PATCHing the given object to the URI template, and returns the
  3. * representation found in the response.
  4. * <p>
  5. * URI Template variables are expanded using the given map.
  6. * <p>
  7. * The {@code request} parameter can be a {@link HttpEntity} in order to add
  8. * additional HTTP headers to the request.
  9. * @param url the URL
  10. * @param request the Object to be PATCHed, may be {@code null}
  11. * @param responseType the type of the return value
  12. * @param uriVariables the variables to expand the template
  13. * @param <T> the type of the return value
  14. * @return the converted object
  15. * @throws RestClientException on client-side HTTP error
  16. * @since 1.4.4
  17. * @see HttpEntity
  18. */
  19. public <T> T patchForObject(String url, Object request, Class<T> responseType,
  20. Map<String, ?> uriVariables) throws RestClientException {
  21. return this.restTemplate.patchForObject(url, request, responseType, uriVariables);
  22. }

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

  1. public <T> Resource<T> patchForResource(URI uri, Object patch, Class<T> entityType) {
  2. ObjectNode node;
  3. node = restTemplate.patchForObject(uri, patch, ObjectNode.class);
  4. if (node == null) {
  5. return null;
  6. }
  7. JavaType targetType = objectMapper.getTypeFactory().constructParametricType(Resource.class, entityType);
  8. return objectMapper.convertValue(node, targetType);
  9. }

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

  1. public <T> Resource<T> patchForResource(URI uri, Object patch, Class<T> entityType) {
  2. ObjectNode node;
  3. node = restTemplate.patchForObject(uri, patch, ObjectNode.class);
  4. if (node == null) {
  5. return null;
  6. }
  7. JavaType targetType = objectMapper.getTypeFactory().constructParametricType(Resource.class, entityType);
  8. return objectMapper.convertValue(node, targetType);
  9. }

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

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

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

  1. /**
  2. * Update a resource by PATCHing the given object to the URL, and returns the
  3. * representation found in the response.
  4. * <p>
  5. * The {@code request} parameter can be a {@link HttpEntity} in order to add
  6. * additional HTTP headers to the request.
  7. * @param url the URL
  8. * @param request the Object to be POSTed, may be {@code null}
  9. * @param responseType the type of the return value
  10. * @param <T> the type of the return value
  11. * @return the converted object
  12. * @throws RestClientException on client-side HTTP error
  13. * @since 1.4.4
  14. * @see HttpEntity
  15. */
  16. public <T> T patchForObject(URI url, Object request, Class<T> responseType)
  17. throws RestClientException {
  18. return this.restTemplate.patchForObject(applyRootUriIfNecessary(url), request,
  19. responseType);
  20. }

相关文章