master
周文涛 2 years ago
parent 33f86db96d
commit 790d112cea

@ -3,12 +3,18 @@ package org.jeecg.common.util;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.config.RestTemplateConfig;
import org.springframework.http.*;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.Map;
@ -260,4 +266,25 @@ public class RestUtil {
return urlVariables.substring(1);
}
public static JSONObject postTest(String httpUrl,JSONObject requestBodyJson,JSONObject headerJson){
RestTemplate restTemplate = null;
try {
restTemplate = new RestTemplate(RestTemplateConfig.generateHttpRequestFactory());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
}
MultiValueMap<String, Object> headers =(MultiValueMap) headerJson.getInnerMap();;
headers.add("Accept", "*/*");
headers.add("Content-Type", "application/json");
String requestBody = requestBodyJson.toJSONString();
HttpEntity entity = new HttpEntity(requestBody, headers);
ResponseEntity<String> responseEntity=restTemplate.postForEntity(httpUrl,entity,String.class);
//获取返回结果
String result= responseEntity.getBody();
return JSONObject.parseObject(result);
}
}

@ -1,11 +1,25 @@
package org.jeecg.config;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.ssl.TrustStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import javax.net.ssl.SSLContext;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
/**
* httpRestTemplate
* @author: jeecg-boot
@ -28,4 +42,19 @@ public class RestTemplateConfig {
factory.setConnectTimeout(15000);
return factory;
}
public static HttpComponentsClientHttpRequestFactory generateHttpRequestFactory()
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
TrustStrategy acceptingTrustStrategy = (x509Certificates, authType) -> true;
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
SSLConnectionSocketFactory connectionSocketFactory = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder httpClientBuilder = HttpClients.custom();
httpClientBuilder.setSSLSocketFactory(connectionSocketFactory);
CloseableHttpClient httpClient = httpClientBuilder.build();
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(httpClient);
return factory;
}
}

@ -157,7 +157,7 @@ public class ApiController {
public JSONObject imgNotify() {
String ss = "{\t\"requestId\":\"10001\",\t\"result\":{\t\t\"ocrResult\":[\t\t\t{\t\t\t\t\"tag\":\"hospitalName\",\t\t\t\t\"inputText\":\"仁和医院\",\t\t\t\t\"ocrText\":\"仁和医院\",\t\t\t\t\"ocrPrecisionRate\":0.8,\t\t\t\t\"sourceImage\":{\t\t\t\t\t\"fileName\":\"test1.png\",\t\t\t\t\t\"path\":\"/usr/local/ocr/test1.png\"\t\t\t\t},\t\t\t\t\"failureReason\":\"\"\t\t\t}\t\t],\t\t\"ruleValidation\":false,\t\t\"retrieveReviewCompliance\":\"80\",\t\t\"imageTagRetrievePercentage\":\"66.6\",\t\t\"failureReason\":\"医生名称不匹配\"\t}}";
JSONObject requestBody = JSONObject.parseObject(ss);
JSONObject semanticResponseJson = RestUtil.post("http://111.202.228.113:8071/callback", requestBody);
JSONObject semanticResponseJson = RestUtil.postTest("http://111.202.228.113:8071/callback", requestBody, new JSONObject());
return semanticResponseJson;
/*String requestId = jsonObject.getString("requestId");
String fileName = jsonObject.getString("fileName");

Loading…
Cancel
Save