IProgressMonitor monitor) throws ReviewboardException {
this.cookie = "";
if( null == username || username.trim().isEmpty() || null == password || password.trim().isEmpty() ){
throw new ReviewboardException("username and password is required.");
}
RestfulReviewboardReader reviewboardReader = new RestfulReviewboardReader();
HttpMethodBase loginRequest = null;
loginRequest = new GetMethod(serverUrl + URI_LOGIN);
String authorizationKey = "Authorization";
String authorizationValue = "Basic " + ReviewboardUtil.convertStr2BASE64(username + ":" + password);
//Set a HTTP Headers WWW-Authenticate
loginRequest.setRequestHeader(authorizationKey, authorizationValue );
if(monitor == null){
monitor = new NullProgressMonitor();
}
try {
monitor.beginTask("Authorization checking...", IProgressMonitor.UNKNOWN);
this.httpClient.getState().clear();
if (executeRequest(loginRequest, monitor) == HttpStatus.SC_OK) {
String response = getResponseBodyAsString(loginRequest, monitor);
if (reviewboardReader.isStatOK(response)) {
Header header = loginRequest.getResponseHeader("Set-Cookie");
if(null != header){
cookie = header.getValue();
}
} else {
throw new ReviewboardException(reviewboardReader.getErrorMessage(response));
}
} else {
throw new ReviewboardException(RbCoreMessages.getString("ERROR_SERVER_NOT_CONFIFIGURED_0"));
}
} finally {
loginRequest.releaseConnection();
monitor.done();
}