Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public FindUserResponse findUserById()
{
String username = "chathuranga";
String password = "123";
Integer userId = 1;
String url = "http://localhost:" + port + "/users/" + userId;
String authorizationHeader = "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes());
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
requestHeaders.add("Authorization", authorizationHeader);
//fields are empty
AddUserRequest addUserRequest = new AddUserRequest();
HttpEntity<AddUserRequest> requestEntity = new HttpEntity<>(addUserRequest, requestHeaders);
ResponseEntity<FindUserResponse> responseEntity = testRestTemplate.exchange(
url,
HttpMethod.GET,
requestEntity,
FindUserResponse.class
);
FindUserResponse findUserResponse = responseEntity.getBody();
return findUserResponse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.