Hi Team, I am facing the issue of unsupported media type while executing this below code. Need your help .
code
def girserviceRoute: Route = path("girservice" / "globalitemrules" / "locationrules" / "v1" / "us" / "Walmart") {
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()))
val girServiceUri = s"${girServiceHost}/girservice/globalitemrules/locationrules/v1/us/Walmart"
val responseFuture = http
.singleRequest(
request = HttpRequest(method = HttpMethods.POST, uri = Uri(girServiceUri).withRawQueryString(req.uri.rawQueryString.getOrElse("")),
headers = hdrs,
entity = HttpEntity(reqData)),
connectionContext = httpsCtx)
.flatMap(response => response.entity.dataBytes.runReduce(_ ++ _))
onComplete(responseFuture) {
case Success(resp) => complete {
val st = resp.decodeString(StandardCharsets.UTF_8).replace("5585", "")
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}")
}
}
}
}
}
}
and the Error message Runtime.
<html><head><title>Apache Tomcat/7.0.82 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size: 22px;
} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size: 16px;
} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size: 14px;
} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;
} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;
} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size: 12px;
}A {color : black;
}A.name {color : black;
}HR {color : #525D76;
}--></style> </head><body><h1>HTTP Status 415 - Unsupported Media Type</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Unsupported Media Type</u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.82</h3></body></html>