String url = config.getLoginUrl() + OAUTH2_TOKEN_PATH;
loginPost.setURL(url);
loginPost.setMethod(HttpMethods.POST);
loginPost.setRequestContentType(FORM_CONTENT_TYPE);
final UrlEncoded nvps = new UrlEncoded();
nvps.put("grant_type", "password");
nvps.put("client_id", config.getClientId());
nvps.put("client_secret", config.getClientSecret());
nvps.put("username", config.getUserName());
nvps.put("password", config.getPassword());
nvps.put("format", "json");
try {
LOG.info("Logging clientId: {} into Salesforce url: {}", config.getClientId(), url);
// set form content
loginPost.setRequestContent(new ByteArrayBuffer(
nvps.encode(StringUtil.__UTF8, true).getBytes(StringUtil.__UTF8)));
httpClient.send(loginPost);
// wait for the login to finish
final int exchangeState = loginPost.waitForDone();