Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add explicit return type for make_client to support override

Scala narrows the return type of an overridden method to the inferred type of the overriding method.  This prevents subclasses from further overriding according to the original type, HttpClient.  Specify HttpClient explicitly so that any subclass can override make_client.
  • Loading branch information...
commit 3749a80ddcbe8b23d3ae7fdabfec49c80d11b4b7 1 parent 49f593f
cyrus-saks cyrus-saks authored
7 http/src/main/scala/thread/thread.scala
View
@@ -1,9 +1,8 @@
package dispatch.thread
-import org.apache.http.{HttpHost,HttpRequest,HttpResponse}
-import org.apache.http.client.methods.HttpRequestBase
import dispatch._
import dispatch.futures._
+import org.apache.http.client.HttpClient
/** Http with a thread-safe client */
trait Safety { self: BlockingHttp =>
@@ -13,7 +12,7 @@ trait Safety { self: BlockingHttp =>
def maxConnectionsPerRoute = maxConnections
/** Shutdown connection manager if no longer in use. */
- override def make_client = new ThreadSafeHttpClient(
+ override def make_client: HttpClient = new ThreadSafeHttpClient(
credentials, maxConnections, maxConnectionsPerRoute)
}
@@ -36,8 +35,6 @@ class ThreadSafeHttpClient(
maxConnections: Int,
maxConnectionsPerRoute: Int
) extends ConfiguredHttpClient(credentials) {
- import org.apache.http.conn.scheme.{Scheme,SchemeRegistry,PlainSocketFactory}
- import org.apache.http.conn.ssl.SSLSocketFactory
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager
override def createClientConnectionManager = {
val cm = new ThreadSafeClientConnManager()
28 http/src/test/scala/HttpSpec.scala
View
@@ -1,3 +1,7 @@
+import org.apache.http.client.methods.HttpUriRequest
+import org.apache.http.client.{ResponseHandler, HttpClient}
+import org.apache.http.protocol.HttpContext
+import org.apache.http.{HttpRequest, HttpHost}
import org.specs._
object HttpSpec extends Specification {
@@ -27,6 +31,30 @@ object HttpSpec extends Specification {
"Backwards combined request get" should {
get_specs(/("test.text") <& :/("technically.us"))
}
+
+ "Http" should {
+ class SimpleDelegatingHttpClient(realClient: HttpClient) extends HttpClient {
+ def getParams = realClient.getParams
+ def getConnectionManager = realClient.getConnectionManager
+ def execute(request: HttpUriRequest) = realClient.execute(request)
+ def execute(request: HttpUriRequest, context: HttpContext) = realClient.execute(request, context)
+ def execute(target: HttpHost, request: HttpRequest) = realClient.execute(target, request)
+ def execute(target: HttpHost, request: HttpRequest, context: HttpContext) = realClient.execute(target, request, context)
+ def execute[T](request: HttpUriRequest, responseHandler: ResponseHandler[_ <: T]) = realClient.execute(request, responseHandler)
+ def execute[T](request: HttpUriRequest, responseHandler: ResponseHandler[_ <: T], context: HttpContext) = realClient.execute(request, responseHandler, context)
+ def execute[T](target: HttpHost, request: HttpRequest, responseHandler: ResponseHandler[_ <: T]) = realClient.execute(target, request, responseHandler)
+ def execute[T](target: HttpHost, request: HttpRequest, responseHandler: ResponseHandler[_ <: T], context: HttpContext) = realClient.execute(target, request, responseHandler, context)
+ }
+
+ "allow override" in {
+ val http = new Http with thread.Safety {
+ override def make_client: HttpClient = new SimpleDelegatingHttpClient(super.make_client)
+ }
+ http must notBeNull // i.e. this code should compile
+ http.shutdown()
+ }
+ }
+
val http = new Http
val httpfuture = new thread.Http
def get_specs(test: Request) = {
Please sign in to comment.
Something went wrong with that request. Please try again.