Skip to content

Commit e16eb6a

Browse files
committed
Add okResponseXml
1 parent f949f3e commit e16eb6a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/main/scala/akkahttp/SampleRoutes.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.apache.pekko.actor.{ActorSystem, Props}
66
import org.apache.pekko.http.scaladsl.Http
77
import org.apache.pekko.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
88
import org.apache.pekko.http.scaladsl.model.StatusCodes.InternalServerError
9-
import org.apache.pekko.http.scaladsl.model.{ContentTypes, HttpResponse, StatusCodes}
9+
import org.apache.pekko.http.scaladsl.model.{ContentTypes, HttpEntity, HttpResponse, StatusCodes}
1010
import org.apache.pekko.http.scaladsl.server.*
1111
import org.apache.pekko.http.scaladsl.server.Directives.*
1212
import org.apache.pekko.util.Timeout
@@ -124,21 +124,27 @@ object SampleRoutes extends App with DefaultJsonProtocol with SprayJsonSupport {
124124
// curl -X POST http://localhost:6002/jsonRaw -d '{"account":{"name":"TEST"}}'
125125
// https://stackoverflow.com/questions/77490507/apache-pekko-akka-http-extracted-string-body-from-request-doesnt-have-quo
126126
val jsonRaw: Route =
127-
path("jsonRaw")(
128-
post(
129-
entity(as[String]) {
130-
json =>
131-
println("JSON raw: " + json)
132-
complete(StatusCodes.OK)
133-
}
127+
path("jsonRaw")(
128+
post(
129+
entity(as[String]) {
130+
json =>
131+
println(s"JSON raw: $json")
132+
complete(StatusCodes.OK)
133+
}
134+
)
134135
)
135-
)
136+
137+
val okResponseXml: Route =
138+
path("okResponseXml") {
139+
val minValidXml = "<xml version=\"1.0\"/>"
140+
complete(StatusCodes.OK, HttpEntity(ContentTypes.`text/xml(UTF-8)`, minValidXml))
141+
}
136142

137143
val handleErrors = handleRejections(rejectionHandler) & handleExceptions(exceptionHandler)
138144

139145
val routes = {
140146
handleErrors {
141-
concat(getFromBrowsableDir, parseFormData, getFromDocRoot, getFromFaultyActor, acceptAll, jsonRaw)
147+
concat(getFromBrowsableDir, parseFormData, getFromDocRoot, getFromFaultyActor, acceptAll, jsonRaw, okResponseXml)
142148
}
143149
}
144150

0 commit comments

Comments
 (0)