Hello all.  I finally got a breather and did a sync-up
with the Webware CVS this afternoon.  As we talked about
a month and a half ago... (long time), I was wondering
if pathVariables could be added to CVS.

Description:

  Often times you want to store information 
  that sets the "context" for viewing a 
  a collection of related servlets.  Examples
  include the user's language, the user's company,
  preferences, or other contextual information 
  that is relatively constant and shared across
  one or more servlets.

  If you are not using cookies, or if the
  user would like to bookmark these pages
  You must use URLs.  There are two ways
  to do this, use queryParameters or to
  rewrite the URL.  Rewriting the URL can be 
  done in two ways, before or after the servlet.  
  In JavaServlets, the rewriting happens after.
  This has the problem that one must include
  the "parameters" in generated pages.  And
  thus, having parameters after the servlet
  does little to facilitate inter-servlet
  communication.
  
  For this solution, the rewriting happens
  before.  This allows the HTML generated
  by each servlet to be oblivious of the
  contextual information found higher-up
  in the servlet path.

Details:

  This patch includes (a) a parsing mechanism
  that rewrites the incoming URL before the
  appropriate servlet is found, and (b) 
  makes available parameters on the path above
  the servlet name to the servlet through
  the "pathVariable" accessor methods 
  found on the request object.  

  The parameters are identified by path segments
  following the adapter and before the servlet
  context having an equal sign.  

Examples:

  http://myserver/cgi-bin/wk/path=variable/servlet
  In this example, the servlet "servlet" is called
  in the default context.  The request has a 
  pathContext { 'path':'variable' }

  http://myserver/cgi-bin/wk/one=1/two=2/cntx/servlet?query=param
  In this example, the "servlet" is called in the context
  "cntx".  It is passed a pathContext having two entries:
  { 'one':'1', 'two':'2' } and GET params { 'query':'param' }


Attached are the two diff files required to patch
the existing CVS source tree.

Thank you for a *wonderful* Webware!

Clark
*** HTTPRequest.py.bc   Mon Oct 22 13:30:16 2001
--- HTTPRequest.py      Mon Oct 22 13:49:40 2001
***************
*** 121,140 ****
                self._serverRootPath = None
                self._extraURLPath  = None
  
!               # try to get automatic path session
!               # if UseAutomaticPathSessions is enabled in Application.config
!               # Application.py redirects the browser to a url with SID in path 
                # http://gandalf/a/_SID_=2001080221301877755/Examples/
!               # _SID_ is extracted and removed from path 
                self._pathSession = None
!               if self._environ['PATH_INFO'][1:6] == '_SID_':
!                       self._pathSession = 
self._environ['PATH_INFO'][7:].split('/',1)[0]
                        self._cookies['_SID_'] = self._pathSession
-                       sidstring = '_SID_=' +  self._pathSession +'/'
-                       self._environ['REQUEST_URI'] = 
self._environ['REQUEST_URI'].replace(sidstring,'')
-                       self._environ['PATH_INFO'] = 
self._environ['PATH_INFO'].replace(sidstring,'')
-                       if self._environ.has_key('PATH_TRANSLATED'):
-                               self._environ['PATH_TRANSLATED'] = 
self._environ['PATH_TRANSLATED'].replace(sidstring,'')
                        assert(not self._environ.has_key('WK_URI')) # obsolete?
  
                self._sessionExpired = 0
--- 121,163 ----
                self._serverRootPath = None
                self._extraURLPath  = None
  
!               #
!               # Extract path variables, which is a collection of
!               # KEY=VALUE pairs that occur right after the WK, but
!               # before the context.  This includes the _SID_ automatic
!               # path sessions component, such as:
!               # http://localhost/wk/_SID_=2001080221301877755/Examples/
!               #
!               self._pathVariables = {}
!               path = self._environ['PATH_INFO']
!               repl = ''
!               try:
!                       while 1:
!                               (s,r) = path[1:].split('/',1)
!                               (k,v) = s.split('=',1)
!                               self._pathVariables[k] = v
!                               path = '/' + r
!                               repl += ('/'+k+'='+v)
!               except ValueError: pass
!               if repl:
!                       self._environ['PATH_INFO']   = path
!                       self._environ['REQUEST_URI'] = \
!                       self._environ['REQUEST_URI'].replace(repl,'')
!                       if self._environ.has_key('PATH_TRANSLATED'):
!                               self._environ['PATH_TRANSLATED'] = \
!                               self._environ['PATH_TRANSLATED'].replace(repl,'')
!               #
!               # Check to see if the _SID_ key is in the _pathVariables,
!               # if so, then simulate the existance of the SID cookie.
!               # Note: if UseAutomaticPathSessions is enabled in
!               # Application.config, then Application.py redirects the
!               # browser to a url with SID in path, such as:
                # http://gandalf/a/_SID_=2001080221301877755/Examples/
!               #
                self._pathSession = None
!               if self._pathVariables.has_key('_SID_'):
!                       self._pathSession = self._pathVariables['_SID_']
                        self._cookies['_SID_'] = self._pathSession
                        assert(not self._environ.has_key('WK_URI')) # obsolete?
  
                self._sessionExpired = 0
***************
*** 188,193 ****
--- 211,235 ----
        def delField(self, name):
                del self._fields[name]
  
+       ## Path Variables ##
+ 
+       def pathVariable(self, name, default=Tombstone):
+               if default is Tombstone:
+                       return self._pathVariables[name]
+               else:
+                       return self._pathVariables.get(name, default)
+ 
+       def hasPathVariable(self, name):
+               return self._pathVariables.has_key(name)
+ 
+       def pathVariables(self):
+               return self._pathVariables
+ 
+       def setPathVariable(self, name, value):
+               self._pathVariables[name] = value
+ 
+       def delPathVariable(self, name):
+               del self._pathVariables[name]
  
        ## Cookies ##
  
*** Application.py.bc   Mon Oct 22 13:30:02 2001
--- Application.py      Mon Oct 22 13:53:56 2001
***************
*** 470,482 ****
                we redirect the browser to a url with SID in path
                http://gandalf/a/_SID_=2001080221301877755/Examples/
                _SID_ is extracted and removed from path in HTTPRequest.py
- 
                this is for convinient building of webapps that must not
                depend on cookie support
                '''
                newSid = transaction.session().identifier()
                request = transaction.request()
!               url = request.adapterName() + '/_SID_='+ newSid + '/' + 
request.pathInfo()
                if request.queryString():
                        url = url + '?' + request.queryString()
                if self.setting('Debug')['Sessions']:
--- 470,484 ----
                we redirect the browser to a url with SID in path
                http://gandalf/a/_SID_=2001080221301877755/Examples/
                _SID_ is extracted and removed from path in HTTPRequest.py
                this is for convinient building of webapps that must not
                depend on cookie support
                '''
                newSid = transaction.session().identifier()
                request = transaction.request()
!               request.setPathVariables('_SID_',newSid)
!               url = request.adapterName()
!               for item in request.pathVariables(): url += "/%s=%s" % item
!               url += ('/' + request.pathInfo())
                if request.queryString():
                        url = url + '?' + request.queryString()
                if self.setting('Debug')['Sessions']:

Reply via email to