testing out the PUT/POST parts of the main plan. Added an echo service, because I was having trouble understanding what was going on. Fixed a few import problems, that made intellij underline things webid
authorHenry Story <henry.story@bblfish.net>
Thu, 20 Oct 2011 13:50:05 +0200
branchwebid
changeset 89 749d9b5a655f
parent 88 de8692b6c5c8
child 90 35f36ee52d0b
testing out the PUT/POST parts of the main plan. Added an echo service, because I was having trouble understanding what was going on. Fixed a few import problems, that made intellij underline things
INSTALL.txt
src/main/scala/EchoPlan.scala
src/main/scala/Filesystem.scala
src/main/scala/ReadWriteWebMain.scala
src/main/scala/plan.scala
--- a/INSTALL.txt	Tue Oct 18 14:20:08 2011 +0200
+++ b/INSTALL.txt	Thu Oct 20 13:50:05 2011 +0200
@@ -27,9 +27,14 @@
 
 6. connect to different resources
 
+6.1 GETing a public resource
+
  $ curl -k https://localhost:8443/public/ 
+
   If you access this via your browser and you have more than one webid certificate, your browser will ask you for  even when you access this. We are working on a solution to stop this from happening.
 
+6.2 GETing a protected resource
+
 The following is a protected resource so if you access it without authentification credentials you will get  
 
  $  curl  -i -k https://localhost:8443/2011/09/foaf.n3
@@ -55,8 +60,25 @@
 
 If you want to give yourself access then replace Henry's WebID, "http://bblfish.net/people/henry/card#me"  with your own, or make another example for that.
 
-More interesting examples to follow soon.
+6.3 Uploading a resource
 
+Say you wanted to upload an RDF file to the server
 
-  
+$ curl http://bblfish.net/people/henry/card.rdf | curl -i -k  -H "Content-Type: application/rdf+xml" -X PUT https://localhost:8443/2011/09/test2.rdf -T - 
+HTTP/1.1 100 Continue
 
+  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
+                                 Dload  Upload   Total   Spent    Left  Speed
+100 24386  100 24386    0     0   2223      0  0:00:10  0:00:10 --:--:-- 33405
+HTTP/1.1 201 Created
+Content-Length: 0
+Server: Jetty(7.2.2.v20101205)
+
+the file will then be available as /2011/09/test2.rdf  on the localhost server
+
+6.4 querying a resource with SPARQL 
+
+You can write a SPARQL query and then query the given model by POSTing the query to the resource
+
+curl -k -i -H "Content-Type: application/sparql-query"  -X POST https://localhost:8443/2011/09/test.rdf -T queryfriends.sparql
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/EchoPlan.scala	Thu Oct 20 13:50:05 2011 +0200
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011 Henry Story (bblfish.net)
+ * under the MIT licence defined
+ *    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
+
+import unfiltered.request.Path
+import unfiltered.response.{ResponseString, PlainTextContent, ContentType, Ok}
+import io.BufferedSource
+
+
+/**
+ * @author hjs
+ * @created: 19/10/2011
+ */
+
+class EchoPlan {
+  import collection.JavaConversions._
+
+  lazy val plan = unfiltered.filter.Planify({
+    case req@Path(path) if path startsWith "/test/http/echo" => {
+      Ok ~> PlainTextContent ~> {
+        val headers = req.underlying.getHeaderNames()
+        val result = for (name <- headers ;
+             val nameStr = name.asInstanceOf[String]
+        ) yield {
+          nameStr + ": " + req.underlying.getHeader(nameStr)+"\r\n"
+        }
+        ResponseString(result.mkString+ "\r\n" + new BufferedSource(req.inputStream).mkString)
+      }
+    }
+
+  })
+}
\ No newline at end of file
--- a/src/main/scala/Filesystem.scala	Tue Oct 18 14:20:08 2011 +0200
+++ b/src/main/scala/Filesystem.scala	Thu Oct 20 13:50:05 2011 +0200
@@ -5,10 +5,10 @@
 import java.io._
 import java.net.URL
 import org.slf4j.{Logger, LoggerFactory}
-import com.hp.hpl.jena.rdf.model._
+import com.hp.hpl.jena.rdf.model.{Resource=>JResource,_}
 import com.hp.hpl.jena.shared.JenaException
 
-import scalaz.{sys => _, _}
+import scalaz.{Resource => SzResource, sys => _,  _}
 import Scalaz._
 
 class Filesystem(
--- a/src/main/scala/ReadWriteWebMain.scala	Tue Oct 18 14:20:08 2011 +0200
+++ b/src/main/scala/ReadWriteWebMain.scala	Thu Oct 20 13:50:05 2011 +0200
@@ -10,6 +10,9 @@
 
 import org.clapper.argot._
 import ArgotConverters._
+import javax.servlet.http.HttpServletRequest
+import unfiltered.request.HttpRequest
+
 object ReadWriteWebMain {
 
   val logger: Logger = LoggerFactory.getLogger(this.getClass)
@@ -95,7 +98,8 @@
         ctx.resources(ClasspathUtils.fromClasspath("public/").toURI.toURL)
     }.
       filter(app.plan).
-      filter(new X509view().plan).run()
+      filter(new X509view().plan).
+      filter(new EchoPlan().plan).run()
     
   }
 
--- a/src/main/scala/plan.scala	Tue Oct 18 14:20:08 2011 +0200
+++ b/src/main/scala/plan.scala	Thu Oct 20 13:50:05 2011 +0200
@@ -16,7 +16,7 @@
               QueryTypeConstruct => CONSTRUCT,
               QueryTypeDescribe => DESCRIBE}
 
-import scalaz._
+import scalaz.{Resource=>SzResource,_}
 import unfiltered.filter.Plan
 import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
 import unfiltered.request._