adding a bit of logging to see where connections are being made to. Introduced scalaish library for logging. webid
authorHenry Story <henry.story@bblfish.net>
Sat, 07 Jan 2012 23:05:01 +0100
branchwebid
changeset 170 20912130904e
parent 169 288d9317e2f7
child 172 9463e0f50340
adding a bit of logging to see where connections are being made to. Introduced scalaish library for logging.
project/build.scala
src/main/scala/GraphCache.scala
src/main/scala/ReadWriteWebMain.scala
src/main/scala/auth/X509Claim.scala
src/main/scala/netty/ReadWriteWebNetty.scala
src/main/scala/util/LogSecurityManager.scala
src/main/scala/util/package.scala
--- a/project/build.scala	Sat Jan 07 16:09:44 2012 +0100
+++ b/project/build.scala	Sat Jan 07 23:05:01 2012 +0100
@@ -22,9 +22,6 @@
         <exclude org="net.databinder" module="dispatch-mime_2.9.0-1"/>
       </dependency>
     </dependencies>
-  val slf4jSimple = "org.slf4j" % "slf4j-simple" % "1.6.4"
-  val slf4japi = "org.slf4j" % "slf4j-api" % "1.6.4"
-  val slf4jlog = "org.slf4j" % "slf4j-log4j12" % "1.6.4"
   val antiXML = "com.codecommit" %% "anti-xml" % "0.4-SNAPSHOT" % "test"
   val jena = "org.apache.jena" % "jena-core" % "2.7.0-incubating"
   val arq = "org.apache.jena" % "jena-arq" % "2.9.0-incubating"
@@ -37,6 +34,7 @@
 //  val restlet = "org.restlet.dev" % "org.restlet" % "2.1-SNAPSHOT"
 //  val restlet_ssl = "org.restlet.dev" % "org.restlet.ext.ssl" % "2.1-SNAPSHOT"
   val jsslutils = "org.jsslutils" % "jsslutils" % "1.0.5"
+  val slf4s = "com.weiglewilczek.slf4s" %% "slf4s" % "1.0.7"
 }
 
 // some usefull repositories
@@ -111,9 +109,6 @@
       libraryDependencies += unfiltered_filter,
       libraryDependencies += unfiltered_jetty,
       libraryDependencies += unfiltered_netty,
-      libraryDependencies += slf4jSimple,
-      libraryDependencies += slf4japi,
-      libraryDependencies += slf4jlog,
 
       libraryDependencies += jena,
       libraryDependencies += arq,
@@ -126,6 +121,7 @@
       libraryDependencies += scalate,
       libraryDependencies += rdfa,
       libraryDependencies += htmlparser,
+      libraryDependencies += slf4s,
 
       jarName in assembly := "read-write-web.jar",
       mainClass in assembly := Some("org.w3.readwriteweb.netty.ReadWriteWebNetty")
--- a/src/main/scala/GraphCache.scala	Sat Jan 07 16:09:44 2012 +0100
+++ b/src/main/scala/GraphCache.scala	Sat Jan 07 23:05:01 2012 +0100
@@ -31,6 +31,7 @@
 import java.util.concurrent.TimeUnit
 import com.google.common.cache.{LoadingCache, CacheLoader, CacheBuilder, Cache}
 import java.io.{File, FileOutputStream}
+import com.weiglewilczek.slf4s.Logging
 
 
 /**
@@ -41,7 +42,7 @@
  * @created: 12/10/2011
  *
  */
-object GraphCache extends ResourceManager  {
+object GraphCache extends ResourceManager with Logging {
   import dispatch._
   import Scalaz._
 
@@ -101,6 +102,7 @@
       // we can't currently accept */* as we don't have GRDDL implemented
       val request = url(u.toString) <:< Map("Accept"->
         "application/rdf+xml,text/turtle,application/xhtml+xml;q=0.8,text/html;q=0.7,text/n3;q=0.6")
+      logger.info("fetching "+u.toExternalForm)
 
       //we need to tell the model about the content type
       val handler: Handler[Validation[Throwable, Model]] = request.>+>[Validation[Throwable, Model]](res =>  {
@@ -123,7 +125,10 @@
         val future = http(handler)
         future
       } catch {
-        case e: ConnectException => e.fail
+        case e: ConnectException => {
+          logger.info("failed to connect to "+u.getHost,e)
+          e.fail
+        }
       }
 
     }
--- a/src/main/scala/ReadWriteWebMain.scala	Sat Jan 07 16:09:44 2012 +0100
+++ b/src/main/scala/ReadWriteWebMain.scala	Sat Jan 07 23:05:01 2012 +0100
@@ -5,14 +5,17 @@
 import org.w3.readwriteweb.util._
 
 import unfiltered.jetty._
-import java.io.File
 import Console.err
 import org.slf4j.{Logger, LoggerFactory}
 
 import org.clapper.argot._
 import ArgotConverters._
 import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
-import java.security.KeyStore
+import com.weiglewilczek.slf4s.Logging
+import java.lang.{Class, String}
+import java.net.InetAddress
+import java.io.{FileDescriptor, File}
+import java.security.{Permission, KeyStore}
 
 trait ReadWriteWebArgs {
   val logger: Logger = LoggerFactory.getLogger(this.getClass)
@@ -78,6 +81,7 @@
 }
 
 
+
 object ReadWriteWebMain extends ReadWriteWebArgs {
 
   import unfiltered.filter.Planify
@@ -91,6 +95,7 @@
       case e: ArgotUsageException => err.println(e.message); sys.exit(1)
     }
 
+
     val filesystem =
       new Filesystem(
         rootDirectory.value.get,
--- a/src/main/scala/auth/X509Claim.scala	Sat Jan 07 16:09:44 2012 +0100
+++ b/src/main/scala/auth/X509Claim.scala	Sat Jan 07 23:05:01 2012 +0100
@@ -32,10 +32,11 @@
 import unfiltered.request.HttpRequest
 import java.security.interfaces.RSAPublicKey
 import collection.immutable.List
-import com.google.common.cache.{CacheLoader, CacheBuilder, Cache}
 import java.util.concurrent.TimeUnit
 import org.w3.readwriteweb.util.trySome
 import java.util.Date
+import com.weiglewilczek.slf4s.Logging
+import com.google.common.cache.{LoadingCache, CacheLoader, CacheBuilder, Cache}
 
 /**
  * @author hjs
@@ -48,7 +49,7 @@
 
 // this is cool because it is not in danger of running out of memory but it makes it impossible to create the claim
 // with an implicit  GraphCache...
-  val idCache: Cache[X509Certificate, X509Claim] =
+  val idCache: LoadingCache[X509Certificate, X509Claim] =
      CacheBuilder.newBuilder()
      .expireAfterWrite(30, TimeUnit.MINUTES)
      .build(new CacheLoader[X509Certificate, X509Claim] {
@@ -124,13 +125,13 @@
  * @created: 30/03/2011
  */
 // can't be a case class as it then creates object which clashes with defined one
-class X509Claim(val cert: X509Certificate) extends Refreshable with XClaim {
+class X509Claim(val cert: X509Certificate) extends Refreshable with XClaim with Logging {
 
   import X509Claim._
   val claimReceivedDate = new Date()
   lazy val tooLate = claimReceivedDate.after(cert.getNotAfter())
   lazy val tooEarly = claimReceivedDate.before(cert.getNotBefore())
-
+  logger.debug("X509 Claim for certificate with DN="+cert.getSubjectDN)
 
   lazy val claims: List[WebIDClaim] = getClaimedWebIds(cert) map { webid => 
     new WebIDClaim(webid, cert.getPublicKey.asInstanceOf[RSAPublicKey]) 
--- a/src/main/scala/netty/ReadWriteWebNetty.scala	Sat Jan 07 16:09:44 2012 +0100
+++ b/src/main/scala/netty/ReadWriteWebNetty.scala	Sat Jan 07 23:05:01 2012 +0100
@@ -23,6 +23,7 @@
 
 package org.w3.readwriteweb.netty
 
+
 import _root_.auth.WebIDSrvc
 import org.clapper.argot.ArgotUsageException
 import scala.Console._
@@ -34,7 +35,7 @@
 import unfiltered.response._
 import unfiltered.netty._
 import collection.immutable.List
-import java.lang.String
+import util.{NetworkLoggingSM, AllowAllSecurityManager}
 
 /**
  * ReadWrite Web for Netty server, allowing TLS renegotiation
@@ -72,6 +73,7 @@
        case None => new KeyAuth_Https(httpPort.value.get)
      }
 
+
      // configures and launches a Netty server
      service.plan(publicStatic).
        plan( x509v ).
@@ -81,6 +83,7 @@
    }
 
 
+
   trait StaticFiles extends PartialFunction[String, ResponseFunction[Any]] {
     /* override this if the local path is somehow different from the url path */
     def toLocal(webpath: String): String = webpath
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/util/LogSecurityManager.scala	Sat Jan 07 23:05:01 2012 +0100
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2012 Henry Story (bblfish.net)
+ * under the MIT licence defined at
+ *    http://www.opensource.org/licenses/mit-license.html
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of 
+ * this software and associated documentation files (the "Software"), to deal in the
+ * Software without restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so, subject to the
+ * following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+package org.w3.readwriteweb.util
+
+import com.weiglewilczek.slf4s.Logging
+import java.lang.{Class, String}
+import java.net.InetAddress
+import java.io.FileDescriptor
+import java.security.Permission
+
+/**
+ * This class can be set as the SecurityManager on the command line with
+ * -Djava.security.manager=org.w3.readwriteweb.util.NetworkLoggingSM
+ * IT will show all attempts to make outbound network connections, which can be useful to track connections made in
+ * various libraries
+ */
+class NetworkLoggingSM extends AllowAllSecurityManager with Logging {
+
+  override def checkConnect(host: String, port: Int) {
+    logger.info("connecting to "+host+":"+port)
+    super.checkConnect(host,port)
+  }
+
+  override def checkConnect(host: String, port: Int, context: AnyRef) {
+    logger.info("connecting to "+host+":"+port)
+    super.checkConnect(host,port,context)
+  }
+    
+}
+
+class AllowAllSecurityManager extends SecurityManager {
+  override def checkAccept(host: String, port: Int) {}
+
+
+  override def checkAwtEventQueueAccess() {}
+
+  override def checkConnect(host: String, port: Int) {}
+
+  override def checkConnect(host: String, port: Int, context: AnyRef) {}
+
+  override def checkCreateClassLoader() {}
+
+  override def checkDelete(file: String) {}
+
+  override def checkExec(cmd: String) {}
+
+  override def checkExit(status: Int) {}
+
+  override def checkLink(lib: String) {}
+
+  override def checkListen(port: Int) {}
+
+  override def checkMemberAccess(clazz: Class[_], which: Int) {}
+
+  override def checkMulticast(maddr: InetAddress) {}
+
+  override def checkMulticast(maddr: InetAddress, ttl: Byte) {}
+
+  override def checkPackageAccess(pkg: String) {}
+
+  override def checkPackageDefinition(pkg: String) {}
+
+  override def checkPermission(perm: Permission) {}
+
+  override def checkPermission(perm: Permission, context: AnyRef) {}
+
+  override def checkPrintJobAccess() {}
+
+  override def checkPropertiesAccess() {}
+
+  override def checkPropertyAccess(key: String) {}
+
+  override def checkRead(fd: FileDescriptor) {}
+
+  override def checkRead(file: String) {}
+
+  override def checkRead(file: String, context: AnyRef) {}
+
+  override def checkSecurityAccess(target: String) {}
+
+  override def checkSetFactory() {}
+
+  override def checkSystemClipboardAccess() {}
+
+  override def checkTopLevelWindow(window: AnyRef) = false
+
+  override def checkWrite(fd: FileDescriptor) {}
+
+  override def checkWrite(file: String) {}
+}
+
+trait WrappedSecurityManager extends SecurityManager  {
+  val wrap: SecurityManager
+  override def getSecurityContext = wrap.getSecurityContext
+
+  override def checkPermission(perm: Permission) { wrap.checkPermission(perm)}
+
+  override def checkPermission(perm: Permission, context: AnyRef) {wrap.checkPermission(perm,context)}
+
+  override def checkCreateClassLoader() { wrap.checkCreateClassLoader() }
+
+  override def checkAccess(t: Thread) { wrap.checkAccess(t)}
+
+  override def checkAccess(g: ThreadGroup) { wrap.checkAccess(g)}
+
+  override def checkExit(status: Int) { wrap.checkExit(status) }
+
+  override def checkExec(cmd: String) { wrap.checkExec(cmd) }
+
+  override def checkLink(lib: String) { wrap.checkLink(lib)}
+
+  override def checkRead(fd: FileDescriptor) {wrap.checkRead(fd)}
+
+  override def checkRead(file: String) { wrap.checkRead(file)}
+
+  override def checkRead(file: String, context: AnyRef) { wrap.checkRead(file)}
+
+  override def checkWrite(fd: FileDescriptor) {wrap.checkWrite(fd)}
+
+  override def checkWrite(file: String) {wrap.checkWrite(file)}
+
+  override def checkDelete(file: String) {wrap.checkDelete(file)}
+
+  override def checkListen(port: Int) {wrap.checkListen(port)}
+
+  override def checkAccept(host: String, port: Int) {wrap.checkAccept(host,port)}
+
+  override def checkMulticast(maddr: InetAddress) { wrap.checkMulticast(maddr)}
+
+  override def checkPropertiesAccess() { wrap.checkPropertiesAccess()}
+
+  override def checkPropertyAccess(key: String) {wrap.checkPropertyAccess(key)}
+
+  override def checkTopLevelWindow(window: AnyRef) = wrap.checkTopLevelWindow(window)
+
+  override def checkPrintJobAccess() { wrap.checkPrintJobAccess()}
+
+  override def checkSystemClipboardAccess() { wrap.checkSystemClipboardAccess()}
+
+  override def checkAwtEventQueueAccess() { wrap.checkAwtEventQueueAccess()}
+
+  override def checkPackageAccess(pkg: String) { wrap.checkPackageAccess(pkg)}
+
+  override def checkPackageDefinition(pkg: String) {wrap.checkPackageDefinition(pkg)}
+
+  override def checkSetFactory() {wrap.checkSetFactory()}
+
+  override def checkMemberAccess(clazz: Class[_], which: Int) {wrap.checkMemberAccess(clazz,which)}
+
+  override def checkSecurityAccess(target: String) {wrap.checkSecurityAccess(target)}
+
+  override def getThreadGroup = wrap.getThreadGroup
+}
+
+
+
+
+
+
--- a/src/main/scala/util/package.scala	Sat Jan 07 16:09:44 2012 +0100
+++ b/src/main/scala/util/package.scala	Sat Jan 07 23:05:01 2012 +0100
@@ -5,9 +5,9 @@
 import scalaz._
 import Scalaz._
 import java.net.URL
-import com.hp.hpl.jena.shared.WrappedIOException
+import com.weiglewilczek.slf4s.Logging
 
-package object util {
+package object util extends Logging {
   
   def modelFromInputStream(
       is: InputStream,
@@ -18,7 +18,10 @@
       m.getReader(lang.jenaLang).read(m, is, base.toString)
       m.success
     } catch {
-      case t => t.fail
+      case t =>  {
+        logger.info("cought exception turning stream into model ",t)
+        t.fail
+      }
     }
   
   def modelFromString(