diff --git a/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HighLevelServerExample.java b/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HighLevelServerExample.java index 9b471fcaba..3a276f0bab 100644 --- a/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HighLevelServerExample.java +++ b/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HighLevelServerExample.java @@ -6,6 +6,7 @@ package docs.http.javadsl.server; //#high-level-server-example import akka.actor.ActorSystem; +import akka.http.javadsl.model.ContentTypes; import akka.http.javadsl.model.MediaTypes; import akka.http.javadsl.server.*; import akka.http.javadsl.server.values.Parameters; @@ -50,7 +51,7 @@ public class HighLevelServerExample extends HttpApp { // matches the empty path pathSingleSlash().route( // return a constant string with a certain content type - complete(MediaTypes.TEXT_HTML.toContentType(), + complete(ContentTypes.TEXT_HTML, "Hello world!") ), path("ping").route( diff --git a/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HttpServerExampleDocTest.java b/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HttpServerExampleDocTest.java index 3d44d6ecf5..7a40c9c906 100644 --- a/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HttpServerExampleDocTest.java +++ b/akka-docs-dev/rst/java/code/docs/http/javadsl/server/HttpServerExampleDocTest.java @@ -72,7 +72,7 @@ public class HttpServerExampleDocTest { if (uri.path().equals("/")) return HttpResponse.create() - .withEntity(MediaTypes.TEXT_HTML.toContentType(), + .withEntity(ContentTypes.TEXT_HTML, "Hello world!"); else if (uri.path().equals("/hello")) { String name = Util.getOrElse(uri.parameter("name"), "Mister X"); diff --git a/akka-http-core/src/main/java/akka/http/javadsl/model/ContentTypes.java b/akka-http-core/src/main/java/akka/http/javadsl/model/ContentTypes.java new file mode 100644 index 0000000000..d212b04c1e --- /dev/null +++ b/akka-http-core/src/main/java/akka/http/javadsl/model/ContentTypes.java @@ -0,0 +1,21 @@ +/** + * Copyright (C) 2009-2015 Typesafe Inc. + */ +package akka.http.javadsl.model; + + +/** + * Contains the set of predefined content-types. + *

+ * If the {@link ContentType} you're looking for is not pre-defined here, + * you can obtain it from a {@link MediaType} by using: + *

+ * {@code MediaTypes.TEXT_HTML.toContentType()} + */ +public final class ContentTypes { + public static final ContentType APPLICATION_JSON = MediaTypes.APPLICATION_JSON.toContentType(); + public static final ContentType TEXT_PLAIN = MediaTypes.TEXT_PLAIN.toContentType(); + public static final ContentType TEXT_PLAIN_UTF8 = akka.http.scaladsl.model.ContentTypes.text$divplain$u0028UTF$minus8$u0029(); + public static final ContentType TEXT_HTML = MediaTypes.TEXT_HTML.toContentType(); + public static final ContentType APPLICATION_OCTET_STREAM = MediaTypes.APPLICATION_OCTET_STREAM.toContentType(); +} diff --git a/akka-http-core/src/main/scala/akka/http/scaladsl/model/ContentType.scala b/akka-http-core/src/main/scala/akka/http/scaladsl/model/ContentType.scala index 25fc0b6b80..8781803933 100644 --- a/akka-http-core/src/main/scala/akka/http/scaladsl/model/ContentType.scala +++ b/akka-http-core/src/main/scala/akka/http/scaladsl/model/ContentType.scala @@ -92,6 +92,7 @@ object ContentTypes { val `application/json` = ContentType(MediaTypes.`application/json`) val `text/plain` = ContentType(MediaTypes.`text/plain`) val `text/plain(UTF-8)` = ContentType(MediaTypes.`text/plain`, HttpCharsets.`UTF-8`) + val `text/html` = ContentType(MediaTypes.`text/html`) val `application/octet-stream` = ContentType(MediaTypes.`application/octet-stream`) // used for explicitly suppressing the rendering of Content-Type headers on requests and responses