mirror of
https://github.com/google/nomulus.git
synced 2025-05-12 22:38:16 +02:00
Migrate to Flogger (green)
This is a 'green' Flogger migration CL. Green CLs are intended to be as safe as possible and should be easy to review and submit. No changes should be necessary to the code itself prior to submission, but small changes to BUILD files may be required. Changes within files are completely independent of each other, so this CL can be safely split up for review using tools such as Rosie. For more information, see [] Base CL: 197826149 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=198560170
This commit is contained in:
parent
0d2fb3a8f0
commit
70b13596e4
178 changed files with 984 additions and 988 deletions
|
@ -20,7 +20,7 @@ import static com.google.common.net.HttpHeaders.X_CONTENT_TYPE_OPTIONS;
|
|||
import static com.google.common.net.MediaType.JSON_UTF_8;
|
||||
import static org.json.simple.JSONValue.writeJSONString;
|
||||
|
||||
import com.google.common.logging.FormattingLogger;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.common.net.MediaType;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
@ -39,7 +39,7 @@ import org.json.simple.parser.ParseException;
|
|||
*/
|
||||
public final class JsonHttp {
|
||||
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
/** String prefixed to all JSON-like responses. */
|
||||
public static final String JSON_SAFETY_PREFIX = ")]}'\n";
|
||||
|
@ -55,18 +55,18 @@ public final class JsonHttp {
|
|||
public static Map<String, ?> read(HttpServletRequest req) throws IOException {
|
||||
if (!"POST".equals(req.getMethod())
|
||||
&& !"PUT".equals(req.getMethod())) {
|
||||
logger.warning("JSON request payload only allowed for POST/PUT");
|
||||
logger.atWarning().log("JSON request payload only allowed for POST/PUT");
|
||||
return null;
|
||||
}
|
||||
if (!JSON_UTF_8.is(MediaType.parse(req.getContentType()))) {
|
||||
logger.warningfmt("Invalid JSON Content-Type: %s", req.getContentType());
|
||||
logger.atWarning().log("Invalid JSON Content-Type: %s", req.getContentType());
|
||||
return null;
|
||||
}
|
||||
try (Reader jsonReader = req.getReader()) {
|
||||
try {
|
||||
return checkNotNull((Map<String, ?>) JSONValue.parseWithException(jsonReader));
|
||||
} catch (ParseException | NullPointerException | ClassCastException e) {
|
||||
logger.warning(e, "Malformed JSON");
|
||||
logger.atWarning().withCause(e).log("Malformed JSON");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue