{"action":"created","issue":{"url":"https://api.github.com/repos/playframework-ja/translation-project/issues/952","labels_url":"https://api.github.com/repos/playframework-ja/translation-project/issues/952/labels{/name}","comments_url":"https://api.github.com/repos/playframework-ja/translation-project/issues/952/comments","events_url":"https://api.github.com/repos/playframework-ja/translation-project/issues/952/events","html_url":"https://github.com/playframework-ja/translation-project/issues/952","id":46186662,"number":952,"title":"manual/javaGuide/main/http/JavaBodyParsers.md","user":{"login":"garbagetown","id":78121,"avatar_url":"https://avatars.githubusercontent.com/u/78121?v=3","gravatar_id":"","url":"https://api.github.com/users/garbagetown","html_url":"https://github.com/garbagetown","followers_url":"https://api.github.com/users/garbagetown/followers","following_url":"https://api.github.com/users/garbagetown/following{/other_user}","gists_url":"https://api.github.com/users/garbagetown/gists{/gist_id}","starred_url":"https://api.github.com/users/garbagetown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garbagetown/subscriptions","organizations_url":"https://api.github.com/users/garbagetown/orgs","repos_url":"https://api.github.com/users/garbagetown/repos","events_url":"https://api.github.com/users/garbagetown/events{/privacy}","received_events_url":"https://api.github.com/users/garbagetown/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/playframework-ja/translation-project/labels/update","name":"update","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/playframework-ja/translation-project/milestones/16","html_url":"https://github.com/playframework-ja/translation-project/milestones/2.3.5","labels_url":"https://api.github.com/repos/playframework-ja/translation-project/milestones/16/labels","id":796584,"number":16,"title":"2.3.5","description":"2.2.0 から 2.3.5 の間に更新された内容を翻訳して 2.3.x ブランチに反映します。完了後、2.3.x ブランチを 2.3.5 としてタグ付けします。\r\n\r\n本来は 2.3.0〜2.3.4 も翻訳してタグ付けしたいところですが、たぶん誰も読まないので省略します。","creator":{"login":"garbagetown","id":78121,"avatar_url":"https://avatars.githubusercontent.com/u/78121?v=3","gravatar_id":"","url":"https://api.github.com/users/garbagetown","html_url":"https://github.com/garbagetown","followers_url":"https://api.github.com/users/garbagetown/followers","following_url":"https://api.github.com/users/garbagetown/following{/other_user}","gists_url":"https://api.github.com/users/garbagetown/gists{/gist_id}","starred_url":"https://api.github.com/users/garbagetown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garbagetown/subscriptions","organizations_url":"https://api.github.com/users/garbagetown/orgs","repos_url":"https://api.github.com/users/garbagetown/repos","events_url":"https://api.github.com/users/garbagetown/events{/privacy}","received_events_url":"https://api.github.com/users/garbagetown/received_events","type":"User","site_admin":false},"open_issues":82,"closed_issues":103,"state":"open","created_at":"2014-09-20T07:54:31Z","updated_at":"2015-02-27T22:41:29Z","due_on":"2014-12-31T08:00:00Z","closed_at":null},"comments":2,"created_at":"2014-10-18T20:28:41Z","updated_at":"2015-02-27T22:41:29Z","closed_at":"2015-02-27T22:41:29Z","body":"- https://github.com/playframework-ja/translation-project/tree/2.3.5/manual/javaGuide/main/http/JavaBodyParsers.md\n- diffs between [2.2.0/manual/javaGuide/main/http/JavaBodyParsers.md](https://github.com/playframework-ja/translation-project/tree/2.2.0/manual/javaGuide/main/http/JavaBodyParsers.md) and [2.3.5/manual/javaGuide/main/http/JavaBodyParsers.md](https://github.com/playframework-ja/translation-project/tree/2.3.5/manual/javaGuide/main/http/JavaBodyParsers.md).\n```\n--- /Users/garbagetown/Desktop/2.2.0/manual/javaGuide/main/http/JavaBodyParsers.md\t2013-09-19 10:11:22.000000000 +0900\n+++ //Users/garbagetown/Desktop/2.3.5/manual/javaGuide/main/http/JavaBodyParsers.md\t2014-08-12 10:21:26.000000000 +0900\n@@ -1,49 +1,33 @@\n+<!--- Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> -->\n # Body parsers\n \n ## What is a body parser?\n \n An HTTP request (at least for those using the POST and PUT operations) contains a body. This body can be formatted with any format specified in the Content-Type header. A **body parser** transforms this request body into a Java value. \n \n-> **Note:** You can't write `BodyParser` implementation directly using Java. Because a Play `BodyParser` must handle the body content incrementaly using an `Iteratee[Array[Byte], A]` it must be implemented in Scala.\n+> **Note:** You can't write `BodyParser` implementation directly using Java. Because a Play `BodyParser` must handle the body content incrementally using an `Iteratee[Array[Byte], A]` it must be implemented in Scala.\n >\n > However Play provides default `BodyParser`s that should fit most use cases (parsing Json, Xml, Text, uploading files). And you can reuse these default parsers to create your own directly in Java; for example you can provide an RDF parsers based on the Text one.\n \n ## The `BodyParser` Java API\n \n+When working with request bodies, ensure that have the following imports in your controller:\n+\n+@[imports](code/javaguide/http/JavaBodyParsers.java)\n+\n In the Java API, all body parsers must generate a `play.mvc.Http.RequestBody` value. This value computed by the body parser can then be retrieved via `request().body()`:\n \n-'''java\n-public static Result index() {\n-  RequestBody body = request().body();\n-  return ok(\"Got body: \" + body);\n-}\n-'''\n+@[request-body](code/javaguide/http/JavaBodyParsers.java)\n \n You can specify the `BodyParser` to use for a particular action using the `@BodyParser.Of` annotation:\n \n-'''java\n-@BodyParser.Of(BodyParser.Json.class)\n-public static Result index() {\n-  RequestBody body = request().body();\n-  return ok(\"Got json: \" + body.asJson());\n-}\n-'''\n+@[particular-body-parser](code/javaguide/http/JavaBodyParsers.java)\n \n ## The `Http.RequestBody` API\n \n As we just said all body parsers in the Java API will give you a `play.mvc.Http.RequestBody` value. From this body object you can retrieve the request body content in the most appropriate Java type.\n \n-> **Note:** The `RequestBody` methods like `asText()` or `asJson()` will return null if the parser used to compute this request body doesn't support this content type. For example in an action method annotated with `@BodyParser.Of(BodyParser.Json.class)`, calling `asXml()` on the generated body will retun null.\n-\n-Some parsers can provide a most specific type than `Http.RequestBody` (ie. a subclass of `Http.RequestBody`). You can automatically cast the request body into another type using the `as(...)` helper method:\n-\n-'''java\n-@BodyParser.Of(BodyLengthParser.class)\n-public static Result index() {\n-  BodyLength body = request().body().as(BodyLength.class);\n-  ok(\"Request body length: \" + body.getLength());\n-}\n-'''\n+> **Note:** The `RequestBody` methods like `asText()` or `asJson()` will return `null` if the parser used to compute this request body doesn't support this content type. For example in an action method annotated with `@BodyParser.Of(BodyParser.Json.class)`, calling `asXml()` on the generated body will return `null`.\n \n ## Default body parser: AnyContent\n \n@@ -56,44 +40,20 @@\n - **multipart/form-data**: `Http.MultipartFormData`, accessible via `asMultipartFormData()`\n - Any other content type: `Http.RawBuffer`, accessible via `asRaw()`\n \n-Example:\n+For example:\n \n-'''java\n-public static Result save() {\n-  RequestBody body = request().body();\n-  String textBody = body.asText();\n-  \n-  if(textBody != null) {\n-    ok(\"Got: \" + text);\n-  } else {\n-    badRequest(\"Expecting text/plain request body\");\n-  }\n-}\n-'''\n+@[default-parser](code/javaguide/http/JavaBodyParsers.java)\n \n ## Max content length\n \n Text based body parsers (such as **text**, **json**, **xml** or **formUrlEncoded**) use a max content length because they have to load all the content into memory. \n \n-There is a default content length (the default is 100KB). \n-\n-> **Tip:** The default content size can be defined in `application.conf`:\n-> \n-> `parsers.text.maxLength=128K`\n+There is a default maximum content length of 100KB.  It can be overridden by specifying the `parsers.text.maxLength` property in `application.conf`:\n \n+    parsers.text.maxLength=128K\n \n You can also specify a maximum content length via the `@BodyParser.Of` annotation:\n \n-'''java\n-// Accept only 10KB of data.\n-@BodyParser.Of(value = BodyParser.Text.class, maxLength = 10 * 1024)\n-public static Result index() {\n-  if(request().body().isMaxSizeExceeded()) {\n-    return badRequest(\"Too much data!\");\n-  } else {\n-    ok(\"Got body: \" + request().body().asText()); \n-  }\n-}\n-'''\n+@[max-length](code/javaguide/http/JavaBodyParsers.java)\n \n > **Next:** [[Actions composition | JavaActionsComposition]]\n\n```"},"comment":{"url":"https://api.github.com/repos/playframework-ja/translation-project/issues/comments/76486410","html_url":"https://github.com/playframework-ja/translation-project/issues/952#issuecomment-76486410","issue_url":"https://api.github.com/repos/playframework-ja/translation-project/issues/952","id":76486410,"user":{"login":"garbagetown","id":78121,"avatar_url":"https://avatars.githubusercontent.com/u/78121?v=3","gravatar_id":"","url":"https://api.github.com/users/garbagetown","html_url":"https://github.com/garbagetown","followers_url":"https://api.github.com/users/garbagetown/followers","following_url":"https://api.github.com/users/garbagetown/following{/other_user}","gists_url":"https://api.github.com/users/garbagetown/gists{/gist_id}","starred_url":"https://api.github.com/users/garbagetown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garbagetown/subscriptions","organizations_url":"https://api.github.com/users/garbagetown/orgs","repos_url":"https://api.github.com/users/garbagetown/repos","events_url":"https://api.github.com/users/garbagetown/events{/privacy}","received_events_url":"https://api.github.com/users/garbagetown/received_events","type":"User","site_admin":false},"created_at":"2015-02-27T22:41:28Z","updated_at":"2015-02-27T22:41:28Z","body":"merged #1126 "}}