[kune-commits] r1273 - in trunk: . src/main/java/cc/kune/core/client src/main/java/cc/kune/core/client/rpcservices src/main/java/cc/kune/core/public src/main/java/cc/kune/core/shared/dto src/main/java/cc/kune/wave/client src/main/java/cc/kune/wave/server src/main/java/cc/ourproject/kune/core/client src/main/java/org/ourproject/kune/platf/server/rpc

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Sun Mar 13 21:51:49 CET 2011


Author: vjrj_
Date: 2011-03-13 21:51:48 +0100 (Sun, 13 Mar 2011)
New Revision: 1273

Added:
   trunk/src/main/java/cc/kune/core/shared/dto/WaveClientParams.java
   trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java
Removed:
   trunk/src/main/java/cc/kune/wave/server/ServerRpcControllerImpl.java
   trunk/src/main/java/cc/ourproject/kune/core/client/services/
Modified:
   trunk/INSTALL
   trunk/src/main/java/cc/kune/core/client/CoreGinModule.java
   trunk/src/main/java/cc/kune/core/client/CoreParts.java
   trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java
   trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java
   trunk/src/main/java/cc/kune/core/public/ws.html
   trunk/src/main/java/cc/kune/wave/client/WaveClientSimpleAuthenticator.java
   trunk/src/main/java/cc/kune/wave/client/WebClient.java
   trunk/src/main/java/cc/kune/wave/client/WebClient.ui.xml
   trunk/src/main/java/cc/kune/wave/server/CustomUserRegistrationServlet.java
   trunk/src/main/java/cc/kune/wave/server/CustomWaveClientServlet.java
   trunk/src/main/java/cc/kune/wave/server/WaveMain.java
   trunk/src/main/java/org/ourproject/kune/platf/server/rpc/UserRPC.java
Log:
NEW - # 33: WIAB Client integration 
http://kune.ourproject.org/issues/ticket/33

Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/INSTALL	2011-03-13 20:51:48 UTC (rev 1273)
@@ -105,7 +105,7 @@
 
 Run the server for the first time and initialize the db:
 
- mvn exec:java -Dliquibase.should.run=false
+ mvn exec:java
 
 Once started for the first time the db is initialized. Then you should stop (Ctrl-C) and start the db migration process: 
 

Modified: trunk/src/main/java/cc/kune/core/client/CoreGinModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/CoreGinModule.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/core/client/CoreGinModule.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -101,6 +101,7 @@
 import cc.kune.gspace.client.WsArmorImpl;
 import cc.kune.msgs.client.UserMessagesPanel;
 import cc.kune.msgs.client.UserMessagesPresenter;
+import cc.kune.wave.client.WaveClientManager;
 
 import com.google.gwt.event.shared.EventBus;
 import com.google.inject.Singleton;
@@ -194,6 +195,7 @@
         bind(CookiesManager.class).to(CookiesManagerImpl.class).in(Singleton.class);
         bind(BeforeSignOut.class).in(Singleton.class);
         bind(SiteTokenListeners.class).asEagerSingleton();
+        bind(WaveClientManager.class).in(Singleton.class);
         bind(CoreParts.class).asEagerSingleton();
 
         // SN

Modified: trunk/src/main/java/cc/kune/core/client/CoreParts.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/CoreParts.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/core/client/CoreParts.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -3,12 +3,13 @@
 import cc.kune.core.client.init.AppStartEvent;
 import cc.kune.core.client.init.AppStartEvent.AppStartHandler;
 import cc.kune.core.client.sitebar.SiteUserOptionsPresenter;
+import cc.kune.core.client.sn.GroupSNPresenter;
 import cc.kune.core.client.sn.UserSNPresenter;
-import cc.kune.core.client.sn.GroupSNPresenter;
 import cc.kune.core.client.sn.actions.registry.GroupSNConfActions;
 import cc.kune.core.client.sn.actions.registry.UserSNConfActions;
 import cc.kune.core.client.state.Session;
 import cc.kune.core.client.ui.footer.license.EntityLicensePresenter;
+import cc.kune.wave.client.WaveClientManager;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -20,7 +21,7 @@
             final Provider<UserSNPresenter> buddiesAndParticipationPresenter,
             final Provider<GroupSNConfActions> groupMembersConfActions,
             final Provider<UserSNConfActions> userSNConfActions, final Provider<SiteUserOptionsPresenter> userOptions,
-            final Provider<EntityLicensePresenter> licenseFooter) {
+            final Provider<EntityLicensePresenter> licenseFooter, final Provider<WaveClientManager> waveClientManager) {
         session.onInitDataReceived(true, new AppStartHandler() {
             @Override
             public void onAppStart(final AppStartEvent event) {
@@ -30,6 +31,7 @@
                 buddiesAndParticipationPresenter.get();
                 userOptions.get();
                 licenseFooter.get();
+                waveClientManager.get();
             }
         });
     }

Modified: trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -24,6 +24,7 @@
 import cc.kune.core.shared.domain.utils.StateToken;
 import cc.kune.core.shared.dto.UserDTO;
 import cc.kune.core.shared.dto.UserInfoDTO;
+import cc.kune.core.shared.dto.WaveClientParams;
 
 import com.google.gwt.user.client.rpc.RemoteService;
 import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@@ -45,4 +46,6 @@
 
     void setBuddiesVisibility(String userHash, StateToken groupToken, UserSNetVisibility visibility);
 
+    WaveClientParams getWaveClientParameters(String userHash);
+
 }

Modified: trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -23,6 +23,7 @@
 import cc.kune.core.shared.domain.utils.StateToken;
 import cc.kune.core.shared.dto.UserDTO;
 import cc.kune.core.shared.dto.UserInfoDTO;
+import cc.kune.core.shared.dto.WaveClientParams;
 
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
@@ -32,6 +33,8 @@
 
     void getUserAvatarBaser64(String userHash, StateToken userToken, AsyncCallback<String> asyncCallback);
 
+    void getWaveClientParameters(String userHash, AsyncCallback<WaveClientParams> asyncCallback);
+
     void login(String nickOrEmail, String passwd, String waveCookieValue, AsyncCallback<UserInfoDTO> asyncCallback);
 
     void logout(String userHash, AsyncCallback<Void> asyncCallback);
@@ -42,5 +45,4 @@
 
     void setBuddiesVisibility(String userHash, StateToken groupToken, UserSNetVisibility visibility,
             AsyncCallback<Void> asyncCallback);
-
 }

