@@ -61,11 +61,10 @@ public CBSessionManager(CBApplication application) {
6161 @ Override
6262 public BaseWebSession closeSession (@ NotNull HttpServletRequest request ) {
6363 HttpSession session = request .getSession ();
64- if (session = = null ) {
65- return null ;
64+ if (session ! = null ) {
65+ return closeSession ( session . getId ()) ;
6666 }
67-
68- return closeSession (session .getId ());
67+ return null ;
6968 }
7069
7170 @ Override
@@ -74,13 +73,12 @@ public BaseWebSession closeSession(@NotNull String sessionId) {
7473 synchronized (sessionMap ) {
7574 webSession = sessionMap .remove (sessionId );
7675 }
77- if (webSession == null ) {
78- return null ;
76+ if (webSession != null ) {
77+ log .debug ("> Close session '" + sessionId + "'" );
78+ webSession .close ();
79+ return webSession ;
7980 }
80-
81- log .debug ("> Close session '" + sessionId + "'" );
82- webSession .close ();
83- return webSession ;
81+ return null ;
8482 }
8583
8684 protected CBApplication getApplication () {
@@ -122,14 +120,14 @@ public WebSession getWebSession(
122120 var baseWebSession = sessionMap .get (sessionId );
123121 if (baseWebSession == null && CBApplication .getInstance ().isConfigurationMode ()) {
124122 try {
125- webSession = createWebSession (new WebHttpRequestInfo (request ));
123+ webSession = createWebSessionImpl (new WebHttpRequestInfo (request ));
126124 } catch (DBException e ) {
127125 throw new DBWebException ("Failed to create web session" , e );
128126 }
129127 sessionMap .put (sessionId , webSession );
130128 } else if (baseWebSession == null ) {
131129 try {
132- webSession = createWebSession (new WebHttpRequestInfo (request ));
130+ webSession = createWebSessionImpl (new WebHttpRequestInfo (request ));
133131 } catch (DBException e ) {
134132 throw new DBWebException ("Failed to create web session" , e );
135133 }
@@ -190,7 +188,7 @@ public WebSession getOrRestoreWebSession(@NotNull WebHttpRequestInfo requestInfo
190188 return null ;
191189 }
192190
193- webSession = createWebSession (requestInfo );
191+ webSession = createWebSessionImpl (requestInfo );
194192 restorePreviousUserSession (webSession , oldAuthInfo );
195193
196194 sessionMap .put (sessionId , webSession );
@@ -224,7 +222,7 @@ private void restorePreviousUserSession(
224222 }
225223
226224 @ NotNull
227- public WebSession createWebSession (@ NotNull WebHttpRequestInfo request ) throws DBException {
225+ protected WebSession createWebSessionImpl (@ NotNull WebHttpRequestInfo request ) throws DBException {
228226 return new WebSession (request , application , getSessionHandlers ());
229227 }
230228
@@ -414,4 +412,21 @@ public void closeAllSessions(@Nullable String initiatorSessionId) {
414412 }
415413 }
416414 }
415+
416+ /**
417+ * Creates new web session or returns existing one.
418+ */
419+ public WebSession createWebSession (WebHttpRequestInfo requestInfo ) throws DBException {
420+ String id = requestInfo .getId ();
421+ synchronized (sessionMap ) {
422+ BaseWebSession baseWebSession = sessionMap .get (id );
423+ if (baseWebSession instanceof WebSession ) {
424+ return (WebSession ) baseWebSession ;
425+ } else {
426+ WebSession webSessionImpl = createWebSessionImpl (requestInfo );
427+ sessionMap .put (id , webSessionImpl );
428+ return webSessionImpl ;
429+ }
430+ }
431+ }
417432}
0 commit comments