Author: rineholt
Date: Wed Oct  4 10:49:04 2006
New Revision: 452953

URL: http://svn.apache.org/viewvc?view=rev&rev=452953
Log:
HTTP Session support.  Seems to work with respect to what BB needs.

Added:
    
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java
    
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java
    
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java
Modified:
    
incubator/tuscany/java/sampleapps/bigbank/webclient/src/main/webapp/WEB-INF/web.xml
    
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
    
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
    
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java

Modified: 
incubator/tuscany/java/sampleapps/bigbank/webclient/src/main/webapp/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sampleapps/bigbank/webclient/src/main/webapp/WEB-INF/web.xml?view=diff&rev=452953&r1=452952&r2=452953
==============================================================================
--- 
incubator/tuscany/java/sampleapps/bigbank/webclient/src/main/webapp/WEB-INF/web.xml
 (original)
+++ 
incubator/tuscany/java/sampleapps/bigbank/webclient/src/main/webapp/WEB-INF/web.xml
 Wed Oct  4 10:49:04 2006
@@ -39,6 +39,10 @@
     <listener>
         
<listener-class>org.apache.tuscany.runtime.webapp.TuscanySessionListener</listener-class>
     </listener>
+    
+    <listener>
+            
<listener-class>org.apache.tuscany.runtime.webapp.TuscanyRequestListener</listener-class>
+    </listener>
 
     <servlet>
         <servlet-name>LoginServlet</servlet-name>

Added: 
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java?view=auto&rev=452953
==============================================================================
--- 
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java
 (added)
+++ 
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestEnded.java
 Wed Oct  4 10:49:04 2006
@@ -0,0 +1,38 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you 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 org.apache.tuscany.core.component.event;

+

+/**

+ * Propagated when an HTTP-based request has ended.

+ *

+ * @version $$Rev: 430937 $$ $$Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 
2006) $$

+ */

+public class HttpRequestEnded extends HttpSessionEvent {

+

+    /**

+     * Creates a new event

+     *

+     * @param source the source of the event

+     * @param id     the id of the HTTP session being ended

+     */

+    public HttpRequestEnded(Object source, Object id) {

+        super(source, id);

+    }

+

+}


Added: 
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java?view=auto&rev=452953
==============================================================================
--- 
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java
 (added)
+++ 
incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/event/HttpRequestStart.java
 Wed Oct  4 10:49:04 2006
@@ -0,0 +1,38 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you 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 org.apache.tuscany.core.component.event;

+

+/**

+ * Propagated when an HTTP-based request has started

+ *

+ * @version $$Rev: 430937 $$ $$Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 
2006) $$

+ */

+public class HttpRequestStart extends HttpSessionEvent {

+

+    /**

+     * Creates a new event

+     *

+     * @param source the source of the event

+     * @param id     the id of the HTTP session being ended

+     */

+    public HttpRequestStart(Object source, Object id) {

+        super(source, id);

+    }

+

+}


Modified: 
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java?view=diff&rev=452953&r1=452952&r2=452953
==============================================================================
--- 
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ServletHostImpl.java
 Wed Oct  4 10:49:04 2006
@@ -18,6 +18,8 @@
  */
 package org.apache.tuscany.runtime.webapp;
 
+import static 
org.apache.tuscany.core.component.scope.HttpSessionScopeContainer.HTTP_IDENTIFIER;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -28,10 +30,15 @@
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.tuscany.core.component.event.HttpRequestEnded;
+import org.apache.tuscany.core.component.event.HttpRequestStart;
+import org.apache.tuscany.core.component.event.HttpSessionEnd;
+import org.apache.tuscany.core.component.event.HttpSessionStart;
 import org.apache.tuscany.host.servlet.ServletRequestInjector;
 import org.apache.tuscany.spi.annotation.Autowire;
 import org.apache.tuscany.spi.component.ScopeContainer;
 import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.WorkContext;
 import org.apache.tuscany.spi.event.Event;
 import org.apache.tuscany.spi.event.EventFilter;
 import org.apache.tuscany.spi.event.EventPublisher;
@@ -42,13 +49,12 @@
 import org.osoa.sca.annotations.Service;
 
 /**
- * A <code>ServletHost</code> implementation that forwards requests to 
registered servlets 
+ * A <code>ServletHost</code> implementation that forwards requests to 
registered servlets
  */
 @Service(ServletHost.class)
 public class ServletHostImpl implements ServletHost, ServletRequestInjector, 
EventPublisher {
 
     protected Map<String, Servlet> servlets;
-    
 
     public ServletHostImpl() {
         this.servlets = new HashMap<String, Servlet>();
@@ -57,15 +63,20 @@
     @Init(eager = true)
     public void init() {
     }
-    
-    protected ScopeRegistry registry= null;
-    
-    
-    @Autowire(required=false)
+
+    protected ScopeRegistry registry = null;
+
+    @Autowire(required = false)
     public void setSessionScopeContainer(ScopeRegistry registry) {
-       this.registry = registry;     
+        this.registry = registry;
     }
 
+    WorkContext workContext = null;
+
+    @Autowire(required = false)
+    public void setWorkContext(WorkContext workContext) {
+        this.workContext = workContext;
+    }
 
     public void service(ServletRequest req, ServletResponse resp) throws 
ServletException, IOException {
         assert req instanceof HttpServletRequest : "implementation only 
supports HttpServletRequest";
@@ -89,29 +100,43 @@
     }
 
     public void addListener(RuntimeEventListener listener) {
-       throw new UnSupportedRuntimeException("Not Supported");
-        
+        throw new UnSupportedRuntimeException("Not Supported");
+
     }
 
     public void addListener(EventFilter filter, RuntimeEventListener listener) 
{
         throw new UnSupportedRuntimeException("Not Supported");
-        
+
     }
 
     public void publish(Event event) {
-       if(registry != null){
-          ScopeContainer sc = registry.getScopeContainer(Scope.SESSION);
-          if(null != sc) {
-              sc.onEvent(event);
-          
-          }
-       }
-        
+        if (null != registry && (event instanceof HttpSessionStart || event 
instanceof HttpSessionEnd)) {
+            ScopeContainer sc = registry.getScopeContainer(Scope.SESSION);
+            if (null != sc) {
+                sc.onEvent(event);
+
+            }
+        }
+        if (null != workContext) {
+            if (event instanceof HttpRequestStart) {
+                Object key = ((HttpRequestStart) event).getId();
+                if (null != key) {
+                    workContext.setIdentifier(HTTP_IDENTIFIER, 
((HttpRequestStart) event).getId());
+                } else { // new request with no session.
+                    workContext.clearIdentifier(HTTP_IDENTIFIER);
+                }
+            } else if (event instanceof HttpRequestEnded) {
+                workContext.clearIdentifier(HTTP_IDENTIFIER);
+
+            }
+
+        }
+
     }
 
     public void removeListener(RuntimeEventListener listener) {
         throw new UnSupportedRuntimeException("Not Supported");
-        
+
     }
 
-}
+}
\ No newline at end of file

Modified: 
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java?view=diff&rev=452953&r1=452952&r2=452953
==============================================================================
--- 
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/runtime/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
 Wed Oct  4 10:49:04 2006
@@ -28,6 +28,8 @@
 
 import org.apache.tuscany.core.bootstrap.Bootstrapper;
 import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
+import org.apache.tuscany.core.component.event.HttpRequestEnded;
+import org.apache.tuscany.core.component.event.HttpRequestStart;
 import org.apache.tuscany.core.component.event.HttpSessionEnd;
 import org.apache.tuscany.core.component.event.HttpSessionStart;
 import org.apache.tuscany.core.component.event.RequestEnd;
@@ -187,6 +189,19 @@
         application.publish(endSession);
         ((EventPublisher)requestInjector).publish(endSession);
     }
