def sbuRoute: Route = path("si" / "telocmdm" / "locationservices" / "location" / Segment / Segment / "businessunits" / IntNumber) { (country, businessUnit, store) =>
get {
extractRequest { req =>
log.debug(s"received sbu request, ${req.method} ${req.uri} ${country} ${businessUnit} ${store} ${req.headers} ")
req.headers.map(x => log.debug(x.name()))
val hdrs = req.headers.filter(header => (header.isNot("timeout-access") && header.isNot("host")))
hdrs.map(x => log.debug(x.name()))
val sbuUri = s"${sbuHost}/si/telocmdm/locationservices/location/${country}/${businessUnit}/businessunits/${storeMap.getOrElse(store, store).toString}"
val responseFuture = http
.singleRequest(request = HttpRequest(uri = Uri(sbuUri).withRawQueryString(req.uri.rawQueryString.getOrElse("")), headers = hdrs), connectionContext = httpsCtx)
.flatMap(response => response.entity.dataBytes.runReduce(_ ++ _))
onComplete(responseFuture) {
case Success(resp) => complete {
val st = resp.decodeString(StandardCharsets.UTF_8).replace("5585", store.toString)
log.debug("response is " + st)
HttpEntity(ContentTypes.`application/json`, st)
}
case Failure(ex) => complete {
ex.printStackTrace()
log.error(ex, ex.getMessage)
(StatusCodes.InternalServerError, s"An error occurred: ${ex.getMessage}")
}
}
}
}
Hi Team, Can you please help me how to transfer the response with chunked response “Transfer-Encoding:Chunked” ? The above code works fine in terminal with curl command but not working in postman. Further checking that the HttpEntity is not returning the response properly.