...
|
...
|
@@ -110,4 +110,40 @@ public class HttpRestClientServiceImpl implements HttpRestClientService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public <T> T getWithHost(String path, Map request, Class<T> responseType) {
|
|
|
|
|
|
logger.debug("begin to do http get host. path:{}, request params:{}", path, request);
|
|
|
|
|
|
//add accept json
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
|
|
headers.set("Host","erp.yoho.yohoops.org");
|
|
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
|
|
|
|
|
//url
|
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(path);
|
|
|
|
|
|
//添加参数
|
|
|
if(request!=null){
|
|
|
Map<String, ?> params = (Map<String, ?>) request;
|
|
|
if (params != null && params.size() > 0) {
|
|
|
for (Map.Entry<String, ?> urlParam : params.entrySet()) {
|
|
|
builder.queryParam(urlParam.getKey(), urlParam.getValue());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
final URI getURI = builder.build().encode().toUri();
|
|
|
|
|
|
try {
|
|
|
HttpEntity<T> response = restTemplate.exchange(getURI, HttpMethod.GET, entity, responseType);
|
|
|
logger.debug("end to do http get. path:{}, request params:{}. response body: {}", path, request, response.getBody());
|
|
|
return response.getBody();
|
|
|
} catch (Exception e) {
|
|
|
logger.error("doPostStringJson failed!url:"+path, e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|