Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java @ 5818:a4ff4167be1e
Request feature info on all layers and show it as html if
the server does not return valid gml.
Non queryable layers produce an error message when the request
fails. This is good enough
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 24 Apr 2013 17:33:27 +0200 |
parents | af2aa716152f |
children |
comparison
equal
deleted
inserted
replaced
5817:a1dd784d8b07 | 5818:a4ff4167be1e |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import java.io.InputStream; | 3 import java.io.InputStream; |
4 import java.io.UnsupportedEncodingException; | |
5 import java.io.ByteArrayOutputStream; | |
4 import java.io.IOException; | 6 import java.io.IOException; |
5 import java.net.URL; | 7 import java.net.URL; |
6 import java.net.URLConnection; | 8 import java.net.URLConnection; |
7 import java.util.ArrayList; | 9 import java.util.ArrayList; |
8 import java.util.List; | 10 import java.util.List; |
11 import java.util.Scanner; | |
9 | 12 |
10 import org.w3c.dom.Document; | 13 import org.w3c.dom.Document; |
11 import org.w3c.dom.Node; | 14 import org.w3c.dom.Node; |
12 import org.w3c.dom.NodeList; | 15 import org.w3c.dom.NodeList; |
13 | 16 |
18 import de.intevation.artifacts.common.utils.XMLUtils; | 21 import de.intevation.artifacts.common.utils.XMLUtils; |
19 | 22 |
20 import de.intevation.flys.client.shared.exceptions.ServerException; | 23 import de.intevation.flys.client.shared.exceptions.ServerException; |
21 import de.intevation.flys.client.shared.model.AttributedTheme; | 24 import de.intevation.flys.client.shared.model.AttributedTheme; |
22 import de.intevation.flys.client.shared.model.FeatureInfo; | 25 import de.intevation.flys.client.shared.model.FeatureInfo; |
26 import de.intevation.flys.client.shared.model.FeatureInfoResponse; | |
23 import de.intevation.flys.client.shared.model.Theme; | 27 import de.intevation.flys.client.shared.model.Theme; |
24 | 28 |
25 import de.intevation.flys.client.client.services.GFIService; | 29 import de.intevation.flys.client.client.services.GFIService; |
26 | 30 |
27 | 31 |
55 * @param x | 59 * @param x |
56 * @param y | 60 * @param y |
57 * | 61 * |
58 * @return | 62 * @return |
59 */ | 63 */ |
60 public List<FeatureInfo> query( | 64 public FeatureInfoResponse query( |
61 Theme theme, | 65 Theme theme, |
62 String format, | 66 String format, |
63 String bbox, | 67 String bbox, |
64 String projection, | 68 String projection, |
65 int height, | 69 int height, |
149 } | 153 } |
150 | 154 |
151 | 155 |
152 protected String getUrl(Theme theme) { | 156 protected String getUrl(Theme theme) { |
153 AttributedTheme attr = (AttributedTheme) theme; | 157 AttributedTheme attr = (AttributedTheme) theme; |
154 | 158 return attr.getAttr("url"); |
155 if (attr.getAttrAsBoolean("queryable")) { | 159 } |
156 return attr.getAttr("url"); | 160 |
157 } | 161 |
158 return null; | 162 protected FeatureInfoResponse parseResponse(InputStream is) { |
159 } | |
160 | |
161 | |
162 protected List<FeatureInfo> parseResponse(InputStream is) { | |
163 logger.debug("GFIServiceImpl.parseResponse"); | 163 logger.debug("GFIServiceImpl.parseResponse"); |
164 | 164 |
165 Document response = XMLUtils.parseDocument(is); | 165 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
166 | 166 byte [] buf = new byte[1024]; |
167 List<FeatureInfo> features = new ArrayList<FeatureInfo>(); | 167 |
168 | 168 int r = -1; |
169 parseFeatureInfos(response, features); | 169 try { |
170 | 170 while ((r = is.read(buf)) >= 0) { |
171 return features; | 171 baos.write(buf, 0, r); |
172 } | |
173 } catch (IOException ex) { | |
174 logger.warn("GetFeatureInfo response could not be read: ", ex); | |
175 return new FeatureInfoResponse(); | |
176 } | |
177 | |
178 String content; | |
179 try { | |
180 content = baos.toString("UTF-8"); | |
181 } | |
182 catch (UnsupportedEncodingException uee) { | |
183 content = baos.toString(); | |
184 } | |
185 | |
186 Document response = XMLUtils.parseDocument(content); | |
187 if (response != null) { | |
188 List<FeatureInfo> features = new ArrayList<FeatureInfo>(); | |
189 parseFeatureInfos(response, features); | |
190 return new FeatureInfoResponse(features, null); | |
191 } | |
192 // Unable to parse just return the response as is | |
193 return new FeatureInfoResponse(new ArrayList<FeatureInfo>(), content); | |
172 } | 194 } |
173 | 195 |
174 | 196 |
175 protected void parseFeatureInfos(Node node, List<FeatureInfo> features) { | 197 protected void parseFeatureInfos(Node node, List<FeatureInfo> features) { |
176 logger.debug("GFIServiceImpl.parseFeatureInfos"); | 198 logger.debug("GFIServiceImpl.parseFeatureInfos"); |