@@ -95,6 +95,34 @@ public static void solveHttpRequest(Object obj, Object req, Object resp, Map<Str
9595 } catch (Throwable ignore ) {
9696 }
9797
98+ try {
99+ String contentType = ((Map <String , String >) requestMeta .get ("headers" )).get ("Content-Type" );
100+ String method = (String ) requestMeta .get ("method" );
101+ if (("POST" .equalsIgnoreCase (method ) || "PUT" .equalsIgnoreCase (method ))
102+ && !isRawBody (contentType )) {
103+ Method getParameterNamesMethod = ReflectUtils .getDeclaredMethodFromSuperClass (req .getClass (),
104+ "getParameterNames" , null );
105+ Method getParameterMethod = ReflectUtils .getDeclaredMethodFromSuperClass (req .getClass (),
106+ "getParameter" , new Class []{String .class });
107+ Enumeration <?> parameterNames = (Enumeration <?>) getParameterNamesMethod .invoke (req );
108+ StringBuilder postBody = new StringBuilder ();
109+ boolean first = true ;
110+ while (parameterNames .hasMoreElements ()) {
111+ String key = (String ) parameterNames .nextElement ();
112+ if (first ) {
113+ first = false ;
114+ postBody .append (key ).append ("=" ).append ((String ) getParameterMethod .invoke (req , key ));
115+ } else {
116+ postBody .append ("&" ).append (key ).append ("=" ).append ((String ) getParameterMethod .invoke (req , key ));
117+ }
118+ }
119+ if (postBody .length () > 0 ) {
120+ requestMeta .put ("body" , postBody .toString ());
121+ }
122+ }
123+ } catch (Throwable ignore ) {
124+ }
125+
98126 EngineManager .enterHttpEntry (requestMeta );
99127 DongTaiLog .debug ("HTTP Request:{} {} from: {}" , requestMeta .get ("method" ), requestMeta .get ("requestURI" ),
100128 obj .getClass ().getName ());
@@ -111,6 +139,9 @@ public static Map<String, String> parseRequestHeaders(Object req, Enumeration<?>
111139 try {
112140 String key = (String ) headerNames .nextElement ();
113141 String val = (String ) getHeaderMethod .invoke (req , key );
142+ if ("content-type" .equalsIgnoreCase (key )) {
143+ key = "Content-Type" ;
144+ }
114145 headers .put (key , val );
115146 } catch (Throwable ignore ) {
116147 }
@@ -119,6 +150,13 @@ public static Map<String, String> parseRequestHeaders(Object req, Enumeration<?>
119150 }
120151
121152 public static void onServletInputStreamRead (int ret , String desc , Object stream , byte [] bs , int offset , int len ) {
153+ if (EngineManager .REQUEST_CONTEXT .get () != null
154+ && EngineManager .REQUEST_CONTEXT .get ().get ("body" ) != null
155+ && EngineManager .REQUEST_CONTEXT .get ().get ("body" ) != ""
156+ ) {
157+ return ;
158+ }
159+
122160 if ("()I" .equals (desc )) {
123161 if (ret == -1 ) {
124162 return ;
@@ -218,4 +256,9 @@ public static void onServletOutputStreamWrite(String desc, Object stream, int b,
218256 public static IastClassLoader getClassLoader () {
219257 return iastClassLoader ;
220258 }
259+
260+ public static boolean isRawBody (String contentType ) {
261+ return contentType != null
262+ && (contentType .contains ("application/json" ) || contentType .contains ("application/xml" ));
263+ }
221264}
0 commit comments