Untested support for proxies webid
authorHenry Story <henry.story@bblfish.net>
Sun, 15 Apr 2012 20:39:51 +0200
branchwebid
changeset 200 9c6bd1aa7ea9
parent 199 af8ab11f6192
child 201 48c7b927b241
Untested support for proxies
src/main/scala/GraphCache.scala
src/main/scala/ReadWriteWebMain.scala
--- a/src/main/scala/GraphCache.scala	Fri Apr 13 23:22:11 2012 +0200
+++ b/src/main/scala/GraphCache.scala	Sun Apr 15 20:39:51 2012 +0200
@@ -24,7 +24,6 @@
 package org.w3.readwriteweb
 
 import com.hp.hpl.jena.rdf.model.Model
-import org.apache.http.MethodNotSupportedException
 import org.w3.readwriteweb.util._
 import java.net.{ConnectException, URL}
 import scalaz.{Scalaz, Validation}
@@ -37,6 +36,8 @@
 import org.apache.http.conn.ssl.{TrustStrategy, SSLSocketFactory}
 import java.security.cert.X509Certificate
 import java.io.{InputStream, File, FileOutputStream}
+import org.apache.http.conn.params.ConnRoutePNames
+import org.apache.http.{HttpHost, MethodNotSupportedException}
 
 
 /**
@@ -70,8 +71,15 @@
     import org.apache.http.params.CoreConnectionPNames
     client.getParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000)
     client.getParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, 15000)
+    Option(System.getProperty("http.proxy")).map{ uriStr =>
+      val url = new URL(uriStr)
+      val proxy = new HttpHost(url.getHost, url.getPort, url.getProtocol);
+      client.getParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy)
+    }
   }
 
+
+
   Option(System.getProperty("rww.clientTLSsecurity")).map {
     case "noCA" => {
       val sf = new SSLSocketFactory(new TrustStrategy {
--- a/src/main/scala/ReadWriteWebMain.scala	Fri Apr 13 23:22:11 2012 +0200
+++ b/src/main/scala/ReadWriteWebMain.scala	Sun Apr 15 20:39:51 2012 +0200
@@ -12,6 +12,7 @@
 import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
 import java.lang.String
 import java.io.File
+import java.net.{MalformedURLException, URL}
 
 trait ReadWriteWebArgs {
   val logger: Logger = LoggerFactory.getLogger(this.getClass)
@@ -40,6 +41,7 @@
   |   * noCA: if the server certificate is not signed by well known CA ignore and continue
   |   * noDomain: for test situations where the server certificate does not even name the machine it is on correctly
   |   * [todo: add more flexible server certificate verification mechanisms]
+  |  --proxy url: url in the form http://host.example:port
   |
   |NOTES
   |
@@ -89,6 +91,18 @@
       }
   }
 
+  val proxy = parser.option[URL](List("proxy"),"p","Proxy to use when making client http(s) connections") {
+    (sValue, opt) =>
+        try {
+          val proxy = new URL(sValue);
+          System.getProperties().put("http.proxy", proxy);
+          proxy
+        } catch {
+          case e: MalformedURLException => throw new ArgotConversionException("Option %s: url does not parse correctly "
+            format (opt.name, sValue))
+        }
+  }
+
   val httpPort = parser.option[Int]("http", "Port","start the http server on port")
   val httpsPort = parser.option[Int]("https","port","start the https server on port")