use of org.jsoup.nodes.FormElement in project jsoup by jhy.
the class HtmlTreeBuilder method insertForm.
FormElement insertForm(Token.StartTag startTag, boolean onStack, boolean checkTemplateStack) {
Tag tag = tagFor(startTag.name(), settings);
FormElement el = new FormElement(tag, null, settings.normalizeAttributes(startTag.attributes));
if (checkTemplateStack) {
if (!onStack("template"))
setFormElement(el);
} else
setFormElement(el);
insertNode(el);
if (onStack)
stack.add(el);
return el;
}
use of org.jsoup.nodes.FormElement in project syndesis-qe by syndesisio.
the class BoxUtils method getAccessToken.
/**
* From org.apache.camel.component.box.internal.BoxConnectionHelper
*
* @return box access token
*/
private String getAccessToken() throws Exception {
final String csrfToken = String.valueOf(new SecureRandom().nextLong());
final String url = OAUTH_URL + boxAccount.getProperty("clientId") + "&state=" + csrfToken;
final Connection.Response loginPageResponse = Jsoup.connect(url).method(Connection.Method.GET).execute();
Document loginPage = loginPageResponse.parse();
validatePage(loginPage);
final FormElement loginForm = (FormElement) loginPage.select("form[name=login_form]").first();
final Element loginField = loginForm.select("input[name=login]").first();
loginField.val(boxAccount.getProperty("userName"));
final Element passwordField = loginForm.select("input[name=password]").first();
passwordField.val(boxAccount.getProperty("userPassword"));
final Map<String, String> cookies = new HashMap<>(loginPageResponse.cookies());
Connection.Response response = loginForm.submit().cookies(cookies).execute();
cookies.putAll(response.cookies());
final Document consentPage = response.parse();
validatePage(consentPage);
final FormElement consentForm = (FormElement) consentPage.select("form[name=consent_form]").first();
consentForm.elements().removeIf(e -> e.attr("name").equals("consent_reject"));
// parse request_token from javascript from head, it is the first script in the header
final String requestTokenScript = consentPage.select("script").first().html();
final String requestToken = StringUtils.substringBetween(requestTokenScript, "'", "'");
if (requestToken == null) {
fail("Coudln't parse request token from " + requestTokenScript);
}
response = consentForm.submit().data("request_token", requestToken).followRedirects(false).cookies(cookies).execute();
final String location = response.header("Location");
final String code = StringUtils.substringAfterLast(location, "code=");
if (code == null) {
fail("Unable to get code from " + location);
}
return code;
}
Aggregations