|
|
|
@ -1,23 +1,37 @@
|
|
|
|
|
package com.glxp.sale.admin.idc.controller;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.net.URISyntaxException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import com.glxp.sale.admin.idc.service.DownloadRestTemplate;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
import org.springframework.http.*;
|
|
|
|
|
import org.springframework.http.client.ClientHttpRequest;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.client.RequestCallback;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
@ -87,11 +101,11 @@ public class IdcController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/mapi/**")
|
|
|
|
|
public Object mapi(HttpServletRequest request) {
|
|
|
|
|
public Object mapi(HttpServletRequest request, HttpServletResponse httpServletResponse) {
|
|
|
|
|
String uri = parseUri(request.getRequestURL().toString());
|
|
|
|
|
|
|
|
|
|
if (uri.contains("image")) {
|
|
|
|
|
return redirectIamge(request, uri);
|
|
|
|
|
if (uri.contains("getImage")) {
|
|
|
|
|
return redirectIamge(request, httpServletResponse, uri);
|
|
|
|
|
} else {
|
|
|
|
|
return redirect(request, uri);
|
|
|
|
|
}
|
|
|
|
@ -101,14 +115,32 @@ public class IdcController {
|
|
|
|
|
HttpEntity<String> buildHeader(HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
|
log.info(request.getMethod());
|
|
|
|
|
|
|
|
|
|
String bodyContent = "";
|
|
|
|
|
Map<String, Object> headerParam = new HashMap<>();
|
|
|
|
|
Map<String, Object> bodyParam = new HashMap<String, Object>();
|
|
|
|
|
Enumeration pNames = request.getParameterNames();
|
|
|
|
|
while (pNames.hasMoreElements()) {
|
|
|
|
|
String name = (String) pNames.nextElement();
|
|
|
|
|
String value = request.getParameter(name);
|
|
|
|
|
bodyParam.put(name, value);
|
|
|
|
|
|
|
|
|
|
if (request.getMethod().equals(HttpMethod.GET)) {
|
|
|
|
|
Map<String, Object> bodyParam = new HashMap<String, Object>();
|
|
|
|
|
Enumeration pNames = request.getParameterNames();
|
|
|
|
|
while (pNames.hasMoreElements()) {
|
|
|
|
|
String name = (String) pNames.nextElement();
|
|
|
|
|
String value = request.getParameter(name);
|
|
|
|
|
bodyParam.put(name, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bodyContent = JSON.toJSONString(bodyParam);
|
|
|
|
|
} else {
|
|
|
|
|
BufferedReader reader = null;
|
|
|
|
|
try {
|
|
|
|
|
reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
|
|
|
|
|
bodyContent = IoUtil.read(reader);
|
|
|
|
|
log.info(bodyContent);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
Enumeration<String> enumeration = request.getHeaderNames();
|
|
|
|
|
while (enumeration.hasMoreElements()) {
|
|
|
|
@ -118,13 +150,13 @@ public class IdcController {
|
|
|
|
|
headers.add(name, value);
|
|
|
|
|
}
|
|
|
|
|
//headers.add("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
|
HttpEntity<String> http = new HttpEntity<>(JSON.toJSONString(bodyParam), headers);
|
|
|
|
|
HttpEntity<String> http = new HttpEntity<>(bodyContent, headers);
|
|
|
|
|
return http;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Resource redirectIamge(HttpServletRequest request, String uri) {
|
|
|
|
|
private byte[] redirectIamge(HttpServletRequest request, HttpServletResponse httpServletResponse, String uri) {
|
|
|
|
|
uri = uri.replace("mapi/", "");
|
|
|
|
|
uri = "http://127.0.0.1:9993/" + uri;
|
|
|
|
|
uri = "http://116.204.106.103:9150/UDI_SPMS_SERVER/" + uri;
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
// HttpEntity<String> httpEntity = buildHeader(request);
|
|
|
|
|
log.info(request.getMethod());
|
|
|
|
@ -153,20 +185,31 @@ public class IdcController {
|
|
|
|
|
|
|
|
|
|
log.info(uri);
|
|
|
|
|
// ResponseEntity<Resource> entity = restTemplate.exchange(uri, HttpMethod.GET, httpEntity, Resource.class);
|
|
|
|
|
ResponseEntity<Resource> responseEntity = restTemplate.exchange(uri,
|
|
|
|
|
HttpMethod.GET, http, Resource.class, new Object[0]);
|
|
|
|
|
// ResponseEntity<Resource> responseEntity = restTemplate.exchange(uri,
|
|
|
|
|
// HttpMethod.GET, http, Resource.class, new Object[0]);
|
|
|
|
|
// ResponseEntity<HttpServletResponse> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, http, HttpServletResponse.class);
|
|
|
|
|
return responseEntity.getBody();
|
|
|
|
|
|
|
|
|
|
ResponseEntity<byte[]> rsp = restTemplate.getForEntity(uri, byte[].class);
|
|
|
|
|
// String targetPath = "D:\\wmslog\\splash-down.png";
|
|
|
|
|
// try {
|
|
|
|
|
// Files.write(Paths.get(targetPath), Objects.requireNonNull(rsp.getBody(),
|
|
|
|
|
// "未获取到下载文件"));
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return rsp.getBody();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject redirect(HttpServletRequest request, String uri) {
|
|
|
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
HttpEntity<String> httpEntity = buildHeader(request);
|
|
|
|
|
log.info(uri);
|
|
|
|
|
uri = uri.replace("mapi/", "");
|
|
|
|
|
uri = "http://127.0.0.1:9993/" + uri;
|
|
|
|
|
uri = "http://116.204.106.103:9150/UDI_SPMS_SERVER/" + uri;
|
|
|
|
|
log.info(uri);
|
|
|
|
|
ResponseEntity<JSONObject> responseBody = null;
|
|
|
|
|
if (request.getMethod().equals("POST"))
|
|
|
|
|