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

项目:apache-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 );
    }

}
项目:microbule    文件:WebApplicationExceptions.java   
public static Class<? extends WebApplicationException> getWebApplicationExceptionClass(Response response) {
    int status = response.getStatus();
    final Class<? extends WebApplicationException> exceptionType = EXCEPTIONS_MAP.get(status);
    if (exceptionType == null) {
        final int family = status / 100;
        switch (family) {
            case 3:
                return RedirectionException.class;
            case 4:
                return ClientErrorException.class;
            case 5:
                return ServerErrorException.class;
            default:
                return WebApplicationException.class;
        }
    }
    return exceptionType;
}
项目:microbule    文件:AbstractErrorResponseStrategyTest.java   
@Test
public void testCreateException() {
    assertExceptionType(Response.Status.INTERNAL_SERVER_ERROR, InternalServerErrorException.class);
    assertExceptionType(Response.Status.NOT_FOUND, NotFoundException.class);
    assertExceptionType(Response.Status.FORBIDDEN, ForbiddenException.class);
    assertExceptionType(Response.Status.BAD_REQUEST, BadRequestException.class);
    assertExceptionType(Response.Status.METHOD_NOT_ALLOWED, NotAllowedException.class);
    assertExceptionType(Response.Status.UNAUTHORIZED, NotAuthorizedException.class);
    assertExceptionType(Response.Status.NOT_ACCEPTABLE, NotAcceptableException.class);
    assertExceptionType(Response.Status.UNSUPPORTED_MEDIA_TYPE, NotSupportedException.class);
    assertExceptionType(Response.Status.SERVICE_UNAVAILABLE, ServiceUnavailableException.class);
    assertExceptionType(Response.Status.TEMPORARY_REDIRECT, RedirectionException.class);
    assertExceptionType(Response.Status.LENGTH_REQUIRED, ClientErrorException.class);
    assertExceptionType(Response.Status.BAD_GATEWAY, ServerErrorException.class);
    assertExceptionType(Response.Status.NO_CONTENT, WebApplicationException.class);
}
项目: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 );
    }

}
项目: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();
}
项目:apache-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 );
    }

}
项目:reddcrawl    文件:RedditClient.java   
/**
 * Given (up to MAX_ITEMS_PER_LISTING_PAGE) story ids,
 * fetch the latest information about those stories in bulk and return a hashmap of (story id -> story)
 *
 * @param storyShortIds list of SHORT reddit story ids to fetch (can be max MAX_ITEMS_PER_LISTING_PAGE) size
 * @return map of story id -> story pairs, not guaranteed though to exist
 * @throws RedditClientException
 */
@Nonnull
public Map<String, RedditStory> getStoriesById(@Nonnull final Set<String> storyShortIds) throws RedditClientException {
    Preconditions.checkArgument(storyShortIds.size() <= MAX_ITEMS_PER_LISTING_PAGE,
            "Cannot request more than " + MAX_ITEMS_PER_LISTING_PAGE + " stories by id at a given time");
    Preconditions.checkArgument(storyShortIds.size() > 0, "Empty list of ids passed to getStoriesById");

    final Set<String> storyLongIds = new HashSet<>(storyShortIds.size());
    for (final String storyId : storyShortIds) storyLongIds.add(RedditKind.STORY.getKey() + "_" + storyId);

    final RedditListing<RedditStory> stories;
    try {
        //fetch listing of all stories
        final JsonNode jsonNodeResponse = redditEndpoint.path("/by_id/" + Joiner.on(",").join(storyLongIds) + ".json")
                .queryParam("limit", MAX_ITEMS_PER_LISTING_PAGE)
                .request(MediaType.APPLICATION_JSON)
                .get(JsonNode.class);
        stories = new RedditListing<>(jsonNodeResponse, RedditStory.class);
    } catch (@Nonnull RedirectionException | ProcessingException | ClientErrorException | JsonProcessingException e) {
        this.clientExceptionMeter.mark();
        throw new RedditClientException(e);
    }

    //convert to a map
    final Map<String, RedditStory> storyMap = new LinkedHashMap<>(storyShortIds.size());
    for (final RedditStory story : stories) {
        storyMap.put(story.getId(), story);
    }

    return storyMap;
}
项目:reddcrawl    文件:RedditClient.java   
/**
 * Gets the details about a specific subreddit
 *
 * @param subredditName the subreddit name (eg 'news' or 'gaybros')
 * @return RedditSubreddit object
 * @throws RedditClientException
 */
