comparison flys-client/src/main/java/de/intevation/flys/client/server/GCServiceImpl.java @ 1408:5b5a20e4c4e5

Added a service that loads the Capabilities of a specified WMS - display those information in the ExternalWMSWindow. flys-client/trunk@3295 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 21 Nov 2011 12:00:48 +0000
parents
children ec6e4dad1279
comparison
equal deleted inserted replaced
1407:ee2875510c12 1408:5b5a20e4c4e5
1 package de.intevation.flys.client.server;
2
3 import java.io.InputStream;
4 import java.io.IOException;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7 import java.net.URLConnection;
8
9 import javax.xml.xpath.XPathConstants;
10
11 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
12
13 import org.w3c.dom.Document;
14
15 import org.apache.log4j.Logger;
16
17 import de.intevation.artifacts.common.utils.XMLUtils;
18
19 import de.intevation.flys.client.shared.exceptions.ServerException;
20 import de.intevation.flys.client.shared.model.Capabilities;
21 import de.intevation.flys.client.client.services.GCService;
22
23
24 /**
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
26 */
27 public class GCServiceImpl
28 extends RemoteServiceServlet
29 implements GCService
30 {
31 public static final String ERR_GC_REQUEST_FAILED =
32 "error_gc_req_failed";
33
34 public static final String ERR_GC_DOC_NOT_VALID =
35 "error_gc_doc_not_valid";
36
37 public static final String ERR_MALFORMED_URL =
38 "error_malformed_url";
39
40 public static final String XPATH_FEES =
41 "/WMS_Capabilities/Service/Fees/text()";
42
43 public static final String XPATH_ACCESS_CONSTRAINTS =
44 "/WMS_Capabilities/Service/AccessConstraints/text()";
45
46
47 private Logger logger = Logger.getLogger(GCServiceImpl.class);
48
49
50 public Capabilities query(String path)
51 throws ServerException
52 {
53 logger.info("GCServiceImpl.query");
54
55 try {
56 URL url = new URL(path);
57
58 logger.debug("Open connection to url: " + path);
59
60 URLConnection conn = url.openConnection();
61 conn.connect();
62
63 InputStream is = conn.getInputStream();
64
65 return parseCapabilitiesResponse(is);
66 }
67 catch (MalformedURLException mue) {
68 logger.warn(mue, mue);
69 throw new ServerException(ERR_MALFORMED_URL);
70 }
71 catch (IOException ioe) {
72 logger.warn(ioe, ioe);
73 }
74
75 throw new ServerException(ERR_GC_REQUEST_FAILED);
76 }
77
78
79 protected Capabilities parseCapabilitiesResponse(InputStream is)
80 throws ServerException
81 {
82 logger.debug("GCServiceImpl.parseCapabilitiesResponse");
83
84 Document doc = XMLUtils.parseDocument(is, false);
85
86 if (doc == null) {
87 throw new ServerException(ERR_GC_DOC_NOT_VALID);
88 }
89
90 String fees = (String) XMLUtils.xpath(
91 doc,
92 XPATH_FEES,
93 XPathConstants.STRING);
94
95 String accessConstraints = (String) XMLUtils.xpath(
96 doc,
97 XPATH_ACCESS_CONSTRAINTS,
98 XPathConstants.STRING);
99
100 logger.debug("Found fees: " + fees);
101 logger.debug("Found access constraints: " + accessConstraints);
102
103 // TODO PARSE LAYERS
104
105 return new Capabilities(fees, accessConstraints, null);
106 }
107 }
108 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org