All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.aguacate.http.impl.HttpBodyParserImpl Maven / Gradle / Ivy

There is a newer version: 0.10.9
Show newest version
package net.sf.aguacate.http.impl;

import java.io.IOException;
import java.io.Reader;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.sf.aguacate.http.HttpBodyParser;
import net.sf.aguacate.util.codec.bridge.CodecCoupling;

public class HttpBodyParserImpl implements HttpBodyParser {

	private static final Logger LOGGER = LogManager.getLogger(HttpBodyParserImpl.class);

	private static final String MIME_TYPE = "application/json";

	@Override
	public Map parse(HttpServletRequest request) throws IOException {
		String contentType = request.getContentType().toLowerCase();
		if (contentType.startsWith(MIME_TYPE)) {
			Reader reader = request.getReader();
			try {
				return CodecCoupling.jsonCodecBridge().decodeMap(reader);
			} finally {
				try {
					reader.close();
				} catch (IOException e) {
					LOGGER.error("On closing reader", e);
				}
			}
		} else {
			throw new IllegalArgumentException(contentType);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy