def seqServiceRoute: Route = path("api" / "v1" / "sequences" / "commodities" ) {
post {
entity(as[String]) { reqData =>
extractRequest { req =>
log.debug(s"received sbu request, ${req.method} ${req.uri} ${req.headers} ${req.entity}")
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()))
hdrs.map(x => x.name() match
{
case "X-nodeId" => x.value().replace("30001","5585")
case _ => x
})
val seqServiceUri = s"${seqHost}/api/v1/sequences/commodities"
val responseFuture = http
.singleRequest(
request = HttpRequest(method= HttpMethods.POST, uri = Uri(seqServiceUri).withRawQueryString(req.uri.rawQueryString.getOrElse("")),
headers = hdrs,
entity = HttpEntity(ContentTypes.`application/json`,reqData)),
connectionContext = httpsCtx)
.flatMap(response => response.entity.dataBytes.runReduce(_ ++ _))
onComplete(responseFuture) {
case Success(resp) => complete {
log.debug("response is " + resp)
HttpEntity(ContentTypes.`application/json`, resp)
}
case Failure(ex) => complete {
ex.printStackTrace()
log.error(ex, ex.getMessage)
(StatusCodes.InternalServerError, s"An error occurred: ${ex.getMessage}")
}
}
}
}
}
HI Team, I am trying to replace one of the header value but it is not working. I tried the statement.
case “X-nodeId” => x.value().replace(“30001”,“5585”)
But it seems not working in the HTTPEntity. Can someone please help?