# HG changeset patch # User Sascha L. Teichmann # Date 1252511027 0 # Node ID 1cd268e07e4444eed3d0b9b23b49a147747989f0 # Parent ff666592c1c3812b2229e5618edb5d9058c835fb Added resource to create artifacts to web server. artifacts/trunk@54 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ff666592c1c3 -r 1cd268e07e44 Changelog --- 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 + + * 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 * artifact-database/pom.xml: Added dependency to restlet.ext.xml diff -r ff666592c1c3 -r 1cd268e07e44 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/CreateResource.java --- /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: diff -r ff666592c1c3 -r 1cd268e07e44 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/FactoriesResource.java --- 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(); diff -r ff666592c1c3 -r 1cd268e07e44 artifact-database/src/main/java/de/intevation/artifactdatabase/rest/RestApp.java --- 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; }