tags:

views:

363

answers:

2

Hi all, I am trying to upload a file to some url using ssl. I use this code to set trust manager -

public static void trustAll () {
    TrustManage[] trustEverythingTrustManager = new TrustManager[] {
        new X509TrustManager() {

            public void checkClientTrusted(X509Certificate[] chain,
            String authType) throws CertificateException {
            // TODO Auto-generated method stub
            }

            public void checkServerTrusted(X509Certificate[] chain,
            String authType) throws CertificateException {
            // TODO Auto-generated method stub

            }

            public X509Certificate[] getAcceptedIssuers() {
            // TODO Auto-generated method stub
            return null;
            }

        }
    };

    SSLContext sc;
    try {
        sc = SSLContext.getInstance("TLS");
        sc.init(null, trustEverythingTrustManager, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
    }
}

and this one to set host name verifier -

public static HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {

    public boolean verify(String hostname, SSLSession session) {
        return true;
    }
};

then i am opening connection like this -

URL url = new URL("some_url");
HttpURLConnection connection = null;
// check if this is https or just http
if (url.getProtocol().toLowerCase().equals("https")) {
    trustAll();
    HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
    https.setHostnameVerifier(DO_NOT_VERIFY);
    connection = https;
} else {
    connection = (HttpURLConnection) url.openConnection();
}

After i get the connection i use it to upload the data. Is i use http everything is ok but when i try https i get the following exception -

Write error: I/O error during system call, Broken pipe java.io.IOException: Write error: I/O error during system call, Broken pipe at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativewrite(Native Method) at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.access$600(OpenSSLSocketImpl.java:55) at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:565) at java.io.OutputStream.write(OutputStream.java:82) at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection$HttpOutputStream.write(HttpURLConnection.java:652) at java.io.DataOutputStream.write(DataOutputStream.java:101)

The strange thing is that i don't get exception all the time. When i try to upload small files (200K) it's working O.K. or it's crashing very rare but when i try to upload bigger ones (more than 1MB) i get the exception almost every time.

Any ideas ?

A: 

Did you get an answer to this issue..

I am having a similar issue on Android using the httpclient library

orcking
No sry still nothing
Mojo Risin
A: 

The guys from android reported that is bug in android sdk http://code.google.com/p/android/issues/detail?id=8625.

Mojo Risin