alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (BodyParser.java)

This example Play Framework source code file (BodyParser.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

anycontent, bodyparser, bodyparser's, empty, illegalargumentexception, json, mvc, of, play, play framework, target, text, tolerantjson, tolerantxml

The BodyParser.java Play Framework example source code

/*
 * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
 */
package play.mvc;

import java.lang.annotation.*;

/**
 * A body parser parses the HTTP request body content.
 */
public interface BodyParser {

    play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength);

    /**
     * Specify the body parser to use for an Action method.
     */
    @Target({ElementType.TYPE, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface Of {
        Class<? extends BodyParser> value();
        int maxLength() default -1;
    }

    /**
     * Guess the body content by checking the Content-Type header.
     */
    public static class AnyContent implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.anyContent(maxLength);
        }
    }

    /**
     * Parse the body as Json if the Content-Type is text/json or application/json.
     */
    public static class Json implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.json(maxLength);
        }
    }

    /**
     * Parse the body as Json without checking the Content-Type.
     */
    public static class TolerantJson implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.tolerantJson(maxLength);
        }
    }

    /**
     * Parse the body as Xml if the Content-Type is application/xml.
     */
    public static class Xml implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.xml(maxLength);
        }
    }

    /**
     * Parse the body as Xml without checking the Content-Type.
     */
    public static class TolerantXml implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.tolerantXml(maxLength);
        }
    }

    /**
     * Parse the body as text if the Content-Type is text/plain.
     */
    public static class Text implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.text(maxLength);
        }
    }

    /**
     * Parse the body as text without checking the Content-Type.
     */
    public static class TolerantText implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.tolerantText(maxLength);
        }
    }

    /**
     * Store the body content in a RawBuffer.
     */
    public static class Raw implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.raw(maxLength);
        }
    }

    /**
     * Parse the body as form url encoded if the Content-Type is application/x-www-form-urlencoded.
     */
    public static class FormUrlEncoded implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.formUrlEncoded(maxLength);
        }
    }

    /**
     * Parse the body as form url encoded without checking the Content-Type.
     */
    public static class MultipartFormData implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            return play.core.j.JavaParsers.multipartFormData(maxLength);
        }
    }

    /**
     * Don't parse the body.
     */
    public static class Empty implements BodyParser {
        public play.api.mvc.BodyParser<Http.RequestBody> parser(int maxLength) {
            if (maxLength != -1) throw new IllegalArgumentException("Empty BodyParser's maxLength argument is ignored so it must have a value of -1, was: " + maxLength);
            return play.core.j.JavaParsers.empty();
        }
    }

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework BodyParser.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.