public RedditSubreddit getSubredditByName(@Nonnull final String subredditName) throws RedditClientException {
    try {
        final JsonNode jsonNodeResponse = redditEndpoint.path("/r/" + subredditName + "/about.json")
                .request(MediaType.APPLICATION_JSON)
                .get(JsonNode.class);
        return RedditThing.parseThing(jsonNodeResponse, RedditSubreddit.class);
    } catch (@Nonnull RedirectionException | ProcessingException | ClientErrorException e) {
        this.clientExceptionMeter.mark();
        throw new RedditClientException(e);
    }
}
项目: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 );
    }

}
项目:whois    文件:RdapRedirectTestIntegration.java   
@Test
public void autnum_redirect() throws Exception {
    try {
        RestTest.target(getPort(), String.format("rdap/%s", "autnum/100"))
                .request(MediaType.APPLICATION_JSON_TYPE)
                .get(String.class);
        fail();
    } catch (final RedirectionException e) {
        assertThat(e.getResponse().getHeaders().getFirst("Location").toString(), is("https://rdap.one.net/autnum/100"));
    }
}
项目:whois    文件:RdapRedirectTestIntegration.java   
@Test
public void inetnum_exact_match_redirect() {
    try {
        RestTest.target(getPort(), String.format("rdap/%s", "ip/193.0.0.0/21"))
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get(String.class);
        fail();
    } catch (final RedirectionException e) {
        assertThat(e.getResponse().getHeaders().getFirst("Location").toString(), is("https://rdap.one.net/ip/193.0.0.0/21"));
    }
}
项目:whois    文件:RdapRedirectTestIntegration.java   
@Test
public void inetnum_child_redirect() {
    try {
        RestTest.target(getPort(), String.format("rdap/%s", "ip/193.0.0.1"))
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get(String.class);
        fail();
    } catch (final RedirectionException e) {
        assertThat(e.getResponse().getHeaders().getFirst("Location").toString(), is("https://rdap.one.net/ip/193.0.0.1"));
    }
}
项目:whois    文件:RdapRedirectTestIntegration.java   
@Test
public void inet6num_exact_match_redirect() {
    try {
        RestTest.target(getPort(), String.format("rdap/%s", "ip/2001:67c:370::/48"))
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get(String.class);
        fail();
    } catch (final RedirectionException e) {
        assertThat(e.getResponse().getHeaders().getFirst("Location").toString(), is("https://rdap.one.net/ip/2001:67c:370::/48"));
    }
}
项目:whois    文件:RdapRedirectTestIntegration.java   
@Test
public void inet6num_child_redirect() {
    try {
        RestTest.target(getPort(), String.format("rdap/%s", "ip/2001:67c:370::1234"))
            .request(MediaType.APPLICATION_JSON_TYPE)
            .get(String.class);
        fail();
    } catch (final RedirectionException e) {
        assertThat(e.getResponse().getHeaders().getFirst("Location").toString(), is("https://rdap.one.net/ip/2001:67c:370::1234"));
    }
}
项目:reddcrawl    文件:RedditClient.java   
/**
 * Get a story listing for a given set of subreddits
 *
 * @param subreddits the subreddits to look at
 * @param sort       the sort style
 * @param timeRange  the time range to filter on
 * @param limit      the max number of stories
 * @return set of reddit stories found in the search
 * @throws RedditClientException
 */
@Nonnull
public Set<RedditStory> getStoryListingForSubreddits(@Nonnull final Set<String> subreddits,
                                                     @Nonnull final SortStyle sort,
                                                     @Nonnull final TimeRange timeRange,
                                                     final int limit) throws RedditClientException {
    final Set<RedditStory> stories = new LinkedHashSet<>();
    String currentAfter = "";
    int lastCount = 0;
    while (stories.size() < limit) {
        final RedditListing<RedditStory> subListing;
        try {
            final JsonNode jsonNodeResponse =
                    redditEndpoint.path("/r/" + Joiner.on("+").join(subreddits) + "/" + sort.toString() + ".json")
                            .queryParam("limit", MAX_ITEMS_PER_LISTING_PAGE)
                            .queryParam("after", currentAfter)
                            .queryParam("t", timeRange.toString())
                            .request(MediaType.APPLICATION_JSON)
                            .get(JsonNode.class);
            subListing = new RedditListing<>(jsonNodeResponse, RedditStory.class);
        } catch (@Nonnull RedirectionException | ProcessingException | ClientErrorException | JsonProcessingException e) {
            this.clientExceptionMeter.mark();
            throw new RedditClientException(e);
        }

        if (subListing.getChildren().size() == 0) {
            break; //no more listing!
        }

        for (int i = 0; i < subListing.getChildren().size() && stories.size() < limit; i++) {
            stories.add(subListing.getChildren().get(i));
        }

        if (stories.size() == lastCount) {
            break; //no more stories added, fail early
        }

        lastCount = stories.size();
        currentAfter = subListing.getAfter();
    }

    return stories;
}