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:28 UTC

[isis] branch master updated (fa02b2c -> c7c25f6)

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

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


    from fa02b2c  ISIS-2158: fixes broken SSE demo
     new abc0f11  ISIS-2262: adds missing java doc to the new service
     new c7c25f6  ISIS-2262: further improve API and remove experimental code

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../exceprecog/ExceptionRecognizerAbstract.java    | 11 ++---
 .../exceprecog/ExceptionRecognizerForType.java     |  9 ++--
 .../exceprecog/ExceptionRecognizerService.java     | 14 +++++-
 .../exceprecog/ExceptionRecognizerForTypeTest.java |  9 +---
 .../diagnostics/IsisLogOnExceptionFilter.java      | 50 ++++++++++++++++------
 ...RecognizerForJDODataStoreExceptionAbstract.java |  6 +--
 .../viewer/integration/WebRequestCycleForIsis.java |  8 +---
 7 files changed, 63 insertions(+), 44 deletions(-)


[isis] 01/02: ISIS-2262: adds missing java doc to the new service

Posted by ah...@apache.org.
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 abc0f118d8c599ee9b2bdc6b78c2e06e42f9fd3c
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 13 13:38:04 2020 +0100

    ISIS-2262: adds missing java doc to the new service
---
 .../services/exceprecog/ExceptionRecognizerService.java    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java
index 8c6cf6f..a25350d 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/exceprecog/ExceptionRecognizerService.java
@@ -32,12 +32,24 @@ public interface ExceptionRecognizerService {
 
     /**
      * 
-     * @return all ExceptionRecognizer implementations as discovered by the IoC container. 
+     * @return all ExceptionRecognizer implementations as discovered by the IoC container, 
+     * honoring order of precedence. 
      */
     Can<ExceptionRecognizer> getExceptionRecognizers();
 
+    /**
+     * @param ex
+     * @return optionally a recognition object, that describes both the category and reason, 
+     * that will be included with the user-friendly message. 
+     */
     Optional<Recognition> recognize(Exception ex);
 
+    /**
+     * Extends {@link #recognize(Exception)} with additional recognizers to be taken into consideration,
+     * with least precedence order.  
+     * @param ex
+     * @param additionalRecognizers
+     */
     Optional<Recognition> recognize(Exception ex, Can<ExceptionRecognizer> additionalRecognizers);
 
 }


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

Posted by ah...@apache.org.
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) {