Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
switch over to subdomains for issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
bblfish committed Nov 24, 2013
1 parent 97a57cd commit eaad35d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/rww/ldp/RWWeb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RWWeb[Rdf<:RDF](val baseUri: Rdf#URI)
(implicit ops: RDFOps[Rdf], timeout: Timeout) extends RWW[Rdf] {
import RWW._
val system = ActorSystem(systemPath)
val rwwActorRef = system.actorOf(Props(new RWWebActor(baseUri)),name="router")
val rwwActorRef = system.actorOf(Props(new RWWebActorSubdomains(baseUri)),name="router")
import RWWeb.logger

logger.info(s"Created rwwActorRef=<$rwwActorRef>")
Expand Down
24 changes: 13 additions & 11 deletions app/rww/ldp/RWWebActorSubdomains.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import scalaz.{\/-, -\/}
import java.net.{URI=>jURI}

object RWWebActorSubdomains {
case class Switch(subhost: String, path: String)

val nosubdomain = "self"
case class Switch(subhost: Option[String], path: String)

def local(u: jURI, base: jURI): Option[Switch] = {
if (!u.isAbsolute ) {
RWWebActor.local(u,base).map(path=>Switch(nosubdomain,path))
RWWebActor.local(u,base).map(path=>Switch(None,path))
} else if (u.getScheme == base.getScheme && u.getHost.endsWith(base.getHost) && u.getPort == base.getPort) {
val subhost = if (u.getHost == base.getHost)
nosubdomain
None
else
u.getHost.substring(0,u.getHost.length - base.getHost.length-1)
Some(u.getHost.substring(0,u.getHost.length - base.getHost.length-1) )

val pathStart = if (u.getPath.startsWith("/")) u.getPath.substring(1) else u.getPath
val path = if (pathStart.endsWith("/")) pathStart.substring(0,pathStart.length-1) else pathStart
Option(Switch(subhost,path))
if (subhost == None) RWWebActor.local(u, base).map(p=>Switch(None,p))
else {
val pathStart = if (u.getPath.startsWith("/")) u.getPath.substring(1) else u.getPath
val path = if (pathStart.endsWith("/")) pathStart.substring(0, pathStart.length - 1) else pathStart
Option(Switch(subhost,path))
}
} else None
}

Expand All @@ -33,7 +34,7 @@ object RWWebActorSubdomains {
* A actor that receives commands on a server with subdomains, and knows how to ship
* them off either to the right WebActor or to the right LDPSActor
*
* @param baseUri
* @param baseUri: the base URI of the main domain. From this the subdomains are constructed
* @param ops
* @param timeout
* @tparam Rdf
Expand Down Expand Up @@ -70,7 +71,8 @@ class RWWebActorSubdomains[Rdf<:RDF](val baseUri: Rdf#URI)
local(cmd.command.uri.underlying,baseUri.underlying).map { switch =>
rootContainer match {
case Some(root) => {
val p = root.path / switch.subhost/switch.path.split('/').toIterable
val pathList = switch.path.split('/').toList
val p = root.path / switch.subhost.map(_::pathList).getOrElse(pathList)
val to = context.actorSelection(p)
log.info(s"forwarding message $cmd to akka('$switch')=$to ")
to.tell(cmd,context.sender)
Expand Down
22 changes: 11 additions & 11 deletions test/ldp/RWWActorSubdomainsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ class RWWActorSubdomainsTest extends WordSpec with Matchers {
val localBase = new URI("https://localhost:8443/2013/")

s"base=$localBase tests " in {
local(new URI("/2013/"), localBase ) should be (Some(Switch(nosubdomain,"")))
local(new URI("/2013/test"), localBase ) should be (Some(Switch(nosubdomain,"test")))
local(new URI("/2013/test/"), localBase ) should be (Some(Switch(nosubdomain,"test")))
local(new URI("/2013/test/img"), localBase ) should be (Some(Switch(nosubdomain,"test/img")))
local(new URI("/2013/test/img/"), localBase ) should be (Some(Switch(nosubdomain,"test/img")))
local(new URI("/2013/test/img/cat.jpg"), localBase ) should be (Some(Switch(nosubdomain,"test/img/cat")))
local(new URI("/2013/test/img/.acl.ttl"), localBase ) should be (Some(Switch(nosubdomain,"test/img")))
local(new URI("/2013/card.acl"), localBase ) should be (Some(Switch(nosubdomain,"card")))
local(new URI("/2013/"), localBase ) should be (Some(Switch(None,"")))
local(new URI("/2013/test"), localBase ) should be (Some(Switch(None,"test")))
local(new URI("/2013/test/"), localBase ) should be (Some(Switch(None,"test")))
local(new URI("/2013/test/img"), localBase ) should be (Some(Switch(None,"test/img")))
local(new URI("/2013/test/img/"), localBase ) should be (Some(Switch(None,"test/img")))
local(new URI("/2013/test/img/cat.jpg"), localBase ) should be (Some(Switch(None,"test/img/cat")))
local(new URI("/2013/test/img/.acl.ttl"), localBase ) should be (Some(Switch(None,"test/img")))
local(new URI("/2013/card.acl"), localBase ) should be (Some(Switch(None,"card")))
}

s"base=$localBase tests with subdomains" in {
local(new URI("https://joe.localhost:8443/2013/"),localBase) should be (Some(Switch("joe","2013")))
local(new URI("https://james.localhost:8443/2013"),localBase) should be (Some(Switch("james","2013")))
local(new URI("https://james.localhost:8443"),localBase) should be (Some(Switch("james","")))
local(new URI("https://joe.localhost:8443/2013/"),localBase) should be (Some(Switch(Some("joe"),"2013")))
local(new URI("https://james.localhost:8443/2013"),localBase) should be (Some(Switch(Some("james"),"2013")))
local(new URI("https://james.localhost:8443"),localBase) should be (Some(Switch(Some("james"),"")))

}
}

0 comments on commit eaad35d

Please sign in to comment.