|
|
package com.ui.service.impl;
|
|
|
package com.ui.http;
|
|
|
|
|
|
import com.ui.service.HttpRestClientService;
|
|
|
import com.ui.config.SystemConfig;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service("httpRestClientService")
|
|
|
public class HttpRestClientServiceImpl implements HttpRestClientService {
|
|
|
public class HttpRestClient {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory
|
|
|
.getLogger(HttpRestClientServiceImpl.class);
|
|
|
.getLogger(HttpRestClient.class);
|
|
|
|
|
|
@Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
@Override
|
|
|
public <T> T postForObject(String url, Object request, Class<T> responseType) {
|
|
|
private SystemConfig systemConfig;
|
|
|
|
|
|
public <T> T defaultPost(String uri, Object request, Class<T> responseType) {
|
|
|
try {
|
|
|
return restTemplate.postForObject(url, request,responseType);
|
|
|
return restTemplate.postForObject(systemConfig.getServiceUrl() + uri, request,responseType);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("postForObject failed!url:"+url, e);
|
|
|
logger.error("postForObject failed!url:"+uri, e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void setRestTemplate(RestTemplate restTemplate) {
|
|
|
this.restTemplate = restTemplate;
|
|
|
}
|
|
|
public void setSystemConfig(SystemConfig systemConfig) {
|
|
|
this.systemConfig = systemConfig;
|
|
|
}
|
|
|
} |
...
|
...
|
|