Mercurial > dive4elements > river
view gwt-client/src/main/java/org/dive4elements/river/client/server/ServerInfoServiceImpl.java @ 7139:6efa25f97f7e
issue971: Let ExportServiceImpl handle encoding parameter,
configure http-client accordingly.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 25 Sep 2013 12:21:45 +0200 |
parents | b0b0ba6e7bb0 |
children | 238fc722f87a |
line wrap: on
line source
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; } }