torquebox-web 1.0.0-java → 1.0.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,99 +15,12 @@
15
15
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
16
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
17
 
18
+ require 'torquebox/session/servlet_store'
19
+
18
20
  module ActionController
19
21
  module Session
20
- class TorqueBoxStore
21
-
22
- RAILS_SESSION_KEY = '__current_rails_session'
23
-
24
- def initialize(app, options={})
25
- @app = app
26
- end
27
-
28
- def call(env)
29
- load_session(env)
30
- status, headers, body = @app.call(env)
31
- commit_session(env, status, headers, body)
32
- return [ status, headers, body ]
33
- end
34
-
35
- def load_session(env)
36
- env['rack.session'] = load_session_data( env['java.servlet_request'].getSession(true) )
37
- env['rack.session.options' ] = {}
38
- end
39
-
40
- def commit_session(env, status, headers, body)
41
- session_data = env['rack.session' ]
42
- store_session_data( env['java.servlet_request'].getSession(true), session_data )
43
- end
44
-
45
- def load_session_data(session)
46
- session_data = SessionData.new
47
- session_data.java_session = session
48
- session.getAttributeNames.each do |key|
49
- if ( key == RAILS_SESSION_KEY )
50
- marshalled_bytes = session.getAttribute(RAILS_SESSION_KEY)
51
- if ( marshalled_bytes )
52
- data = Marshal.load( String.from_java_bytes( marshalled_bytes ) )
53
- session_data.update( data ) if Hash === data
54
- end
55
- else
56
- session_data[key.to_sym] = session.getAttribute(key)
57
- end
58
- end
59
- initial_keys = session_data.keys
60
- session_data[:session_id] = session.getId()
61
- session_data[:TORQUEBOX_INITIAL_KEYS] = initial_keys
62
- session_data
63
- end
64
-
65
- def store_session_data(session, session_data)
66
- hash = session_data.dup
67
- # java session shouldn't be marshalled
68
- hash.java_session = nil if hash.respond_to?(:java_session=)
69
- initial_keys = hash[:TORQUEBOX_INITIAL_KEYS] || []
70
- removed_keys = initial_keys - hash.keys
71
- hash.delete(:TORQUEBOX_INITIAL_KEYS)
72
- hash.delete_if do |key,value|
73
- if ( String === key || Symbol === key )
74
- case value
75
- when String, Numeric, true, false, nil
76
- session.setAttribute( key.to_s, value )
77
- true
78
- else
79
- if value.respond_to?(:java_object)
80
- session.setAttribute( key.to_s, value )
81
- true
82
- else
83
- false
84
- end
85
- end
86
- end
87
- end
88
- unless hash.empty?
89
- marshalled_string = Marshal.dump(hash)
90
- marshalled_bytes = marshalled_string.to_java_bytes
91
- session.setAttribute(RAILS_SESSION_KEY, marshalled_bytes)
92
- end
93
- removed_keys.each do |k|
94
- session.removeAttribute( k.to_s )
95
- end
96
- end
97
- end
98
-
99
- class SessionData < Hash
100
- attr_accessor :java_session
101
-
102
- def url_suffix
103
- ";jsessionid=#{self[:session_id]}"
104
- end
105
-
106
- def destroy
107
- @java_session.invalidate if @java_session
108
- end
22
+ class TorqueBoxStore < TorqueBox::Session::ServletStore
109
23
  end
110
-
111
24
  end
112
25
  end
113
26
 
@@ -15,99 +15,12 @@
15
15
  # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
16
  # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
17
 
18
+ require 'torquebox/session/servlet_store'
19
+
18
20
  module ActionDispatch
19
21
  module Session
20
- class TorqueBoxStore
21
-
22
- RAILS_SESSION_KEY = '__current_rails_session'
23
-
24
- def initialize(app, options={})
25
- @app = app
26
- end
27
-
28
- def call(env)
29
- load_session(env)
30
- status, headers, body = @app.call(env)
31
- commit_session(env, status, headers, body)
32
- return [ status, headers, body ]
33
- end
34
-
35
- def load_session(env)
36
- env['rack.session'] = load_session_data( env['java.servlet_request'].getSession(true) )
37
- env['rack.session.options' ] = {}
38
- end
39
-
40
- def commit_session(env, status, headers, body)
41
- session_data = env['rack.session' ]
42
- store_session_data( env['java.servlet_request'].getSession(true), session_data )
43
- end
44
-
45
- def load_session_data(session)
46
- session_data = SessionData.new
47
- session_data.java_session = session
48
- session.getAttributeNames.each do |key|
49
- if ( key == RAILS_SESSION_KEY )
50
- marshalled_bytes = session.getAttribute(RAILS_SESSION_KEY)
51
- if ( marshalled_bytes )
52
- data = Marshal.load( String.from_java_bytes( marshalled_bytes ) )
53
- session_data.update( data ) if Hash === data
54
- end
55
- else
56
- session_data[key.to_sym] = session.getAttribute(key)
57
- end
58
- end
59
- initial_keys = session_data.keys
60
- session_data[:session_id] = session.getId()
61
- session_data[:TORQUEBOX_INITIAL_KEYS] = initial_keys
62
- session_data
63
- end
64
-
65
- def store_session_data(session, session_data)
66
- hash = session_data.dup
67
- # java session shouldn't be marshalled
68
- hash.java_session = nil if hash.respond_to?(:java_session=)
69
- initial_keys = hash[:TORQUEBOX_INITIAL_KEYS] || []
70
- removed_keys = initial_keys - hash.keys
71
- hash.delete(:TORQUEBOX_INITIAL_KEYS)
72
- hash.delete_if do |key,value|
73
- if ( String === key || Symbol === key )
74
- case value
75
- when String, Numeric, true, false, nil
76
- session.setAttribute( key.to_s, value )
77
- true
78
- else
79
- if value.respond_to?(:java_object)
80
- session.setAttribute( key.to_s, value )
81
- true
82
- else
83
- false
84
- end
85
- end
86
- end
87
- end
88
- unless hash.empty?
89
- marshalled_string = Marshal.dump(hash)
90
- marshalled_bytes = marshalled_string.to_java_bytes
91
- session.setAttribute(RAILS_SESSION_KEY, marshalled_bytes)
92
- end
93
- removed_keys.each do |k|
94
- session.removeAttribute( k.to_s )
95
- end
96
- end
97
- end
98
-
99
- class SessionData < Hash
100
- attr_accessor :java_session
101
-
102
- def url_suffix
103
- ";jsessionid=#{self[:session_id]}"
104
- end
105
-
106
- def destroy
107
- @java_session.invalidate if @java_session
108
- end
22
+ class TorqueBoxStore < TorqueBox::Session::ServletStore
109
23
  end
110
-
111
24
  end
112
25
  end
113
26
 
data/lib/gem_hook.rb CHANGED
@@ -1,2 +1,3 @@
1
1
 
2
2
  require 'action_dispatch/session/torque_box_store'
