I've a trait:
trait OAuthService {
def sendWithAuthorizationQueryParams[A](request: OAuthRequest)(implicit unmarshaller: Unmarshaller[ResponseEntity, A]): Future[A] = {
val httpRequest = request.toHttpRequestWithAuthorizationQueryParams
sendAndReceive(httpRequest, request.signature)
}
def sendWithAuthorizationHeader[A](request: OAuthRequest)(implicit unmarshaller: Unmarshaller[ResponseEntity, A]): Future[A] = {
val httpRequest = request.toHttpRequestWithAuthorizationHeader
sendAndReceive(httpRequest, request.signature)
}
protected def sendAndReceive[A](httpRequest: HttpRequest, id: String)(implicit unmarshaller: Unmarshaller[ResponseEntity, A]): Future[A]
}
I'm creating a subclass:
class StreamingOAuthService()(implicit val actorPlumbing: ActorPlumbing) extends OAuthService {
private val log = LoggerFactory.getLogger(getClass())
override protected def sendAndReceive[A](httpRequest: HttpRequest, id: String)(implicit unmarshaller: Unmarshaller[ResponseEntity, A]) = {
log.debug(s"Http request: {}.", httpRequest)
import actorPlumbing._
val host = httpRequest.uri.authority.host.address()
val connectionFlow: Flow[HttpRequest, HttpResponse, Future[OutgoingConnection]] = Http().outgoingConnectionTls(host)
Source.single(httpRequest)
.via(connectionFlow)
.runWith(Sink.head)
}
}
In StreamingOAuthService
, I want to freeze the generic type as ResponseEntity
. In other words, I want to specify that the only type supported by the methods of StreamingOAuthService
is ResponseEntity
. As shown, StreamingOAuthService.sendAndReceive
doesn't compile because the return type is Future[ResponseEntity]
and not Future[A]
, as specified by the trait.