Modified: trunk/src/main/java/cc/kune/core/public/ws.html
===================================================================
--- trunk/src/main/java/cc/kune/core/public/ws.html	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/core/public/ws.html	2011-03-13 20:51:48 UTC (rev 1273)
@@ -36,16 +36,6 @@
     }
   });
 </script>
-<!-- Only for wave testing  -->
-<script type="text/javascript" language="javascript">
-  var __session = {
-    "id" : "TK8O7UyqvT",
-    "address" : "kune at localhost",
-    "domain" : "localhost"
-  };
-  var __client_flags = {};
-  var __useSocketIO = true;
-</script>
 <link
     href='http://fonts.googleapis.com/css?family=Ubuntu:regular,italic,bold,bolditalic'
     rel='stylesheet' type='text/css'>

Added: trunk/src/main/java/cc/kune/core/shared/dto/WaveClientParams.java
===================================================================
--- trunk/src/main/java/cc/kune/core/shared/dto/WaveClientParams.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/shared/dto/WaveClientParams.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -0,0 +1,43 @@
+package cc.kune.core.shared.dto;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+public class WaveClientParams implements IsSerializable {
+    private String clientFlags;
+    private String sessionJSON;
+    private boolean useSocketIO;
+
+    public WaveClientParams() {
+    }
+
+    public WaveClientParams(final String sessionJSON, final String clientFlags, final boolean useSocketIO) {
+        this.sessionJSON = sessionJSON;
+        this.clientFlags = clientFlags;
+        this.useSocketIO = useSocketIO;
+    }
+
+    public String getClientFlags() {
+        return clientFlags;
+    }
+
+    public String getSessionJSON() {
+        return sessionJSON;
+    }
+
+    public boolean useSocketIO() {
+        return useSocketIO;
+    }
+
+    public void setClientFlags(final String clientFlags) {
+        this.clientFlags = clientFlags;
+    }
+
+    public void setSessionJSON(final String sessionJSON) {
+        this.sessionJSON = sessionJSON;
+    }
+
+    public void setUseSocketIO(final boolean useSocketIO) {
+        this.useSocketIO = useSocketIO;
+    }
+
+}
\ No newline at end of file


Property changes on: trunk/src/main/java/cc/kune/core/shared/dto/WaveClientParams.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -0,0 +1,88 @@
+package cc.kune.wave.client;
+
+import org.waveprotocol.box.webclient.client.ClientEvents;
+import org.waveprotocol.box.webclient.client.events.NetworkStatusEvent;
+import org.waveprotocol.box.webclient.client.events.NetworkStatusEventHandler;
+
+import cc.kune.common.client.noti.NotifyUser;
+import cc.kune.core.client.rpcservices.AsyncCallbackSimple;
+import cc.kune.core.client.rpcservices.UserServiceAsync;
+import cc.kune.core.client.state.Session;
+import cc.kune.core.client.state.StateManager;
+import cc.kune.core.client.state.UserSignInEvent;
+import cc.kune.core.client.state.UserSignInEvent.UserSignInHandler;
+import cc.kune.core.client.state.UserSignOutEvent;
+import cc.kune.core.client.state.UserSignOutEvent.UserSignOutHandler;
+import cc.kune.core.shared.dto.WaveClientParams;
+import cc.kune.gspace.client.WsArmor;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsonUtils;
+import com.google.gwt.user.client.ui.InsertPanel.ForIsWidget;
+import com.google.inject.Inject;
+
+public class WaveClientManager {
+    @Inject
+    public WaveClientManager(final Session session, final StateManager stateManager,
+            final UserServiceAsync userService, final WsArmor wsArmor) {
+        session.onUserSignIn(true, new UserSignInHandler() {
+            @Override
+            public void onUserSignIn(final UserSignInEvent event) {
+                userService.getWaveClientParameters(session.getUserHash(), new AsyncCallbackSimple<WaveClientParams>() {
+                    private WebClient webClient;
+
+                    @Override
+                    public void onSuccess(final WaveClientParams result) {
+                        // NotifyUser.info(result.getSessionJSON(), true);
+                        setUseSocketIO(result.useSocketIO());
+                        setSessionJSON(JsonUtils.safeEval(result.getSessionJSON()));
+                        setClientFlags(JsonUtils.safeEval(result.getClientFlags()));
+                        // Only for testing:
+                        final ForIsWidget userSpace = wsArmor.getUserSpace();
+                        if (userSpace.getWidgetCount() > 0) {
+                            userSpace.remove(0);
+                        }
+                        if (webClient ==  null) {
+                            webClient = new WebClient();
+                            userSpace.add(webClient);
+                        }
+                    }
+                });
+            }
+        });
+        session.onUserSignOut(true, new UserSignOutHandler() {
+            @Override
+            public void onUserSignOut(final UserSignOutEvent event) {
+            }
+        });
+        ClientEvents.get().addNetworkStatusEventHandler(new NetworkStatusEventHandler() {
+            @Override
+            public void onNetworkStatus(NetworkStatusEvent event) {
+                switch (event.getStatus()) {
+                  case CONNECTED:
+                  case RECONNECTED:
+                      NotifyUser.info("Online");
+                    break;
+                  case DISCONNECTED:
+                    NotifyUser.info("Offline");
+                    break;
+                  case RECONNECTING:
+                      NotifyUser.showProgress("Connecting");
+                    break;
+                }
+            }
+          });
+    }
+
+    private native void setClientFlags(JavaScriptObject object) /*-{
+        $wnd.__client_flags = object;
+    }-*/;
+
+    private native void setSessionJSON(JavaScriptObject object) /*-{
+        $wnd.__session = object;
+    }-*/;
+
+    private native void setUseSocketIO(boolean use) /*-{
+        $wnd.__useSocketIO = use;
+    }-*/;
+}


Property changes on: trunk/src/main/java/cc/kune/wave/client/WaveClientManager.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/main/java/cc/kune/wave/client/WaveClientSimpleAuthenticator.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/client/WaveClientSimpleAuthenticator.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/wave/client/WaveClientSimpleAuthenticator.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -43,12 +43,6 @@
                 @Override
                 public void onResponseReceived(final Request request, final Response response) {
                     callback.onSuccess(null);
-                    // Only for testing:
-                    // final ForIsWidget userSpace = wsArmor.getUserSpace();
-                    // if (userSpace.getWidgetCount() > 0) {
-                    // userSpace.remove(0);
-                    // }
-                    // userSpace.add(new WebClient());
                 }
             });
         } catch (final RequestException e) {

Modified: trunk/src/main/java/cc/kune/wave/client/WebClient.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/client/WebClient.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/wave/client/WebClient.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -46,7 +46,6 @@
 import org.waveprotocol.box.webclient.search.SimpleSearch;
 import org.waveprotocol.box.webclient.search.WaveStore;
 import org.waveprotocol.box.webclient.util.Log;
-import org.waveprotocol.box.webclient.widget.error.ErrorIndicatorPresenter;
 import org.waveprotocol.wave.client.account.ProfileManager;
 import org.waveprotocol.wave.client.account.impl.ProfileManagerImpl;
 import org.waveprotocol.wave.client.common.safehtml.SafeHtml;
@@ -59,6 +58,8 @@
 import org.waveprotocol.wave.model.wave.ParticipantId;
 import org.waveprotocol.wave.model.waveref.WaveRef;
 
+import cc.kune.common.client.noti.NotifyUser;
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.dom.client.Document;
@@ -71,7 +72,6 @@
 import com.google.gwt.user.client.History;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.DockLayoutPanel;
-import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.SplitLayoutPanel;
 
 /**
@@ -239,12 +239,10 @@
    * Returns <code>ws://yourhost[:port]/</code>.
    */
   // XXX check formatting wrt GPE
-  private native String getWebSocketBaseUrl(String moduleBase) /*-{
-	return "ws" + /:\/\/[^\/]+/.exec(moduleBase)[0] + "/";
-}-*/;
+  private native String getWebSocketBaseUrl(String moduleBase) /*-{return "ws" + /:\/\/[^\/]+/.exec(moduleBase)[0] + "/";}-*/;
 
   private native boolean useSocketIO() /*-{
-	return !!$wnd.__useSocketIO
+    return !!$wnd.__useSocketIO
 }-*/;
 
   /**
@@ -316,12 +314,13 @@
     public void onUncaughtException(Throwable e) {
       if (!hasFired) {
         hasFired = true;
-        final ErrorIndicatorPresenter error =
-            ErrorIndicatorPresenter.create(RootPanel.get("banner"));
+      //  final ErrorIndicatorPresenter error =
+        //    ErrorIndicatorPresenter.create(RootPanel.get("banner"));
         getStackTraceAsync(e, new Accessor<SafeHtml>() {
           @Override
           public void use(SafeHtml stack) {
-            error.addDetail(stack, null);
+              NotifyUser.error("Error in wave client", true);
+          //  error.addDetail(stack, null);
           }
         });
       }

Modified: trunk/src/main/java/cc/kune/wave/client/WebClient.ui.xml
===================================================================
--- trunk/src/main/java/cc/kune/wave/client/WebClient.ui.xml	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/wave/client/WebClient.ui.xml	2011-03-13 20:51:48 UTC (rev 1273)
@@ -58,7 +58,7 @@
           <d:DebugMessagePanel ui:field="logPanel" addStyleNames="{style.subPanel} {style.debugPanel}" />
         </g:south>
         <g:west size="400">
-          <s:SearchPanelWidget ui:field="searchPanel"/>
+          <s:SearchPanelWidget ui:field="searchPanel"/> 
         </g:west>
         <g:center>
           <w:ImplPanel ui:field="contentPanel"/>
@@ -66,4 +66,4 @@
       </g:SplitLayoutPanel>
     </g:center>
   </g:DockLayoutPanel>
-</ui:UiBinder>
\ No newline at end of file
+</ui:UiBinder>

Modified: trunk/src/main/java/cc/kune/wave/server/CustomUserRegistrationServlet.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/CustomUserRegistrationServlet.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/wave/server/CustomUserRegistrationServlet.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -42,7 +42,7 @@
 
 /**
  * The user registration servlet allows new users to register accounts.
- * 
+ *
  * @author josephg at gmail.com (Joseph Gentle)
  */
 public class CustomUserRegistrationServlet extends HttpServlet {

Modified: trunk/src/main/java/cc/kune/wave/server/CustomWaveClientServlet.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/CustomWaveClientServlet.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/wave/server/CustomWaveClientServlet.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -1,3 +1,4 @@
+// @formatter:off
 /**
  * Copyright 2010 Google Inc.
  *
@@ -34,6 +35,7 @@
 import org.waveprotocol.box.server.authentication.SessionManager;
 import org.waveprotocol.box.server.gxp.TopBar;
 import org.waveprotocol.box.server.gxp.WaveClientPage;
+import org.waveprotocol.box.server.rpc.WaveClientServlet;
 import org.waveprotocol.box.server.util.RandomBase64Generator;
 import org.waveprotocol.wave.client.util.ClientFlagsBase;
 import org.waveprotocol.wave.common.bootstrap.FlagConstants;
@@ -43,142 +45,143 @@
 import com.google.common.collect.Maps;
 import com.google.gxp.base.GxpContext;
 import com.google.inject.Inject;
+import com.google.inject.Singleton;
 import com.google.inject.name.Named;
 
 /**
  * The HTTP servlet for serving a wave client along with content generated on
  * the server.
- * 
+ *
  * @author kalman at google.com (Benjamin Kalman)
  */
+ at Singleton
 public class CustomWaveClientServlet extends HttpServlet {
 
-    private static final HashMap<String, String> FLAG_MAP = Maps.newHashMap();
+  private static final Log LOG = Log.get(WaveClientServlet.class);
 
-    private static final Log LOG = Log.get(CustomWaveClientServlet.class);
-    static {
-        // __NAME_MAPPING__ is a map of name to obfuscated id
-        for (int i = 0; i < FlagConstants.__NAME_MAPPING__.length; i += 2) {
-            FLAG_MAP.put(FlagConstants.__NAME_MAPPING__[i], FlagConstants.__NAME_MAPPING__[i + 1]);
-        }
+  private static final HashMap<String, String> FLAG_MAP = Maps.newHashMap();
+  static {
+    // __NAME_MAPPING__ is a map of name to obfuscated id
+    for (int i = 0; i < FlagConstants.__NAME_MAPPING__.length; i += 2) {
+      FLAG_MAP.put(FlagConstants.__NAME_MAPPING__[i], FlagConstants.__NAME_MAPPING__[i + 1]);
     }
+  }
 
-    private final String domain;
-    private final SessionManager sessionManager;
-    private final Boolean useSocketIO;
+  private final String domain;
+  private final Boolean useSocketIO;
+  private final SessionManager sessionManager;
 
-    /**
-     * Creates a servlet for the wave client.
-     */
-    @Inject
-    public CustomWaveClientServlet(@Named(CoreSettings.WAVE_SERVER_DOMAIN) final String domain,
-            @Named(CoreSettings.USE_SOCKETIO) final Boolean useSocketIO, final SessionManager sessionManager) {
-        this.domain = domain;
-        this.useSocketIO = useSocketIO;
-        this.sessionManager = sessionManager;
-    }
+  /**
+   * Creates a servlet for the wave client.
+   */
+  @Inject
+  public CustomWaveClientServlet(
+      @Named(CoreSettings.WAVE_SERVER_DOMAIN) String domain,
+      @Named(CoreSettings.USE_SOCKETIO) Boolean useSocketIO,
+      SessionManager sessionManager) {
+    this.domain = domain;
+    this.useSocketIO = useSocketIO;
+    this.sessionManager = sessionManager;
+  }
 
-    @Override
-    protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
-        final ParticipantId id = sessionManager.getLoggedInUser(request.getSession(false));
+  @Override
+  protected void doGet(HttpServletRequest request, HttpServletResponse response)
+      throws IOException {
+    ParticipantId id = sessionManager.getLoggedInUser(request.getSession(false));
 
-        // Eventually, it would be nice to show users who aren't logged in the
-        // public waves.,
-        // However, public waves aren't implemented yet. For now, we'll just
-        // redirect users
-        // who haven't signed in to the sign in page.
-        // COMMENTED (vjrj)
-        if (id == null) {
-            response.sendRedirect(sessionManager.getLoginUrl("/"));
-            return;
-        }
+    // Eventually, it would be nice to show users who aren't logged in the public waves.
+    // However, public waves aren't implemented yet. For now, we'll just redirect users
+    // who haven't signed in to the sign in page.
+    //if (id == null) {
+     // response.sendRedirect(sessionManager.getLoginUrl("/"));
+      // return;
+    //}
 
-        String username = null;
-        String userDomain = null;
-        if (id != null) {
-            final String[] parts = id.getAddress().split("@");
-            username = parts[0];
-            userDomain = id.getDomain();
-        }
+    String username = null;
+    String userDomain = null;
+    if (id != null) {
+      String[] parts = id.getAddress().split("@");
+      username = parts[0];
+      userDomain = id.getDomain();
+    }
 
-        try {
-            WaveClientPage.write(response.getWriter(), new GxpContext(request.getLocale()),
-                    getSessionJson(request.getSession(false)), getClientFlags(request),
-                    TopBar.getGxpClosure(username, userDomain), useSocketIO);
-        } catch (final IOException e) {
-            LOG.warning("Failed to write GXP for request " + request, e);
-            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-            return;
-        }
-
-        response.setContentType("text/html");
-        response.setStatus(HttpServletResponse.SC_OK);
+    try {
+      WaveClientPage.write(response.getWriter(), new GxpContext(request.getLocale()),
+          getSessionJson(request.getSession(false)), getClientFlags(request),
+          TopBar.getGxpClosure(username, userDomain), useSocketIO);
+    } catch (IOException e) {
+      LOG.warning("Failed to write GXP for request " + request, e);
+      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+      return;
     }
 
-    private JSONObject getClientFlags(final HttpServletRequest request) {
-        try {
-            final JSONObject ret = new JSONObject();
+    response.setContentType("text/html");
+    response.setStatus(HttpServletResponse.SC_OK);
+  }
 
-            final Enumeration<?> iter = request.getParameterNames();
-            while (iter.hasMoreElements()) {
-                final String name = (String) iter.nextElement();
-                final String value = request.getParameter(name);
+  public JSONObject getClientFlags(HttpServletRequest request) {
+    try {
+      JSONObject ret = new JSONObject();
 
-                if (FLAG_MAP.containsKey(name)) {
-                    // Set using the correct type of data in the json using
-                    // reflection
-                    try {
-                        final Method getter = ClientFlagsBase.class.getMethod(name);
-                        final Class<?> retType = getter.getReturnType();
+      Enumeration<?> iter = request.getParameterNames();
+      while (iter.hasMoreElements()) {
+        String name = (String) iter.nextElement();
+        String value = request.getParameter(name);
 
-                        if (retType.equals(String.class)) {
-                            ret.put(FLAG_MAP.get(name), value);
-                        } else if (retType.equals(Integer.class)) {
-                            ret.put(FLAG_MAP.get(name), Integer.parseInt(value));
-                        } else if (retType.equals(Boolean.class)) {
-                            ret.put(FLAG_MAP.get(name), Boolean.parseBoolean(value));
-                        } else if (retType.equals(Float.class)) {
-                            ret.put(FLAG_MAP.get(name), Float.parseFloat(value));
-                        } else if (retType.equals(Double.class)) {
-                            ret.put(FLAG_MAP.get(name), Double.parseDouble(value));
-                        } else {
-                            // Flag exists, but its type is unknown, so it can
-                            // not be
-                            // properly encoded in JSON.
-                            LOG.warning("Ignoring flag [" + name + "] with unknown return type: " + retType);
-                        }
+        if (FLAG_MAP.containsKey(name)) {
+          // Set using the correct type of data in the json using reflection
+          try {
+            Method getter = ClientFlagsBase.class.getMethod(name);
+            Class<?> retType = getter.getReturnType();
 
-                        // Ignore the flag on any exception
-                    } catch (final SecurityException ex) {
-                    } catch (final NoSuchMethodException ex) {
-                        LOG.warning("Failed to find the flag [" + name + "] in ClientFlagsBase.");
-                    } catch (final NumberFormatException ex) {
-                    }
-                }
+            if (retType.equals(String.class)) {
+              ret.put(FLAG_MAP.get(name), value);
+            } else if (retType.equals(Integer.class)) {
+              ret.put(FLAG_MAP.get(name), Integer.parseInt(value));
+            } else if (retType.equals(Boolean.class)) {
+              ret.put(FLAG_MAP.get(name), Boolean.parseBoolean(value));
+            } else if (retType.equals(Float.class)) {
+              ret.put(FLAG_MAP.get(name), Float.parseFloat(value));
+            } else if (retType.equals(Double.class)) {
+              ret.put(FLAG_MAP.get(name), Double.parseDouble(value));
+            } else {
+              // Flag exists, but its type is unknown, so it can not be
+              // properly encoded in JSON.
+              LOG.warning("Ignoring flag [" + name + "] with unknown return type: " + retType);
             }
 
-            return ret;
-        } catch (final JSONException ex) {
-            LOG.severe("Failed to create flags JSON");
-            return new JSONObject();
+            // Ignore the flag on any exception
+          } catch (SecurityException ex) {
+          } catch (NoSuchMethodException ex) {
+            LOG.warning("Failed to find the flag [" + name + "] in ClientFlagsBase.");
+          } catch (NumberFormatException ex) {
+          }
         }
+      }
+
+      return ret;
+    } catch (JSONException ex) {
+      LOG.severe("Failed to create flags JSON");
+      return new JSONObject();
     }
+  }
 
-    private JSONObject getSessionJson(final HttpSession session) {
-        try {
-            final ParticipantId user = sessionManager.getLoggedInUser(session);
-            final String address = (user != null) ? user.getAddress() : null;
+  public JSONObject getSessionJson(HttpSession session) {
+    try {
+      ParticipantId user = sessionManager.getLoggedInUser(session);
+      String address = (user != null) ? user.getAddress() : null;
 
-            // TODO(zdwang): Figure out a proper session id rather than
-            // generating a
-            // random number
-            final String sessionId = (new RandomBase64Generator()).next(10);
+      // TODO(zdwang): Figure out a proper session id rather than generating a
+      // random number
+      String sessionId = (new RandomBase64Generator()).next(10);
 
-            return new JSONObject().put(SessionConstants.DOMAIN, domain).putOpt(SessionConstants.ADDRESS, address).putOpt(
-                    SessionConstants.ID_SEED, sessionId);
-        } catch (final JSONException e) {
-            LOG.severe("Failed to create session JSON");
-            return new JSONObject();
-        }
+      return new JSONObject()
+          .put(SessionConstants.DOMAIN, domain)
+          .putOpt(SessionConstants.ADDRESS, address)
+          .putOpt(SessionConstants.ID_SEED, sessionId);
+    } catch (JSONException e) {
+      LOG.severe("Failed to create session JSON");
+      return new JSONObject();
     }
+  }
 }

Deleted: trunk/src/main/java/cc/kune/wave/server/ServerRpcControllerImpl.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/ServerRpcControllerImpl.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/wave/server/ServerRpcControllerImpl.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -1,226 +0,0 @@
-/**
- * Copyright 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package cc.kune.wave.server;
-
-import org.waveprotocol.box.server.rpc.Rpc;
-import org.waveprotocol.box.server.rpc.ServerRpcController;
-import org.waveprotocol.wave.model.wave.ParticipantId;
-
-import com.google.protobuf.Descriptors;
-import com.google.protobuf.Message;
-import com.google.protobuf.RpcCallback;
-import com.google.protobuf.Service;
-
-/**
- * Implements the server end-point of a wave server RPC connection. This is a
- * single-use RPC controller.
- * 
- * 
- */
-public class ServerRpcControllerImpl implements ServerRpcController {
-    private final Service backingService;
-    private final RpcCallback<Message> callback;
-    private RpcCallback<Object> cancelCallback = null;
-    private boolean cancelled = false;
-    private boolean complete = false;
-
-    private final boolean isStreamingRpc;
-    private final ParticipantId loggedInUser;
-    private final Message requestMessage;
-    private final Descriptors.MethodDescriptor serviceMethod;
-    // The following variables represent the current status of this instance,
-    // and
-    // must all only be accessed or modified while synchronised on statusLock.
-    private final Object statusLock = new Object();
-
-    /**
-     * Instantiate a new ServerRpcController that may later be completely
-     * invoked by calling {#link run}.
-     * 
-     * @param requestMessage
-     *            the request being handled
-     * @param backingService
-     *            the backing service type
-     * @param serviceMethod
-     *            the specific method within the backing service type
-     * @param loggedInUser
-     *            the currently logged in user
-     * @param callback
-     *            the destination where responses may be passed - may be called
-     *            once (normal RPC) or 1-n times (streaming RPC), and will pass
-     *            instances of RpcFinished as required (error cases, or
-     *            streaming RPC shutdown); is also always called under the
-     *            ServerRpcController's statusLock to ensure that consecutive
-     *            calls (in the streaming case) are called in series
-     */
-    ServerRpcControllerImpl(final Message requestMessage, final Service backingService,
-            final Descriptors.MethodDescriptor serviceMethod, final ParticipantId loggedInUser,
-            final RpcCallback<Message> callback) {
-        this.requestMessage = requestMessage;
-        this.backingService = backingService;
-        this.serviceMethod = serviceMethod;
-        this.loggedInUser = loggedInUser;
-        this.isStreamingRpc = serviceMethod.getOptions().getExtension(Rpc.isStreamingRpc);
-        this.callback = callback;
-    }
-
-    @Override
-    public void cancel() {
-        RpcCallback<Object> runCallback = null;
-        synchronized (statusLock) {
-            if (cancelled) {
-                throw new IllegalStateException("Can't cancel RPC, already cancelled.");
-            }
-            cancelled = true;
-            if (cancelCallback != null && !complete) {
-                runCallback = cancelCallback;
-            }
-        }
-        if (runCallback != null) {
-            runCallback.run(null);
-        }
-    }
-
-    @Override
-    public String errorText() {
-        throw new UnsupportedOperationException("Client-side method of RpcController only.");
-    }
-
-    @Override
-    public boolean failed() {
-        throw new UnsupportedOperationException("Client-side method of RpcController only.");
-    }
-
-    @Override
-    public ParticipantId getLoggedInUser() {
-        return loggedInUser;
-    }
-
-    @Override
-    public boolean isCanceled() {
-        return cancelled;
-    }
-
-    /**
-     * Registers a cancellation callback. This will always be called as part of
-     * this RPC, and always at most once; either when the client asks to cancel
-     * it, or when the RPC finishes (regardless of error case).
-     * 
-     * This callback will be called outside normal locks on ServerRpcController
-     * state, i.e., not within a block synchronised on statusLock.
-     */
-    @Override
-    public void notifyOnCancel(final RpcCallback<Object> callback) {
-        RpcCallback<Object> runCallback = null;
-        synchronized (statusLock) {
-            if (cancelCallback != null) {
-                throw new IllegalStateException("Must only be called once per request.");
-            } else {
-                cancelCallback = callback;
-                if (cancelled || complete) {
-                    runCallback = cancelCallback;
-                }
-            }
-        }
-        if (runCallback != null) {
-            runCallback.run(null);
-        }
-    }
-
-    @Override
-    public void reset() {
-        throw new UnsupportedOperationException("Client-side method of RpcController only.");
-    }
-
-    /**
-     * Run this ServerRpcController in the current thread. This must only be
-     * invoked ONCE, and will throw an IllegalStateException otherwise.
-     */
-    @Override
-    public void run() {
-        final RpcCallback<Message> messageCallback = new RpcCallback<Message>() {
-            @Override
-            public void run(Message result) { // NOPMD by vjrj on 12/02/11 0:16
-                RpcCallback<Object> runCallback = null;
-                synchronized (statusLock) {
-                    if (complete) {
-                        throw new IllegalStateException("Can't send responses over this RPC, as it is"
-                                + " already complete: " + result);
-                    }
-                    if (!isStreamingRpc || result == null) {
-                        // This either completes the streaming RPC (by passing
-                        // an instance
-                        // of RpcFinished in place of null) or completes a
-                        // normal RPC (by
-                        // passing any other message).
-                        if (result == null) {
-                            result = Rpc.RpcFinished.newBuilder().setFailed(false).build();
-                        }
-                        callback.run(result);
-
-                        // Now complete, mark as such and invoke the
-                        // cancellation callback.
-                        complete = true;
-                        if (cancelCallback != null && !cancelled) {
-                            runCallback = cancelCallback;
-                        }
-                    } else {
-                        // Streaming RPC update.
-                        callback.run(result);
-                    }
-                }
-                if (runCallback != null) {
-                    runCallback.run(null);
-                }
-            }
-        };
-        try {
-            backingService.callMethod(serviceMethod, this, requestMessage, messageCallback);
-        } catch (final RuntimeException e) {
-            // Pass the description of any RuntimeException back to the caller.
-            e.printStackTrace();
-            if (!complete) {
-                setFailed(e.toString());
-            }
-        }
-    }
-
-    @Override
-    public void setFailed(final String reason) {
-        RpcCallback<Object> runCallback = null;
-        synchronized (statusLock) {
-            if (complete) {
-                throw new IllegalStateException("Can't fail this RPC, as it is already complete.");
-            } else {
-                complete = true;
-                callback.run(Rpc.RpcFinished.newBuilder().setFailed(true).setErrorText(reason).build());
-                if (cancelCallback != null && !cancelled) {
-                    runCallback = cancelCallback;
-                }
-            }
-        }
-        if (runCallback != null) {
-            runCallback.run(null);
-        }
-    }
-
-    @Override
-    public void startCancel() {
-        throw new UnsupportedOperationException("Client-side method of RpcController only.");
-    }
-}

Modified: trunk/src/main/java/cc/kune/wave/server/WaveMain.java
===================================================================
--- trunk/src/main/java/cc/kune/wave/server/WaveMain.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/cc/kune/wave/server/WaveMain.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -1,3 +1,5 @@
+// @formatter:off
+
 /**
  * Copyright 2009 Google Inc.
  *
@@ -67,134 +69,136 @@
  */
 public class WaveMain {
 
-    private static final Log LOG = Log.get(WaveMain.class);
+  /**
+   * This is the name of the system property used to find the server config file.
+   */
+  private static final String PROPERTIES_FILE_KEY = "wave.server.config";
 
-    /**
-     * This is the name of the system property used to find the server config
-     * file.
-     */
-    private static final String PROPERTIES_FILE_KEY = "wave.server.config";
+  private static final Log LOG = Log.get(WaveMain.class);
 
-    private static Module buildFederationModule(final Injector settingsInjector, final boolean enableFederation)
-            throws ConfigurationException {
-        Module federationModule;
-        if (enableFederation) {
-            federationModule = settingsInjector.getInstance(XmppFederationModule.class);
-        } else {
-            federationModule = settingsInjector.getInstance(NoOpFederationModule.class);
-        }
-        return federationModule;
+  public static void main(String... args) {
+    try {
+      Module coreSettings = SettingsBinder.bindSettings(PROPERTIES_FILE_KEY, CoreSettings.class);
+      run(coreSettings);
+      return;
+    } catch (PersistenceException e) {
+      LOG.severe("PersistenceException when running server:", e);
+    } catch (ConfigurationException e) {
+      LOG.severe("ConfigurationException when running server:", e);
+    } catch (WaveServerException e) {
+      LOG.severe("WaveServerException when running server:", e);
     }
+  }
 
-    private static void initializeFederation(final Injector injector) {
-        final FederationTransport federationManager = injector.getInstance(FederationTransport.class);
-        federationManager.startFederation();
+  public static void run(Module coreSettings) throws PersistenceException,
+      ConfigurationException, WaveServerException {
+    Injector settingsInjector = Guice.createInjector(coreSettings);
+    boolean enableFederation = settingsInjector.getInstance(Key.get(Boolean.class,
+        Names.named(CoreSettings.ENABLE_FEDERATION)));
+
+    if (enableFederation) {
+      Module federationSettings =
+        SettingsBinder.bindSettings(PROPERTIES_FILE_KEY, FederationSettings.class);
+      // This MUST happen first, or bindings will fail if federation is enabled.
+      settingsInjector = settingsInjector.createChildInjector(federationSettings);
     }
 
-    private static void initializeFrontend(final Injector injector, final ServerRpcProvider server,
-            final WaveBus waveBus) throws WaveServerException {
-        final HashedVersionFactory hashFactory = injector.getInstance(HashedVersionFactory.class);
-        final WaveletProvider provider = injector.getInstance(WaveletProvider.class);
-        final ClientFrontend frontend = ClientFrontendImpl.create(hashFactory, provider, waveBus);
+    Module federationModule = buildFederationModule(settingsInjector, enableFederation);
+    PersistenceModule persistenceModule = settingsInjector.getInstance(PersistenceModule.class);
+    Injector injector =
+        settingsInjector.createChildInjector(new ServerModule(enableFederation),
+            new RobotApiModule(), federationModule, persistenceModule);
 
-        final ProtocolWaveClientRpc.Interface rpcImpl = WaveClientRpcImpl.create(frontend, false);
-        server.registerService(ProtocolWaveClientRpc.newReflectiveService(rpcImpl));
-    }
+    ServerRpcProvider server = injector.getInstance(ServerRpcProvider.class);
+    WaveBus waveBus = injector.getInstance(WaveBus.class);
 
-    private static void initializeRobots(final Injector injector, final WaveBus waveBus) {
-        final RobotsGateway robotsGateway = injector.getInstance(RobotsGateway.class);
-        waveBus.subscribe(robotsGateway);
-    }
+    initializeServer(injector);
+    initializeServlets(injector, server);
+    initializeRobots(injector, waveBus);
+    initializeFrontend(injector, server, waveBus);
+    initializeFederation(injector);
 
-    private static void initializeServer(final Injector injector) throws PersistenceException, WaveServerException {
-        final AccountStore accountStore = injector.getInstance(AccountStore.class);
-        accountStore.initializeAccountStore();
-        AccountStoreHolder.init(accountStore,
-                injector.getInstance(Key.get(String.class, Names.named(CoreSettings.WAVE_SERVER_DOMAIN))));
+    LOG.info("Starting server");
+    server.startWebSocketServer(injector);
+  }
 
-        // Initialize the SignerInfoStore.
-        final CertPathStore certPathStore = injector.getInstance(CertPathStore.class);
-        if (certPathStore instanceof SignerInfoStore) {
-            ((SignerInfoStore) certPathStore).initializeSignerInfoStore();
-        }
-
-        // Initialize the server.
-        final WaveletProvider waveServer = injector.getInstance(WaveletProvider.class);
-        waveServer.initialize();
+  private static Module buildFederationModule(Injector settingsInjector, boolean enableFederation)
+      throws ConfigurationException {
+    Module federationModule;
+    if (enableFederation) {
+      federationModule = settingsInjector.getInstance(XmppFederationModule.class);
+    } else {
+      federationModule = settingsInjector.getInstance(NoOpFederationModule.class);
     }
+    return federationModule;
+  }
 
-    private static void initializeServlets(final Injector injector, final ServerRpcProvider server) {
-        server.addServlet("/attachment/*", injector.getInstance(AttachmentServlet.class));
+  private static void initializeServer(Injector injector) throws PersistenceException,
+      WaveServerException {
+    AccountStore accountStore = injector.getInstance(AccountStore.class);
+    accountStore.initializeAccountStore();
+    AccountStoreHolder.init(accountStore,
+        injector.getInstance(Key.get(String.class, Names.named(CoreSettings.WAVE_SERVER_DOMAIN))));
 
-        server.addServlet(SessionManager.SIGN_IN_URL, injector.getInstance(AuthenticationServlet.class));
-        server.addServlet("/auth/signout", injector.getInstance(SignOutServlet.class));
-        server.addServlet("/auth/register", injector.getInstance(CustomUserRegistrationServlet.class));
+    // Initialize the SignerInfoStore.
+    CertPathStore certPathStore = injector.getInstance(CertPathStore.class);
+    if (certPathStore instanceof SignerInfoStore) {
+      ((SignerInfoStore)certPathStore).initializeSignerInfoStore();
+    }
 
-        server.addServlet("/fetch/*", injector.getInstance(FetchServlet.class));
+    // Initialize the server.
+    WaveletProvider waveServer = injector.getInstance(WaveletProvider.class);
+    waveServer.initialize();
+  }
 
-        server.addServlet("/search/*", injector.getInstance(SearchServlet.class));
+  private static void initializeServlets(Injector injector, ServerRpcProvider server) {
+    server.addServlet("/attachment/*", injector.getInstance(AttachmentServlet.class));
 
-        server.addServlet("/robot/dataapi", injector.getInstance(DataApiServlet.class));
-        server.addServlet(DataApiOAuthServlet.DATA_API_OAUTH_PATH + "/*",
-                injector.getInstance(DataApiOAuthServlet.class));
-        server.addServlet("/robot/dataapi/rpc", injector.getInstance(DataApiServlet.class));
-        server.addServlet("/robot/register/*", injector.getInstance(RobotRegistrationServlet.class));
-        server.addServlet("/robot/rpc", injector.getInstance(ActiveApiServlet.class));
+    server.addServlet(SessionManager.SIGN_IN_URL,
+        injector.getInstance(AuthenticationServlet.class));
+    server.addServlet("/auth/signout", injector.getInstance(SignOutServlet.class));
+    server.addServlet("/auth/register", injector.getInstance(CustomUserRegistrationServlet.class));
 
-        final String gadgetServerHostname = injector.getInstance(Key.get(String.class,
-                Names.named(CoreSettings.GADGET_SERVER_HOSTNAME)));
-        final ProxyServlet.Transparent proxyServlet = new ProxyServlet.Transparent("/gadgets", "http",
-                gadgetServerHostname, injector.getInstance(Key.get(int.class,
-                        Names.named(CoreSettings.GADGET_SERVER_PORT))), "/gadgets");
-        final ServletHolder proxyServletHolder = server.addServlet("/gadgets/*", proxyServlet);
-        proxyServletHolder.setInitParameter("HostHeader", gadgetServerHostname);
+    server.addServlet("/fetch/*", injector.getInstance(FetchServlet.class));
 
-        // server.addServlet("/",
-        // injector.getInstance(CustomWaveClientServlet.class));
-    }
+    server.addServlet("/search/*", injector.getInstance(SearchServlet.class));
 
-    public static void main(final String... args) {
-        try {
-            final Module coreSettings = SettingsBinder.bindSettings(PROPERTIES_FILE_KEY, CoreSettings.class);
-            run(coreSettings);
-            return;
-        } catch (final PersistenceException e) {
-            LOG.severe("PersistenceException when running server:", e);
-        } catch (final ConfigurationException e) {
-            LOG.severe("ConfigurationException when running server:", e);
-        } catch (final WaveServerException e) {
-            LOG.severe("WaveServerException when running server:", e);
-        }
-    }
+    server.addServlet("/robot/dataapi", injector.getInstance(DataApiServlet.class));
+    server.addServlet(DataApiOAuthServlet.DATA_API_OAUTH_PATH + "/*",
+        injector.getInstance(DataApiOAuthServlet.class));
+    server.addServlet("/robot/dataapi/rpc", injector.getInstance(DataApiServlet.class));
+    server.addServlet("/robot/register/*", injector.getInstance(RobotRegistrationServlet.class));
+    server.addServlet("/robot/rpc", injector.getInstance(ActiveApiServlet.class));
 
-    public static void run(final Module coreSettings) throws PersistenceException, ConfigurationException,
-            WaveServerException {
-        Injector settingsInjector = Guice.createInjector(coreSettings);
-        final boolean enableFederation = settingsInjector.getInstance(Key.get(Boolean.class,
-                Names.named(CoreSettings.ENABLE_FEDERATION)));
+    String gadgetServerHostname =injector.getInstance(Key.get(String.class,
+        Names.named(CoreSettings.GADGET_SERVER_HOSTNAME)));
+    ProxyServlet.Transparent proxyServlet =
+        new ProxyServlet.Transparent("/gadgets", "http", gadgetServerHostname, injector
+            .getInstance(Key.get(int.class, Names.named(CoreSettings.GADGET_SERVER_PORT))),
+            "/gadgets");
+    ServletHolder proxyServletHolder = server.addServlet("/gadgets/*", proxyServlet);
+    proxyServletHolder.setInitParameter("HostHeader", gadgetServerHostname);
 
-        if (enableFederation) {
-            final Module federationSettings = SettingsBinder.bindSettings(PROPERTIES_FILE_KEY, FederationSettings.class);
-            // This MUST happen first, or bindings will fail if federation is
-            // enabled.
-            settingsInjector = settingsInjector.createChildInjector(federationSettings);
-        }
+    //  server.addServlet("/", injector.getInstance(CustomWaveClientServlet.class));
+  }
 
-        final Module federationModule = buildFederationModule(settingsInjector, enableFederation);
-        final PersistenceModule persistenceModule = settingsInjector.getInstance(PersistenceModule.class);
-        final Injector injector = settingsInjector.createChildInjector(new ServerModule(enableFederation),
-                new RobotApiModule(), federationModule, persistenceModule);
+  private static void initializeRobots(Injector injector, WaveBus waveBus) {
+    RobotsGateway robotsGateway = injector.getInstance(RobotsGateway.class);
+    waveBus.subscribe(robotsGateway);
+  }
 
-        final ServerRpcProvider server = injector.getInstance(ServerRpcProvider.class);
-        final WaveBus waveBus = injector.getInstance(WaveBus.class);
+  private static void initializeFrontend(Injector injector, ServerRpcProvider server,
+      WaveBus waveBus) throws WaveServerException {
+    HashedVersionFactory hashFactory = injector.getInstance(HashedVersionFactory.class);
+    WaveletProvider provider = injector.getInstance(WaveletProvider.class);
+    ClientFrontend frontend = ClientFrontendImpl.create(hashFactory, provider, waveBus);
 
-        initializeServer(injector);
-        initializeServlets(injector, server);
-        initializeRobots(injector, waveBus);
-        initializeFrontend(injector, server, waveBus);
-        initializeFederation(injector);
+    ProtocolWaveClientRpc.Interface rpcImpl = WaveClientRpcImpl.create(frontend, false);
+    server.registerService(ProtocolWaveClientRpc.newReflectiveService(rpcImpl));
+  }
 
-        LOG.info("Starting server");
-        server.startWebSocketServer(injector);
-    }
+  private static void initializeFederation(Injector injector) {
+    FederationTransport federationManager = injector.getInstance(FederationTransport.class);
+    federationManager.startFederation();
+  }
 }

Modified: trunk/src/main/java/org/ourproject/kune/platf/server/rpc/UserRPC.java
===================================================================
--- trunk/src/main/java/org/ourproject/kune/platf/server/rpc/UserRPC.java	2011-03-13 14:44:03 UTC (rev 1272)
+++ trunk/src/main/java/org/ourproject/kune/platf/server/rpc/UserRPC.java	2011-03-13 20:51:48 UTC (rev 1273)
@@ -19,7 +19,10 @@
  */
 package org.ourproject.kune.platf.server.rpc;
 
+import javax.servlet.http.HttpSession;
+
 import org.jivesoftware.smack.util.Base64;
+import org.json.JSONObject;
 import org.ourproject.kune.platf.server.UserSession;
 import org.ourproject.kune.platf.server.auth.ActionLevel;
 import org.ourproject.kune.platf.server.auth.Authenticated;
@@ -30,6 +33,8 @@
 import org.ourproject.kune.platf.server.mapper.Mapper;
 import org.ourproject.kune.platf.server.users.UserInfo;
 import org.ourproject.kune.platf.server.users.UserInfoService;
+import org.waveprotocol.box.server.CoreSettings;
+import org.waveprotocol.box.server.authentication.SessionManager;
 
 import cc.kune.core.client.errors.AccessViolationException;
 import cc.kune.core.client.errors.DefaultException;
@@ -40,12 +45,15 @@
 import cc.kune.core.shared.domain.utils.StateToken;
 import cc.kune.core.shared.dto.UserDTO;
 import cc.kune.core.shared.dto.UserInfoDTO;
+import cc.kune.core.shared.dto.WaveClientParams;
 import cc.kune.domain.Group;
 import cc.kune.domain.User;
+import cc.kune.wave.server.CustomWaveClientServlet;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
+import com.google.inject.name.Named;
 import com.google.inject.persist.Transactional;
 
 @Singleton
@@ -57,18 +65,26 @@
     private final UserInfoService userInfoService;
     private final UserManager userManager;
     private final Provider<UserSession> userSessionProvider;
+    private final Boolean useSocketIO;
+    private final CustomWaveClientServlet waveClientServlet;
+    private final SessionManager waveSessionManager;
 
     @Inject
     public UserRPC(final Provider<SessionService> sessionServiceProvider,
             final Provider<UserSession> userSessionProvider, final UserManager userManager,
-            final GroupManager groupManager, final UserInfoService userInfoService, final Mapper mapper) {
+            @Named(CoreSettings.USE_SOCKETIO) final Boolean useSocketIO, final GroupManager groupManager,
+            final UserInfoService userInfoService, final Mapper mapper, final SessionManager waveSessionManager,
+            final CustomWaveClientServlet waveClientServlet) {
 
         this.sessionServiceProvider = sessionServiceProvider;
         this.userSessionProvider = userSessionProvider;
         this.userManager = userManager;
+        this.useSocketIO = useSocketIO;
         this.groupManager = groupManager;
         this.userInfoService = userInfoService;
         this.mapper = mapper;
+        this.waveSessionManager = waveSessionManager;
+        this.waveClientServlet = waveClientServlet;
     }
 
     @Override
@@ -102,6 +118,15 @@
         return userSessionProvider.get();
     }
 
+    @Override
+    @Authenticated(mandatory = true)
+    public WaveClientParams getWaveClientParameters(final String userHash) {
+        final HttpSession sessionFromToken = waveSessionManager.getSessionFromToken(userHash);
+        final JSONObject sessionJson = waveClientServlet.getSessionJson(sessionFromToken);
+        final JSONObject clientFlags = new JSONObject(); // waveClientServlet.getClientFlags();
+        return new WaveClientParams(sessionJson.toString(), clientFlags.toString(), useSocketIO);
+    }
+
     private UserInfoDTO loadUserInfo(final User user) throws DefaultException {
         final UserInfo userInfo = userInfoService.buildInfo(user, getUserSession().getHash());
         return mapper.map(userInfo, UserInfoDTO.class);
@@ -125,7 +150,7 @@
         } else {
             throw new UserAuthException();
         }
-    }
+    };
 
     @Override
     @Authenticated
@@ -135,7 +160,7 @@
         // FIXME final SessionService sessionService =
         // sessionServiceProvider.get();
         // FIXME sessionService.getNewSession();
-    };
+    }
 
     @Override
     @Authenticated(mandatory = false)
@@ -166,5 +191,4 @@
         }
         user.setSNetVisibility(visibility);
     }
-
 }




More information about the kune-commits mailing list