+    
+    public void httpRequestStarted(Object sessionid) {
+        HttpRequestStart httpRequestStart = new HttpRequestStart(this, 
sessionid);
+        application.publish(httpRequestStart);
+        ((EventPublisher)requestInjector).publish(httpRequestStart);
+    }
+    
+    public void httpRequestEnded(Object sessionid) {
+        HttpRequestEnded httpRequestEnded = new HttpRequestEnded(this, 
sessionid);
+        application.publish(httpRequestEnded);
+        ((EventPublisher)requestInjector).publish(httpRequestEnded);
+    }
+
 
     public void startRequest() {
         application.publish(new RequestStart(this));

Added: 
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java?view=auto&rev=452953
==============================================================================
--- 
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java
 (added)
+++ 
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java
 Wed Oct  4 10:49:04 2006
@@ -0,0 +1,78 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you 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 org.apache.tuscany.runtime.webapp;

+

+import static org.apache.tuscany.runtime.webapp.Constants.RUNTIME_ATTRIBUTE;

+

+import javax.servlet.ServletContext;

+import javax.servlet.ServletException;

+import javax.servlet.ServletRequest;

+import javax.servlet.ServletRequestEvent;

+import javax.servlet.ServletRequestListener;

+import javax.servlet.http.HttpServletRequest;

+import javax.servlet.http.HttpSession;

+

+/**

+ * Notifies the Tuscany runtime of session creation and expiration events.

+ * 

+ * @version $Rev: 441961 $ $Date: 2006-09-10 11:48:29 -0400 (Sun, 10 Sep 2006) 
$

+ */

+public class TuscanyRequestListener implements ServletRequestListener {

+    private WebappRuntime runtime;

+

+    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {

+

+        final ServletContext context = servletRequestEvent.getServletContext();

+        getRuntime(context);

+        ServletRequest servletRequest = 
servletRequestEvent.getServletRequest();

+        if (servletRequest instanceof HttpServletRequest) {

+            HttpServletRequest httpServletRequest = (HttpServletRequest) 
servletRequest;

+            HttpSession session = httpServletRequest.getSession(false);

+            runtime.httpRequestEnded(session.getId());

+

+        }

+

+    }

+

+    public void requestInitialized(ServletRequestEvent servletRequestEvent) {

+

+        final ServletContext context = servletRequestEvent.getServletContext();

+        getRuntime(context);

+        ServletRequest servletRequest = 
servletRequestEvent.getServletRequest();

+        if (servletRequest instanceof HttpServletRequest) {

+            HttpServletRequest httpServletRequest = (HttpServletRequest) 
servletRequest;

+            HttpSession session = httpServletRequest.getSession(false);

+            runtime.httpRequestStarted(session == null ? null : 
session.getId());

+

+        }

+

+    }

+

+    protected WebappRuntime getRuntime(final ServletContext context) {

+        if (runtime == null) {

+

+            runtime = (WebappRuntime) context.getAttribute(RUNTIME_ATTRIBUTE);

+            if (runtime == null) {

+                context.log("requestInitialized", new 
ServletException("Tuscany runtime not configured"));

+                return null;

+            }

+        }

+        return runtime;

+    }

+}
\ No newline at end of file

Modified: 
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java?view=diff&rev=452953&r1=452952&r2=452953
==============================================================================
--- 
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
 (original)
+++ 
incubator/tuscany/java/sca/runtime/webapp/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
 Wed Oct  4 10:49:04 2006
@@ -62,4 +62,17 @@
      * Notification that the web application has stopped servicing a request
      */
     void stopRequest();
+
+    /**
+     * httpRequestStarted  request has been started with sessid id
+     * @param session id.
+     */
+    void httpRequestStarted(Object id);
+    
+    /**
+     * httpRequestEnded  request has been ended with sessid id
+     * @param session id.
+     */
+    
+    void httpRequestEnded(Object id);
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to