+str #17361: Unified http java/scala projects except marshallers
This commit is contained in:
parent
454a393af1
commit
be82e85ffc
182 changed files with 13693 additions and 0 deletions
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.http.impl.server
|
||||
|
||||
import scala.concurrent.Future
|
||||
import akka.http.javadsl.{ model ⇒ jm }
|
||||
import akka.http.impl.util.JavaMapping.Implicits._
|
||||
import akka.http.scaladsl.server.{ RequestContext ⇒ ScalaRequestContext }
|
||||
import akka.http.javadsl.server._
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
private[http] final case class RequestContextImpl(underlying: ScalaRequestContext) extends RequestContext {
|
||||
import underlying.executionContext
|
||||
|
||||
// provides auto-conversion to japi.RouteResult
|
||||
import RouteResultImpl._
|
||||
|
||||
def request: jm.HttpRequest = underlying.request
|
||||
def unmatchedPath: String = underlying.unmatchedPath.toString
|
||||
|
||||
def completeWith(futureResult: Future[RouteResult]): RouteResult =
|
||||
futureResult.flatMap {
|
||||
case r: RouteResultImpl ⇒ r.underlying
|
||||
}
|
||||
def complete(text: String): RouteResult = underlying.complete(text)
|
||||
def completeWithStatus(statusCode: Int): RouteResult =
|
||||
completeWithStatus(jm.StatusCodes.get(statusCode))
|
||||
def completeWithStatus(statusCode: jm.StatusCode): RouteResult =
|
||||
underlying.complete(statusCode.asScala)
|
||||
def completeAs[T](marshaller: Marshaller[T], value: T): RouteResult = marshaller match {
|
||||
case MarshallerImpl(m) ⇒
|
||||
implicit val marshaller = m(underlying.executionContext)
|
||||
underlying.complete(value)
|
||||
case _ ⇒ throw new IllegalArgumentException("Unsupported marshaller: $marshaller")
|
||||
}
|
||||
def complete(response: jm.HttpResponse): RouteResult = underlying.complete(response.asScala)
|
||||
|
||||
def notFound(): RouteResult = underlying.reject()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue