Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jforge/68ff5e5f149c874cdc0e to your computer and use it in GitHub Desktop.

Select an option

Save jforge/68ff5e5f149c874cdc0e to your computer and use it in GitHub Desktop.
private static class RedirectFilterWorkAround implements ClientResponseFilter {
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
if (responseContext.getStatusInfo().getFamily() != Response.Status.Family.REDIRECTION) {
return;
}
Response resp = requestContext.getClient().target(responseContext.getLocation()).request()
.method(requestContext.getMethod());
responseContext.setEntityStream((InputStream) resp.getEntity());
responseContext.setStatusInfo(resp.getStatusInfo());
responseContext.setStatus(resp.getStatus());
}
}
@Test
public void testFileServer() throws Exception {
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(RedirectFilterWorkAround.class);
clientConfig.register(new LoggingFilter());
clientConfig.property(ClientProperties.FOLLOW_REDIRECTS, true);
Client client = ClientBuilder.newClient(clientConfig);
WebTarget webTarget = client.target(baseURI);
log.info("Calling path /repository...");
log.info(webTarget.path("repository").request(MediaType.TEXT_PLAIN).get(String.class));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment