Author: julien_viet
Date: 2010-01-22 17:39:11 -0500 (Fri, 22 Jan 2010)
New Revision: 1424
Added:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ApplicationState.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ReplicatingStateManager.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/SerializationContextSingleton.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/UIComponentFactory.java
Removed:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ReplicatingStateManager.java
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/PortalLoginModule.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
Log:
more replication work
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/PortalLoginModule.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/PortalLoginModule.java 2010-01-22
22:25:49 UTC (rev 1423)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/PortalLoginModule.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -31,8 +31,8 @@
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.login.LoginException;
-import javax.security.jacc.PolicyContext;
import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
/**
* A login module implementation that relies on the token store to check the
@@ -50,11 +50,37 @@
public class PortalLoginModule extends AbstractLoginModule
{
- /**
- * Logger.
- */
- protected Log log = ExoLogger.getLogger(PortalLoginModule.class);
+ /** Logger. */
+ private static final Log log = ExoLogger.getLogger(PortalLoginModule.class);
+ /** JACC get context method. */
+ private static final Method getContextMethod;
+
+ static
+ {
+ Method getContext = null;
+ if (isClusteredSSO())
+ {
+ log.debug("About to configure clustered SSO");
+ try
+ {
+ Class<?> policyContextClass =
Thread.currentThread().getContextClassLoader().loadClass("javax.security.jacc.PolicyContext");
+ getContext = policyContextClass.getDeclaredMethod("getContext",
String.class);
+ }
+ catch (ClassNotFoundException ignore)
+ {
+ log.debug("JACC not found ignoring it", ignore);
+ }
+ catch (Exception e)
+ {
+ log.error("Could not obtain JACC get context method", e);
+ }
+ }
+
+ //
+ getContextMethod = getContext;
+ }
+
public static final String AUTHENTICATED_CREDENTIALS =
"authenticatedCredentials";
/**
@@ -85,15 +111,13 @@
// For clustered config check credentials stored and propagated in session. This
won't work in tomcat because
// of lack of JACC PolicyContext so the code must be a bit defensive
- if (o == null && isClusteredSSO() &&
password.startsWith(InitiateLoginServlet.COOKIE_NAME))
+ if (o == null && getContextMethod != null &&
password.startsWith(InitiateLoginServlet.COOKIE_NAME))
{
- HttpServletRequest request = null;
+ HttpServletRequest request;
try
{
- request =
(HttpServletRequest)PolicyContext.getContext("javax.servlet.http.HttpServletRequest");
-
+ request = (HttpServletRequest)getContextMethod.invoke(null,
"javax.servlet.http.HttpServletRequest");
o = request.getSession().getAttribute(AUTHENTICATED_CREDENTIALS);
-
}
catch(Throwable e)
{
@@ -128,7 +152,7 @@
public boolean commit() throws LoginException
{
- if (isClusteredSSO() &&
+ if (getContextMethod != null &&
sharedState.containsKey("javax.security.auth.login.name") &&
sharedState.containsKey("javax.security.auth.login.password"))
{
@@ -140,10 +164,8 @@
HttpServletRequest request = null;
try
{
- request =
(HttpServletRequest)PolicyContext.getContext("javax.servlet.http.HttpServletRequest");
-
+ request = (HttpServletRequest)getContextMethod.invoke(null,
"javax.servlet.http.HttpServletRequest");
request.getSession().setAttribute(AUTHENTICATED_CREDENTIALS, wc);
-
}
catch(Exception e)
{
@@ -177,7 +199,7 @@
return log;
}
- protected boolean isClusteredSSO()
+ protected static boolean isClusteredSSO()
{
return ExoContainer.getProfiles().contains("cluster");
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java 2010-01-22
22:25:49 UTC (rev 1423)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -25,9 +25,7 @@
import org.exoplatform.webui.application.replication.serial.ObjectReader;
import org.exoplatform.webui.application.replication.serial.ObjectWriter;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
+import java.io.*;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;
@@ -101,6 +99,13 @@
return (O)in.readObject();
}
+ public void write(Object o, OutputStream out) throws IOException
+ {
+ ObjectWriter writer = new ObjectWriter(this, out);
+ writer.writeObject(o);
+ writer.flush();
+ }
+
public byte[] write(Object o) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -116,4 +121,10 @@
ObjectReader in = new ObjectReader(this, bais);
return in.readObject();
}
+
+ public Object read(InputStream in ) throws IOException, ClassNotFoundException
+ {
+ ObjectReader or = new ObjectReader(this, in);
+ return or.readObject();
+ }
}
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2010-01-22
22:25:49 UTC (rev 1423)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStateManager.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -20,6 +20,7 @@
package org.exoplatform.portal.application;
import org.exoplatform.container.ExoContainer;
+import org.exoplatform.portal.application.replication.ReplicatingStateManager;
import org.exoplatform.webui.application.StateManager;
import org.exoplatform.webui.application.WebuiApplication;
import org.exoplatform.webui.application.WebuiRequestContext;
Deleted:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ReplicatingStateManager.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ReplicatingStateManager.java 2010-01-22
22:25:49 UTC (rev 1423)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ReplicatingStateManager.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -1,255 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.exoplatform.portal.application;
-
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.portal.config.UserPortalConfig;
-import org.exoplatform.portal.config.UserPortalConfigService;
-import org.exoplatform.services.organization.Query;
-import org.exoplatform.webui.Util;
-import org.exoplatform.webui.application.ConfigurationManager;
-import org.exoplatform.webui.application.StateManager;
-import org.exoplatform.webui.application.WebuiApplication;
-import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.webui.application.portlet.PortletRequestContext;
-import org.exoplatform.webui.application.replication.SerializationContext;
-import org.exoplatform.webui.application.replication.api.annotations.Serialized;
-import org.exoplatform.webui.application.replication.api.factory.CreateException;
-import org.exoplatform.webui.application.replication.api.factory.ObjectFactory;
-import org.exoplatform.webui.application.replication.model.FieldModel;
-import org.exoplatform.webui.application.replication.model.TypeDomain;
-import org.exoplatform.webui.application.replication.model.metadata.DomainMetaData;
-import org.exoplatform.webui.application.replication.serial.ObjectWriter;
-import org.exoplatform.webui.config.Component;
-import org.exoplatform.webui.core.UIApplication;
-import org.exoplatform.webui.core.UIComponent;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-import java.util.Map;
-
-/**
- * The basis is either {@link org.exoplatform.webui.core.UIPortletApplication} or
- * {@link org.exoplatform.portal.webui.workspace.UIPortalApplication}.
- *
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public class ReplicatingStateManager extends StateManager
-{
-
- @Override
- public UIApplication restoreUIRootComponent(WebuiRequestContext context) throws
Exception
- {
- context.setStateManager(this);
-
- //
- WebuiApplication app = (WebuiApplication)context.getApplication();
-
- //
- HttpSession session = getSession(context);
- String key = getKey(context);
-
- //
- UIApplication uiapp = (UIApplication)session.getAttribute("bilto_" +
key);
-
- // Looks like some necessary hacking
- if (context instanceof PortalRequestContext)
- {
- PortalRequestContext portalRC = (PortalRequestContext)context;
- UserPortalConfig config = getUserPortalConfig(portalRC);
- if (config == null)
- {
- HttpServletResponse response = portalRC.getResponse();
- response.sendRedirect(portalRC.getRequest().getContextPath() +
"/portal-unavailable.jsp");
- portalRC.setResponseComplete(true);
- return null;
- }
- portalRC.setAttribute(UserPortalConfig.class, config);
-// SessionManagerContainer pcontainer =
(SessionManagerContainer)app.getApplicationServiceContainer();
-// pcontainer.createSessionContainer(context.getSessionId(), uiapp.getOwner());
- }
-
- //
- if (uiapp == null)
- {
- ConfigurationManager cmanager = app.getConfigurationManager();
- String uirootClass = cmanager.getApplication().getUIRootComponent();
- Class<? extends UIApplication> type = (Class<UIApplication>)
Thread.currentThread().getContextClassLoader().loadClass(uirootClass);
- uiapp = app.createUIComponent(type, null, null, context);
- }
-
- //
- return uiapp;
- }
-
- @Override
- public void storeUIRootComponent(final WebuiRequestContext context) throws Exception
- {
- UIApplication uiapp = context.getUIApplication();
-
- //
- HttpSession session = getSession(context);
-
- //
- Class<? extends UIApplication> appClass = uiapp.getClass();
- if (appClass.getAnnotation(Serialized.class) != null)
- {
- try
- {
- DomainMetaData domainMetaData = new DomainMetaData();
- domainMetaData.addClassType(Query.class, true);
-
- //
- SerializationContext serializationContext =
(SerializationContext)session.getAttribute("SerializationContext");
- if (serializationContext == null)
- {
- TypeDomain domain = new TypeDomain(domainMetaData, true);
- serializationContext = new SerializationContext(domain);
- session.setAttribute("SerializationContext",
serializationContext);
- ObjectFactory<UIComponent> factory = new
ObjectFactory<UIComponent>()
- {
-
- private <S extends UIComponent> Object getFieldValue(String
fieldName, Map<FieldModel<? super S, ?>, ?> state)
- {
- for (Map.Entry<FieldModel<? super S, ?>, ?> entry :
state.entrySet())
- {
- FieldModel<? super S, ?> fieldModel = entry.getKey();
- if (fieldModel.getOwner().getJavaType() == UIComponent.class
&& fieldModel.getName().equals(fieldName))
- {
- return entry.getValue();
- }
- }
- return null;
- }
-
- @Override
- public <S extends UIComponent> S create(Class<S> type,
Map<FieldModel<? super S, ?>, ?> state) throws CreateException
- {
- // Get config id
- String configId = (String)getFieldValue("configId",
state);
- String id = (String)getFieldValue("id", state);
-
- //
- try
- {
- WebuiApplication webuiApp = (WebuiApplication)
context.getApplication();
- ConfigurationManager configMgr =
webuiApp.getConfigurationManager();
- Component config = configMgr.getComponentConfig(type, configId);
-
- //
- S instance;
- if (config != null)
- {
- instance = Util.createObject(type, config.getInitParams());
- instance.setComponentConfig(id, config);
- }
- else
- {
- instance = Util.createObject(type, null);
- instance.setId(id);
- }
-
- // Now set state
- for (Map.Entry<FieldModel<? super S, ?>, ?> entry :
state.entrySet())
- {
- FieldModel<? super S, ?> fieldModel = entry.getKey();
- Object value = entry.getValue();
- fieldModel.castAndSet(instance, value);
- }
-
- //
- return instance;
- }
- catch (Exception e)
- {
- throw new CreateException(e);
- }
- }
- };
- serializationContext.addFactory(factory);
- }
-
- //
-
- //
- uiapp = serializationContext.clone(uiapp);
- System.out.println("Cloned application");
- }
- catch (Exception e)
- {
- System.out.println("Could not clone application");
- e.printStackTrace();
- }
- }
-
-
- //
- String key = getKey(context);
- session.setAttribute("bilto_" + key, uiapp);
- }
-
- @Override
- public void expire(String sessionId, WebuiApplication app) throws Exception
- {
- // For now do nothing....
- }
-
- private UserPortalConfig getUserPortalConfig(PortalRequestContext context) throws
Exception
- {
- ExoContainer appContainer =
context.getApplication().getApplicationServiceContainer();
- UserPortalConfigService service_ =
(UserPortalConfigService)appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
- String remoteUser = context.getRemoteUser();
- String ownerUser = context.getPortalOwner();
- return service_.getUserPortalConfig(ownerUser, remoteUser);
- }
-
- private String getKey(WebuiRequestContext webuiRC)
- {
- if (webuiRC instanceof PortletRequestContext)
- {
- PortletRequestContext portletRC = (PortletRequestContext)webuiRC;
- return portletRC.getApplication().getApplicationId() + "/" +
portletRC.getWindowId();
- }
- else
- {
- PortalRequestContext portalRC = (PortalRequestContext)webuiRC;
- return "portal";
- }
- }
-
- private HttpSession getSession(WebuiRequestContext webuiRC)
- {
- if (webuiRC instanceof PortletRequestContext)
- {
- PortletRequestContext portletRC = (PortletRequestContext)webuiRC;
- PortalRequestContext portalRC = (PortalRequestContext)
portletRC.getParentAppRequestContext();
- HttpServletRequest req = portalRC.getRequest();
- return req.getSession();
- }
- else
- {
- PortalRequestContext portalRC = (PortalRequestContext)webuiRC;
- HttpServletRequest req = portalRC.getRequest();
- return req.getSession();
- }
- }
-}
Added:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ApplicationState.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ApplicationState.java
(rev 0)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ApplicationState.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application.replication;
+
+import org.exoplatform.webui.application.replication.SerializationContext;
+import org.exoplatform.webui.application.replication.api.annotations.Serialized;
+import org.exoplatform.webui.core.UIApplication;
+
+import java.io.*;
+
+/**
+ * The state of an application.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ApplicationState implements Serializable
+{
+
+ /** . */
+ private UIApplication application;
+
+ /** . */
+ private byte[] serialization;
+
+ /** . */
+ private String userName;
+
+ public ApplicationState(UIApplication application, String userName)
+ {
+ if (application == null)
+ {
+ throw new NullPointerException();
+ }
+ this.application = application;
+ this.userName = userName;
+ }
+
+ public String getUserName()
+ {
+ return userName;
+ }
+
+ public UIApplication getApplication() throws IOException, ClassNotFoundException
+ {
+ if (serialization != null)
+ {
+ SerializationContext serializationContext =
SerializationContextSingleton.getInstance();
+ byte[] bytes = serialization;
+ serialization = null;
+ application = (UIApplication)serializationContext.read(bytes);
+ }
+ return application;
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException
+ {
+ if (userName != null)
+ {
+ oos.writeBoolean(true);
+ oos.writeUTF(userName);
+ }
+ else
+ {
+ oos.writeBoolean(false);
+ }
+
+ //
+ if (application != null &&
application.getClass().getAnnotation(Serialized.class) != null)
+ {
+ oos.writeBoolean(true);
+
+ //
+ SerializationContext serializationContext =
SerializationContextSingleton.getInstance();
+
+ //
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ serializationContext.write(application, baos);
+ baos.close();
+
+ //
+ byte[] bytes = baos.toByteArray();
+ oos.writeInt(bytes.length);
+ oos.write(bytes);
+ }
+ else
+ {
+ oos.writeBoolean(false);
+ }
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException,
ClassNotFoundException
+ {
+ if (ois.readBoolean())
+ {
+ userName = ois.readUTF();
+ }
+
+ //
+ if (ois.readBoolean())
+ {
+ int size = ois.readInt();
+ byte[] bytes = new byte[size];
+ ois.readFully(bytes);
+ serialization = bytes;
+ }
+ else
+ {
+ serialization = null;
+ }
+
+ //
+ application = null;
+ }
+}
Copied:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ReplicatingStateManager.java
(from rev 1418,
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ReplicatingStateManager.java)
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ReplicatingStateManager.java
(rev 0)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/ReplicatingStateManager.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application.replication;
+
+import org.exoplatform.commons.utils.Safe;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.portal.application.LegacyPortalStateManager;
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.config.UserPortalConfig;
+import org.exoplatform.portal.config.UserPortalConfigService;
+import org.exoplatform.webui.application.ConfigurationManager;
+import org.exoplatform.webui.application.StateManager;
+import org.exoplatform.webui.application.WebuiApplication;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.application.portlet.PortletRequestContext;
+import org.exoplatform.webui.core.UIApplication;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * The basis is either {@link org.exoplatform.webui.core.UIPortletApplication} or
+ * {@link org.exoplatform.portal.webui.workspace.UIPortalApplication}.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ReplicatingStateManager extends StateManager
+{
+
+ @Override
+ public UIApplication restoreUIRootComponent(WebuiRequestContext context) throws
Exception
+ {
+ context.setStateManager(this);
+
+ //
+ WebuiApplication app = (WebuiApplication)context.getApplication();
+
+ //
+ HttpSession session = getSession(context);
+ String key = getKey(context);
+
+ //
+ ApplicationState appState =
(ApplicationState)session.getAttribute("bilto_" + key);
+
+ //
+ UIApplication uiapp = null;
+ if (appState != null)
+ {
+ if (Safe.equals(context.getRemoteUser(), appState.getUserName()))
+ {
+ uiapp = appState.getApplication();
+ }
+ }
+
+ //
+ if (appState != null)
+ {
+ System.out.println("Found application " + key + " :" +
appState.getApplication());
+ }
+ else
+ {
+ System.out.println("Application " + key + " not found");
+ }
+
+ // Looks like some necessary hacking
+ if (context instanceof PortalRequestContext)
+ {
+ PortalRequestContext portalRC = (PortalRequestContext)context;
+ UserPortalConfig config = getUserPortalConfig(portalRC);
+ if (config == null)
+ {
+ HttpServletResponse response = portalRC.getResponse();
+ response.sendRedirect(portalRC.getRequest().getContextPath() +
"/portal-unavailable.jsp");
+ portalRC.setResponseComplete(true);
+ return null;
+ }
+ portalRC.setAttribute(UserPortalConfig.class, config);
+// SessionManagerContainer pcontainer =
(SessionManagerContainer)app.getApplicationServiceContainer();
+// pcontainer.createSessionContainer(context.getSessionId(), uiapp.getOwner());
+ }
+
+ //
+ if (uiapp == null)
+ {
+ ConfigurationManager cmanager = app.getConfigurationManager();
+ String uirootClass = cmanager.getApplication().getUIRootComponent();
+ Class<? extends UIApplication> type = (Class<UIApplication>)
Thread.currentThread().getContextClassLoader().loadClass(uirootClass);
+ uiapp = app.createUIComponent(type, null, null, context);
+ }
+
+ //
+ return uiapp;
+ }
+
+ @Override
+ public void storeUIRootComponent(final WebuiRequestContext context) throws Exception
+ {
+ UIApplication uiapp = context.getUIApplication();
+
+ //
+ HttpSession session = getSession(context);
+
+ //
+ String key = getKey(context);
+
+ //
+ System.out.println("Storing application " + key);
+ session.setAttribute("bilto_" + key, new ApplicationState(uiapp,
context.getRemoteUser()));
+ }
+
+ @Override
+ public void expire(String sessionId, WebuiApplication app) throws Exception
+ {
+ // For now do nothing....
+ }
+
+ private UserPortalConfig getUserPortalConfig(PortalRequestContext context) throws
Exception
+ {
+ ExoContainer appContainer =
context.getApplication().getApplicationServiceContainer();
+ UserPortalConfigService service_ =
(UserPortalConfigService)appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
+ String remoteUser = context.getRemoteUser();
+ String ownerUser = context.getPortalOwner();
+ return service_.getUserPortalConfig(ownerUser, remoteUser);
+ }
+
+ private String getKey(WebuiRequestContext webuiRC)
+ {
+ if (webuiRC instanceof PortletRequestContext)
+ {
+ PortletRequestContext portletRC = (PortletRequestContext)webuiRC;
+
+ // We are temporarily not using the window id as it changes when the back end is
not the same
+ return portletRC.getApplication().getApplicationId()/* + "/" +
portletRC.getWindowId()*/;
+ }
+ else
+ {
+ PortalRequestContext portalRC = (PortalRequestContext)webuiRC;
+ return "portal";
+ }
+ }
+
+ private HttpSession getSession(WebuiRequestContext webuiRC)
+ {
+ if (webuiRC instanceof PortletRequestContext)
+ {
+ PortletRequestContext portletRC = (PortletRequestContext)webuiRC;
+ PortalRequestContext portalRC = (PortalRequestContext)
portletRC.getParentAppRequestContext();
+ HttpServletRequest req = portalRC.getRequest();
+ return req.getSession();
+ }
+ else
+ {
+ PortalRequestContext portalRC = (PortalRequestContext)webuiRC;
+ HttpServletRequest req = portalRC.getRequest();
+ return req.getSession();
+ }
+ }
+}
Added:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/SerializationContextSingleton.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/SerializationContextSingleton.java
(rev 0)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/SerializationContextSingleton.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application.replication;
+
+import org.exoplatform.services.organization.Query;
+import org.exoplatform.webui.application.replication.SerializationContext;
+import org.exoplatform.webui.application.replication.model.TypeDomain;
+import org.exoplatform.webui.application.replication.model.metadata.DomainMetaData;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+class SerializationContextSingleton
+{
+
+ /** . */
+ private static SerializationContext instance = createInstance();
+
+ public static SerializationContext getInstance()
+ {
+ return instance;
+ }
+
+ private static SerializationContext createInstance()
+ {
+ DomainMetaData domainMetaData = new DomainMetaData();
+
+ // For now we need to mark the Query class as serialized
+ domainMetaData.addClassType(Query.class, true);
+
+ // Build domain
+ TypeDomain domain = new TypeDomain(domainMetaData, true);
+
+ // Build serialization context
+ SerializationContext serializationContext = new SerializationContext(domain);
+ serializationContext.addFactory(new UIComponentFactory());
+
+ //
+ return serializationContext;
+ }
+}
Added:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/UIComponentFactory.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/UIComponentFactory.java
(rev 0)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/replication/UIComponentFactory.java 2010-01-22
22:39:11 UTC (rev 1424)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.application.replication;
+
+import org.exoplatform.webui.Util;
+import org.exoplatform.webui.application.ConfigurationManager;
+import org.exoplatform.webui.application.WebuiApplication;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.application.replication.api.factory.CreateException;
+import org.exoplatform.webui.application.replication.api.factory.ObjectFactory;
+import org.exoplatform.webui.application.replication.model.FieldModel;
+import org.exoplatform.webui.config.Component;
+import org.exoplatform.webui.core.UIComponent;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class UIComponentFactory extends ObjectFactory<UIComponent>
+{
+
+
+
+ private <S extends UIComponent> Object getFieldValue(String fieldName,
Map<FieldModel<? super S, ?>, ?> state)
+ {
+ for (Map.Entry<FieldModel<? super S, ?>, ?> entry : state.entrySet())
+ {
+ FieldModel<? super S, ?> fieldModel = entry.getKey();
+ if (fieldModel.getOwner().getJavaType() == UIComponent.class &&
fieldModel.getName().equals(fieldName))
+ {
+ return entry.getValue();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public <S extends UIComponent> S create(Class<S> type,
Map<FieldModel<? super S, ?>, ?> state) throws CreateException
+ {
+ // Get config id
+ String configId = (String)getFieldValue("configId", state);
+ String id = (String)getFieldValue("id", state);
+
+ //
+ try
+ {
+ WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
+ WebuiApplication webuiApp = (WebuiApplication) context.getApplication();
+ ConfigurationManager configMgr = webuiApp.getConfigurationManager();
+ Component config = configMgr.getComponentConfig(type, configId);
+
+ //
+ S instance;
+ if (config != null)
+ {
+ instance = Util.createObject(type, config.getInitParams());
+ instance.setComponentConfig(id, config);
+ }
+ else
+ {
+ instance = Util.createObject(type, null);
+ instance.setId(id);
+ }
+
+ // Now set state
+ for (Map.Entry<FieldModel<? super S, ?>, ?> entry :
state.entrySet())
+ {
+ FieldModel<? super S, ?> fieldModel = entry.getKey();
+ Object value = entry.getValue();
+ fieldModel.castAndSet(instance, value);
+ }
+
+ //
+ return instance;
+ }
+ catch (Exception e)
+ {
+ throw new CreateException(e);
+ }
+ }
+}