@Override public Resource retrieveResource(URL url) throws IOException { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); ResponseEntity<String> response; try { RequestEntity<Void> request = new RequestEntity<>(headers, HttpMethod.GET, url.toURI()); response = this.restOperations.exchange(request, String.class); } catch (Exception ex) { throw new IOException(ex); } if (response.getStatusCodeValue() != 200) { throw new IOException(response.toString()); } return new Resource(response.getBody(), "UTF-8"); } }
@Test // SPR-12792 public void headersCopyWithEmptyAndNull() { ResponseEntity<Void> responseEntityWithEmptyHeaders = ResponseEntity.ok().headers(new HttpHeaders()).build(); ResponseEntity<Void> responseEntityWithNullHeaders = ResponseEntity.ok().headers(null).build(); assertEquals(HttpStatus.OK, responseEntityWithEmptyHeaders.getStatusCode()); assertTrue(responseEntityWithEmptyHeaders.getHeaders().isEmpty()); assertEquals(responseEntityWithEmptyHeaders.toString(), responseEntityWithNullHeaders.toString()); }
public static void updateUserToForcePasswordChange(RestTemplate restTemplate, String baseUrl, String adminToken, String userId, String zoneId) { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + adminToken); if (StringUtils.hasText(zoneId)) { headers.add(IdentityZoneSwitchingFilter.HEADER, zoneId); } UserAccountStatus userAccountStatus = new UserAccountStatus(); userAccountStatus.setPasswordChangeRequired(true); ResponseEntity<UserAccountStatus> response = restTemplate.exchange(baseUrl + "/Users/{user-id}/status", HttpMethod.PATCH, new HttpEntity<UserAccountStatus>(userAccountStatus, headers), UserAccountStatus.class, userId); response.toString(); }
public static ResultEntityTemplate resolve(ResponseEntity<String> checkResponse) { if (checkResponse.getStatusCode() == HttpStatus.OK) { return JSONObject.parseObject(checkResponse.getBody(), ResultEntityTemplate.class); } else { throw new RuntimeException(checkResponse.toString()); } }
@Override public String register(final String remoteNodeUri) throws IOException { ResponseEntity<String> result = restTemplate.exchange(remoteNodeUri + registrationQuery, HttpMethod .POST, entity, String.class); logger.info("Registration status: " + result.getStatusCode()); if (!result.getStatusCode().is2xxSuccessful()) { throw new IOException("Registration by remote node " + remoteNodeUri + " failed: " + result.toString()); } return result.getBody(); }
@SuppressWarnings("rawtypes") @Override public String fetch(int id) { ResponseEntity<Map> responseEntity = this.restTemplate.getForEntity( this.endpoint + "/schemas/" + id, Map.class); if (!responseEntity.getStatusCode().is2xxSuccessful()) { throw new RuntimeException("Failed to fetch schema: " + responseEntity.toString()); } return (String) responseEntity.getBody().get("definition"); } }
@SuppressWarnings("rawtypes") @Override public String fetch(int id) { ResponseEntity<Map> responseEntity = this.restTemplate.getForEntity( this.endpoint + "/schemas/" + id, Map.class); if (!responseEntity.getStatusCode().is2xxSuccessful()) { throw new RuntimeException("Failed to fetch schema: " + responseEntity.toString()); } return (String) responseEntity.getBody().get("definition"); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public SchemaRegistrationResponse register(String subject, String format, String schema) { Map<String, String> requestBody = new HashMap<>(); requestBody.put("subject", subject); requestBody.put("format", format); requestBody.put("definition", schema); ResponseEntity<Map> responseEntity = this.restTemplate.postForEntity(this.endpoint, requestBody, Map.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { SchemaRegistrationResponse registrationResponse = new SchemaRegistrationResponse(); Map<String, Object> responseBody = (Map<String, Object>) responseEntity.getBody(); registrationResponse.setId((Integer) responseBody.get("id")); registrationResponse.setSchemaReference( new SchemaReference(subject, (Integer) responseBody.get("version"), responseBody.get("format").toString())); return registrationResponse; } throw new RuntimeException("Failed to register schema: " + responseEntity.toString()); }
@SuppressWarnings("rawtypes") @Override public String fetch(SchemaReference schemaReference) { ResponseEntity<Map> responseEntity = this.restTemplate.getForEntity( this.endpoint + "/" + schemaReference.getSubject() + "/" + schemaReference .getFormat() + "/v" + schemaReference .getVersion(), Map.class); if (!responseEntity.getStatusCode().is2xxSuccessful()) { throw new RuntimeException("Failed to fetch schema: " + responseEntity.toString()); } return (String) responseEntity.getBody().get("definition"); }
@SuppressWarnings("rawtypes") @Override public String fetch(SchemaReference schemaReference) { ResponseEntity<Map> responseEntity = this.restTemplate.getForEntity( this.endpoint + "/" + schemaReference.getSubject() + "/" + schemaReference .getFormat() + "/v" + schemaReference .getVersion(), Map.class); if (!responseEntity.getStatusCode().is2xxSuccessful()) { throw new RuntimeException("Failed to fetch schema: " + responseEntity.toString()); } return (String) responseEntity.getBody().get("definition"); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public SchemaRegistrationResponse register(String subject, String format, String schema) { Map<String, String> requestBody = new HashMap<>(); requestBody.put("subject", subject); requestBody.put("format", format); requestBody.put("definition", schema); ResponseEntity<Map> responseEntity = this.restTemplate.postForEntity(this.endpoint, requestBody, Map.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { SchemaRegistrationResponse registrationResponse = new SchemaRegistrationResponse(); Map<String, Object> responseBody = (Map<String, Object>) responseEntity.getBody(); registrationResponse.setId((Integer) responseBody.get("id")); registrationResponse.setSchemaReference( new SchemaReference(subject, (Integer) responseBody.get("version"), responseBody.get("format").toString())); return registrationResponse; } throw new RuntimeException("Failed to register schema: " + responseEntity.toString()); }
@Override public Resource retrieveResource(URL url) throws IOException { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); ResponseEntity<String> response; try { RequestEntity<Void> request = new RequestEntity<>(headers, HttpMethod.GET, url.toURI()); response = this.restOperations.exchange(request, String.class); } catch (Exception ex) { throw new IOException(ex); } if (response.getStatusCodeValue() != 200) { throw new IOException(response.toString()); } return new Resource(response.getBody(), "UTF-8"); } }
OAuth2AccessToken token = tokenExtractor.extract(new Response( resp.getStatusCodeValue(), resp.toString(), resp.getHeaders().toSingleValueMap(), resp.getBody(), null
private HermesResponse fromRestTemplateResponse(ResponseEntity response) { return hermesResponse() .withHttpStatus(response.getStatusCode().value()) .withBody(response.toString()) .withHeaderSupplier(header -> response.getHeaders().toSingleValueMap().getOrDefault(header, null)) .build(); }
response.toString());