类javax.ws.rs.RedirectionException源码实例Demo

下面列出了怎么用javax.ws.rs.RedirectionException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: trellis   文件: TrellisHttpResource.java
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();
}
 
源代码2 项目: trellis   文件: HttpUtils.java
/**
 * 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());
        }
    }
 }
 
源代码3 项目: cxf   文件: SpecExceptions.java
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;
}
 
源代码4 项目: archiva   文件: DownloadArtifactFromQueryTest.java
@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 );
    }

}
 
源代码5 项目: micrometer   文件: TestResource.java
@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();
}
 
源代码6 项目: trellis   文件: HttpUtils.java
/**
 * 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());
        }
    }
}
 
源代码7 项目: trellis   文件: GetHandler.java
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()) + "/"));
    }
}
 
源代码8 项目: trellis   文件: HttpUtilsTest.java
@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));
}
 
源代码9 项目: archiva   文件: DownloadArtifactFromQueryTest.java
@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 );
    }

}
 
 类所在包
 类方法
 同包方法