public class CommonMethods {
final Logger logger = (Logger) LoggerFactory.getLogger(CommonMethods.class);
@Autowired
HttpClientFactory httpClientFactory;
enter code here
@Autowired
JSONCreation jsonCreation;
String responseAsStringEmployment;
public String getEmploymentDetails(EmpProfile empProfile) throws IOException, JSONException {
HttpClient clientEmployment = httpClientFactory.getHttpClient();
String urlEmployment = Config.getDefaultCommonServiceURL();
HttpPost requestEmployment = new HttpPost(urlEmployment + "getEmploymentDetails");
requestEmployment.addHeader("content-type", "application/json");
StringEntity params;
String a = jsonCreation.createJsonforNode(empProfile);
params = new StringEntity(a);
requestEmployment.setEntity(params);
logger.info("Request Employment :" + requestEmployment);
logger.info("clientEmployment :" + clientEmployment);
HttpResponse responseEmployment = clientEmployment.execute(requestEmployment);
logger.info("responseEmployment :" + responseEmployment);
responseAsStringEmployment = EntityUtils.toString(responseEmployment.getEntity());
logger.info("Response Employment : " + responseAsStringEmployment);
logger.info("responseAsStringEmployment " + responseAsStringEmployment);
return responseAsStringEmployment;
}
而不是httpclient,我必須使用rest模板。 http客戶端運行正常。想要使用服務使用休息模板的post方法
我已經嘗試了其他模板的方法如下:
public String getEmployment() {
String url = "https://empprofile-blue.bdt.com/getEmploymentDetails";
EmpProfile empProfile = new EmpProfile();
RestTemplate restTemplate = new RestTemplate();
EmpProfile result = restTemplate.postForObject(url, empProfile, EmpProfile.class);
System.out.println(result);
logger.info(empProfile.toString());
return result.toString();
}
想休息模板如何才能實現配置超時。
格式代碼正確 – pvpkiran