org.apache.http.client.CircularRedirectException Java Examples
The following examples show how to use
org.apache.http.client.CircularRedirectException.
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: HttpRedirectsProvider.java From vividus with Apache License 2.0 | 6 votes |
/** * Executes HEAD request to get redirects. * Throws IllegalStateException in case of status code outside of "200-207" * @param from URI to issue HEAD request * @return List of redirects. {@code null} if there are no redirects. */ public List<URI> getRedirects(URI from) { try { HttpClientContext httpContext = HttpClientContext.create(); httpClient.doHttpHead(from, httpContext).verifyStatusCodeInRange(HttpStatus.SC_OK, HttpStatus.SC_MULTI_STATUS); return httpContext.getRedirectLocations(); } catch (IOException | ExternalServiceException e) { String exceptionMsg; if (e.getCause() instanceof CircularRedirectException) { exceptionMsg = e.getCause().getMessage() + " Circular redirects are forbidden by default. " + "To allow them, please set property " + "'http.redirects-provider.circular-redirects-allowed=true'"; } else { exceptionMsg = e.getMessage(); } throw new IllegalStateException(exceptionMsg, e); } }
Example #2
Source File: HttpRedirectsProviderTests.java From vividus with Apache License 2.0 | 5 votes |
@Test public void shouldUpdateErrorMessageAndRethrowAsIllegalStateExceptionInCaseOfCircularRedirectException() throws IOException { ClientProtocolException clientProtocolException = new ClientProtocolException( new CircularRedirectException("Circular reference")); when(httpClient.doHttpHead(URI_EXAMPLES, httpClientContext)).thenThrow(clientProtocolException); IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, () -> redirectsProvider.getRedirects(URI_EXAMPLES)); assertEquals("Circular reference Circular redirects are forbidden by default. To allow them, please set " + "property 'http.redirects-provider.circular-redirects-allowed=true'", illegalStateException.getMessage()); }