-
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.
- Loading branch information
Showing
1 changed file
with
14 additions
and
18 deletions.
There are no files selected for viewing
32 changes: 14 additions & 18 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 |
---|---|---|
@@ -1,32 +1,28 @@ | ||
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 final int MAX_BODY_SIZE = 10; // Move to a common utility class | ||
public static boolean logBody = true; | ||
|
||
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]"; | ||
} | ||
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; | ||
} | ||
// 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; | ||
} | ||
|
||
} |