From c3de69dc956dc9c8c39b050cbc957abe0a51931b Mon Sep 17 00:00:00 2001 From: wj <1285151836@qq.com> Date: Fri, 12 May 2023 16:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/idc/controller/IdcController.java | 98 ++++++++++++++----- 1 file changed, 73 insertions(+), 25 deletions(-) diff --git a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java index f80e0dc..7994ed9 100644 --- a/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java +++ b/api-admin/src/main/java/com/glxp/sale/admin/idc/controller/IdcController.java @@ -1,38 +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 com.glxp.sale.admin.util.MyStrUtil; -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; /** @@ -159,6 +158,24 @@ 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")) { @@ -172,6 +189,37 @@ public class IdcController { 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(); // HttpEntity httpEntity = buildHeader(request);