Created
February 11, 2016 17:11
-
-
Save jforge/68ff5e5f149c874cdc0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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