|
|
package com.ui.http;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ui.config.SystemConfig;
|
|
|
import com.ui.model.BaseResponse;
|
|
|
import com.ui.model.req.User;
|
|
|
import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
public class HttpRestClient {
|
...
|
...
|
@@ -45,6 +30,19 @@ public class HttpRestClient { |
|
|
}
|
|
|
}
|
|
|
|
|
|
public <T> T defaultPostJson(String uri, String requestJson,Class<T> responseType) {
|
|
|
try {
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
headers.setContentType(type);
|
|
|
HttpEntity<String> entity = new HttpEntity<String>(requestJson,headers);
|
|
|
return restTemplate.postForObject(systemConfig.getServiceUrl() + uri, entity, responseType);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("postForObject failed!url:"+uri, e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public <T> T defaultGet(String uri, Class<T> responseType,Map<String, ?> map) {
|
|
|
try {
|
|
|
StringBuilder url = new StringBuilder(uri);
|
...
|
...
|
|