Source:
public ResponseEntity<String> lost(@RequestHeader final String authorization, @PathVariable final String userId) throws IOException, MessagingException { String uri = resourceServerUriBuilder.buildUsersUriWithUserId(userId); String otp = UUID.randomUUID().toString(); User userForUpdate = buildUserForUpdate(otp); String userAsString = mapper.writeValueAsString(userForUpdate); HttpClientRequestResult saveUserResponse = httpClient.executeHttpPatch(uri, userAsString, HttpHeader.AUTHORIZATION, authorization); if (saveUserResponse.getStatusCode() != HttpStatus.OK.value()) { LOGGER.warning("Problems updating the user with extensions!"); return new ResponseEntity<>("{\"error\":\"Problems updating the user with extensions!\"}", HttpStatus.valueOf(saveUserResponse.getStatusCode())); } User updatedUser = mapper.readValue(saveUserResponse.getBody(), User.class); Optional<String> email = RegistrationHelper.extractSendToEmail(updatedUser); if (!email.isPresent()) { LOGGER.log(Level.WARNING, "Could not change password. No email of user " + updatedUser.getUserName() + " found!"); return new ResponseEntity<>("{\"error\":\"Could not change password. No email of user " + updatedUser.getUserName() + " found!\"}", HttpStatus.BAD_REQUEST); } String passwordLostLink = RegistrationHelper.createLinkForEmail(passwordlostLinkPrefix, updatedUser.getId(), "oneTimePassword", oneTimePassword); Map<String, String> vars = new HashMap<>(); vars.put("lostpasswordlink", passwordLostLink); try { sendEmail(email.get(), updatedUser, vars); } catch (OsiamException e) { return new ResponseEntity<>("{\"error\":\"Problems confirming new user email: \"" + e.getMessage() + "}", HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>(HttpStatus.OK); }

Target:
public ResponseEntity<String> lost(@RequestHeader final String authorization, @PathVariable final String userId) throws IOException, MessagingException { String uri = resourceServerUriBuilder.buildUsersUriWithUserId(userId); String otp = UUID.randomUUID().toString(); User userForUpdate = buildUserForUpdate(otp); String userAsString = mapper.writeValueAsString(userForUpdate); HttpClientRequestResult saveUserResponse = httpClient.executeHttpPatch(uri, userAsString, HttpHeader.AUTHORIZATION, authorization); if (saveUserResponse.getStatusCode() != HttpStatus.OK.value()) { LOGGER.warning("Problems updating the user with extensions!"); return new ResponseEntity<>("{\"error\":\"Problems updating the user with extensions!\"}", HttpStatus.valueOf(saveUserResponse.getStatusCode())); } User updatedUser = mapper.readValue(saveUserResponse.getBody(), User.class); Optional<String> email = RegistrationHelper.extractSendToEmail(updatedUser); if (!email.isPresent()) { LOGGER.log(Level.WARNING, "Could not change password. No email of user " + updatedUser.getUserName() + " found!"); return new ResponseEntity<>("{\"error\":\"Could not change password. No email of user " + updatedUser.getUserName() + " found!\"}", HttpStatus.BAD_REQUEST); } String passwordLostLink = RegistrationHelper.createLinkForEmail(passwordlostLinkPrefix, updatedUser.getId(), "oneTimePassword", oneTimePassword); Map<String, String> vars = new HashMap<>(); vars.put("lostpasswordlink", passwordLostLink); try { sendEmail(email.get(), updatedUser, vars); } catch (OsiamException e) { return new ResponseEntity<>("{\"error\":\"Problems creating email for lost password: \"" + e.getMessage() + "}", HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>(HttpStatus.OK); }