-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save body only if it is under the max limit otherwise add an error me…
…ssage explaining this
- Loading branch information
Showing
9 changed files
with
199 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
moesif-servlet/src/main/java/com/moesif/servlet/wrappers/BodyHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.moesif.servlet.wrappers; | ||
import org.apache.commons.io.output.ByteArrayOutputStream; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class BodyHandler { | ||
|
||
public static boolean logBody = true; | ||
public static final int MAX_BODY_SIZE = 10; // Move to a common utility class | ||
|
||
public static String encodeContent(byte[] content, String encoding) { | ||
try { | ||
return new String(content, encoding != null ? encoding : StandardCharsets.UTF_8.name()); | ||
} catch (UnsupportedEncodingException e) { | ||
return "[UNSUPPORTED ENCODING]"; | ||
} | ||
} | ||
|
||
// a method that returns a simple java map representing an error message for large body meant to be serialized into json | ||
public static Map<String, String> getLargeBodyError(long contentLength) { | ||
Map<String, String> error = new HashMap<>(); | ||
error.put("msg", "request.body.length " + contentLength + " exceeded requestMaxBodySize of " + MAX_BODY_SIZE + " bytes"); | ||
return error; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.