| Line 12... |
Line 12... |
| 12 |
|
12 |
|
| 13 |
import org.apache.http.HttpResponse;
|
13 |
import org.apache.http.HttpResponse;
|
| 14 |
import org.apache.http.NameValuePair;
|
14 |
import org.apache.http.NameValuePair;
|
| 15 |
import org.apache.http.client.ClientProtocolException;
|
15 |
import org.apache.http.client.ClientProtocolException;
|
| 16 |
import org.apache.http.client.HttpClient;
|
16 |
import org.apache.http.client.HttpClient;
|
| - |
|
17 |
import org.apache.http.client.config.RequestConfig;
|
| 17 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
18 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
| 18 |
import org.apache.http.client.methods.HttpGet;
|
19 |
import org.apache.http.client.methods.HttpGet;
|
| 19 |
import org.apache.http.client.methods.HttpPost;
|
20 |
import org.apache.http.client.methods.HttpPost;
|
| 20 |
import org.apache.http.client.methods.HttpUriRequest;
|
21 |
import org.apache.http.client.methods.HttpUriRequest;
|
| - |
|
22 |
import org.apache.http.conn.HttpClientConnectionManager;
|
| 21 |
import org.apache.http.conn.HttpHostConnectException;
|
23 |
import org.apache.http.conn.HttpHostConnectException;
|
| 22 |
import org.apache.http.entity.ContentType;
|
24 |
import org.apache.http.entity.ContentType;
|
| 23 |
import org.apache.http.entity.StringEntity;
|
25 |
import org.apache.http.entity.StringEntity;
|
| - |
|
26 |
import org.apache.http.impl.client.HttpClientBuilder;
|
| 24 |
import org.apache.http.impl.client.HttpClients;
|
27 |
import org.apache.http.impl.client.HttpClients;
|
| - |
|
28 |
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
|
| 25 |
import org.apache.http.message.BasicNameValuePair;
|
29 |
import org.apache.http.message.BasicNameValuePair;
|
| - |
|
30 |
import org.apache.http.params.BasicHttpParams;
|
| - |
|
31 |
import org.apache.http.params.HttpParams;
|
| 26 |
import org.apache.logging.log4j.LogManager;
|
32 |
import org.apache.logging.log4j.LogManager;
|
| 27 |
import org.apache.logging.log4j.Logger;
|
33 |
import org.apache.logging.log4j.Logger;
|
| 28 |
import org.springframework.http.HttpStatus;
|
34 |
import org.springframework.http.HttpStatus;
|
| 29 |
import org.springframework.stereotype.Component;
|
35 |
import org.springframework.stereotype.Component;
|
| 30 |
import org.springframework.web.util.UriComponentsBuilder;
|
36 |
import org.springframework.web.util.UriComponentsBuilder;
|
| Line 41... |
Line 47... |
| 41 |
|
47 |
|
| 42 |
private HttpClient httpClient;
|
48 |
private HttpClient httpClient;
|
| 43 |
|
49 |
|
| 44 |
public RestClient() {
|
50 |
public RestClient() {
|
| 45 |
this.httpClient = HttpClients.createDefault();
|
51 |
this.httpClient = HttpClients.createDefault();
|
| - |
|
52 |
|
| - |
|
53 |
}
|
| - |
|
54 |
|
| - |
|
55 |
public RestClient(int connectionTimeoutMillis) {
|
| - |
|
56 |
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5* 1000).build();
|
| - |
|
57 |
this.httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
|
| - |
|
58 |
|
| 46 |
}
|
59 |
}
|
| 47 |
|
60 |
|
| 48 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
61 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params,
|
| 49 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|
62 |
Map<String, String> headers) throws ProfitMandiBusinessException, HttpHostConnectException {
|
| 50 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString()
|
63 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString()
|
| Line 143... |
Line 156... |
| 143 |
return this.post(url, params, headers);
|
156 |
return this.post(url, params, headers);
|
| 144 |
}
|
157 |
}
|
| 145 |
|
158 |
|
| 146 |
public String post(String url, Map<String, String> params, Map<String, String> headers)
|
159 |
public String post(String url, Map<String, String> params, Map<String, String> headers)
|
| 147 |
throws ProfitMandiBusinessException, HttpHostConnectException {
|
160 |
throws ProfitMandiBusinessException, HttpHostConnectException {
|
| 148 |
//UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
161 |
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
| 149 |
List<NameValuePair> bodyParameters = new ArrayList<NameValuePair>();
|
162 |
List<NameValuePair> bodyParameters = new ArrayList<NameValuePair>();
|
| 150 |
for (Map.Entry<String, String> entry : params.entrySet()) {
|
163 |
for (Map.Entry<String, String> entry : params.entrySet()) {
|
| 151 |
bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
164 |
bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
| 152 |
}
|
165 |
}
|
| 153 |
|
166 |
|