Last active
February 12, 2016 17:17
-
-
Save jforge/bf5e21ba27765f8b40e4 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 { | |
| TrustManager[] trustmanager = { | |
| new X509TrustManager() { | |
| @Override | |
| public X509Certificate[] getAcceptedIssuers() { | |
| return new X509Certificate[0]; | |
| } | |
| @Override | |
| public void checkClientTrusted(X509Certificate[] certs, String authType) {} | |
| @Override | |
| public void checkServerTrusted(X509Certificate[] certs, String authType) {} | |
| } }; | |
| SSLContext sslContext = SSLContext.getInstance("SSL"); | |
| sslContext.init(null, trustmanager, null); | |
| ClientBuilder builder = ClientBuilder.newBuilder() | |
| .sslContext(sslContext) | |
| .hostnameVerifier(((hostname, session) -> true)) | |
| .register(RedirectFilterWorkAround.class) | |
| .register(new LoggingFilter()) | |
| .property(ClientProperties.FOLLOW_REDIRECTS, true); | |
| Client client = builder.build(); | |
| WebTarget webTarget = client.target(baseURI); | |
| log.info(webTarget.path("resources").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