package com.example.config.web; import lombok.extern.slf4j.Slf4j; import org.springframework.web.servlet.DispatcherServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @Slf4j public class MyDispatcherServlet extends DispatcherServlet { /** * 上传和返回文件流的接口uri,不替换request和response */ public static final Set UN_WRAPPER = Stream.of( "/house-car/house/dist/api/data-import/dataImport", "/house-car/house/dist/api/WzBuildManageDetails/ideListExport", "/house-car/house/dist/api/WzBuildManageDetails/queryHouseDetailExport", "/house-car/house/dist/api/WzBuildManageDetails/queryHouseYearExport", "/house-car/house/dist/api/WzBuildManageDetails/buildingIdleStatExport", "/house-car/house/dist/api/wzHouseMaintenaCost/queryHighPriceExport", "/house-car/house/dist/api/wzHouseMaintenaCost/queryHighFrequencyExport", "/house-car/house/dist/api/wzHouseMaintenaCost/queryDailyModifyExport", "/house-car/house/dist/api/wzHouseMaintenaCost/buildingIdleRepairExport", "/house-car/house/dist/api/wzHouseMaintenaCost/buildingRepairStatExport", "/house-car/house/dist/api/wzHouseMaintenaCost/listBuildingRepairMonthExport", "/house-car/house/dist/api/WzHouseLeaseInCon/rentInContractStatExport", "/house-car/house/dist/api/WzHouseContractIn/listRentInContractExport", "/house-car/house/dist/api/WzHouseUse/rentInUseStatExport", "/house-car/house/dist/api/WzHouseContractTop/listRentInTopExport", "/house-car/house/dist/api/WzHouseContractCompare/listRentInCompareExport", "/house-car/house/dist/api/siteStat/siteStatExport", "/house-car/house/dist/api/WzBuildmanageAvagearea/buildingOfficeAreaStatExport", "/house-car/house/dist/api/WzBuildManageDetails/excel", "/house-car/house/dist/api/WzHouseContractOut/excel", "/house-car/house/dist/api/WzHouseContrac/excel", "/house-car/house/dist/api/WzHouseLeaseInCon/excel", "/house-car/house/dist/api/wzHouseMaintenaCost/excel", "/house-car/house/dist/api/WzHouseUse/excel", "/house-car/house/dist/api/WzLandManageDetails/excel", "/house-car/house/dist/api/wzLowestUnitPrice/excel", "/house-car/house/dist/api/wzRentHouseArrears/excel", "/house-car/house/dist/api/wzRentThreeMonth/excel", "/house-car/house/dist/api/wzScoreRanking/excel", "/house-car/house/dist/api/WzBuildManageDetails/loadWord" ).collect(Collectors.toSet()); @Override protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception { String uri = request.getRequestURI(); if (UN_WRAPPER.contains(request.getRequestURI())) { super.doDispatch(request, response); } else { // 替换request和response log.info("替换 {} 的request和response", uri); super.doDispatch(new MyHttpServletRequestWrapper(request), new MyHttpServletResponseWrapper(response)); } } }