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

Commit

Permalink
Issue #15: curl on /2013/test times out (end "/")
Browse files Browse the repository at this point in the history
  • Loading branch information
bblfish committed Nov 12, 2013
1 parent 4e68fd4 commit 7939ebe
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 30 deletions.
15 changes: 11 additions & 4 deletions app/rww/ldp/LDPStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,29 @@ trait RActor extends Actor with akka.actor.ActorLogging {
}
}

}

object RActor {
def local(u: jURI, base: jURI): Option[String] = {
val res = if ((!u.isAbsolute ) || (u.getScheme == base.getScheme && u.getHost == base.getHost && u.getPort == base.getPort)) {
if (u.getPath.startsWith(base.getPath)) {
val res = u.getPath.substring(base.getPath.size)
val sections = res.split('/')
val fileName = sections.last
var idot= fileName.indexOf('.')
if (idot>=0) sections.update(sections.length-1,fileName.substring(0,idot))
Option(sections.mkString("/"))
val treated = if (idot>0) {
sections.update(sections.length-1,fileName.substring(0,idot))
sections.toSeq
}else if (idot==0) sections.toSeq.dropRight(1)
else sections.toSeq
Option(treated.mkString("/"))
} else None
} else None
res
}

}


class LocalSetup {
def aclPath(path: String) = {
val p = path+".acl"
Expand Down Expand Up @@ -354,7 +361,7 @@ class RWWebActor[Rdf<:RDF](val baseUri: Rdf#URI)

/** We in fact ignore the R and A types, since we cannot capture */
protected def forwardSwitch[A](cmd: Cmd[Rdf,A]) {
local(cmd.command.uri.underlying,baseUri.underlying).map { path=>
RActor.local(cmd.command.uri.underlying,baseUri.underlying).map { path=>
rootContainer match {
case Some(root) => {
val p = root.path / path.split('/').toIterable
Expand Down
2 changes: 1 addition & 1 deletion app/rww/ldp/LDPWebActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class LDPWebActor[Rdf<:RDF](val excluding: Rdf#URI, val webc: WebClient[Rdf])
final def run[A](sender: ActorRef, script: LDPCommand.Script[Rdf,A]) {
script.resume match {
case -\/(cmd) => {
if(local(cmd.uri.underlying,excluding.underlying) == None) {
if(RActor.local(cmd.uri.underlying,excluding.underlying) == None) {
runCmd(cmd)
//if we were to have some commands return an immediate value, then we could do
// the following with the returned script
Expand Down
42 changes: 25 additions & 17 deletions app/rww/ldp/PlantainLDPCActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ class PlantainLDPCActor(baseUri: Plantain#URI, root: Path)
})
}


override
def localName(uri: Plantain#URI): String = {
val requestedPath = uri.underlying.getPath
uriW[Plantain](uri).lastPathSegment
val ldpcPath = baseUri.underlying.getPath
if (ldpcPath.length > requestedPath.length) fileName
else super.localName(uri)
}


private def descriptionFor(path: Path, attrs: BasicFileAttributes): Plantain#Graph = {
def graphFor(uri: Plantain#URI) = {
var res = emptyGraph +
Expand Down Expand Up @@ -126,10 +137,6 @@ class PlantainLDPCActor(baseUri: Plantain#URI, root: Path)

def randomPathSegment(): String = java.util.UUID.randomUUID().toString.replaceAll("-", "")

protected def aclPath(path: String) = path+".acl"

protected def isAclPath(path: String) = path.endsWith(".acl")

/**
* for directories we resolve requests for metadata files as referring to .xxx.ext files
* inside the directory
Expand Down Expand Up @@ -372,7 +379,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
//todo: the file should be verified to see if it is up to date.
cache.getOrElseUpdate(name, {
//at this point it is still very easy - only two cases! but won't stay like this...
val (file,iri) = path(name)
val (file,iri) = fileAndURIFor(name)

if (file.createNewFile()) {
if (file.toString.endsWith(ext)) {
Expand Down Expand Up @@ -416,7 +423,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
* @param name
* @return
*/
private def path(name: String): (File,Plantain#URI) = {
private def fileAndURIFor(name: String): (File,Plantain#URI) = {
//note: this is really simple at present, but is bound to get more complex,...
val file = fileFrom(name)
val uriw =uriW[Plantain](baseUri)
Expand All @@ -438,7 +445,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
def setResource(name: String, graph: Plantain#Graph) {
import scalax.io.{Resource=>xResource}
implicit val codec = Codec.UTF8
val (file,iri) = path(name)
val (file,iri) = fileAndURIFor(name)
file.createNewFile()
writer.write(graphW[Plantain](graph).relativize(baseUri),xResource.fromOutputStream(new FileOutputStream(file)),"") match {
case scala.util.Failure(t) => throw new StoreProblem(t)
Expand All @@ -447,6 +454,9 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
cache.put(name,LocalLDPR[Plantain](iri,graph,Some(new Date(file.lastModified()))))
}


def localName(uri: Plantain#URI): String = uriW[Plantain](uri).lastPathSegment

/*
* Runs a command that can be evaluated on this container.
* @param cmd the command to evaluate
Expand All @@ -456,19 +466,17 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
def runLocalCmd[A](cmd: LDPCommand[Plantain, LDPCommand.Script[Plantain,A]]) {
log.info(s"in PlantainLDPRActor.runLocalCmd - received $cmd")

def name(uri: Plantain#URI): String = {
uriW[Plantain](uri).lastPathSegment
}

cmd match {
case GetResource(uri, agent, k) => {
val res = getResource(uriW[Plantain](uri).lastPathSegment)
val res = getResource(localName(uri))
self forward Scrpt(k(res))
}
case GetMeta(uri, k) => {
//todo: GetMeta here is very close to GetResource, as currently there is no big work difference between the two
//The point of GetMeta is mostly to remove work if there were work that was very time
//consuming ( such as serialising a graph )
val res = getResource(uriW[Plantain](uri).lastPathSegment)
val res = getResource(localName(uri))
self forward Scrpt(k(res))
}
case DeleteResource(uri, a) => {
Expand All @@ -486,7 +494,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
rwwActor.tell(Scrpt(a),context.sender) //todo: why no function here?
}
case UpdateLDPR(uri, remove, add, a) => {
val nme = name(uri)
val nme = localName(uri)
getResource(nme) match {
case LocalLDPR(_,graph,updated) => {
val temp = remove.foldLeft(graph) {
Expand All @@ -502,7 +510,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
self forward Scrpt(a)
}
case PatchLDPR(uri, update, bindings, k) => {
val nme = name(uri)
val nme = localName(uri)
getResource(nme) match {
case LocalLDPR(_,graph,updated) => {
PlantainLDPatch.executePatch(graph,update,bindings) match {
Expand All @@ -517,7 +525,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
}
}
case SelectLDPR(uri, query, bindings, k) => {
getResource(name(uri)) match {
getResource(localName(uri)) match {
case LocalLDPR(_,graph,_) => {
val solutions = sparqlGraph(graph).executeSelect(query, bindings)
self forward Scrpt(k(solutions))
Expand All @@ -526,7 +534,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)
}
}
case ConstructLDPR(uri, query, bindings, k) => {
getResource(name(uri)) match {
getResource(localName(uri)) match {
case LocalLDPR(_,graph,_) => {
val result = sparqlGraph(graph).executeConstruct(query, bindings)
self forward Scrpt(k(result))
Expand All @@ -536,7 +544,7 @@ class PlantainLDPRActor(val baseUri: Plantain#URI,path: Path)

}
case AskLDPR(uri, query, bindings, k) => {
getResource(name(uri)) match {
getResource(localName(uri)) match {
case LocalLDPR(_,graph,_) => {
val result = sparqlGraph(graph).executeAsk(query, bindings)
self forward Scrpt(k(result))
Expand Down
5 changes: 3 additions & 2 deletions test/ldp/LDRTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rww.ldp
package test.ldp

import akka.actor.Props
import akka.util.Timeout
Expand All @@ -13,7 +13,8 @@ import org.w3.banana.plantain.Plantain
import play.api.libs.iteratee._
import scala.concurrent.{ExecutionContext, Await}
import scala.concurrent.duration.Duration
import auth._
import rww.ldp._
import rww.ldp.auth._


object LDRTestSuite {
Expand Down
3 changes: 2 additions & 1 deletion test/ldp/LinkHeaderParserTest.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package rww.ldp
package test.ldp

import org.w3.banana._
import org.scalatest.{BeforeAndAfterAll, WordSpec}
import org.scalatest.matchers.MustMatchers
import org.w3.banana.plantain.Plantain
import rww.ldp._

class PlantainLinkHeaderParserTest extends LinkHeaderParserTest[Plantain]()(plantain.PlantainOps)

Expand Down
3 changes: 2 additions & 1 deletion test/ldp/PlantainGraphStoreTest.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rww.ldp
package test.ldp

import org.w3.banana._
import org.w3.banana.plantain._
Expand All @@ -16,6 +16,7 @@ import scala.Some
import akka.actor.Props
import rww.ldp.auth.WACAuthZ
import scala.util.Try
import rww.ldp._

object PlantainTest {
val dir = Files.createTempDirectory("plantain" )
Expand Down
29 changes: 29 additions & 0 deletions test/ldp/RActorTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package test.ldp

import org.scalatest.WordSpec
import org.scalatest.Matchers
import rww.ldp.RActor
import java.net.{URI, URL}

/**
* Created by hjs on 12/11/2013.
*/
class RActorTest extends WordSpec with Matchers {
import RActor._

val localBase = new URI("https://localhost:8443/2013/")

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




}
3 changes: 2 additions & 1 deletion test/ldp/TestGraphs.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rww.ldp
package test.ldp

import java.security.interfaces.{RSAPrivateKey, RSAPublicKey}
import java.security.{KeyPair, KeyPairGenerator}
Expand All @@ -9,6 +9,7 @@ import scala.concurrent.Future
import org.w3.play.api.libs.ws.ResponseHeaders
import org.w3.banana
import org.scalatest.{Suite, BeforeAndAfter}
import rww.ldp._

/**
* Build up a set of Graphs with representing some realistic scenarios that can then be used
Expand Down
2 changes: 1 addition & 1 deletion test/ldp/TestHelper.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rww.ldp
package test.ldp

import org.scalatest._
import scala.concurrent._
Expand Down
3 changes: 2 additions & 1 deletion test/ldp/WebIDVerifierTest.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rww.ldp
package test.ldp

import akka.actor.Props
import akka.util.Timeout
Expand All @@ -14,6 +14,7 @@ import rww.ldp.LDPCommand._
import scala.Some
import sun.security.x509.X500Name
import java.security.Principal
import rww.ldp._

import org.w3.banana.plantain.Plantain

Expand Down
3 changes: 2 additions & 1 deletion test/ldp/WebTestSuite.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rww.ldp
package test.ldp

import akka.actor.Props
import akka.util.Timeout
Expand All @@ -15,6 +15,7 @@ import scala.Some
import scala.concurrent.{ExecutionContext, Await}
import scala.concurrent.duration.Duration
import rww.ldp.auth.{WebIDPrincipal, WebIDVerifier, WACAuthZ}
import rww.ldp._


object WebTestSuite {
Expand Down

0 comments on commit 7939ebe

Please sign in to comment.