Mercurial > dive4elements > river
view 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 |
line wrap: on
line source
package de.intevation.flys.client.server; import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import javax.xml.xpath.XPathConstants; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import org.w3c.dom.Document; import org.apache.log4j.Logger; import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.flys.client.shared.exceptions.ServerException; import de.intevation.flys.client.shared.model.Capabilities; import de.intevation.flys.client.client.services.GCService; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class GCServiceImpl extends RemoteServiceServlet implements GCService { public static final String ERR_GC_REQUEST_FAILED = "error_gc_req_failed"; public static final String ERR_GC_DOC_NOT_VALID = "error_gc_doc_not_valid"; public static final String ERR_MALFORMED_URL = "error_malformed_url"; public static final String XPATH_FEES = "/WMS_Capabilities/Service/Fees/text()"; public static final String XPATH_ACCESS_CONSTRAINTS = "/WMS_Capabilities/Service/AccessConstraints/text()"; private Logger logger = Logger.getLogger(GCServiceImpl.class); public Capabilities query(String path) throws ServerException { logger.info("GCServiceImpl.query"); try { URL url = new URL(path); logger.debug("Open connection to url: " + path); URLConnection conn = url.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); return parseCapabilitiesResponse(is); } catch (MalformedURLException mue) { logger.warn(mue, mue); throw new ServerException(ERR_MALFORMED_URL); } catch (IOException ioe) { logger.warn(ioe, ioe); } throw new ServerException(ERR_GC_REQUEST_FAILED); } protected Capabilities parseCapabilitiesResponse(InputStream is) throws ServerException { logger.debug("GCServiceImpl.parseCapabilitiesResponse"); Document doc = XMLUtils.parseDocument(is, false); if (doc == null) { throw new ServerException(ERR_GC_DOC_NOT_VALID); } String fees = (String) XMLUtils.xpath( doc, XPATH_FEES, XPathConstants.STRING); String accessConstraints = (String) XMLUtils.xpath( doc, XPATH_ACCESS_CONSTRAINTS, XPathConstants.STRING); logger.debug("Found fees: " + fees); logger.debug("Found access constraints: " + accessConstraints); // TODO PARSE LAYERS return new Capabilities(fees, accessConstraints, null); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :