/** * Go to a particular page. * * @throws TestingEngineResponseException if an error response code is encountered * and ignoreFailingStatusCodes is not enabled. */ @Override public void gotoPage(URL initialURL) throws TestingEngineResponseException { try { wc.getPage(initialURL); win = wc.getCurrentWindow(); form = null; } catch (FailingHttpStatusCodeException ex) { throw new TestingEngineResponseException(ex.getStatusCode(), "unexpected status code [" + ex.getStatusCode() + "] at URL: [" + initialURL + "]", ex); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * {@inheritDoc} */ @Override public String getMessage() { final int code = getStatusCode(); final String msg = getStatusMessage(); final URL url = getResponse().getRequestSettings().getUrl(); return code + " " + msg + " for " + url; }
private void checkRecursion() { final StackTraceElement[] elements = new Exception().getStackTrace(); if (elements.length > 500) { for (int i = 0; i < 500; i++) { if (!elements[i].getClassName().startsWith("com.gargoylesoftware.htmlunit.")) { return; } } final WebResponse webResponse = getWebResponse(); throw new FailingHttpStatusCodeException("Too much redirect for " + webResponse.getWebRequest().getUrl(), webResponse); } }
if (e.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY || e.getStatusCode() == HttpStatus.SC_SEE_OTHER) { final URL location = new URL(e.getResponse().getResponseHeaderValue(HttpHeaders.LOCATION)); final String locationQuery = location.getQuery(); if (locationQuery != null && locationQuery.contains("error=")) { } catch (FailingHttpStatusCodeException e) { if (e.getStatusCode() != HttpStatus.SC_MOVED_TEMPORARILY) { throw e; final String location = e.getResponse().getResponseHeaderValue("Location"); redirectQuery = new URL(location).getQuery();
LOG.error(e.getMessage(), e);
private void checkUrl(JenkinsRule.WebClient wc, String url) throws Exception { try { wc.goTo(url); fail(); } catch (FailingHttpStatusCodeException e) { WebResponse response = e.getResponse(); assertEquals(404, response.getStatusCode()); String content = response.getContentAsString(); assertFalse(content.contains("Search for")); } } }
LOG.error(e.getMessage(), e);
} catch (FailingHttpStatusCodeException e) { assertEquals(e.getResponse().getStatusCode(),403);
/** * Submit the current form with the default submit button. See {@link #getForm}for an explanation of how the * current form is established. */ @Override public void submit() { HtmlElement btn = getSubmitButton(); if (btn == null) { throw new RuntimeException("No submit button found in current form."); } try { btn.click(); } catch (FailingHttpStatusCodeException e) { throw new TestingEngineResponseException( e.getStatusCode(), e); } catch (IOException e) { throw new RuntimeException( "HtmlUnit Error submitting form using default submit button, " + "check that form has single submit button, otherwise use submit(name): \n", e); } }
/** * {@inheritDoc} */ @Override public String getMessage() { final int code = getStatusCode(); final String msg = getStatusMessage(); final URL url = getResponse().getRequestSettings().getUrl(); return code + " " + msg + " for " + url; }
private void checkRecursion() { final StackTraceElement[] elements = new Exception().getStackTrace(); if (elements.length > 500) { for (int i = 0; i < 500; i++) { if (!elements[i].getClassName().startsWith("com.gargoylesoftware.htmlunit.")) { return; } } final WebResponse webResponse = getWebResponse(); throw new FailingHttpStatusCodeException("Too much redirect for " + webResponse.getWebRequest().getUrl(), webResponse); } }
LOG.error(e.getMessage(), e);
/** * Verify that the server rejects an attempt to load the given page. * @param url a URL path (relative to Jenkins root) * @param statusCode the expected failure code (such as {@link HttpURLConnection#HTTP_FORBIDDEN}) * @since 1.502 */ public void assertFails(String url, int statusCode) throws Exception { try { fail(url + " should have been rejected but produced: " + super.getPage(getContextPath() + url).getWebResponse().getContentAsString()); } catch (FailingHttpStatusCodeException x) { assertEquals(statusCode, x.getStatusCode()); } }
/** * {@inheritDoc} */ @Override public String getMessage() { final int code = getStatusCode(); final String msg = getStatusMessage(); final URL url = getResponse().getRequestSettings().getUrl(); return code + " " + msg + " for " + url; }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span> * * <p>Throws a {@link FailingHttpStatusCodeException} if the request's status code indicates a request * failure and {@link #isThrowExceptionOnFailingStatusCode()} returns <tt>true</tt>. * * @param webResponse the response which may trigger a {@link FailingHttpStatusCodeException} */ public void throwFailingHttpStatusCodeExceptionIfNecessary(final WebResponse webResponse) { final int statusCode = webResponse.getStatusCode(); final boolean successful = (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_MULTIPLE_CHOICES) || statusCode == HttpStatus.SC_USE_PROXY || statusCode == HttpStatus.SC_NOT_MODIFIED; if (isThrowExceptionOnFailingStatusCode() && !successful) { throw new FailingHttpStatusCodeException(webResponse); } }
LOG.error(e.getMessage(), e);
/** * Submit the current form with the specified submit button. See {@link #getForm}for an explanation of how the * current form is established. * * @param buttonName name of the button to use for submission. */ @Override public void submit(String buttonName) { HtmlElement btn = getSubmitButton(buttonName); if (btn == null) { throw new RuntimeException("No submit button found in current form."); } try { btn.click(); } catch (FailingHttpStatusCodeException e) { throw new TestingEngineResponseException( e.getStatusCode(), e); } catch (IOException e) { throw new RuntimeException( "HtmlUnit Error submitting form using default submit button", e); } }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span> * * <p>Throws a {@link FailingHttpStatusCodeException} if the request's status code indicates a request * failure and {@link #isThrowExceptionOnFailingStatusCode()} returns <tt>true</tt>. * * @param webResponse the response which may trigger a {@link FailingHttpStatusCodeException} */ public void throwFailingHttpStatusCodeExceptionIfNecessary(final WebResponse webResponse) { final int statusCode = webResponse.getStatusCode(); final boolean successful = (statusCode >= HttpStatus.SC_OK && statusCode < HttpStatus.SC_MULTIPLE_CHOICES) || statusCode == HttpStatus.SC_USE_PROXY || statusCode == HttpStatus.SC_NOT_MODIFIED; if (isThrowExceptionOnFailingStatusCode() && !successful) { throw new FailingHttpStatusCodeException(webResponse); } }
LOG.error(e.getMessage()); final InputSource source = new InputSource(new StringReader("")); sheet = new Stylesheet(element, source, uri);
e.getStatusCode(), e); } catch (IOException e) { throw new RuntimeException(