OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 177
Line 15... Line 15...
15
 
15
 
16
import java.io.ByteArrayOutputStream;
16
import java.io.ByteArrayOutputStream;
17
import java.io.IOException;
17
import java.io.IOException;
18
import java.io.InputStream;
18
import java.io.InputStream;
19
import java.io.OutputStream;
19
import java.io.OutputStream;
-
 
20
import java.io.UnsupportedEncodingException;
20
import java.net.InetAddress;
21
import java.net.InetAddress;
21
import java.net.NetworkInterface;
22
import java.net.NetworkInterface;
22
import java.net.ServerSocket;
23
import java.net.ServerSocket;
23
import java.net.SocketException;
24
import java.net.SocketException;
24
import java.net.URL;
25
import java.net.URL;
-
 
26
import java.net.URLEncoder;
-
 
27
import java.nio.charset.StandardCharsets;
25
import java.security.KeyManagementException;
28
import java.security.KeyManagementException;
26
import java.security.NoSuchAlgorithmException;
29
import java.security.NoSuchAlgorithmException;
27
import java.security.cert.X509Certificate;
30
import java.security.cert.X509Certificate;
28
import java.util.Enumeration;
31
import java.util.Enumeration;
-
 
32
import java.util.LinkedHashMap;
-
 
33
import java.util.Map;
-
 
34
import java.util.Map.Entry;
29
 
35
 
30
import javax.net.ssl.HostnameVerifier;
36
import javax.net.ssl.HostnameVerifier;
31
import javax.net.ssl.HttpsURLConnection;
37
import javax.net.ssl.HttpsURLConnection;
32
import javax.net.ssl.SSLContext;
38
import javax.net.ssl.SSLContext;
33
import javax.net.ssl.SSLSession;
39
import javax.net.ssl.SSLSession;
Line 176... Line 182...
176
        }
182
        }
177
 
183
 
178
        return content;
184
        return content;
179
    }
185
    }
180
 
186
 
-
 
187
    static public final String urlEncode(final String... kv) {
-
 
188
        final int size = kv.length;
-
 
189
        if (size % 2 != 0)
-
 
190
            throw new IllegalArgumentException("Odd number of items : " + size);
-
 
191
        final LinkedHashMap<String, Object> map = new LinkedHashMap<>(size / 2, 1);
-
 
192
        for (int i = 0; i < size; i += 2) {
-
 
193
            map.put(kv[i], kv[i + 1]);
-
 
194
        }
-
 
195
        return urlEncode(map);
-
 
196
    }
-
 
197
 
-
 
198
    static public final String urlEncode(final Map<String, ?> map) {
-
 
199
        if (map.isEmpty())
-
 
200
            return "";
-
 
201
        final String charset = StandardCharsets.UTF_8.name();
-
 
202
        final StringBuilder sb = new StringBuilder(256);
-
 
203
        for (final Entry<String, ?> e : map.entrySet()) {
-
 
204
            final Object value = e.getValue();
-
 
205
            // Avoid null and "null" confusion.
-
 
206
            if (value != null) {
-
 
207
                try {
-
 
208
                    sb.append(URLEncoder.encode(e.getKey(), charset));
-
 
209
                    sb.append('=');
-
 
210
                    sb.append(URLEncoder.encode(String.valueOf(value), charset));
-
 
211
                    sb.append('&');
-
 
212
                } catch (UnsupportedEncodingException exn) {
-
 
213
                    throw new IllegalStateException("UTF-8 should be standard", exn);
-
 
214
                }
-
 
215
            }
-
 
216
        }
-
 
217
        // remove last '&'
-
 
218
        sb.setLength(sb.length() - 1);
-
 
219
        return sb.toString();
-
 
220
    }
-
 
221
 
181
    // Create a trust manager that does not validate certificate chains
222
    // Create a trust manager that does not validate certificate chains
182
    static private final TrustManager[] TRUSTALL_MANAGERS = new TrustManager[] { new X509TrustManager() {
223
    static private final TrustManager[] TRUSTALL_MANAGERS = new TrustManager[] { new X509TrustManager() {
183
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
224
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
184
            return null;
225
            return null;
185
        }
226
        }