Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dirac/src/main/scala/gridscale/dirac/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ package object dirac {

object DIRAC {

class Interpreters {
class Interpreters(proxy: Option[HTTPProxy] = None) {
implicit val fileSystemInterpreter = FileSystem()
implicit val systemInterpreter = System()
implicit val httpInterpreter = HTTP()
implicit val httpInterpreter = HTTP(proxy)
}

def apply[T](f: Interpreters ⇒ T) = {
val interpreters = new Interpreters()
def apply[T](f: Interpreters ⇒ T, proxy: Option[HTTPProxy] = None) = {
val interpreters = new Interpreters(proxy)
f(interpreters)
}

Expand Down
10 changes: 5 additions & 5 deletions egi/src/main/scala/gridscale/egi/EGI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import effectaside._
import gridscale.http._

object EGI {
class Interpreters {
implicit val http: Effect[HTTP] = HTTP()
class Interpreters(proxy: Option[HTTPProxy] = None) {
implicit val http: Effect[HTTP] = HTTP(proxy)
implicit val fileSystem: Effect[FileSystem] = FileSystem()
implicit val bdii: Effect[BDII] = BDII()
implicit val system: Effect[System] = System()
}

def apply() = new Interpreters
def apply(proxy: Option[HTTPProxy] = None) = new Interpreters(proxy)

def apply[T](f: Interpreters ⇒ T) = {
val intp = new Interpreters
def apply[T](f: Interpreters ⇒ T)(proxy: Option[HTTPProxy]) = {
val intp = new Interpreters(proxy)
f(intp)
}
}
6 changes: 3 additions & 3 deletions examples/egi/dirac/src/main/scala/TestDIRAC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import gridscale.http._

object TestDIRAC extends App {

val password = scala.io.Source.fromFile("/home/reuillon/.globus/password").getLines().next().trim
val p12 = P12Authentication(new java.io.File("/home/reuillon/.globus/certificate.p12"), password)
val certificateDirectory = new java.io.File("/home/reuillon/.openmole/simplet/persistent/CACertificates/")
val password = scala.io.Source.fromFile("/home/julien/.globus/password").getLines().next().trim
val p12 = P12Authentication(new java.io.File("/home/julien/.globus/certificate.p12"), password)
val certificateDirectory = new java.io.File("/home/julien/.openmole/DEL1701P003-Ubuntu/persistent/CACertificates/")

val description = JobDescription("/bin/uname", "-a", stdOut = Some("output"), outputSandbox = Seq("output"))

Expand Down
5 changes: 3 additions & 2 deletions examples/egi/webdav/src/main/scala/WedDAVExample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import java.io.ByteArrayInputStream
import gridscale.egi._
import gridscale.webdav._
import gridscale.authentication._
import gridscale.http.HTTPProxy

object WedDAVExample extends App {

val password = scala.io.Source.fromFile("/home/reuillon/.globus/password").getLines().next().trim
val p12 = P12Authentication(new java.io.File("/home/reuillon/.globus/certificate.p12"), password)
val certificateDirectory = new java.io.File("/home/reuillon/.openmole/simplet/persistent/CACertificates/")
val bdiiServer = BDIIServer("topbdii.grif.fr", 2170)

val proxy: Option[HTTPProxy] = None
EGI { impl ⇒
import impl._

Expand All @@ -29,5 +30,5 @@ object WedDAVExample extends App {
val c = read(webdav, "youpi2.txt")

println(c)
}
}(proxy)
}
49 changes: 29 additions & 20 deletions http/src/main/scala/gridscale/http/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import java.security.cert.{ Certificate, CertificateFactory }

import effectaside._
import org.apache.commons.codec.binary
import org.apache.http.{ HttpEntity, client }
import org.apache.http.{ HttpEntity, HttpHost, client }
import org.apache.http.client.methods
import org.apache.http.entity.InputStreamEntity
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.message.BasicHttpRequest
import sun.security.provider.X509Factory

Expand Down Expand Up @@ -50,13 +51,13 @@ package object http {
}
}

def get[T](url: String) = {
implicit val interpreter = HTTP()
def get[T](url: String, proxy: Option[HTTPProxy] = None) = {
implicit val interpreter = HTTP(proxy)
read(buildServer(url), "")
}

def getStream[T](url: String)(f: InputStream ⇒ T) = {
implicit val interpreter = HTTP()
def getStream[T](url: String, proxy: Option[HTTPProxy] = None)(f: InputStream ⇒ T) = {
implicit val interpreter = HTTP(proxy)
readStream[T](buildServer(url), "", f)
}

Expand All @@ -76,14 +77,21 @@ package object http {
case class Head(headers: Headers = Seq.empty) extends HTTPMethod
case class Move(to: String, headers: Headers = Seq.empty) extends HTTPMethod

case class HTTPProxy(hostname: String, port: Int)

def addProxy(httpClientBuilder: HttpClientBuilder, proxy: Option[HTTPProxy]) = proxy match {
case Some(p) ⇒ httpClientBuilder.setProxy(new HttpHost(p.hostname, p.port))
case None ⇒ httpClientBuilder
}

object HTTP {

def apply() = Effect(new HTTP())
def apply(proxy: Option[HTTPProxy] = None) = Effect(new HTTP(proxy))

def client(server: Server) =
def client(server: Server, proxy: Option[HTTPProxy]) =
server match {
case s: HTTPServer ⇒ httpClient(s.timeout)
case s: HTTPSServer ⇒ HTTPS.newClient(s.socketFactory, s.timeout)
case s: HTTPServer ⇒ httpClient(s.timeout, proxy)
case s: HTTPSServer ⇒ HTTPS.newClient(s.socketFactory, s.timeout, proxy)
}

def requestConfig(timeout: Time) =
Expand All @@ -93,7 +101,7 @@ package object http {
.setConnectionRequestTimeout(timeout.toMillis.toInt)
.build()

def httpClient(timeout: Time) = {
def httpClient(timeout: Time, proxy: Option[HTTPProxy]) = {
def connectionManager(timeout: Time) = {
val client = new BasicHttpClientConnectionManager()
val socketConfig = SocketConfig.custom().setSoTimeout(timeout.toMillis.toInt).build()
Expand All @@ -102,10 +110,11 @@ package object http {
}

def newClient(timeout: Time) =
HttpClients.custom().
//setRedirectStrategy(redirectStrategy).
setConnectionManager(connectionManager(timeout)).
setDefaultRequestConfig(requestConfig(timeout)).build()
addProxy(
HttpClients.custom().
//setRedirectStrategy(redirectStrategy).
setConnectionManager(connectionManager(timeout)).
setDefaultRequestConfig(requestConfig(timeout)), proxy).build()

newClient(timeout)
}
Expand All @@ -125,7 +134,7 @@ package object http {

}

class HTTP {
class HTTP(proxy: Option[HTTPProxy] = None) {

def withInputStream[T](server: Server, path: String, f: (HttpRequest, HttpResponse) ⇒ T, method: HTTPMethod, test: Boolean) = {
def fullURI(path: String) =
Expand Down Expand Up @@ -167,7 +176,7 @@ package object http {
def error(e: Throwable) = new HTTP.ConnectionError(s"Error while connecting to ${uri}, method ${method}", e)

try {
val httpClient = HTTP.client(server)
val httpClient = HTTP.client(server, proxy)
try {
val response = httpClient.execute(methodInstance)
try {
Expand Down Expand Up @@ -380,11 +389,11 @@ package object http {
client
}

def newClient(factory: SSLSocketFactory, timeout: Time) =
HttpClients.custom().
def newClient(factory: SSLSocketFactory, timeout: Time, proxy: Option[HTTPProxy]) = {
addProxy(HttpClients.custom().
setConnectionManager(connectionManager(factory(timeout), timeout)).
setDefaultRequestConfig(HTTP.requestConfig(timeout)).build()

setDefaultRequestConfig(HTTP.requestConfig(timeout)), proxy).build()
}
def readPem(pem: java.io.File)(implicit fileSystem: Effect[FileSystem]) = {
val content = fileSystem().readStream(pem)(is ⇒ Source.fromInputStream(is).mkString)
val stripped = content.replaceAll(X509Factory.BEGIN_CERT, "").replaceAll(X509Factory.END_CERT, "")
Expand Down