curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From madrob <...@git.apache.org>
Subject [GitHub] curator pull request: initial BasicAuthExhibitorRestClient
Date Wed, 10 Sep 2014 02:56:29 GMT
Github user madrob commented on a diff in the pull request:

    https://github.com/apache/curator/pull/10#discussion_r17340570
  
    --- Diff: curator-client/src/main/java/org/apache/curator/ensemble/exhibitor/BasicAuthExhibitorRestClient.java
---
    @@ -0,0 +1,65 @@
    +package org.apache.curator.ensemble.exhibitor;
    +
    +import com.google.common.io.CharStreams;
    +import org.apache.curator.utils.CloseableUtils;
    +import sun.misc.BASE64Encoder;
    +
    +import javax.net.ssl.*;
    +import java.io.BufferedInputStream;
    +import java.io.InputStream;
    +import java.io.InputStreamReader;
    +import java.io.Reader;
    +import java.net.HttpURLConnection;
    +import java.net.URI;
    +import java.security.cert.CertificateException;
    +import java.security.cert.X509Certificate;
    +
    +public class BasicAuthExhibitorRestClient  implements ExhibitorRestClient
    +{
    +    private final boolean useSsl;
    +    private final boolean validateSsl;
    +    private final String userInfo;
    +
    +    public BasicAuthExhibitorRestClient(boolean useSsl, boolean validateSsl, String userInfo)
    +    {
    +        this.useSsl = useSsl;
    +        this.validateSsl = validateSsl;
    +        this.userInfo = userInfo;
    +    }
    +
    +    @Override
    +    public String getRaw(String hostname, int port, String uriPath, String mimeType)
throws Exception
    +    {
    +        URI uri = new URI(useSsl ? "https" : "http", null, hostname, port, uriPath, null,
null);
    +        HttpURLConnection connection = (HttpURLConnection)uri.toURL().openConnection();
    +        if (useSsl && !validateSsl) {
    +            X509TrustManager trustAllCert = new X509TrustManager() {
    --- End diff --
    
    This could be a statifc object instead of creating a new one on every single request.
Same for the HostnameVerifier below.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message