OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 177 Rev 180
Line 114... Line 114...
114
 
114
 
115
    public final boolean hasToken() {
115
    public final boolean hasToken() {
116
        return this.getToken() != null;
116
        return this.getToken() != null;
117
    }
117
    }
118
 
118
 
119
    protected final String getToken() {
119
    public final String getToken() {
120
        return this.token;
120
        return this.token;
121
    }
121
    }
122
 
122
 
123
    public final void setThrowException(boolean throwException) {
123
    public final void setThrowException(boolean throwException) {
124
        this.throwException = throwException;
124
        this.throwException = throwException;
Line 142... Line 142...
142
    public final HttpsURLConnection openConnection(final String path) throws IOException {
142
    public final HttpsURLConnection openConnection(final String path) throws IOException {
143
        final HttpsURLConnection con = (HttpsURLConnection) new URL(this.url + path).openConnection();
143
        final HttpsURLConnection con = (HttpsURLConnection) new URL(this.url + path).openConnection();
144
        con.setRequestProperty("Accept-Encoding", "gzip");
144
        con.setRequestProperty("Accept-Encoding", "gzip");
145
        if (this.getSocketFactory() != null)
145
        if (this.getSocketFactory() != null)
146
            con.setSSLSocketFactory(this.getSocketFactory());
146
            con.setSSLSocketFactory(this.getSocketFactory());
147
        if (getToken() != null)
147
        if (getToken() != null) {
148
            con.setRequestProperty("Authorization", "Bearer " + Base64.getEncoder().encodeToString(getToken().getBytes(StandardCharsets.UTF_8)));
148
            con.setRequestProperty("Authorization", "Bearer " + Base64.getEncoder().encodeToString(getToken().getBytes(StandardCharsets.UTF_8)));
-
 
149
        }
149
        return con;
150
        return con;
150
    }
151
    }
151
 
152
 
152
    public final InputStream getInputStream(final HttpsURLConnection con) throws IOException {
153
    public final InputStream getInputStream(final HttpsURLConnection con) throws IOException {
153
        return "gzip".equals(con.getContentEncoding()) ? new GZIPInputStream(con.getInputStream()) : con.getInputStream();
154
        return "gzip".equals(con.getContentEncoding()) ? new GZIPInputStream(con.getInputStream()) : con.getInputStream();
154
    }
155
    }
155
 
156
 
156
    public final HttpsURLConnection send(final HttpsURLConnection con, final String params) throws IOException {
157
    public final HttpsURLConnection send(final HttpsURLConnection con, final String formUrlEncodedParams) throws IOException {
157
        return this.send(con, params, true);
158
        return this.send(con, formUrlEncodedParams, true);
158
    }
159
    }
159
 
160
 
160
    public final HttpsURLConnection send(final HttpsURLConnection con, final String params, final boolean allowGzip) throws IOException {
161
    public final HttpsURLConnection send(final HttpsURLConnection con, final String formUrlEncodedParams, final boolean allowGzip) throws IOException {
-
 
162
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
161
        return this.send(con, params.getBytes(StandardCharsets.UTF_8), allowGzip);
163
        return this.send(con, formUrlEncodedParams.getBytes(StandardCharsets.UTF_8), allowGzip);
162
    }
164
    }
163
 
165
 
164
    public final HttpsURLConnection send(final HttpsURLConnection con, final byte[] toSend, final boolean allowGzip) throws IOException {
166
    public final HttpsURLConnection send(final HttpsURLConnection con, final byte[] toSend, final boolean allowGzip) throws IOException {
165
        final boolean useGzip = allowGzip && toSend.length >= MIN_GZIP_SIZE;
167
        final boolean useGzip = allowGzip && toSend.length >= MIN_GZIP_SIZE;
166
        if (useGzip)
168
        if (useGzip)