Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/RiverServiceImpl.java @ 217:907b61e4d702
Improved the exception handling - added warnings for user authentication errors and errors that occur while fetching supported rivers.
flys-client/trunk@1659 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 08 Apr 2011 10:05:14 +0000 |
parents | 44c63e7fd0d0 |
children | 924da6695800 |
comparison
equal
deleted
inserted
replaced
216:4b0fb079ead9 | 217:907b61e4d702 |
---|---|
16 | 16 |
17 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | 17 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
18 import de.intevation.artifacts.httpclient.http.HttpClient; | 18 import de.intevation.artifacts.httpclient.http.HttpClient; |
19 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | 19 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
20 | 20 |
21 import de.intevation.flys.client.shared.exceptions.ServerException; | |
21 import de.intevation.flys.client.shared.model.DefaultRiver; | 22 import de.intevation.flys.client.shared.model.DefaultRiver; |
22 import de.intevation.flys.client.shared.model.River; | 23 import de.intevation.flys.client.shared.model.River; |
23 import de.intevation.flys.client.client.services.RiverService; | 24 import de.intevation.flys.client.client.services.RiverService; |
24 | 25 |
25 | 26 |
34 implements RiverService | 35 implements RiverService |
35 { | 36 { |
36 /** The XPath string that points to the rivers in the resulting document.*/ | 37 /** The XPath string that points to the rivers in the resulting document.*/ |
37 public static final String XPATH_RIVERS = "/art:rivers/art:river"; | 38 public static final String XPATH_RIVERS = "/art:rivers/art:river"; |
38 | 39 |
40 /** The error message key that is thrown if an error occured while reading | |
41 * the supported rivers from server.*/ | |
42 public static final String ERROR_NO_RIVERS_FOUND = "error_no_rivers_found"; | |
39 | 43 |
40 public River[] list(String serverUrl) { | 44 |
45 public River[] list(String serverUrl) | |
46 throws ServerException | |
47 { | |
41 Document doc = XMLUtils.newDocument(); | 48 Document doc = XMLUtils.newDocument(); |
42 | 49 |
43 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | 50 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
44 doc, | 51 doc, |
45 ArtifactNamespaceContext.NAMESPACE_URI, | 52 ArtifactNamespaceContext.NAMESPACE_URI, |
56 res, | 63 res, |
57 XPATH_RIVERS, | 64 XPATH_RIVERS, |
58 XPathConstants.NODESET, | 65 XPathConstants.NODESET, |
59 ArtifactNamespaceContext.INSTANCE); | 66 ArtifactNamespaceContext.INSTANCE); |
60 | 67 |
68 if (rivers == null || rivers.getLength() == 0) { | |
69 throw new ServerException(ERROR_NO_RIVERS_FOUND); | |
70 } | |
71 | |
61 int count = rivers.getLength(); | 72 int count = rivers.getLength(); |
62 | 73 |
63 List<River> theRivers = new ArrayList<River>(count); | 74 List<River> theRivers = new ArrayList<River>(count); |
64 | 75 |
65 for (int i = 0; i < count; i++) { | 76 for (int i = 0; i < count; i++) { |
75 } | 86 } |
76 catch (ConnectionException ce) { | 87 catch (ConnectionException ce) { |
77 System.err.println(ce.getLocalizedMessage()); | 88 System.err.println(ce.getLocalizedMessage()); |
78 } | 89 } |
79 | 90 |
80 return null; | 91 throw new ServerException(ERROR_NO_RIVERS_FOUND); |
81 } | 92 } |
82 } | 93 } |
83 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 94 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |