You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by mg...@apache.org on 2016/03/25 15:11:16 UTC
[40/50] isis git commit: ISIS-1342: IsisSystem no longer throws
MetaModelException,
instead pushes it onto the IsisContext. Its callers (IsisWicketApplication,
or IsisSessionFilter - for RO - or CukeGlueAbstract,
or IsisSystemForTest) then expose the er
ISIS-1342: IsisSystem no longer throws MetaModelException, instead pushes it onto the IsisContext. Its callers (IsisWicketApplication, or IsisSessionFilter - for RO - or CukeGlueAbstract, or IsisSystemForTest) then expose the error appropriately, accessing from IsisContext.
Additional details:
- IsisSystem no longer initializes the AuthenticationManager, AuthorizationManager or PersistenceSessionFactory if there was a metamodel validation, to minimize impact on runtime.
- IsisSystemForTest will fail with a minimal error for any subsequent tests
- IsisContext now as new metamodeInvalidException field. This is static rather than held on the IsisContext instance as a threadlocal; that's because IsisSystemForTest actually calls IsisContext.testReset() to discard the IsisContext singleton.
- IsisSessionFilter (which sits in front of RO viewer) now always checks that the metamodel is vaild. It does this simply by querying the IsisContext. (If WebAppBootstrapper was used to bootstrap, rather than wicket viewer, then IsisSystem.init() is still called so no diff in end result)
- ScenarioException simply does a fail() if no instance available on threadlocal.
- CukeGlueAbstract similarly has simple guards for if ScenarioException available, to reduce amount of noise when problem is metamodel invalid
- formatting changes only for IsisWicketApplication
- WebRequestCycleForIsis looks for validation errors first-off in its onException handler, if any are found then immediately redirects to the MmvErrorPage. This seems to work fine for always rendering MMV page.
Improvements:
- IsisMojoAbstract keeps the IsisSystem initialized while it executes.
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/8bf7fd7f
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/8bf7fd7f
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/8bf7fd7f
Branch: refs/heads/ISIS-1223-upgrade-to-wicket-7
Commit: 8bf7fd7f04049e3632454c34e1ca329df1a936f7
Parents: 7f068ef
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Mar 24 15:23:57 2016 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Mar 25 06:35:58 2016 +0000
----------------------------------------------------------------------
.../integtestsupport/IsisSystemForTest.java | 85 +++++++++++++-------
.../isis/tool/mavenplugin/IsisMojoAbstract.java | 17 ++--
.../core/runtime/runner/IsisInjectModule.java | 2 +
.../isis/core/runtime/system/IsisSystem.java | 69 +++++++++++-----
.../runtime/system/context/IsisContext.java | 15 ++++
.../isis/core/webapp/IsisSessionFilter.java | 19 ++++-
.../scenarios/ScenarioExecution.java | 3 +-
.../specsupport/specs/CukeGlueAbstract.java | 23 +++---
.../wicket/viewer/IsisWicketApplication.java | 61 +++++++-------
.../wicket/WebRequestCycleForIsis.java | 11 ++-
10 files changed, 195 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
index 2dc250c..16b4f84 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IsisSystemForTest.java
@@ -21,12 +21,12 @@ package org.apache.isis.core.integtestsupport;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@@ -46,6 +46,7 @@ import org.apache.isis.core.metamodel.adapter.oid.RootOid;
import org.apache.isis.core.metamodel.progmodel.ProgrammingModel;
import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException;
import org.apache.isis.core.metamodel.specloader.validator.MetaModelValidator;
import org.apache.isis.core.runtime.authentication.AuthenticationManager;
import org.apache.isis.core.runtime.authentication.AuthenticationRequest;
@@ -67,6 +68,8 @@ import org.apache.isis.core.runtime.systemusinginstallers.IsisComponentProvider;
import org.apache.isis.core.security.authentication.AuthenticationRequestNameOnly;
import org.apache.isis.core.specsupport.scenarios.DomainServiceProvider;
+import static org.junit.Assert.fail;
+
/**
* Wraps a plain {@link IsisSystem}, and provides a number of features to assist with testing.
*/
@@ -272,7 +275,7 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
}
public IsisSystemForTest build() {
- final IsisSystemForTest isisSystem =
+ final IsisSystemForTest isisSystemForTest =
new IsisSystemForTest(
appManifestIfAny,
configuration,
@@ -281,24 +284,20 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
authenticationRequest,
listeners);
if(level != null) {
- isisSystem.setLevel(level);
+ isisSystemForTest.setLevel(level);
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public synchronized void run() {
try {
- if (isisSystem != null) {
- isisSystem.tearDownSystem();
- }
+ isisSystemForTest.tearDownSystem();
} catch (Exception e) {
e.printStackTrace();
}
try {
- if (isisSystem != null) {
- isisSystem.shutdown();
- }
+ isisSystemForTest.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
@@ -310,7 +309,7 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
}
});
- return isisSystem;
+ return isisSystemForTest;
}
@@ -380,11 +379,17 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
private void setUpSystem(FireListeners fireListeners) throws Exception {
+ // exit as quickly as possible for this case... (will already have been logged)
+ if(IsisContext.getMetaModelInvalidExceptionIfAny() != null) {
+ fail("Metamodel invalid");
+ return;
+ }
+
boolean firstTime = isisSystem == null;
if(fireListeners.shouldFire()) {
fireInitAndPreSetupSystem(firstTime);
}
-
+
if(firstTime) {
IsisLoggingConfigurer isisLoggingConfigurer = new IsisLoggingConfigurer(getLevel());
isisLoggingConfigurer.configureLogging(".", new String[] {});
@@ -401,18 +406,33 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
isisSystem = new IsisSystem(componentProvider);
-
// ensures that a FixtureClock is installed as the singleton underpinning the ClockService
FixtureClock.initialize();
isisSystem.init();
IsisContext.closeSession();
+
+ // if the IsisSystem does not initialize properly, then - as a side effect - the resulting
+ // MetaModelInvalidException will be pushed onto the IsisContext (as a static field).
+ final MetaModelInvalidException ex = IsisContext.getMetaModelInvalidExceptionIfAny();
+ if (ex != null) {
+
+ // for subsequent tests; the attempt to bootstrap the framework will leave
+ // the IsisContext singleton as set.
+ IsisContext.testReset();
+
+ final Set<String> validationErrors = ex.getValidationErrors();
+ final StringBuilder buf = new StringBuilder();
+ for (String validationError : validationErrors) {
+ buf.append(validationError).append("\n");
+ }
+ fail("Metamodel is invalid: \n" + buf.toString());
+ }
}
- final AuthenticationManager authenticationManager = isisSystem.getSessionFactory().getAuthenticationManager();
- authenticationSession = authenticationManager.authenticate(authenticationRequestIfAny);
- setContainer(getContainer());
+ final AuthenticationManager authenticationManager = IsisContext.getAuthenticationManager();
+ authenticationSession = authenticationManager.authenticate(authenticationRequestIfAny);
openSession();
@@ -422,7 +442,6 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
}
}
-
private void wireAndInstallFixtures() {
FixturesInstaller fixturesInstaller = componentProvider.provideFixturesInstaller();
fixturesInstaller.installFixtures();
@@ -437,7 +456,7 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
}
public DomainObjectContainer getContainer() {
- for (Object service : isisSystem.getSessionFactory().getServices()) {
+ for (Object service : IsisContext.getSessionFactory().getServices()) {
if(service instanceof DomainObjectContainer) {
return (DomainObjectContainer) service;
}
@@ -456,14 +475,18 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
if(fireListeners.shouldFire()) {
firePreTeardownSystem();
}
- IsisContext.closeSession();
+ if(IsisContext.exists() && IsisContext.inSession()) {
+ IsisContext.closeSession();
+ }
if(fireListeners.shouldFire()) {
firePostTeardownSystem();
}
}
private void shutdown() {
- isisSystem.shutdown();
+ if(IsisContext.exists() && isisSystem != null) {
+ isisSystem.shutdown();
+ }
}
public void bounceSystem() throws Exception {
@@ -662,10 +685,10 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
// nothing to do
break;
case MUST_ABORT:
- Assert.fail("Transaction is in state of '" + state + "'");
+ fail("Transaction is in state of '" + state + "'");
break;
default:
- Assert.fail("Unknown transaction state '" + state + "'");
+ fail("Unknown transaction state '" + state + "'");
}
}
@@ -689,7 +712,7 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
final IsisTransactionManager transactionManager = getTransactionManager();
final IsisTransaction transaction = transactionManager.getTransaction();
if(transaction == null) {
- Assert.fail("No transaction exists");
+ fail("No transaction exists");
return;
}
@@ -702,13 +725,13 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
case ABORTED:
break;
case IN_PROGRESS:
- Assert.fail("Transaction is still in state of '" + state + "'");
+ fail("Transaction is still in state of '" + state + "'");
break;
case MUST_ABORT:
- Assert.fail("Transaction is still in state of '" + state + "'");
+ fail("Transaction is still in state of '" + state + "'");
break;
default:
- Assert.fail("Unknown transaction state '" + state + "'");
+ fail("Unknown transaction state '" + state + "'");
}
}
@@ -722,7 +745,7 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
final IsisTransactionManager transactionManager = getTransactionManager();
final IsisTransaction transaction = transactionManager.getTransaction();
if(transaction == null) {
- Assert.fail("No transaction exists");
+ fail("No transaction exists");
return;
}
final State state = transaction.getState();
@@ -730,13 +753,13 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
case COMMITTED:
case ABORTED:
case MUST_ABORT:
- Assert.fail("Transaction is in state of '" + state + "'");
+ fail("Transaction is in state of '" + state + "'");
break;
case IN_PROGRESS:
transactionManager.endTransaction();
break;
default:
- Assert.fail("Unknown transaction state '" + state + "'");
+ fail("Unknown transaction state '" + state + "'");
}
}
@@ -750,7 +773,7 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
final IsisTransactionManager transactionManager = getTransactionManager();
final IsisTransaction transaction = transactionManager.getTransaction();
if(transaction == null) {
- Assert.fail("No transaction exists");
+ fail("No transaction exists");
return;
}
final State state = transaction.getState();
@@ -758,14 +781,14 @@ public class IsisSystemForTest implements org.junit.rules.TestRule, DomainServic
case ABORTED:
break;
case COMMITTED:
- Assert.fail("Transaction is in state of '" + state + "'");
+ fail("Transaction is in state of '" + state + "'");
break;
case MUST_ABORT:
case IN_PROGRESS:
transactionManager.abortTransaction();
break;
default:
- Assert.fail("Unknown transaction state '" + state + "'");
+ fail("Unknown transaction state '" + state + "'");
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
----------------------------------------------------------------------
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
index 8ecfc9b..c8af7e3 100644
--- a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
+++ b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
@@ -64,20 +64,17 @@ public abstract class IsisMojoAbstract extends AbstractMojo {
try {
isisSystem.init();
- } catch(RuntimeException ex) {
- ;
- // ignore
+ try {
+ doExecute(context, isisSystem);
+ } catch (IOException e) {
+ ;
+ // ignore
+ }
+
} finally {
isisSystem.shutdown();
}
- try {
- doExecute(context, isisSystem);
- } catch (IOException e) {
- ;
- // ignore
- }
-
}
protected abstract void doExecute(final ContextForMojo context, final IsisSystem system)
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/runtime/src/main/java/org/apache/isis/core/runtime/runner/IsisInjectModule.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/runner/IsisInjectModule.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/runner/IsisInjectModule.java
index 27a40b6..6241769 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/runner/IsisInjectModule.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/runner/IsisInjectModule.java
@@ -137,6 +137,8 @@ public class IsisInjectModule extends AbstractModule {
final IsisSystemFactory systemFactory,
final AppManifest appManifestIfAny) {
final IsisSystem system = systemFactory.createSystem(deploymentType, appManifestIfAny);
+ // as a side-effect, if the metamodel turns out to be invalid, then
+ // this will push the MetaModelInvalidException into IsisContext.
system.init();
return system;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystem.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystem.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystem.java
index 84fda30..1b2f88c 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystem.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/IsisSystem.java
@@ -46,6 +46,7 @@ import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
import org.apache.isis.core.metamodel.specloader.ServiceInitializer;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException;
import org.apache.isis.core.runtime.authentication.AuthenticationManager;
import org.apache.isis.core.runtime.authentication.exploration.ExplorationSession;
import org.apache.isis.core.runtime.authorization.AuthorizationManager;
@@ -197,20 +198,35 @@ public class IsisSystem implements DebugSelection, ApplicationScopedComponent {
specificationLoader.init(runtimeContext);
- authenticationManager.init();
- authorizationManager.init();
+ try {
+ // validate here after all entities have been registered in the persistence session factory
+ specificationLoader.validateAndAssert();
+
+
+ //
+ // remaining functionality only done if metamodel is valid.
+ //
+ authenticationManager.init();
+ authorizationManager.init();
- persistenceSessionFactory.init();
+ persistenceSessionFactory.init();
- // validate here after all entities have been registered in the persistence session factory
- specificationLoader.validateAndAssert();
+ // do postConstruct. We store the initializer to do preDestroy on shutdown
+ this.serviceInitializer = initializeServices();
- // store simply so can do postConstruct when shutdown
- this.serviceInitializer = initializeServices();
+ installFixturesIfRequired();
- installFixturesIfRequired();
+ translateServicesAndEnumConstants();
+
+ } catch (final MetaModelInvalidException ex) {
+ // no need to use a higher level, such as error(...); the calling code will expose any metamodel
+ // validation errors in their own particular way.
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Meta model invalid", ex);
+ }
+ IsisContext.setMetaModelInvalidException(ex);
+ }
- translateServicesAndEnumConstants();
} catch (final IsisSystemException ex) {
LOG.error("failed to initialise", ex);
@@ -344,25 +360,28 @@ public class IsisSystem implements DebugSelection, ApplicationScopedComponent {
*/
private void shutdownServices(final ServiceInitializer serviceInitializer) {
+ // may not be set if the metamodel validation failed during initialization
+ if (serviceInitializer == null) {
+ return;
+ }
+
// call @PostDestroy (in a session)
- if(serviceInitializer != null) {
- IsisContext.openSession(new InitialisationSession());
+ IsisContext.openSession(new InitialisationSession());
+ try {
+ getTransactionManager().startTransaction();
try {
- getTransactionManager().startTransaction();
- try {
- serviceInitializer.preDestroy();
+ serviceInitializer.preDestroy();
- } catch (RuntimeException ex) {
- getTransactionManager().getTransaction().setAbortCause(
- new IsisTransactionManagerException(ex));
- } finally {
- // will commit or abort
- getTransactionManager().endTransaction();
- }
+ } catch (RuntimeException ex) {
+ getTransactionManager().getTransaction().setAbortCause(
+ new IsisTransactionManagerException(ex));
} finally {
- IsisContext.closeSession();
+ // will commit or abort
+ getTransactionManager().endTransaction();
}
+ } finally {
+ IsisContext.closeSession();
}
}
@@ -380,6 +399,12 @@ public class IsisSystem implements DebugSelection, ApplicationScopedComponent {
}
//endregion
+ // region > metaModel validity
+ public boolean isMetaModelValid() {
+ return IsisContext.getMetaModelInvalidExceptionIfAny() == null;
+ }
+ //endregion
+
//region > logonFixture
private LogonFixture logonFixture;
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
index 238d297..718e3bd 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
@@ -38,6 +38,7 @@ import org.apache.isis.core.commons.exceptions.IsisException;
import org.apache.isis.core.metamodel.runtimecontext.LocalizationDefault;
import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException;
import org.apache.isis.core.runtime.authentication.AuthenticationManager;
import org.apache.isis.core.runtime.system.DeploymentType;
import org.apache.isis.core.runtime.system.internal.InitialisationSession;
@@ -68,6 +69,11 @@ public class IsisContext implements DebuggableWithTitle {
private static IsisConfiguration configuration;
+ /**
+ * Populated only if the metamodel was found to be invalid
+ */
+ private static MetaModelInvalidException metamodelInvalidException;
+
// ///////////////////////////////////////////////////////////
// Singleton & Constructor, shutdown
// ///////////////////////////////////////////////////////////
@@ -93,6 +99,15 @@ public class IsisContext implements DebuggableWithTitle {
singleton = null;
}
+
+ public static MetaModelInvalidException getMetaModelInvalidExceptionIfAny() {
+ return IsisContext.metamodelInvalidException;
+ }
+ public static void setMetaModelInvalidException(final MetaModelInvalidException metaModelInvalid) {
+ IsisContext.metamodelInvalidException = metaModelInvalid;
+ }
+
+
protected static enum SessionClosePolicy {
/**
* Sessions must be explicitly closed.
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java
index 5ab43d5..af3a5cf 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisSessionFilter.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
import java.util.regex.Pattern;
import javax.servlet.Filter;
@@ -42,7 +43,7 @@ import com.google.common.collect.Lists;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.factory.InstanceUtil;
import org.apache.isis.core.commons.lang.StringExtensions;
-import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.session.IsisSession;
import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
@@ -306,6 +307,8 @@ public class IsisSessionFilter implements Filter {
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
+ ensureMetamodelIsValid();
+
final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
final HttpServletResponse httpServletResponse = (HttpServletResponse) response;
@@ -357,6 +360,20 @@ public class IsisSessionFilter implements Filter {
}
+
+ private static void ensureMetamodelIsValid() {
+ final MetaModelInvalidException ex = IsisContext.getMetaModelInvalidExceptionIfAny();
+ if(ex != null) {
+ final Set<String> validationErrors = ex.getValidationErrors();
+ final StringBuilder buf = new StringBuilder();
+ for (String validationError : validationErrors) {
+ buf.append(validationError).append("\n");
+ }
+ throw new IllegalStateException("Metamodel validation errors: \n" + buf.toString());
+ }
+ }
+
+
protected boolean requestIsPassThru(final HttpServletRequest httpServletRequest) {
return passThru != null && httpServletRequest.getRequestURI().startsWith(passThru);
}
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
----------------------------------------------------------------------
diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
index c9ce6a0..511e3cb 100644
--- a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
+++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
@@ -35,6 +35,7 @@ import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.metamodel.exceptions.MetaModelException;
+import static org.junit.Assert.fail;
/**
* Represents the currently executing scenario, allowing information to be shared
@@ -72,7 +73,7 @@ public abstract class ScenarioExecution {
public static ScenarioExecution current() {
final ScenarioExecution execution = current.get();
if(execution == null) {
- throw new IllegalStateException("Scenario has not yet been instantiated");
+ fail();
}
return execution;
}
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/specsupport/src/main/java/org/apache/isis/core/specsupport/specs/CukeGlueAbstract.java
----------------------------------------------------------------------
diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/specs/CukeGlueAbstract.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/specs/CukeGlueAbstract.java
index 3aa51b0..675ea26 100644
--- a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/specs/CukeGlueAbstract.java
+++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/specs/CukeGlueAbstract.java
@@ -16,9 +16,6 @@
*/
package org.apache.isis.core.specsupport.specs;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
@@ -29,10 +26,6 @@ import com.google.common.collect.Lists;
import org.jmock.Sequence;
import org.jmock.States;
import org.jmock.internal.ExpectationBuilder;
-import org.junit.Assert;
-
-import cucumber.api.DataTable;
-import cucumber.api.java.Before;
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
@@ -40,6 +33,10 @@ import org.apache.isis.core.specsupport.scenarios.ScenarioExecution;
import org.apache.isis.core.specsupport.scenarios.ScenarioExecutionForUnit;
import org.apache.isis.core.specsupport.scenarios.ScenarioExecutionScope;
+import cucumber.api.java.Before;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
/**
* Base class for Cucumber-JVM step definitions.
@@ -58,7 +55,8 @@ public abstract class CukeGlueAbstract {
*/
protected ScenarioExecution scenarioExecution() {
if(ScenarioExecution.current() == null) {
- throw new IllegalStateException("The scenario execution has not been set up; call #before(ScenarioExecutionScope) first");
+ fail();
+ return null;
}
return ScenarioExecution.current();
}
@@ -74,8 +72,11 @@ public abstract class CukeGlueAbstract {
* then {@link ScenarioExecution#beginTran() starts a new one}.
*/
protected void nextTransaction() {
- scenarioExecution().endTran(true);
- scenarioExecution().beginTran();
+ final ScenarioExecution scenarioExecution = scenarioExecution();
+ if(scenarioExecution != null) {
+ scenarioExecution.endTran(true);
+ scenarioExecution.beginTran();
+ }
}
@@ -205,7 +206,7 @@ public abstract class CukeGlueAbstract {
}
}
if(buf.length() != 0) {
- Assert.fail("\n" + buf.toString());
+ fail("\n" + buf.toString());
}
}
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
----------------------------------------------------------------------
diff --git a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
index 9f712c6..2b24c80 100644
--- a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
+++ b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
@@ -27,15 +27,12 @@ import java.util.Set;
import javax.servlet.ServletContext;
import com.google.common.base.Function;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Module;
-import org.wicketstuff.select2.ApplicationSettings;
import org.apache.wicket.Application;
import org.apache.wicket.ConverterLocator;
@@ -60,6 +57,7 @@ import org.apache.wicket.settings.IRequestCycleSettings.RenderStrategy;
import org.apache.wicket.util.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.wicketstuff.select2.ApplicationSettings;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.authentication.AuthenticationSessionProvider;
@@ -196,9 +194,8 @@ public class IsisWicketApplication
/**
* {@link Inject}ed when {@link #init() initialized}.
*/
- @SuppressWarnings("unused")
@Inject
- private IsisSystem system;
+ private IsisSystem isisSystem;
private boolean determiningDeploymentType;
@@ -291,31 +288,34 @@ public class IsisWicketApplication
@SuppressWarnings("unused")
SharedResources sharedResources = getSharedResources();
-
- } catch(RuntimeException ex) {
- List<MetaModelInvalidException> mmies = locateMetaModelInvalidExceptions(ex);
- if(!mmies.isEmpty()) {
- final MetaModelInvalidException mmie = mmies.get(0);
- log("");
- logBanner();
- log("");
- validationErrors.addAll(mmie.getValidationErrors());
- for (String validationError : validationErrors) {
- logError(validationError);
- }
- log("");
- log("Please inspect the above messages and correct your domain model.");
- log("");
- logBanner();
- log("");
- } else {
- // because Wicket's handling in its WicketFilter (that calls this method) does not log the exception.
- LOG.error("Failed to initialize", ex);
- throw ex;
+
+ final MetaModelInvalidException mmie = IsisContext.getMetaModelInvalidExceptionIfAny();
+ if(mmie != null) {
+ this.validationErrors.addAll(mmie.getValidationErrors());
+ log(this.validationErrors);
}
+
+ } catch(RuntimeException ex) {
+ // because Wicket's handling in its WicketFilter (that calls this method) does not log the exception.
+ LOG.error("Failed to initialize", ex);
+ throw ex;
}
}
+ private void log(final List<String> validationErrors) {
+ log("");
+ logBanner();
+ log("");
+ for (String validationError : validationErrors) {
+ logError(validationError);
+ }
+ log("");
+ log("Please inspect the above messages and correct your domain model.");
+ log("");
+ logBanner();
+ log("");
+ }
+
private void configureWicketSelect2() {
ApplicationSettings select2Settings = ApplicationSettings.get();
select2Settings.setCssReference(new Select2BootstrapCssReference());
@@ -609,11 +609,6 @@ public class IsisWicketApplication
// //////////////////////////////////////
- protected List<MetaModelInvalidException> locateMetaModelInvalidExceptions(RuntimeException ex) {
- return Lists.newArrayList(
- Iterables.filter(Throwables.getCausalChain(ex), MetaModelInvalidException.class));
- }
-
/**
* The validation errors, if any, that occurred on {@link #init() startup}.
*/
@@ -678,8 +673,8 @@ public class IsisWicketApplication
@Override
protected void onDestroy() {
try {
- if (system != null) {
- system.shutdown();
+ if (isisSystem != null) {
+ isisSystem.shutdown();
}
IsisContext.shutdown();
super.onDestroy();
http://git-wip-us.apache.org/repos/asf/isis/blob/8bf7fd7f/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
----------------------------------------------------------------------
diff --git a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
index 64d239d..6bcf74c 100644
--- a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
+++ b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
@@ -145,9 +145,18 @@ public class WebRequestCycleForIsis extends AbstractRequestCycleListener {
@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex) {
+
+ List<String> validationErrors = IsisWicketApplication.get().getValidationErrors();
+ if(!validationErrors.isEmpty()) {
+ final MmvErrorPage mmvErrorPage = new MmvErrorPage(Model.ofList(validationErrors));
+ return new RenderPageRequestHandler(new PageProvider(mmvErrorPage), RedirectPolicy.ALWAYS_REDIRECT);
+ }
+
PageProvider errorPageProvider = errorPageProviderFor(ex);
// avoid infinite redirect loops
- RedirectPolicy redirectPolicy = ex instanceof PageExpiredException? RedirectPolicy.NEVER_REDIRECT: RedirectPolicy.ALWAYS_REDIRECT;
+ RedirectPolicy redirectPolicy = ex instanceof PageExpiredException
+ ? RedirectPolicy.NEVER_REDIRECT
+ : RedirectPolicy.ALWAYS_REDIRECT;
return errorPageProvider != null
? new RenderPageRequestHandler(errorPageProvider, redirectPolicy)
: null;