You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/01/16 10:37:20 UTC

svn commit: r496640 - in /incubator/tuscany/java/sca/runtime/webapp: webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/ webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/ webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/

Author: antelder
Date: Tue Jan 16 01:37:19 2007
New Revision: 496640

URL: http://svn.apache.org/viewvc?view=rev&rev=496640
Log:
TUSCANY-936, reinstate use of LazyHTTPSessionId

Added:
    incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java
    incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java   (with props)
Modified:
    incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java
    incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
    incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
    incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java

Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java?view=diff&rev=496640&r1=496639&r2=496640
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/TuscanyRequestListener.java Tue Jan 16 01:37:19 2007
@@ -56,9 +56,7 @@
         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());
+            runtime.httpRequestStarted((HttpServletRequest) servletRequest);
 
         }
 

Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java?view=diff&rev=496640&r1=496639&r2=496640
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-api/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntime.java Tue Jan 16 01:37:19 2007
@@ -19,6 +19,7 @@
 package org.apache.tuscany.runtime.webapp;
 
 import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSessionListener;
 
 import org.apache.tuscany.host.runtime.TuscanyRuntime;
@@ -64,13 +65,13 @@
     void stopRequest();
 
     /**
-     * Request has been started with the given session id
+     * Request has been started for the given request
      */
-    void httpRequestStarted(Object id);
+    void httpRequestStarted(HttpServletRequest request);
 
     /**
      * Request has been ended with the given session id
      */
-
     void httpRequestEnded(Object id);
+    
 }

Added: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java?view=auto&rev=496640
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionId.java Tue Jan 16 01:37:19 2007
@@ -0,0 +1,58 @@
+/*
+ * 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 javax.servlet.http.HttpServletRequest;
+
+import org.apache.tuscany.core.component.ScopeIdentifier;
+
+/**
+ * Implements a <code>ScopeIdentifier</code> for a Servlet-based transport.
+ * Wraps an <code>HttpServletRequest</code> so that the session id associated
+ * with the current request may be lazily retrieved by the module context - i.e.
+ * if a session context or session-scoped component is not accessed, no session
+ * is created.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LazyHTTPSessionId implements ScopeIdentifier {
+
+    private HttpServletRequest request;
+
+    //----------------------------------
+    // Constructors
+    //----------------------------------
+
+    public LazyHTTPSessionId(HttpServletRequest request) {
+        this.request = request;
+    }
+
+    //----------------------------------
+    // Methods
+    //----------------------------------
+
+    /**
+     * Returns the session identifier
+     *
+     * @see org.apache.tuscany.core.context.ScopeIdentifier#getIdentifier()
+     */
+    public Object getIdentifier() {
+        return request.getSession(true);
+    }
+}

Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java?view=diff&rev=496640&r1=496639&r2=496640
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java Tue Jan 16 01:37:19 2007
@@ -19,11 +19,12 @@
 package org.apache.tuscany.runtime.webapp;
 
 import java.util.StringTokenizer;
+
 import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionEvent;
 
-import org.osoa.sca.SCA;
-
 import org.apache.tuscany.core.component.event.HttpRequestEnded;
 import org.apache.tuscany.core.component.event.HttpRequestStart;
 import org.apache.tuscany.core.component.event.HttpSessionEnd;
@@ -39,6 +40,7 @@
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.component.SCAObject;
 import org.apache.tuscany.spi.event.EventPublisher;
+import org.osoa.sca.SCA;
 
 /**
  * Bootstrapper for the Tuscany runtime in a web application host. This listener manages one runtime per servlet
@@ -150,8 +152,10 @@
         ((EventPublisher) requestInjector).publish(endSession);
     }
 
-    public void httpRequestStarted(Object sessionid) {
-        HttpRequestStart httpRequestStart = new HttpRequestStart(this, sessionid);
+    public void httpRequestStarted(HttpServletRequest request) {
+        HttpSession session = request.getSession(false);
+        Object sessionId = session == null ? new LazyHTTPSessionId(request) : session.getId();
+        HttpRequestStart httpRequestStart = new HttpRequestStart(this, sessionId);
         application.publish(httpRequestStart);
         ((EventPublisher) requestInjector).publish(httpRequestStart);
     }

Added: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java?view=auto&rev=496640
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java (added)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java Tue Jan 16 01:37:19 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import junit.framework.TestCase;
+
+public class LazyHTTPSessionIdTestCase extends TestCase {
+    
+    public void testGetIdentifier() {
+        HttpSession id = createMock(HttpSession.class);
+
+        HttpServletRequest request = createMock(HttpServletRequest.class);
+        expect(request.getSession(true)).andReturn(id);
+        replay(request);
+        
+        LazyHTTPSessionId lazyHTTPSessionId = new LazyHTTPSessionId(request);
+        assertEquals(id, lazyHTTPSessionId.getIdentifier());
+    }
+
+}

Propchange: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/LazyHTTPSessionIdTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java?view=diff&rev=496640&r1=496639&r2=496640
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/test/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImplTestCase.java Tue Jan 16 01:37:19 2007
@@ -18,15 +18,22 @@
  */
 package org.apache.tuscany.runtime.webapp;
 
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
 import java.net.URL;
+
 import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
 
 import junit.framework.TestCase;
+
 import org.apache.tuscany.core.monitor.NullMonitorFactory;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import org.apache.tuscany.host.servlet.ServletRequestInjector;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Scope;
 
 /**
  * @version $Rev$ $Date$
@@ -46,6 +53,35 @@
         replay(context);
         runtime.initialize();
         verify(context);
+    }
+
+    public void testLazyHttpSessionId() throws Exception {
+        expect(context.getResourcePaths("/WEB-INF/tuscany/extensions/")).andReturn(null);
+        expect(context.getInitParameter("tuscany.currentCompositePath")).andReturn(null);
+        replay(context);
+        runtime.initialize();
+        verify(context);
+
+        HttpServletRequest request = createMock(HttpServletRequest.class);;
+        expect(request.getSession(true)).andReturn(null);
+        expect(request.getSession(false)).andReturn(null);
+        replay(request);
+
+        runtime.httpRequestStarted(request);
+        
+        ServletRequestInjector injector = runtime.getRequestInjector();
+        class WorkContextAccessor extends ServletHostImpl {
+            ServletHostImpl servletHostImpl;
+            WorkContextAccessor(ServletHostImpl servletHostImpl){
+                this.servletHostImpl = servletHostImpl;
+            }
+            WorkContext getWorkContext() {
+                return servletHostImpl.workContext;
+            }
+        }
+        WorkContext workContext = new WorkContextAccessor((ServletHostImpl)injector).getWorkContext();
+        workContext.getIdentifier(Scope.SESSION);
+        verify(request);
     }
 
     protected void setUp() throws Exception {



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org