This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 6cb706a5933b7b3cb36ad9d488c61b051d11cd63
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Mon Feb 19 09:48:37 2018 +0100

    ISIS-1865 provide default fallback for SessionLoggingService + minor
    test fixes
---
 .../wicket/AuthenticatedWebSessionForIsis.java     | 54 ++++++++++++++++------
 ...thenticatedWebSessionForIsis_Instantiation.java |  2 +-
 ...ageClassListDefault_RegistrationAndCaching.java |  2 +-
 3 files changed, 42 insertions(+), 16 deletions(-)

diff --git 
a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/AuthenticatedWebSessionForIsis.java
 
b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/AuthenticatedWebSessionForIsis.java
index d3470db..607f8c1 100644
--- 
a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/AuthenticatedWebSessionForIsis.java
+++ 
b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/AuthenticatedWebSessionForIsis.java
@@ -22,6 +22,8 @@ package 
org.apache.isis.viewer.wicket.viewer.integration.wicket;
 import java.util.Arrays;
 import java.util.List;
 
+import javax.validation.constraints.NotNull;
+
 import org.apache.wicket.Session;
 import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
 import org.apache.wicket.authroles.authorization.strategies.role.Roles;
@@ -29,6 +31,7 @@ import org.apache.wicket.request.Request;
 import org.apache.wicket.request.cycle.RequestCycle;
 
 import org.apache.isis.applib.clock.Clock;
+import org.apache.isis.applib.internal.context._Context;
 import org.apache.isis.applib.services.session.SessionLoggingService;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.runtime.authentication.AuthenticationManager;
@@ -169,21 +172,35 @@ public class AuthenticatedWebSessionForIsis extends 
AuthenticatedWebSession impl
             final SessionLoggingService.Type type,
             final String username,
             final SessionLoggingService.CausedBy causedBy) {
+       
+       
+       final IsisSessionFactory isisSessionFactory = 
getIsisSessionFactoryIfAny();
         final SessionLoggingService sessionLoggingService = 
getSessionLoggingService();
-        if (sessionLoggingService != null) {
-            getIsisSessionFactory().doInSession(new Runnable() {
-                    @Override
-                    public void run() {
-                        // use hashcode as session identifier, to avoid 
re-binding http sessions if using Session#getId()
-                        int sessionHashCode = 
System.identityHashCode(AuthenticatedWebSessionForIsis.this);
-                        sessionLoggingService.log(type, username, 
Clock.getTimeAsDateTime().toDate(), causedBy, 
Integer.toString(sessionHashCode));
-                    }
-                });
-        }
+               
+       final Runnable loggingTask = ()->{
+            // use hashcode as session identifier, to avoid re-binding http 
sessions if using Session#getId()
+            int sessionHashCode = 
System.identityHashCode(AuthenticatedWebSessionForIsis.this);
+            sessionLoggingService.log(type, username, 
Clock.getTimeAsDateTime().toDate(), causedBy, 
Integer.toString(sessionHashCode));                        
+       };
+       
+       if(isisSessionFactory!=null) {
+               isisSessionFactory.doInSession(loggingTask);
+       } else {
+               loggingTask.run();
+       }
+        
     }
 
-    protected SessionLoggingService getSessionLoggingService() {
-        return 
getIsisSessionFactory().getServicesInjector().lookupService(SessionLoggingService.class);
+    protected @NotNull SessionLoggingService getSessionLoggingService() {
+       try {
+               final SessionLoggingService service = 
getIsisSessionFactory().getServicesInjector()
+                               .lookupService(SessionLoggingService.class);
+               return (service!=null) ? service : new 
SessionLoggingService.Stderr();
+       } catch (Exception e) {
+               // fallback to System.err
+               return new SessionLoggingService.Stderr(); 
+               }
+       
     }
 
     @Override
@@ -191,11 +208,20 @@ public class AuthenticatedWebSessionForIsis extends 
AuthenticatedWebSession impl
         // do nothing here because this will lead to problems with Shiro
         // see https://issues.apache.org/jira/browse/ISIS-1018
     }
+    
+    // -- HELPER
 
-
-    IsisSessionFactory getIsisSessionFactory() {
+    private IsisSessionFactory getIsisSessionFactory() {
         return IsisContext.getSessionFactory();
     }
+    
+    private IsisSessionFactory getIsisSessionFactoryIfAny() {
+       try { 
+               return getIsisSessionFactory();
+       } catch (Exception e) {
+               return null;
+               }
+    }
 
 
 }
diff --git 
a/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/app/wicket/AuthenticatedWebSessionForIsis_Instantiation.java
 
b/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/app/wicket/AuthenticatedWebSessionForIsis_Instantiation.java
index 4f5c860..0c5efde 100644
--- 
a/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/app/wicket/AuthenticatedWebSessionForIsis_Instantiation.java
+++ 
b/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/app/wicket/AuthenticatedWebSessionForIsis_Instantiation.java
@@ -55,7 +55,7 @@ public class AuthenticatedWebSessionForIsis_Instantiation {
         new AuthenticatedWebSessionForIsis(stubRequest);
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test(expected = Exception.class)
     public void requestMustBeProvided() {
         new AuthenticatedWebSessionForIsis(null);
     }
diff --git 
a/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/pages/PageClassListDefault_RegistrationAndCaching.java
 
b/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/pages/PageClassListDefault_RegistrationAndCaching.java
index b482435..1898edd 100644
--- 
a/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/pages/PageClassListDefault_RegistrationAndCaching.java
+++ 
b/core/viewer-wicket-impl/src/test/java/org/apache/isis/viewer/wicket/viewer/pages/PageClassListDefault_RegistrationAndCaching.java
@@ -62,7 +62,7 @@ public class PageClassListDefault_RegistrationAndCaching {
         registryImpl.registerPage(PageType.ACTION_PROMPT, 
TestingActionPage.class);
 
         final Class<? extends Page> pageClass = 
registryImpl.getPageClass(PageType.ACTION_PROMPT);
-        assertThat(pageClass, is(instanceOf(TestingActionPage.class)));
+        assertThat(pageClass, 
is(org.hamcrest.Matchers.equalTo(TestingActionPage.class)));
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
ahu...@apache.org.

Reply via email to