| Line 9... |
Line 9... |
| 9 |
import org.apache.http.NameValuePair;
|
9 |
import org.apache.http.NameValuePair;
|
| 10 |
import org.apache.http.client.ClientProtocolException;
|
10 |
import org.apache.http.client.ClientProtocolException;
|
| 11 |
import org.apache.http.client.HttpClient;
|
11 |
import org.apache.http.client.HttpClient;
|
| 12 |
import org.apache.http.client.config.RequestConfig;
|
12 |
import org.apache.http.client.config.RequestConfig;
|
| 13 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
13 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| 14 |
import org.apache.http.client.methods.HttpGet;
|
14 |
import org.apache.http.client.methods.*;
|
| 15 |
import org.apache.http.client.methods.HttpPatch;
|
- |
|
| 16 |
import org.apache.http.client.methods.HttpPost;
|
- |
|
| 17 |
import org.apache.http.client.methods.HttpUriRequest;
|
- |
|
| 18 |
import org.apache.http.conn.HttpHostConnectException;
|
15 |
import org.apache.http.conn.HttpHostConnectException;
|
| 19 |
import org.apache.http.entity.ContentType;
|
16 |
import org.apache.http.entity.ContentType;
|
| 20 |
import org.apache.http.entity.StringEntity;
|
17 |
import org.apache.http.entity.StringEntity;
|
| - |
|
18 |
import org.apache.http.impl.client.CloseableHttpClient;
|
| 21 |
import org.apache.http.impl.client.HttpClientBuilder;
|
19 |
import org.apache.http.impl.client.HttpClientBuilder;
|
| 22 |
import org.apache.http.impl.client.HttpClients;
|
20 |
import org.apache.http.impl.client.HttpClients;
|
| 23 |
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
21 |
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
| 24 |
import org.apache.http.message.BasicNameValuePair;
|
22 |
import org.apache.http.message.BasicNameValuePair;
|
| - |
|
23 |
import org.apache.http.util.EntityUtils;
|
| 25 |
import org.apache.logging.log4j.LogManager;
|
24 |
import org.apache.logging.log4j.LogManager;
|
| 26 |
import org.apache.logging.log4j.Logger;
|
25 |
import org.apache.logging.log4j.Logger;
|
| 27 |
import org.springframework.beans.factory.annotation.Autowired;
|
26 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 28 |
import org.springframework.http.HttpStatus;
|
27 |
import org.springframework.http.HttpStatus;
|
| 29 |
import org.springframework.stereotype.Component;
|
28 |
import org.springframework.stereotype.Component;
|
| Line 368... |
Line 367... |
| 368 |
} catch (IOException e) {
|
367 |
} catch (IOException e) {
|
| 369 |
throw new RuntimeException();
|
368 |
throw new RuntimeException();
|
| 370 |
}
|
369 |
}
|
| 371 |
return responseString.toString();
|
370 |
return responseString.toString();
|
| 372 |
}
|
371 |
}
|
| - |
|
372 |
|
| - |
|
373 |
public byte[] postForBytes(String url, String payload, Map<String, String> headers) throws IOException {
|
| - |
|
374 |
HttpPost post = new HttpPost(url);
|
| - |
|
375 |
headers.forEach(post::setHeader);
|
| - |
|
376 |
|
| - |
|
377 |
post.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
|
| - |
|
378 |
|
| - |
|
379 |
try (CloseableHttpClient client = HttpClients.createDefault();
|
| - |
|
380 |
CloseableHttpResponse response = client.execute(post)) {
|
| - |
|
381 |
|
| - |
|
382 |
int statusCode = response.getStatusLine().getStatusCode();
|
| - |
|
383 |
if (statusCode != 200) {
|
| - |
|
384 |
throw new IOException("Failed : HTTP error code : " + statusCode);
|
| - |
|
385 |
}
|
| - |
|
386 |
|
| - |
|
387 |
return EntityUtils.toByteArray(response.getEntity());
|
| - |
|
388 |
}
|
| - |
|
389 |
}
|
| - |
|
390 |
|
| 373 |
}
|
391 |
}
|
| 374 |
|
392 |
|