3
+ require 'action_controller/session/torque_box_store'
@@ -0,0 +1,133 @@
1
+ # Copyright 2008-2011 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # This is free software; you can redistribute it and/or modify it
4
+ # under the terms of the GNU Lesser General Public License as
5
+ # published by the Free Software Foundation; either version 2.1 of
6
+ # the License, or (at your option) any later version.
7
+ #
8
+ # This software is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this software; if not, write to the Free
15
+ # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
+ # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
+
18
+ module TorqueBox
19
+ module Session
20
+ class ServletStore
21
+
22
+ RAILS_SESSION_KEY = '__current_rails_session'
23
+ SYMBOL_KEYS = '__torquebox_symbol_keys'
24
+
25
+ def initialize(app, options={})
26
+ @app = app
27
+ end
28
+
29
+ def call(env)
30
+ load_session(env)
31
+ status, headers, body = @app.call(env)
32
+ commit_session(env, status, headers, body)
33
+ return [ status, headers, body ]
34
+ end
35
+
36
+ def load_session(env)
37
+ env['rack.session'] = load_session_data( env['java.servlet_request'].getSession(true) )
38
+ env['rack.session.options' ] = {}
39
+ end
40
+
41
+ def commit_session(env, status, headers, body)
42
+ session_data = env['rack.session' ]
43
+ store_session_data( env['java.servlet_request'].getSession(true), session_data )
44
+ end
45
+
46
+ def load_session_data(session)
47
+ session_data = SessionData.new
48
+ session_data.java_session = session
49
+ session.getAttributeNames.each do |key|
50
+ if ( key == RAILS_SESSION_KEY )
51
+ marshalled_bytes = session.getAttribute(RAILS_SESSION_KEY)
52
+ if ( marshalled_bytes )
53
+ data = Marshal.load( String.from_java_bytes( marshalled_bytes ) )
54
+ session_data.update( data ) if Hash === data
55
+ end
56
+ else
57
+ session_data[key] = session.getAttribute(key)
58
+ end
59
+ end
60
+ symbolize_keys!(session_data)
61
+ initial_keys = session_data.keys
62
+ session_data[:session_id] = session.getId()
63
+ session_data[:TORQUEBOX_INITIAL_KEYS] = initial_keys
64
+ session_data
65
+ end
66
+
67
+ def symbolize_keys!(session_data)
68
+ symbol_keys = session_data[ SYMBOL_KEYS ] || []
69
+ keys = session_data.keys
70
+ keys.each do |key|
71
+ if ( symbol_keys.include?( key ) )
72
+ session_data[ key.to_sym ] = session_data.delete( key )
73
+ end
74
+ end
75
+ end
76
+
77
+ def store_session_data(session, session_data)
78
+ hash = session_data.dup
79
+ # java session shouldn't be marshalled
80
+ hash.java_session = nil if hash.respond_to?(:java_session=)
81
+ initial_keys = hash[:TORQUEBOX_INITIAL_KEYS] || []
82
+ removed_keys = initial_keys - hash.keys
83
+ symbol_keys = []
84
+ hash.delete(:TORQUEBOX_INITIAL_KEYS)
85
+ hash.delete(:TORQUEBOX_SYMBOL_KEYS)
86
+ hash.delete_if do |key,value|
87
+ if ( Symbol === key )
88
+ key = key.to_s
89
+ symbol_keys << key.to_s
90
+ end
91
+ if ( String === key )
92
+ case value
93
+ when String, Numeric, true, false, nil
94
+ session.setAttribute( key, value )
95
+ true
96
+ else
97
+ if value.respond_to?(:java_object)
98
+ session.setAttribute( key, value )
99
+ true
100
+ else
101
+ false
102
+ end
103
+ end
104
+ end
105
+ end
106
+ session.setAttribute( SYMBOL_KEYS, symbol_keys.to_java )
107
+ unless hash.empty?
108
+ marshalled_string = Marshal.dump(hash)
109
+ marshalled_bytes = marshalled_string.to_java_bytes
110
+ session.setAttribute(RAILS_SESSION_KEY, marshalled_bytes)
111
+ end
112
+ removed_keys.each do |k|
113
+ session.removeAttribute( k.to_s )
114
+ end
115
+ end
116
+ end
117
+
118
+ class SessionData < Hash
119
+ attr_accessor :java_session
120
+
121
+ def url_suffix
122
+ ";jsessionid=#{self[:session_id]}"
123
+ end
124
+
125
+ def destroy
126
+ @java_session.invalidate if @java_session
127
+ end
128
+ end
129
+
130
+ end
131
+ end
132
+
133
+
Binary file
data/lib/torquebox-web.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module TorqueboxWeb
2
- VERSION = '1.0.0'
3
- MAVEN_VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
+ MAVEN_VERSION = '1.0.1'
4
4
  end
5
5
  begin
6
6
  require 'java'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torquebox-web
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.1
6
6
  platform: java
7
7
  authors: []
8
8
 
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-29 00:00:00 -04:00
13
+ date: 2011-05-25 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,7 @@ files:
50
50
  - lib/gem_hook.rb
51
51
  - lib/action_controller/session/torque_box_store.rb
52
52
  - lib/action_dispatch/session/torque_box_store.rb
53
+ - lib/torquebox/session/servlet_store.rb
53
54
  has_rdoc: true
54
55
  homepage: http://www.torquebox.org/gem-parent/torquebox-web/
55
56
  licenses: