You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/01/13 13:20:30 UTC

[isis] 02/02: ISIS-2262: further improve API and remove experimental code

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 c7c25f6ac968077c3ab4fc681f3408fb183d1ddf
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 13 14:20:16 2020 +0100

    ISIS-2262: further improve API and remove experimental code
---
 .../exceprecog/ExceptionRecognizerAbstract.java    | 11 ++---
 .../exceprecog/ExceptionRecognizerForType.java     |  9 ++--
 .../exceprecog/ExceptionRecognizerForTypeTest.java |  9 +---
 .../diagnostics/IsisLogOnExceptionFilter.java      | 50 ++++++++++++++++------
 ...RecognizerForJDODataStoreExceptionAbstract.java |  6 +--
 .../viewer/integration/WebRequestCycleForIsis.java |  8 +---
 6 files changed, 50 insertions(+), 43 deletions(-)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java
index 77433b4..dd849bb 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerAbstract.java
@@ -22,6 +22,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
 
 import javax.inject.Inject;
 
@@ -79,14 +80,8 @@ public abstract class ExceptionRecognizerAbstract implements ExceptionRecognizer
      * Convenience for subclass implementations that always prefixes the exception message
      * with the supplied text
      */
-    protected static Function<String, String> prefix(final String prefix) {
-        return new Function<String, String>() {
-
-            @Override
-            public String apply(String input) {
-                return prefix + ": " + input;
-            }
-        };
+    protected static UnaryOperator<String> prefix(final String prefix) {
+        return $->prefix + ": " + $;
     }
 
     // //////////////////////////////////////
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
index 0cb2674..ee4feeb 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForType.java
@@ -21,6 +21,7 @@ package org.apache.isis.applib.services.exceprecog;
 import java.util.List;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
 import java.util.stream.Stream;
 
 import org.apache.isis.core.commons.internal.exceptions._Exceptions;
@@ -147,14 +148,14 @@ public class ExceptionRecognizerForType extends ExceptionRecognizerAbstract {
     public ExceptionRecognizerForType(
             Category category,
             final Class<? extends Exception> exceptionType,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         this(category, ofType(exceptionType), messageParser);
     }
 
     public ExceptionRecognizerForType(
             Category category,
             final Predicate<Throwable> predicate,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         super(category, predicate, messageParser);
     }
 
@@ -164,13 +165,13 @@ public class ExceptionRecognizerForType extends ExceptionRecognizerAbstract {
 
     public ExceptionRecognizerForType(
             final Class<? extends Exception> exceptionType,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         this(Category.OTHER, exceptionType, messageParser);
     }
 
     public ExceptionRecognizerForType(
             final Predicate<Throwable> predicate,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         this(Category.OTHER, predicate, messageParser);
     }
 
diff --git a/api/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java b/api/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java
index e67fcf2..c8bb55a 100644
--- a/api/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java
+++ b/api/applib/src/test/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerForTypeTest.java
@@ -20,7 +20,7 @@
 package org.apache.isis.applib.services.exceprecog;
 
 import java.util.Optional;
-import java.util.function.Function;
+import java.util.function.UnaryOperator;
 
 import org.junit.Test;
 
@@ -45,12 +45,7 @@ public class ExceptionRecognizerForTypeTest {
         }
     }
 
-    private Function<String,String> prepend = new Function<String, String>() {
-        @Override
-        public String apply(String input) {
-            return "pre: " + input;
-        }
-    };
+    private UnaryOperator<String> prepend = $ -> "pre: " + $;
 
     @Test
     public void whenRecognized() {
diff --git a/core/webapp/src/main/java/org/apache/isis/core/webapp/diagnostics/IsisLogOnExceptionFilter.java b/core/webapp/src/main/java/org/apache/isis/core/webapp/diagnostics/IsisLogOnExceptionFilter.java
index f78d81f..35e4269 100644
--- a/core/webapp/src/main/java/org/apache/isis/core/webapp/diagnostics/IsisLogOnExceptionFilter.java
+++ b/core/webapp/src/main/java/org/apache/isis/core/webapp/diagnostics/IsisLogOnExceptionFilter.java
@@ -28,10 +28,13 @@ import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 
-import org.springframework.beans.factory.annotation.Autowired;
-
-import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
-
+//import org.springframework.beans.factory.annotation.Autowired;
+//
+//import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerForType;
+//import org.apache.isis.applib.services.exceprecog.ExceptionRecognizerService;
+//import org.apache.isis.core.commons.collections.Can;
+//
+//import lombok.val;
 import lombok.extern.log4j.Log4j2;
 
 /**
@@ -40,7 +43,7 @@ import lombok.extern.log4j.Log4j2;
 @Log4j2
 public class IsisLogOnExceptionFilter implements Filter {
     
-    @Autowired ExceptionRecognizer r;
+    //@Autowired private ExceptionRecognizerService exceptionRecognizerService;
 
     @Override
     public void init(FilterConfig filterConfig) throws ServletException {
@@ -54,17 +57,36 @@ public class IsisLogOnExceptionFilter implements Filter {
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
         try {
             chain.doFilter(request, response);
-        } catch (IOException ex) {
-            logRequestUrl(request, ex);
-            throw ex;
-        } catch (ServletException ex) {
-            logRequestUrl(request, ex);
-            throw ex;
-        } catch (RuntimeException ex) {
-            logRequestUrl(request, ex);
+        } catch (Exception ex) {
+            if(ex instanceof IOException
+                    || ex instanceof ServletException
+                    || ex instanceof RuntimeException) {
+                logRequestUrl(request, ex);
+            }
+            
+//            val recognition = exceptionRecognizerService.recognize(ex, Can.ofSingleton(connectionAbortRecognizer));
+//            
+//            if(recognition.isPresent()) {
+//                log.error(recognition.get().toMessage(null), ex);
+//                // swallow exception
+//                return;
+//            }
+            
             throw ex;
-        }
+        } 
     }
+    
+    // -- HELPER
+    
+//    private final static ExceptionRecognizerForType connectionAbortRecognizer =
+//            new ExceptionRecognizerForType(IOException.class, originalMsg->{
+//                if(originalMsg!=null 
+//                        && originalMsg.contains("connection")
+//                        && originalMsg.contains("aborted")) {
+//                    return "client connection was aborted";
+//                }
+//                return null;
+//            });
 
     private static void logRequestUrl(ServletRequest request, Exception e) {
         if(!(request instanceof HttpServletRequest)) {
diff --git a/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/exceprecog/ExceptionRecognizerForJDODataStoreExceptionAbstract.java b/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/exceprecog/ExceptionRecognizerForJDODataStoreExceptionAbstract.java
index a0ad27f..6e1164f 100644
--- a/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/exceprecog/ExceptionRecognizerForJDODataStoreExceptionAbstract.java
+++ b/persistence/jdo/datanucleus-5/src/main/java/org/apache/isis/persistence/jdo/datanucleus5/exceprecog/ExceptionRecognizerForJDODataStoreExceptionAbstract.java
@@ -18,8 +18,8 @@
  */
 package org.apache.isis.persistence.jdo.datanucleus5.exceprecog;
 
-import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -39,14 +39,14 @@ abstract class ExceptionRecognizerForJDODataStoreExceptionAbstract extends Excep
     protected ExceptionRecognizerForJDODataStoreExceptionAbstract(
             Category category,
             final Predicate<Throwable> predicate,
-            final Function<String, String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         super(category, predicate, messageParser);
     }
     
     protected ExceptionRecognizerForJDODataStoreExceptionAbstract(
             Category category,
             final Class<? extends Exception> exceptionType,
-            final Function<String,String> messageParser) {
+            final UnaryOperator<String> messageParser) {
         this(category, ofType(exceptionType), messageParser);
     }
     
diff --git a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java
index 16391d0..0989516 100644
--- a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java
+++ b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/WebRequestCycleForIsis.java
@@ -22,7 +22,6 @@ package org.apache.isis.viewer.wicket.viewer.integration;
 import java.lang.reflect.Constructor;
 import java.util.List;
 import java.util.Optional;
-import java.util.function.Function;
 
 import org.apache.wicket.Application;
 import org.apache.wicket.IPageFactory;
@@ -293,12 +292,7 @@ public class WebRequestCycleForIsis implements IRequestCycleListener {
 
     // special case handling for PageExpiredException, otherwise infinite loop
     private final static ExceptionRecognizerForType pageExpiredExceptionRecognizer =
-            new ExceptionRecognizerForType(PageExpiredException.class, new Function<String,String>(){
-                @Override
-                public String apply(String input) {
-                    return "Requested page is no longer available.";
-                }
-            });
+            new ExceptionRecognizerForType(PageExpiredException.class, $->"Requested page is no longer available.");
 
     protected IRequestablePage errorPageFor(Exception ex) {