NVPair[] formParams = new NVPair[formAuthentication.getFormParams().size()];
int pairCount = 0;
for (String key : formAuthentication.getFormParams().keySet())
{
formParams[pairCount++] = new NVPair(key, formAuthentication.getFormParams().get(key));
}
if ("POST".equalsIgnoreCase(formAuthentication.getMethod()))
{
respLogin = connectionLogin.Post(urlLogin.getFile(), formParams);
}
else
{
respLogin = connectionLogin.Get(urlLogin.getFile(), formParams);
}
if (Response.Status.OK.getStatusCode() != respLogin.getStatusCode())
{
System.out.println("Form authentication is fail, status code : " + respLogin.getStatusCode()); //NOSONAR
System.exit(0);
}
}
else
{
// basic authorization
if (realm == null)
{
realm = getRealm(complURL);
if (realm == null)
{
throw new BackupExecuteException(
"Can not connect to server using basic authentication. Try to use form authentication.");
}
}
connection.addBasicAuthorization(realm, login, password);
}
HTTPResponse resp;
if (postData == null)
{
resp = connection.Post(url.getFile());
}
else
{
NVPair[] pairs = new NVPair[2];
pairs[0] = new NVPair("Content-Type", "application/json; charset=UTF-8");
pairs[1] = new NVPair("Content-Length", Integer.toString(postData.length()));
resp = connection.Post(url.getFile(), postData.getBytes(), pairs);
}
BackupAgentResponse responce = new BackupAgentResponse(resp.getData(), resp.getStatusCode());