|
|
|
@ -1,37 +1,37 @@
|
|
|
|
|
package com.glxp.sale.admin.idc.controller;
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
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.RestTemplate;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
import cn.hutool.http.HttpResponse;
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.glxp.sale.admin.idc.dao.DbDao;
|
|
|
|
|
import com.glxp.sale.admin.idc.service.IdcService;
|
|
|
|
|
import com.glxp.sale.admin.idc.utils.UriUtils;
|
|
|
|
|
import com.glxp.sale.admin.service.param.SystemParamConfigService;
|
|
|
|
|
import com.glxp.sale.admin.util.MyStrUtil;
|
|
|
|
|
import com.glxp.sale.common.res.BaseResponse;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
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.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -149,6 +149,7 @@ public class IdcController {
|
|
|
|
|
if (StrUtil.isNotEmpty(upperServerHost)) {
|
|
|
|
|
uri = upperServerHost + "/" + uri;
|
|
|
|
|
}
|
|
|
|
|
uri = changeUri(uri);
|
|
|
|
|
log.info(uri);
|
|
|
|
|
if (uri.contains("getImage")) {
|
|
|
|
|
return redirectIamge(request, httpServletResponse, uri);
|
|
|
|
@ -157,6 +158,67 @@ public class IdcController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @RequestMapping("/dirImages/**")
|
|
|
|
|
// public void images(HttpServletRequest request, HttpServletResponse httpServletResponse) {
|
|
|
|
|
// String uri = uriUtils.parseUri(request.getRequestURL().toString());
|
|
|
|
|
//
|
|
|
|
|
// log.info(uri);
|
|
|
|
|
// String imageHost = "http://192.168.0.66:9000";
|
|
|
|
|
// String url = "";
|
|
|
|
|
//// systemParamConfigService.selectValueByParamKey("is_top_service");
|
|
|
|
|
// if (StrUtil.isNotEmpty(imageHost)) {
|
|
|
|
|
// String prefix = "dirImages/";
|
|
|
|
|
// url = (imageHost.substring(imageHost.length() - 1) == "/" ? imageHost : imageHost + "/")
|
|
|
|
|
// + uri.substring(uri.indexOf(prefix) + prefix.length());
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// log.info(url);
|
|
|
|
|
// redirectIamge2(request, httpServletResponse, url);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public String changeUri(String uri) {
|
|
|
|
|
String isTopService = systemParamConfigService.selectValueByParamKey("is_top_service");
|
|
|
|
|
if (StrUtil.isNotEmpty(isTopService) && isTopService.equals("1")) {
|
|
|
|
|
if (uri.contains("SP_SYNC_SERVER")) {
|
|
|
|
|
uri = uri.replace("SP_SYNC_SERVER/", "");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
uri = MyStrUtil.deDup(uri);
|
|
|
|
|
}
|
|
|
|
|
log.error("changeUri = " + uri);
|
|
|
|
|
return uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void redirectIamge2(HttpServletRequest request, HttpServletResponse httpServletResponse, String uri) {
|
|
|
|
|
HttpRequest result = HttpUtil.createGet(uri);
|
|
|
|
|
HttpResponse execute = result.execute();
|
|
|
|
|
execute.headers().forEach((k, v) -> {
|
|
|
|
|
httpServletResponse.setHeader(k, v.get(0));
|
|
|
|
|
});
|
|
|
|
|
ServletOutputStream outputStream = null;
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
outputStream = httpServletResponse.getOutputStream();
|
|
|
|
|
inputStream = execute.bodyStream();
|
|
|
|
|
outputStream.write(inputStream.readAllBytes());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (outputStream != null)
|
|
|
|
|
outputStream.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if (inputStream != null)
|
|
|
|
|
inputStream.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte[] redirectIamge(HttpServletRequest request, HttpServletResponse httpServletResponse, String uri) {
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|