MyDispatcherServlet.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.example.config.web;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.springframework.web.servlet.DispatcherServlet;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import java.util.Set;
  7. import java.util.stream.Collectors;
  8. import java.util.stream.Stream;
  9. @Slf4j
  10. public class MyDispatcherServlet extends DispatcherServlet {
  11. /**
  12. * 上传和返回文件流的接口uri,不替换request和response
  13. */
  14. public static final Set<String> UN_WRAPPER = Stream.of(
  15. "/house-car/house/dist/api/data-import/dataImport",
  16. "/house-car/house/dist/api/WzBuildManageDetails/ideListExport",
  17. "/house-car/house/dist/api/WzBuildManageDetails/queryHouseDetailExport",
  18. "/house-car/house/dist/api/WzBuildManageDetails/queryHouseYearExport",
  19. "/house-car/house/dist/api/WzBuildManageDetails/buildingIdleStatExport",
  20. "/house-car/house/dist/api/wzHouseMaintenaCost/queryHighPriceExport",
  21. "/house-car/house/dist/api/wzHouseMaintenaCost/queryHighFrequencyExport",
  22. "/house-car/house/dist/api/wzHouseMaintenaCost/queryDailyModifyExport",
  23. "/house-car/house/dist/api/wzHouseMaintenaCost/buildingIdleRepairExport",
  24. "/house-car/house/dist/api/wzHouseMaintenaCost/buildingRepairStatExport",
  25. "/house-car/house/dist/api/wzHouseMaintenaCost/listBuildingRepairMonthExport",
  26. "/house-car/house/dist/api/siteStat/siteStatExport",
  27. "/house-car/house/dist/api/WzBuildmanageAvagearea/buildingOfficeAreaStatExport",
  28. "/house-car/house/dist/api/WzBuildManageDetails/excel",
  29. "/house-car/house/dist/api/WzHouseContractOut/excel",
  30. "/house-car/house/dist/api/WzHouseContrac/excel",
  31. "/house-car/house/dist/api/WzHouseLeaseInCon/excel",
  32. "/house-car/house/dist/api/wzHouseMaintenaCost/excel",
  33. "/house-car/house/dist/api/WzHouseUse/excel",
  34. "/house-car/house/dist/api/WzLandManageDetails/excel",
  35. "/house-car/house/dist/api/wzLowestUnitPrice/excel",
  36. "/house-car/house/dist/api/wzRentHouseArrears/excel",
  37. "/house-car/house/dist/api/wzRentThreeMonth/excel",
  38. "/house-car/house/dist/api/wzScoreRanking/excel",
  39. "/house-car/house/dist/api/WzBuildManageDetails/loadWord"
  40. ).collect(Collectors.toSet());
  41. @Override
  42. protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
  43. String uri = request.getRequestURI();
  44. if (UN_WRAPPER.contains(request.getRequestURI())) {
  45. super.doDispatch(request, response);
  46. } else {
  47. // 替换request和response
  48. log.info("替换 {} 的request和response", uri);
  49. super.doDispatch(new MyHttpServletRequestWrapper(request), new MyHttpServletResponseWrapper(response));
  50. }
  51. }
  52. }