changeset 21:1cd268e07e44

Added resource to create artifacts to web server. artifacts/trunk@54 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 Sep 2009 15:43:47 +0000
parents ff666592c1c3
children 72abee95fd64
files Changelog artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateResource.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java
diffstat 4 files changed, 78 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Changelog	Wed Sep 09 14:33:25 2009 +0000
+++ b/Changelog	Wed Sep 09 15:43:47 2009 +0000
@@ -1,3 +1,14 @@
+2009-09-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateResource.java:
+	New. Resource to create an artifact. Not working on artifact database yet.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java:
+	Attached create to web server.
+
+	* artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java:
+	Added meta data to Get annotation.
+
 2009-09-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* artifact-database/pom.xml: Added dependency to restlet.ext.xml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateResource.java	Wed Sep 09 15:43:47 2009 +0000
@@ -0,0 +1,61 @@
+package de.intevation.artifactdatabase.rest;
+
+import org.w3c.dom.Document;
+
+import org.restlet.ext.xml.DomRepresentation;
+
+import org.restlet.resource.Post;  
+import org.restlet.resource.ServerResource;
+
+import org.restlet.data.Request;
+import org.restlet.data.Response;
+import org.restlet.data.Status;
+
+import org.restlet.data.MediaType;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifactdatabase.XMLUtils;
+import de.intevation.artifactdatabase.Config;
+
+import org.restlet.representation.Representation;
+import org.restlet.representation.EmptyRepresentation;
+
+import java.io.IOException;
+
+/**
+ * @author Sascha L. Teichmann (sascha.teichmann@intevation)
+ */
+public class CreateResource
+extends      ServerResource
+{
+    private static Logger logger = Logger.getLogger(CreateResource.class);
+
+    public static final String PATH = "/create";
+
+    @Post("xml:xml")
+    public Representation represent() {
+
+        Request request = getRequest();
+
+        Representation requestRepr = request.getEntity();
+
+        Document inputDocument = null;
+        try {
+            DomRepresentation input = new DomRepresentation(requestRepr);
+            inputDocument = input.getDocument();
+        }
+        catch (IOException ioe) {
+            logger.error(ioe.getMessage());
+            Response response = getResponse();
+            response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe);
+            return new EmptyRepresentation();
+        }
+        
+        Document outputDocument = XMLUtils.newDocument();
+
+        return new DomRepresentation(
+            MediaType.APPLICATION_XML, outputDocument);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java	Wed Sep 09 14:33:25 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java	Wed Sep 09 15:43:47 2009 +0000
@@ -1,6 +1,5 @@
 package de.intevation.artifactdatabase.rest;
 
-
 import de.intevation.artifacts.ArtifactDatabase;
 
 import org.restlet.data.MediaType;
@@ -10,8 +9,6 @@
 
 import org.restlet.ext.xml.DomRepresentation;
 
-import java.io.IOException;
-
 import de.intevation.artifactdatabase.XMLUtils;
 import de.intevation.artifactdatabase.XMLUtils.ElementCreator;
 
@@ -22,14 +19,17 @@
 
 import org.apache.log4j.Logger;
 
+/**
+ * @author Sascha L. Teichmann (sascha.teichmann@intevation)
+ */
 public class FactoriesResource
 extends      ServerResource
 {
-    private static final Logger logger = Logger.getLogger(FactoriesResource.class);
+    private static Logger logger = Logger.getLogger(FactoriesResource.class);
     
     public static final String PATH = "/factories";
 
-    @Get
+    @Get("xml:xml")
     public DomRepresentation represent() {
 
         Document document = XMLUtils.newDocument();
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java	Wed Sep 09 14:33:25 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java	Wed Sep 09 15:43:47 2009 +0000
@@ -36,6 +36,7 @@
         Router router = new Router(context);
 
         router.attach(FactoriesResource.PATH, FactoriesResource.class);
+        router.attach(CreateResource.PATH,    CreateResource.class);
 
         return router;
     }

http://dive4elements.wald.intevation.org