| Line 46... |
Line 46... |
| 46 |
}
|
46 |
}
|
| 47 |
|
47 |
|
| 48 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params, Map<String, String> headers)
|
48 |
public String get(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params, Map<String, String> headers)
|
| 49 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
49 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
| 50 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString() : scheme.getValue() + hostName + ":" + port + "/" + uri;
|
50 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString() : scheme.getValue() + hostName + ":" + port + "/" + uri;
|
| - |
|
51 |
return this.get(url, params, headers);
|
| - |
|
52 |
}
|
| - |
|
53 |
|
| - |
|
54 |
public String get(String url, Map<String, String> params, Map<String, String> headers)
|
| - |
|
55 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
| 51 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
56 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
| 52 |
Set<String> keys = params.keySet();
|
57 |
Set<String> keys = params.keySet();
|
| 53 |
for(String key : keys){
|
58 |
for(String key : keys){
|
| 54 |
builder.queryParam(key, params.get(key));
|
59 |
builder.queryParam(key, params.get(key));
|
| 55 |
}
|
60 |
}
|
| Line 99... |
Line 104... |
| 99 |
}
|
104 |
}
|
| 100 |
|
105 |
|
| 101 |
public String post(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params, Map<String, String> headers)
|
106 |
public String post(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params, Map<String, String> headers)
|
| 102 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
107 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
| 103 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString() : scheme.getValue() + hostName + ":" + port + "/" + uri;
|
108 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString() : scheme.getValue() + hostName + ":" + port + "/" + uri;
|
| - |
|
109 |
return this.post(url, params, headers);
|
| - |
|
110 |
}
|
| - |
|
111 |
|
| - |
|
112 |
public String post(String url, Map<String, String> params, Map<String, String> headers)
|
| - |
|
113 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
| 104 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
114 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
| 105 |
List<NameValuePair> bodyParameters = new ArrayList<NameValuePair>();
|
115 |
List<NameValuePair> bodyParameters = new ArrayList<NameValuePair>();
|
| 106 |
for(Map.Entry<String, String> entry : params.entrySet()){
|
116 |
for(Map.Entry<String, String> entry : params.entrySet()){
|
| 107 |
bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
117 |
bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
| 108 |
}
|
118 |
}
|
| Line 126... |
Line 136... |
| 126 |
}
|
136 |
}
|
| 127 |
|
137 |
|
| 128 |
public String postJson(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params, Map<String, String> headers)
|
138 |
public String postJson(SchemeType scheme, String hostName, int port, String uri, Map<String, String> params, Map<String, String> headers)
|
| 129 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
139 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
| 130 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString() : scheme.getValue() + hostName + ":" + port + "/" + uri;
|
140 |
String url = scheme.getValue() == null ? SchemeType.HTTP.toString() : scheme.getValue() + hostName + ":" + port + "/" + uri;
|
| - |
|
141 |
return this.postJson(url, params, headers);
|
| - |
|
142 |
}
|
| - |
|
143 |
|
| - |
|
144 |
public String postJson(String url, Map<String, String> params, Map<String, String> headers)
|
| - |
|
145 |
throws ProfitMandiBusinessException, HttpHostConnectException{
|
| 131 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
146 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
|
| 132 |
List<NameValuePair> bodyParameters = new ArrayList<NameValuePair>();
|
147 |
List<NameValuePair> bodyParameters = new ArrayList<NameValuePair>();
|
| 133 |
for(Map.Entry<String, String> entry : params.entrySet()){
|
148 |
for(Map.Entry<String, String> entry : params.entrySet()){
|
| 134 |
bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
149 |
bodyParameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
|
| 135 |
}
|
150 |
}
|
| Line 139... |
Line 154... |
| 139 |
jsonString = StringUtils.toString(params);
|
154 |
jsonString = StringUtils.toString(params);
|
| 140 |
} catch (Exception e) {
|
155 |
} catch (Exception e) {
|
| 141 |
e.printStackTrace();
|
156 |
e.printStackTrace();
|
| 142 |
}
|
157 |
}
|
| 143 |
|
158 |
|
| 144 |
|
- |
|
| 145 |
StringEntity requestEntity = new StringEntity(
|
159 |
StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
|
| 146 |
jsonString,
|
- |
|
| 147 |
ContentType.APPLICATION_JSON);
|
- |
|
| 148 |
|
160 |
|
| 149 |
LOGGER.info("Body {}", jsonString);
|
161 |
LOGGER.info("Body {}", jsonString);
|
| 150 |
HttpPost request = new HttpPost(builder.build().encode().toUri());
|
162 |
HttpPost request = new HttpPost(builder.build().encode().toUri());
|
| 151 |
for(Map.Entry<String, String> entry : headers.entrySet()){
|
163 |
for(Map.Entry<String, String> entry : headers.entrySet()){
|
| 152 |
request.setHeader(entry.getKey(), entry.getValue());
|
164 |
request.setHeader(entry.getKey(), entry.getValue());
|
| 153 |
}
|
165 |
}
|
| 154 |
|
- |
|
| 155 |
request.setEntity(requestEntity);
|
166 |
request.setEntity(requestEntity);
|
| 156 |
|
- |
|
| 157 |
|
- |
|
| 158 |
|
- |
|
| 159 |
return this.execute(request);
|
167 |
return this.execute(request);
|
| 160 |
|
- |
|
| 161 |
}
|
168 |
}
|
| 162 |
|
169 |
|
| 163 |
private String toString(InputStream inputStream){
|
170 |
private String toString(InputStream inputStream){
|
| 164 |
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
171 |
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
| 165 |
StringBuilder responseString = new StringBuilder();
|
172 |
StringBuilder responseString = new StringBuilder();
|