diff 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
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java	Wed Apr 24 15:20:50 2013 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/GFIServiceImpl.java	Wed Apr 24 17:33:27 2013 +0200
@@ -1,11 +1,14 @@
 package de.intevation.flys.client.server;
 
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Scanner;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -20,6 +23,7 @@
 import de.intevation.flys.client.shared.exceptions.ServerException;
 import de.intevation.flys.client.shared.model.AttributedTheme;
 import de.intevation.flys.client.shared.model.FeatureInfo;
+import de.intevation.flys.client.shared.model.FeatureInfoResponse;
 import de.intevation.flys.client.shared.model.Theme;
 
 import de.intevation.flys.client.client.services.GFIService;
@@ -57,7 +61,7 @@
      *
      * @return
      */
-    public List<FeatureInfo> query(
+    public FeatureInfoResponse query(
         Theme       theme,
         String      format,
         String      bbox,
@@ -151,24 +155,42 @@
 
     protected String getUrl(Theme theme) {
         AttributedTheme attr = (AttributedTheme) theme;
-
-        if (attr.getAttrAsBoolean("queryable")) {
-            return attr.getAttr("url");
-        }
-        return null;
+        return attr.getAttr("url");
     }
 
 
-    protected List<FeatureInfo> parseResponse(InputStream is) {
+    protected FeatureInfoResponse parseResponse(InputStream is) {
         logger.debug("GFIServiceImpl.parseResponse");
 
-        Document response = XMLUtils.parseDocument(is);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte [] buf = new byte[1024];
 
-        List<FeatureInfo> features = new ArrayList<FeatureInfo>();
+        int r = -1;
+        try {
+            while ((r = is.read(buf)) >= 0) {
+                baos.write(buf, 0, r);
+            }
+        } catch (IOException ex) {
+            logger.warn("GetFeatureInfo response could not be read: ", ex);
+            return new FeatureInfoResponse();
+        }
 
-        parseFeatureInfos(response, features);
+        String content;
+        try {
+            content = baos.toString("UTF-8");
+        }
+        catch (UnsupportedEncodingException uee) {
+            content = baos.toString();
+        }
 
-        return features;
+        Document response = XMLUtils.parseDocument(content);
+        if (response != null) {
+            List<FeatureInfo> features = new ArrayList<FeatureInfo>();
+            parseFeatureInfos(response, features);
+            return new FeatureInfoResponse(features, null);
+        }
+        // Unable to parse just return the response as is
+        return new FeatureInfoResponse(new ArrayList<FeatureInfo>(), content);
     }
 
 

http://dive4elements.wald.intevation.org