Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/ServiceResource.java @ 73:d1b8c91b4506
Added url '/service/{service}' to REST server to offer the actual service over HTTP.
artifacts/trunk@601 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jan 2010 11:56:28 +0000 |
parents | |
children | 48d1a9a082c2 |
comparison
equal
deleted
inserted
replaced
72:b01e47317a78 | 73:d1b8c91b4506 |
---|---|
1 package de.intevation.artifactdatabase.rest; | |
2 | |
3 import org.restlet.representation.Representation; | |
4 import org.restlet.representation.EmptyRepresentation; | |
5 | |
6 import org.restlet.ext.xml.DomRepresentation; | |
7 | |
8 import de.intevation.artifacts.ArtifactDatabase; | |
9 import de.intevation.artifacts.ArtifactDatabaseException; | |
10 | |
11 import org.restlet.data.Request; | |
12 import org.restlet.data.Response; | |
13 import org.restlet.data.Status; | |
14 import org.restlet.data.MediaType; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 import org.w3c.dom.Document; | |
19 | |
20 import java.io.IOException; | |
21 | |
22 /** | |
23 * @author Sascha L. Teichmann (sascha.teichmann@intevation) | |
24 */ | |
25 public class ServiceResource | |
26 extends BaseResource | |
27 { | |
28 private static Logger logger = Logger.getLogger(ServiceResource.class); | |
29 | |
30 public static final String PATH = "/service/{service}"; | |
31 | |
32 public static final String NO_SUCH_ACTION_MESSAGE = "no such service"; | |
33 | |
34 protected Representation innerPost(Representation requestRepr) { | |
35 | |
36 Document inputDocument = null; | |
37 try { | |
38 DomRepresentation input = new DomRepresentation(requestRepr); | |
39 input.setNamespaceAware(true); | |
40 inputDocument = input.getDocument(); | |
41 } | |
42 catch (IOException ioe) { | |
43 logger.error(ioe.getMessage()); | |
44 Response response = getResponse(); | |
45 response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe); | |
46 return new EmptyRepresentation(); | |
47 } | |
48 | |
49 Request request = getRequest(); | |
50 | |
51 String service = (String)request.getAttributes().get("service"); | |
52 | |
53 ArtifactDatabase db = (ArtifactDatabase)getContext() | |
54 .getAttributes().get("database"); | |
55 | |
56 try { | |
57 return new DomRepresentation( | |
58 MediaType.APPLICATION_XML, | |
59 db.process(service, inputDocument, getCallMeta())); | |
60 } | |
61 catch (ArtifactDatabaseException adbe) { | |
62 logger.warn(adbe.getLocalizedMessage(), adbe); | |
63 Response response = getResponse(); | |
64 response.setStatus( | |
65 Status.CLIENT_ERROR_BAD_REQUEST, adbe.getMessage()); | |
66 return new EmptyRepresentation(); | |
67 } | |
68 } | |
69 } | |
70 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |