Technical Project Lead @ Huawei Technologies

My photo
Bangalore/Hyderabad, Karnataka/Andhra Pradesh, India
Have an overall 13 + yrs of experience Currently working as an Senior Architect.Expertise in design,implementation of Automation frameworks for Opensource automation tools like Selenium,Jmeter, Webdriver,Appium, Robotium Expertise in integrating Test & ALM Management tools like Rally,Qmetry,JIRA-Zephyr with Automation frameworks Expertise in design and developmenet Mobile Automation frameworks for tools like Appium, Robotium Remote Control,Cucumber BDD,Manual Testing

Followers

Tuesday, January 28, 2014

How to Login in to Rally using Java Rest API client

To access to Rally you need to login authentication
public RallyRestApi authenticate() throws URISyntaxException, Exception {

            //Provide Rally url,username and password
            RallyRestApi restApi = new RallyRestApi(new URI(https://us1.rallydev.com),
"username, "password");

          //If you are behind a proxy server provide the following
            restApi.setProxy("proxyserver", "userName", "password");
try {
if (restApi == null) {
LOGGER.debug("Authenticating Rally with provided credentials");
System.out.println("Initializing Rally Connector with user : "
+ userName);
LOGGER.debug("Trying to connect and login to rally : ");
restApi = new RallyRestApi(new URI(rallyUrl), userName,
password);
QueryRequest userRequest = new QueryRequest("User");
// userRequest.setFetch(new Fetch("UserName", "Subscription",
// "DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=",
ReadProperties.getInstance().getProperty("username")));
QueryResponse userQueryResponse;

userQueryResponse = restApi.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
JsonElement userQueryElement = userQueryResults.get(0);
JsonObject userQueryObject = userQueryElement.getAsJsonObject();
String userRef = userQueryObject.get("_ref").toString();
LOGGER.info("Rally Authentication Successful!");
}
} catch (Exception e) {
LOGGER.error("Failed to Authenticate User [" + userName + "]"
+ e.getMessage());
e.printStackTrace();
}
return restApi;
}

No comments:

Post a Comment