Java Code Examples for com.gargoylesoftware.htmlunit.html.DomNodeList#get()

The following examples show how to use com.gargoylesoftware.htmlunit.html.DomNodeList#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleRange.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
private static void deleteBefore(final DomNode node, int offset) {
    if (isOffsetChars(node)) {
        String text = getText(node);
        if (offset > -1 && offset < text.length()) {
            text = text.substring(offset);
        }
        else {
            text = "";
        }
        setText(node, text);
    }
    else {
        final DomNodeList<DomNode> children = node.getChildNodes();
        for (int i = 0; i < offset && i < children.getLength(); i++) {
            final DomNode child = children.get(i);
            child.remove();
            i--;
            offset--;
        }
    }
}
 
Example 2
Source File: SimpleRange.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
private static void deleteAfter(final DomNode node, final int offset) {
    if (isOffsetChars(node)) {
        String text = getText(node);
        if (offset > -1 && offset < text.length()) {
            text = text.substring(0, offset);
            setText(node, text);
        }
    }
    else {
        final DomNodeList<DomNode> children = node.getChildNodes();
        for (int i = offset; i < children.getLength(); i++) {
            final DomNode child = children.get(i);
            child.remove();
            i--;
        }
    }
}
 
Example 3
Source File: SimpleRange.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
private static void deleteBefore(final DomNode node, int offset) {
    if (isOffsetChars(node)) {
        String text = getText(node);
        if (offset > -1 && offset < text.length()) {
            text = text.substring(offset);
        }
        else {
            text = "";
        }
        setText(node, text);
    }
    else {
        final DomNodeList<DomNode> children = node.getChildNodes();
        for (int i = 0; i < offset && i < children.getLength(); i++) {
            final DomNode child = children.get(i);
            child.remove();
            i--;
            offset--;
        }
    }
}
 
Example 4
Source File: SimpleRange.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
private static void deleteAfter(final DomNode node, final int offset) {
    if (isOffsetChars(node)) {
        String text = getText(node);
        if (offset > -1 && offset < text.length()) {
            text = text.substring(0, offset);
            setText(node, text);
        }
    }
    else {
        final DomNodeList<DomNode> children = node.getChildNodes();
        for (int i = offset; i < children.getLength(); i++) {
            final DomNode child = children.get(i);
            child.remove();
            i--;
        }
    }
}
 
Example 5
Source File: HTTPTestUtils.java    From cxf-fediz with Apache License 2.0 6 votes vote down vote up
public static void logoutCleanup(String url, CookieManager cookieManager) throws IOException {
    final WebClient webClient = new WebClient();
    webClient.setCookieManager(cookieManager);
    webClient.getOptions().setUseInsecureSSL(true);
    final HtmlPage idpPage = webClient.getPage(url);

    Assert.assertEquals("IDP SignOut Response Page", idpPage.getTitleText());

    Assert.assertTrue(idpPage.asText().contains("CXF Fediz IDP successful logout"));

    DomNodeList<DomElement> images = idpPage.getElementsByTagName("img");
    Assert.assertEquals(1, images.getLength());
    for (int i = 0; i < images.size(); i++) {
        DomElement domElement = images.get(i);
        String imgSrc = domElement.getAttribute("src");

        //we should get a fault if the image isn't available.
        webClient.getPage(imgSrc);
    }

    webClient.close();
}
 
Example 6
Source File: HTTPTestUtils.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
public static void logout(String url, CookieManager cookieManager, boolean wsfed) throws IOException {
    final WebClient webClient = new WebClient();
    webClient.setCookieManager(cookieManager);
    webClient.getOptions().setUseInsecureSSL(true);
    final HtmlPage idpPage = webClient.getPage(url);

    Assert.assertEquals("IDP SignOut Confirmation Response Page", idpPage.getTitleText());

    final HtmlForm form = idpPage.getFormByName("signoutconfirmationresponseform");
    final HtmlSubmitInput button = form.getInputByName("_eventId_submit");

    webClient.getOptions().setJavaScriptEnabled(false);
    final HtmlPage idpLogoutPage = button.click();
    webClient.getOptions().setJavaScriptEnabled(true);

    if (wsfed) {
        DomNodeList<DomElement> images = idpLogoutPage.getElementsByTagName("img");
        Assert.assertEquals(1, images.getLength());
        for (int i = 0; i < images.size(); i++) {
            DomElement domElement = images.get(i);
            String imgSrc = domElement.getAttribute("src");

            //we should get a fault if the image isn't available.
            webClient.getPage(imgSrc);
        }
    } else {
        // For SAML SSO we will be redirected back to the RP
        HtmlForm responseForm = idpLogoutPage.getFormByName("samlsignoutresponseform");
        HtmlSubmitInput button2 = responseForm.getInputByName("_eventId_submit");
        button2.click();
    }

    webClient.close();
}
 
Example 7
Source File: IdpTest.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
private static org.opensaml.saml.saml2.core.Response parseSAMLResponse(HtmlPage idpPage,
                                                                String relayState,
                                                                String consumerURL,
                                                                String authnRequestId
) throws Exception {
    Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText());

    // Parse the form to get the token (SAMLResponse)
    DomNodeList<DomElement> results = idpPage.getElementsByTagName("input");

    String samlResponse = null;
    boolean foundRelayState = false;
    for (DomElement result : results) {
        if ("SAMLResponse".equals(result.getAttributeNS(null, "name"))) {
            samlResponse = result.getAttributeNS(null, "value");
        } else if ("RelayState".equals(result.getAttributeNS(null, "name"))) {
            foundRelayState = true;
            Assert.assertEquals(result.getAttributeNS(null, "value"), relayState);
        }
    }

    Assert.assertNotNull(samlResponse);
    Assert.assertTrue(foundRelayState);

    // Check the "action"
    DomNodeList<DomElement> formResults = idpPage.getElementsByTagName("form");
    Assert.assertFalse(formResults.isEmpty());

    DomElement formResult = formResults.get(0);
    String action = formResult.getAttributeNS(null, "action");
    Assert.assertTrue(action.equals(consumerURL));

    // Decode + verify response
    byte[] deflatedToken = Base64Utility.decode(samlResponse);
    InputStream inputStream = new ByteArrayInputStream(deflatedToken);

    Document responseDoc = StaxUtils.read(new InputStreamReader(inputStream, UTF_8.name()));

    XMLObject responseObject = OpenSAMLUtil.fromDom(responseDoc.getDocumentElement());
    Assert.assertTrue(responseObject instanceof org.opensaml.saml.saml2.core.Response);

    org.opensaml.saml.saml2.core.Response samlResponseObject =
        (org.opensaml.saml.saml2.core.Response)responseObject;
    Assert.assertTrue(authnRequestId.equals(samlResponseObject.getInResponseTo()));

    return samlResponseObject;
}