replaced Lookup service registry with apparently more Scalish default variables after a discussion with Alexandre Bertails. Not completely convinced - not unconvinced either: now the WebCache object has to be passed along through three objects when it is only the last one that requires it. We don't pass along caching objects like that when we do URLConnections for example in Java. Perhaps it is the mistake of the web cache. Perhaps it should just be statically be set, since there should really only be one per system? webid
authorHenry Story <henry.story@bblfish.net>
Wed, 12 Oct 2011 13:36:31 +0200
branchwebid
changeset 54 e027110a59e0
parent 53 73fa8a6a3041
child 55 0a97b1a3c435
replaced Lookup service registry with apparently more Scalish default variables after a discussion with Alexandre Bertails. Not completely convinced - not unconvinced either: now the WebCache object has to be passed along through three objects when it is only the last one that requires it. We don't pass along caching objects like that when we do URLConnections for example in Java. Perhaps it is the mistake of the web cache. Perhaps it should just be statically be set, since there should really only be one per system?
src/main/scala/AuthFilter.scala
src/main/scala/HttpsTrustAll.scala
src/main/scala/Main.scala
--- a/src/main/scala/AuthFilter.scala	Wed Oct 12 12:30:51 2011 +0200
+++ b/src/main/scala/AuthFilter.scala	Wed Oct 12 13:36:31 2011 +0200
@@ -56,7 +56,7 @@
       //well we don't know when two anonymous people are the same or different.
 }
 
-class AuthFilter extends Filter {
+class AuthFilter(implicit webCache: WebCache) extends Filter {
   def init(filterConfig: FilterConfig) {}
 
   def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) {
@@ -124,7 +124,7 @@
  * @author bblfish
  * @created: 30/03/2011
  */
-class X509Claim(val cert: X509Certificate) extends Refreshable {
+class X509Claim(val cert: X509Certificate)(implicit webCache: WebCache) extends Refreshable {
 
   import X509Claim._
   val claimReceivedDate = new Date();
@@ -277,7 +277,7 @@
  * @author bblfish
  * @created 30/03/2011
  */
-class WebIDClaim(val webId: String, val key: PublicKey) {
+class WebIDClaim(val webId: String, val key: PublicKey)(implicit cache: WebCache) {
 
 	val errors = new LinkedList[java.lang.Throwable]()
 
@@ -302,7 +302,6 @@
     } else if (!key.isInstanceOf[RSAPublicKey]) {
       certificateKeyTypeNotSupported::Nil
     } else {
-      val cache = Lookup.get(classOf[WebCache]).head
       val res = for {
         model <- cache.resource(new URL(webId)).get() failMap {
           t => new ProfileError("error fetching profile", t)
--- a/src/main/scala/HttpsTrustAll.scala	Wed Oct 12 12:30:51 2011 +0200
+++ b/src/main/scala/HttpsTrustAll.scala	Wed Oct 12 13:36:31 2011 +0200
@@ -26,8 +26,6 @@
 import unfiltered.jetty.{Ssl, Https}
 
 
-
-
 /**
  * @author Henry Story
  * @created: 12/10/2011
--- a/src/main/scala/Main.scala	Wed Oct 12 12:30:51 2011 +0200
+++ b/src/main/scala/Main.scala	Wed Oct 12 13:36:31 2011 +0200
@@ -15,8 +15,7 @@
 import com.hp.hpl.jena.rdf.model._
 import com.hp.hpl.jena.query._
 import com.hp.hpl.jena.update._
-import com.hp.hpl.jena.shared.JenaException
-import org.w3.readwriteweb.{Resource}
+import org.w3.readwriteweb.Resource
 import Query.{QueryTypeSelect => SELECT, QueryTypeAsk => ASK,
               QueryTypeConstruct => CONSTRUCT, QueryTypeDescribe => DESCRIBE}
 
@@ -24,17 +23,8 @@
 import Scalaz._
 
 import org.w3.readwriteweb.util._
-import java.security.KeyStore
-import org.jsslutils.keystores.KeyStoreLoader
-import org.jsslutils.sslcontext.{X509TrustManagerWrapper, X509SSLContextFactory}
-import javax.net.ssl.{X509TrustManager, SSLContext}
-import org.jsslutils.sslcontext.trustmanagers.TrustAllClientsWrappingTrustManager
-import java.security.cert.X509Certificate
-import scala.sys.SystemProperties
-import collection.{mutable,immutable}
+import collection.mutable
 import webid.AuthFilter
-import org.clapper.argot.ArgotParser
-
 class ReadWriteWeb(rm:ResourceManager) {
   
   val logger:Logger = LoggerFactory.getLogger(this.getClass)
@@ -148,22 +138,6 @@
 
 }
 
-object Lookup {
-  // a place to register services that can be looked up from anywhere.
-  // this is very naive registration, compared to tools like Clerezza that use Apaches Felix's OSGI implementation
-
-  private val db = new mutable.HashMap[Class[_],AnyRef]
-
-  def get[T<:AnyRef](clzz :Class[T]) :Option[T] = db.get(clzz).map(e=>e.asInstanceOf[T])
-
-  //http://stackoverflow.com/questions/3587286/how-does-scalas-2-8-manifest-work
-  def put[T<:AnyRef : Manifest](obj: T): T = {
-    def zref = manifest[T].erasure
-    val ref: AnyRef = obj
-    db.put(zref,ref).asInstanceOf[T]
-  }
-
-}
 
 object ReadWriteWebMain {
   import org.clapper.argot._
@@ -219,8 +193,10 @@
       }
     }
 
+   implicit val webCache = new WebCache()
 
-    val baseURL = parser.parameter[String]("baseURL", "base URL", false)
+
+   val baseURL = parser.parameter[String]("baseURL", "base URL", false)
 
 
   // regular Java main
@@ -245,9 +221,6 @@
       case None => Http(httpPort.value.get)
     }
 
-    val webCache = new WebCache()
-    Lookup.put(webCache)
-
     // configures and launches a Jetty server
     service.filter {
       // a jee Servlet filter that logs HTTP requests