@@ -6,7 +6,7 @@ import org.apache.pekko.actor.{ActorSystem, Props}
6
6
import org .apache .pekko .http .scaladsl .Http
7
7
import org .apache .pekko .http .scaladsl .marshallers .sprayjson .SprayJsonSupport
8
8
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 }
10
10
import org .apache .pekko .http .scaladsl .server .*
11
11
import org .apache .pekko .http .scaladsl .server .Directives .*
12
12
import org .apache .pekko .util .Timeout
@@ -124,21 +124,27 @@ object SampleRoutes extends App with DefaultJsonProtocol with SprayJsonSupport {
124
124
// curl -X POST http://localhost:6002/jsonRaw -d '{"account":{"name":"TEST"}}'
125
125
// https://stackoverflow.com/questions/77490507/apache-pekko-akka-http-extracted-string-body-from-request-doesnt-have-quo
126
126
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
+ )
134
135
)
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
+ }
136
142
137
143
val handleErrors = handleRejections(rejectionHandler) & handleExceptions(exceptionHandler)
138
144
139
145
val routes = {
140
146
handleErrors {
141
- concat(getFromBrowsableDir, parseFormData, getFromDocRoot, getFromFaultyActor, acceptAll, jsonRaw)
147
+ concat(getFromBrowsableDir, parseFormData, getFromDocRoot, getFromFaultyActor, acceptAll, jsonRaw, okResponseXml )
142
148
}
143
149
}
144
150
0 commit comments