Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/GetArtifactServiceImpl.java @ 5737:ce002608992d
Backend: Forget to increment index.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Tue, 16 Apr 2013 18:50:45 +0200 |
parents | bc06a671ef60 |
children |
rev | line source |
---|---|
221
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import org.w3c.dom.Document; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
5 import org.apache.log4j.Logger; |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
6 |
221
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifacts.common.utils.ClientProtocolUtils; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.common.utils.XMLUtils; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.artifacts.httpclient.http.HttpClient; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import de.intevation.flys.client.shared.exceptions.ServerException; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.flys.client.shared.model.Artifact; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import de.intevation.flys.client.client.services.GetArtifactService; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 /** |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 * This service provides a method that returns an artifact based on its |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 * identifier. |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 * |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 */ |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 public class GetArtifactServiceImpl |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 extends RemoteServiceServlet |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 implements GetArtifactService |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
33 private static final Logger logger = |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
34 Logger.getLogger(GetArtifactServiceImpl.class); |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
35 |
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
36 |
221
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 public static final String ERROR_DESCRIBE_ARTIFACT = |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 "error_describe_artifact"; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 public static final String XPATH_RESULT = "/art:result/text()"; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 public static final String OPERATION_FAILURE = "FAILED"; |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
229
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
221
diff
changeset
|
45 public Artifact getArtifact( |
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
221
diff
changeset
|
46 String locale, |
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
221
diff
changeset
|
47 String uuid, |
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
221
diff
changeset
|
48 String hash) |
221
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 throws ServerException |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
51 logger.info("GetArtifactServiceImpl.getArtifact"); |
229
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
221
diff
changeset
|
52 |
1425
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
53 String url = getServletContext().getInitParameter("server-url"); |
bc06a671ef60
Removed the URL parameter from service calls. The service
Raimund Renkert <raimund.renkert@intevation.de>
parents:
1367
diff
changeset
|
54 |
221
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 Document describe = ClientProtocolUtils.newDescribeDocument( |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 uuid, hash, true); |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
229
924da6695800
Each service is now called with the name of the current locale to set the request object's locale manually in the HttpClient.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
221
diff
changeset
|
58 HttpClient client = new HttpClientImpl(url, locale); |
221
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 try { |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 Document description = (Document) client.describe( |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 new de.intevation.artifacts.httpclient.objects.Artifact( |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 uuid, hash), |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 describe, |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 new DocumentResponseHandler()); |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 if (description == null) { |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 throw new ServerException(ERROR_DESCRIBE_ARTIFACT); |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 } |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 String result = XMLUtils.xpathString( |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 description, |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 XPATH_RESULT, |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 ArtifactNamespaceContext.INSTANCE); |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 if (result == null || !result.equals(OPERATION_FAILURE)) { |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 return (Artifact) new FLYSArtifactCreator().create(description); |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 } |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
79 } |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
80 catch (ConnectionException ce) { |
1367
ab8eb2f544f2
Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
229
diff
changeset
|
81 logger.error(ce, ce); |
221
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 } |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
84 throw new ServerException(ERROR_DESCRIBE_ARTIFACT); |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 } |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 } |
f03c34bec364
Added a new service to query an artifact description.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |