[seam-commits] Seam SVN: r11517 - branches/community/Seam_2_2/src/flex/org/jboss/seam/flex.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Mon Sep 28 18:16:35 EDT 2009
Author: norman.richards at jboss.com
Date: 2009-09-28 18:16:35 -0400 (Mon, 28 Sep 2009)
New Revision: 11517
Modified:
branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexAuthenticationBridge.java
branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexFilter.java
branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/MessageBrokerManager.java
branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/SeamAdapter.java
Log:
JBSEAM-4409
Modified: branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexAuthenticationBridge.java
===================================================================
--- branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexAuthenticationBridge.java 2009-09-25 03:33:47 UTC (rev 11516)
+++ branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexAuthenticationBridge.java 2009-09-28 22:16:35 UTC (rev 11517)
@@ -20,6 +20,7 @@
@In Credentials credentials;
public String login(String username, String password) {
+ System.out.println("---");
log.info("*LOGIN " + username + " " + password);
credentials.setUsername(username);
credentials.setPassword(password);
Modified: branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexFilter.java
===================================================================
--- branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexFilter.java 2009-09-25 03:33:47 UTC (rev 11516)
+++ branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/FlexFilter.java 2009-09-28 22:16:35 UTC (rev 11517)
@@ -15,7 +15,6 @@
import org.jboss.seam.deployment.DeploymentStrategy;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
-import org.jboss.seam.servlet.ContextualHttpServletRequest;
import org.jboss.seam.web.AbstractFilter;
@Scope(ScopeType.APPLICATION)
@@ -73,20 +72,11 @@
}
- public void doFilter(final ServletRequest request, final ServletResponse response, FilterChain chain)
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
if (isMappedToCurrentRequestPath(request)) {
- new ContextualHttpServletRequest((HttpServletRequest) request)
- {
- @Override
- public void process()
- throws ServletException, IOException
- {
- messageBrokerManager.service((HttpServletRequest)request,
- (HttpServletResponse)response);
- }
- }.run();
+ messageBrokerManager.service((HttpServletRequest)request, (HttpServletResponse)response);
} else {
chain.doFilter(request, response);
}
Modified: branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/MessageBrokerManager.java
===================================================================
--- branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/MessageBrokerManager.java 2009-09-25 03:33:47 UTC (rev 11516)
+++ branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/MessageBrokerManager.java 2009-09-28 22:16:35 UTC (rev 11517)
@@ -137,8 +137,10 @@
} catch (UnsupportedOperationException ue) {
sendError(res);
} finally {
- FlexContext.clearThreadLocalObjects();
+ FlexContext.clearThreadLocalObjects();
}
+
+ log.info("=========== END FLEX REQUEST");
}
@@ -221,10 +223,10 @@
// configure adapter
registerSeamAdapter(remotingService);
destination.createAdapter(SeamAdapter.SEAM_ADAPTER_ID);
+
+ // XXX configure channel?
+ // System.out.println("-channels " + destination.getChannels());
- // configure channel?
- //System.out.println("-channels " + destination.getChannels());
-
return destination;
}
Modified: branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/SeamAdapter.java
===================================================================
--- branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/SeamAdapter.java 2009-09-25 03:33:47 UTC (rev 11516)
+++ branches/community/Seam_2_2/src/flex/org/jboss/seam/flex/SeamAdapter.java 2009-09-28 22:16:35 UTC (rev 11517)
@@ -1,10 +1,22 @@
package org.jboss.seam.flex;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.jboss.seam.contexts.ServletLifecycle;
+import org.jboss.seam.core.ConversationPropagation;
+import org.jboss.seam.core.Manager;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
+import org.jboss.seam.servlet.ServletRequestSessionMap;
+import org.jboss.seam.web.ServletContexts;
+import flex.messaging.FlexContext;
import flex.messaging.services.remoting.adapters.JavaAdapter;
+import flex.messaging.messages.AcknowledgeMessage;
import flex.messaging.messages.Message;
/**
@@ -15,13 +27,78 @@
extends JavaAdapter
{
public static final String SEAM_ADAPTER_ID = "seam-adapter";
-
+ private static final String CONVERSATION_ID = "conversationId";
+
private static final LogProvider log = Logging.getLogProvider(SeamAdapter.class);
@Override
public Object invoke(Message message) {
log.info("SeamAdapter: " + message);
- return super.invoke(message);
+
+ try {
+ startSeamContexts(message, FlexContext.getHttpRequest());
+
+ Object result = wrapResult(super.invoke(message));
+
+ endSeamContexts(FlexContext.getHttpRequest());
+
+ return result;
+ } catch (RuntimeException e) {
+ // XXX end request properly....
+ e.printStackTrace();
+ throw e;
+ }
}
+
+ protected Object wrapResult(Object result)
+ {
+ AcknowledgeMessage response = new AcknowledgeMessage();
+ response.setHeader(CONVERSATION_ID, Manager.instance().getCurrentConversationId());
+ response.setBody(result);
+
+ return response;
+ }
+
+
+ protected void startSeamContexts(Message message, HttpServletRequest request)
+ {
+ ServletLifecycle.beginRequest(request);
+ ServletContexts.instance().setRequest(request);
+
+ Map conversationParameters = conversationMap(message);
+ ConversationPropagation.instance().restoreConversationId(conversationParameters);
+ Manager.instance().restoreConversation();
+ ServletLifecycle.resumeConversation(request);
+ Manager.instance().handleConversationPropagation(conversationParameters);
+
+ // Force creation of the session
+ if (request.getSession(false) == null) {
+ request.getSession(true);
+ }
+
+ }
+
+ protected void endSeamContexts(HttpServletRequest request)
+ {
+ Manager.instance().endRequest( new ServletRequestSessionMap(request) );
+ ServletLifecycle.endRequest(request);
+ }
+
+ protected Map conversationMap(Message message) {
+ Map result = new HashMap();
+
+ result.put(Manager.instance().getConversationIdParameter(), conversationId(message));
+ return result;
+ }
+
+ protected String conversationId(Message message) {
+ if (message == null) {
+ return null;
+ }
+
+ Object header = message.getHeader(CONVERSATION_ID);
+
+ return header == null ? null : header.toString();
+ }
}
More information about the seam-commits
mailing list