* @param con the connection
* @throws OsmTransferException thrown if something went wrong. Check for nested exceptions
*/
protected void addBasicAuthorizationHeader(HttpURLConnection con) throws OsmTransferException {
CharsetEncoder encoder = StandardCharsets.UTF_8.newEncoder();
CredentialsAgentResponse response;
String token;
try {
synchronized (CredentialsManager.getInstance()) {
response = CredentialsManager.getInstance().getCredentials(RequestorType.SERVER,
con.getURL().getHost(), false /* don't know yet whether the credentials will succeed */);
}
} catch (CredentialsAgentException e) {
throw new OsmTransferException(e);
}
if (response == null) {
token = ":";
} else if (response.isCanceled()) {
cancel = true;
return;
} else {
String username= response.getUsername() == null ? "" : response.getUsername();
String password = response.getPassword() == null ? "" : String.valueOf(response.getPassword());
token = username + ":" + password;
try {
ByteBuffer bytes = encoder.encode(CharBuffer.wrap(token));
con.addRequestProperty("Authorization", "Basic "+Base64.encode(bytes));
} catch(CharacterCodingException e) {