javax.ws.rs.RedirectionException Java Examples
The following examples show how to use
javax.ws.rs.RedirectionException.
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: TrellisHttpResource.java From trellis with Apache License 2.0 | 6 votes |
private Response handleException(final Throwable err) { final Throwable cause = err.getCause(); if (cause instanceof StorageConflictException) { LOGGER.debug("Storage conflict error: {}", err.getMessage()); LOGGER.trace("Storage conflict error: ", err); return Response.status(Response.Status.CONFLICT).build(); } else if (cause instanceof ClientErrorException) { LOGGER.debug("Client error: {}", err.getMessage()); LOGGER.trace("Client error: ", err); } else if (cause instanceof RedirectionException) { LOGGER.debug("Redirection: {}", err.getMessage()); LOGGER.trace("Redirection: ", err); } else { LOGGER.error("Error:", err); } return cause instanceof WebApplicationException ? ((WebApplicationException) cause).getResponse() : new WebApplicationException(err).getResponse(); }
Example #2
Source File: HttpUtils.java From trellis with Apache License 2.0 | 6 votes |
/** * Check for a conditional operation. * @param method the HTTP method * @param ifNoneMatch the If-None-Match header * @param etag the resource etag */ public static void checkIfNoneMatch(final String method, final String ifNoneMatch, final EntityTag etag) { if (ifNoneMatch == null) { return; } final Set<String> items = stream(ifNoneMatch.split(",")).map(String::trim).collect(toSet()); if (isGetOrHead(method)) { if ("*".equals(ifNoneMatch) || items.stream().map(EntityTag::valueOf) .anyMatch(e -> e.equals(etag) || e.equals(new EntityTag(etag.getValue(), !etag.isWeak())))) { throw new RedirectionException(notModified().build()); } } else { if ("*".equals(ifNoneMatch) || items.stream().map(EntityTag::valueOf).anyMatch(isEqual(etag))) { throw new ClientErrorException(status(PRECONDITION_FAILED).build()); } } }
Example #3
Source File: SpecExceptions.java From cxf with Apache License 2.0 | 6 votes |
public static Class<?> getWebApplicationExceptionClass(Response exResponse, Class<?> defaultExceptionType) { int status = exResponse.getStatus(); Class<?> cls = EXCEPTIONS_MAP.get(status); if (cls == null) { int family = status / 100; if (family == 3) { cls = RedirectionException.class; } else if (family == 4) { cls = ClientErrorException.class; } else if (family == 5) { cls = ServerErrorException.class; } } return cls == null ? defaultExceptionType : cls; }
Example #4
Source File: DownloadArtifactFromQueryTest.java From archiva with Apache License 2.0 | 6 votes |
@Test( expected = RedirectionException.class ) public void downloadLatestVersion() throws Exception { String id = createAndScanRepo(); try { Response response = getSearchService().redirectToArtifactFile( null, "org.apache.archiva", "archiva-test", "LATEST", null, null ); } catch ( RedirectionException e ) { Assertions.assertThat( e.getLocation().compareTo( new URI( "http://localhost:" + port + "/repository/" + id + "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) ) ).isEqualTo( 0 ); throw e; } finally { getManagedRepositoriesService().deleteManagedRepository( id, false ); } }
Example #5
Source File: TestResource.java From micrometer with Apache License 2.0 | 5 votes |
@GET @Path("redirect/{status}") public Response redirect(@PathParam("status") int status) { if (status == 307) { throw new RedirectionException(status, URI.create("hello")); } return Response.status(status).header("Location", "/hello").build(); }
Example #6
Source File: HttpUtils.java From trellis with Apache License 2.0 | 5 votes |
/** * Check for a conditional operation. * @param method the HTTP method * @param ifModifiedSince the If-Modified-Since header * @param modified the resource modification date */ public static void checkIfModifiedSince(final String method, final String ifModifiedSince, final Instant modified) { if (isGetOrHead(method)) { final Instant time = parseDate(ifModifiedSince); if (time != null && time.isAfter(modified.truncatedTo(SECONDS))) { throw new RedirectionException(notModified().build()); } } }
Example #7
Source File: GetHandler.java From trellis with Apache License 2.0 | 5 votes |
private void handleTrailingSlashRedirection(final Resource resource) { if (getRequest().hasTrailingSlash() && !isContainer(resource.getInteractionModel())) { throw new RedirectionException(303, create(getBaseUrl() + normalizePath(getRequest().getPath()))); } else if (!getRequest().hasTrailingSlash() && !getRequest().getPath().isEmpty() && isContainer(resource.getInteractionModel())) { throw new RedirectionException(303, create(getBaseUrl() + normalizePath(getRequest().getPath()) + "/")); } }
Example #8
Source File: HttpUtilsTest.java From trellis with Apache License 2.0 | 5 votes |
@Test void testCheckIfModifiedSince() { final String time = "Wed, 21 Oct 2015 07:28:00 GMT"; final Instant timestamp1 = ofEpochSecond(1445412479); assertThrows(RedirectionException.class, () -> HttpUtils.checkIfModifiedSince("GET", time, timestamp1)); final Instant timestamp2 = ofEpochSecond(1445412480); assertDoesNotThrow(() -> HttpUtils.checkIfModifiedSince("GET", time, timestamp2)); }
Example #9
Source File: DownloadArtifactFromQueryTest.java From archiva with Apache License 2.0 | 5 votes |
@Test( expected = RedirectionException.class ) public void downloadFixedVersion() throws Exception { String id = createAndScanRepo(); try { Response response = getSearchService().redirectToArtifactFile( null, "org.apache.archiva", "archiva-test", "1.0", null, null ); } catch ( RedirectionException e ) { Assertions.assertThat( e.getLocation().compareTo( new URI( "http://localhost:" + port + "/repository/" + id + "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) ) ).isEqualTo( 0 ); throw e; } finally { getManagedRepositoriesService().deleteManagedRepository( id, false ); } }