diff artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServiceResource.java @ 380:9798e4d83681

Services are now able to return more than just XML documents. artifacts/trunk@4188 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Apr 2012 11:15:10 +0000
parents 7fc0650f194c
children
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServiceResource.java	Fri Mar 30 07:21:29 2012 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServiceResource.java	Tue Apr 03 11:15:10 2012 +0000
@@ -27,6 +27,8 @@
 
 import org.w3c.dom.Document;
 
+import de.intevation.artifacts.Service;
+
 /**
  * Resource to process incoming XML documents with a given service.
  *
@@ -72,8 +74,7 @@
             .getAttributes().get("database");
 
         try {
-            return new DomRepresentation(
-                MediaType.APPLICATION_XML,
+            return guessRepresentation(
                 db.process(service, inputDocument, getCallMeta()));
         }
         catch (ArtifactDatabaseException adbe) {
@@ -84,5 +85,21 @@
             return new EmptyRepresentation();
         }
     }
+
+    protected static Representation guessRepresentation(Service.Output output) {
+
+        MediaType mediaType = new MediaType(output.getMIMEType());
+        Object    data      = output.getData();
+
+        if (data instanceof Document) {
+            return new DomRepresentation(mediaType, (Document)data);
+        }
+
+        if (data instanceof byte []) {
+            return new ByteArrayRepresentation(mediaType, (byte [])data);
+        }
+
+        return new EmptyRepresentation();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org