Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/server/ServerInfoServiceImpl.java @ 6475:b0b0ba6e7bb0
Add client side servlets and service stubs for ServerInfoService.
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Thu, 27 Jun 2013 14:48:21 +0200 |
parents | |
children | 238fc722f87a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/ServerInfoServiceImpl.java Thu Jun 27 14:48:21 2013 +0200 @@ -0,0 +1,69 @@ +package org.dive4elements.river.client.server; + +import java.util.HashMap; +import java.util.Map; + +import javax.xml.xpath.XPathConstants; + +import org.apache.log4j.Logger; +import org.dive4elements.artifacts.common.ArtifactNamespaceContext; +import org.dive4elements.artifacts.common.utils.XMLUtils; +import org.dive4elements.artifacts.httpclient.http.HttpClient; +import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; +import org.dive4elements.river.client.client.services.ServerInfoService; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class ServerInfoServiceImpl extends RemoteServiceServlet implements + ServerInfoService { + + // This works only because currently there is only one info transmitted + private static final String XPATH_INFO = "/art:server/art:info"; + + private final Logger logger = Logger.getLogger(ServerInfoServiceImpl.class); + + @Override + public Map<String, String> getConfig(String locale) { + Map<String, String> infoMap = new HashMap<String, String>(); + String url = getServletContext().getInitParameter("server-url"); + + Document doc = XMLUtils.newDocument(); + + XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( + doc, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + doc.appendChild(ec.create("action")); + + HttpClient client = new HttpClientImpl(url, locale); + + try { + Document res = client.callService(url, "server-info", doc); + + NodeList info = (NodeList) XMLUtils.xpath(res, + XPATH_INFO, + XPathConstants.NODESET, + ArtifactNamespaceContext.INSTANCE); + + for (int n = 0; n < info.getLength(); n++) { + Element el = (Element)info.item(n); + String key = el.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "key"); + String val = el.getAttributeNS( + ArtifactNamespaceContext.NAMESPACE_URI, "value"); + infoMap.put(key, val); + + logger.debug("ServerInfoServiceImpl: " + key + "=" + val); + } + } + catch (Exception ex) { + logger.error(ex, ex); + } + + return infoMap; + } + + +}