[PATCH] Add client side servlets and service stubs for ServerInfoService

Wald Commits scm-commit at wald.intevation.org
Thu Jun 27 14:48:25 CEST 2013


# HG changeset patch
# User Christian Lins <christian.lins at intevation.de>
# Date 1372337301 -7200
# Node ID b0b0ba6e7bb01e5b2cb6d6832ff8013179ccbf74
# Parent  6aac9ad1f8a8f4e0587b533d4eb1f34a30aa7f82
Add client side servlets and service stubs for ServerInfoService.

diff -r 6aac9ad1f8a8 -r b0b0ba6e7bb0 gwt-client/src/main/java/org/dive4elements/river/client/client/FLYS.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYS.java	Thu Jun 27 12:02:09 2013 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/FLYS.java	Thu Jun 27 14:48:21 2013 +0200
@@ -13,7 +13,6 @@
 import com.google.gwt.event.shared.UmbrellaException;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.xml.client.XMLParser;
-
 import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.HTMLPane;
 import com.smartgwt.client.widgets.Window;
@@ -21,6 +20,12 @@
 import com.smartgwt.client.widgets.events.CloseClickHandler;
 import com.smartgwt.client.widgets.layout.VLayout;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.Set;
+
 import org.dive4elements.river.client.client.event.CollectionChangeEvent;
 import org.dive4elements.river.client.client.event.CollectionChangeHandler;
 import org.dive4elements.river.client.client.services.ArtifactService;
@@ -33,6 +38,8 @@
 import org.dive4elements.river.client.client.services.GetArtifactServiceAsync;
 import org.dive4elements.river.client.client.services.RiverService;
 import org.dive4elements.river.client.client.services.RiverServiceAsync;
+import org.dive4elements.river.client.client.services.ServerInfoService;
+import org.dive4elements.river.client.client.services.ServerInfoServiceAsync;
 import org.dive4elements.river.client.client.services.UserService;
 import org.dive4elements.river.client.client.services.UserServiceAsync;
 import org.dive4elements.river.client.client.ui.CollectionView;
@@ -40,6 +47,7 @@
 import org.dive4elements.river.client.client.ui.FLYSView;
 import org.dive4elements.river.client.client.ui.FLYSWorkspace;
 import org.dive4elements.river.client.client.ui.ProjectList;
+import org.dive4elements.river.client.client.ui.wq.WQAutoTabSet;
 import org.dive4elements.river.client.shared.model.Artifact;
 import org.dive4elements.river.client.shared.model.Collection;
 import org.dive4elements.river.client.shared.model.CollectionItem;
@@ -47,13 +55,6 @@
 import org.dive4elements.river.client.shared.model.River;
 import org.dive4elements.river.client.shared.model.User;
 
-import org.dive4elements.river.client.client.ui.wq.WQAutoTabSet;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.MissingResourceException;
-import java.util.Set;
-
 
 /**
  * Entry point classes define <code>onModuleLoad()</code>.
@@ -68,6 +69,8 @@
     /** The UserService used to retrieve information about the current user. */
     protected UserServiceAsync userService = GWT.create(UserService.class);
 
+    protected ServerInfoServiceAsync serverInfoService = GWT.create(ServerInfoService.class);
+
     /** The RiverService used to retrieve the supported rivers of the server.*/
     protected RiverServiceAsync riverService = GWT.create(RiverService.class);
 
@@ -135,6 +138,8 @@
         //    }
         //});
 
+        initConfiguration();
+
         VLayout vertical = new VLayout();
         vertical.setLayoutMargin(1);
         vertical.setWidth100();
@@ -148,11 +153,24 @@
 
         vertical.draw();
 
-        initConfiguration();
-
         Config config = Config.getInstance();
         String locale = config.getLocale();
 
+        serverInfoService.getConfig(locale, new AsyncCallback<Map<String,String>>() {
+
+            @Override
+            public void onSuccess(Map<String, String> result) {
+                GWT.log("serverInfoService.callBack.onSuccess");
+                GWT.log("help-url=" + result.get("help-url"));
+            }
+
+            @Override
+            public void onFailure(Throwable caught) {
+               GWT.log("serverInfoService.callBack.onFailure");
+
+            }
+        });
+
         userService.getCurrentUser(locale, new AsyncCallback<User>() {
             @Override
             public void onFailure(Throwable caught) {
diff -r 6aac9ad1f8a8 -r b0b0ba6e7bb0 gwt-client/src/main/java/org/dive4elements/river/client/client/services/ServerInfoService.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ServerInfoService.java	Thu Jun 27 14:48:21 2013 +0200
@@ -0,0 +1,18 @@
+package org.dive4elements.river.client.client.services;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+import java.util.Map;
+
+/**
+ * Service that provides server configuration values relevant to the client.
+ *
+ * @author <a href="mailto:christian.lins at intevation.de">Christian Lins</a>
+ *
+ */
+ at RemoteServiceRelativePath("server-info")
+public interface ServerInfoService extends RemoteService {
+
+    Map<String, String> getConfig(String locale);
+}
diff -r 6aac9ad1f8a8 -r b0b0ba6e7bb0 gwt-client/src/main/java/org/dive4elements/river/client/client/services/ServerInfoServiceAsync.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/services/ServerInfoServiceAsync.java	Thu Jun 27 14:48:21 2013 +0200
@@ -0,0 +1,12 @@
+package org.dive4elements.river.client.client.services;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import java.util.Map;
+
+public interface ServerInfoServiceAsync {
+
+    public void getConfig(
+            String locale,
+            AsyncCallback<Map<String, String>> cfg);
+}
diff -r 6aac9ad1f8a8 -r b0b0ba6e7bb0 gwt-client/src/main/java/org/dive4elements/river/client/server/ServerInfoServiceImpl.java
--- /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;
+    }
+
+
+}


More information about the Dive4elements-commits mailing list