You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by "Oscar Bou (JIRA)" <ji...@apache.org> on 2013/11/22 18:30:38 UTC

[jira] [Comment Edited] (ISIS-597) Services still not injected when entering @PostConstruct methods on a Service

    [ https://issues.apache.org/jira/browse/ISIS-597?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13830133#comment-13830133 ] 

Oscar Bou edited comment on ISIS-597 at 11/22/13 5:29 PM:
----------------------------------------------------------

Services perfectly injected when executing the @PostConstruct method for all 3 cases:

1. @Inject
2. setXXX
3. injectXXX

Thanks a lot ! 

But I'm executing it from a test and seems that there's still no Isis Session opened. 

Not sure if it's a problem of "IsisSystemForTest" or an implementation detail of the recently committed work.

The stack trace:

Rerun com.xms.framework.monitoring.integration.tests.RealTimeIntelligentMonitoringServerTests
com.xms.framework.monitoring.integration.tests.RealTimeIntelligentMonitoringServerTests
java.lang.RuntimeException: java.lang.IllegalStateException: No Session opened for this thread
	at org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:280)
	at com.xms.framework.monitoring.integration.MonitoringSystemInitializer.initIsft(MonitoringSystemInitializer.java:64)
	at com.xms.framework.monitoring.integration.MonitoringIntegTestAbstract.initClass(MonitoringIntegTestAbstract.java:14)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: No Session opened for this thread
	at org.apache.isis.core.runtime.system.context.IsisContext.getSession(IsisContext.java:421)
	at org.apache.isis.core.runtime.system.context.IsisContext.getPersistenceSession(IsisContext.java:449)
	at org.apache.isis.core.runtime.system.context.IsisContext.getTransactionManager(IsisContext.java:478)
	at com.xms.framework.common.domain.model.AbstractXMSDomainObjectRepositoryAndFactory.findByPropMultiTenant(AbstractXMSDomainObjectRepositoryAndFactory.java:419)
	at com.xms.framework.common.domain.model.AbstractXMSDomainObjectRepositoryAndFactory.findByProp(AbstractXMSDomainObjectRepositoryAndFactory.java:413)
	at com.xms.framework.risk.domain.model.RiskMatrices.theISO27005_E1Matrix(RiskMatrices.java:39)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.initializeGlobals(RealTimeIntelligentMonitoringServer.java:201)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.createKnowledgeSession(RealTimeIntelligentMonitoringServer.java:177)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.singletonKnowledgeSession(RealTimeIntelligentMonitoringServer.java:48)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.init(RealTimeIntelligentMonitoringServer.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.isis.core.commons.lang.MethodExtensions.invoke(MethodExtensions.java:50)
	at org.apache.isis.core.metamodel.specloader.ServiceInitializer.postConstruct(ServiceInitializer.java:144)
	at org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.initServices(ObjectReflectorDefault.java:379)
	at org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.initAndValidate(ObjectReflectorDefault.java:281)
	at org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.init(ObjectReflectorDefault.java:246)
	at org.apache.isis.core.runtime.system.session.IsisSessionFactoryDefault.init(IsisSessionFactoryDefault.java:218)
	at org.apache.isis.core.runtime.system.IsisSystemFixturesHookAbstract.init(IsisSystemFixturesHookAbstract.java:133)
	at org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:295)
	at org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:278)
	... 17 more





was (Author: oscarbou):
Services perfectly injected when executing the @PostConstruct method for all 3 cases:

1. @Inject
2. setXXX
3. injectXXX

Thanks a lot ! :-)

But I'm executing it from a test and seems that there's still no Isis Session opened. 

Not sure if it's a problem of "IsisSystemForTest" or an implementation detail of the recently committed work.

The stack trace:

Rerun com.xms.framework.monitoring.integration.tests.RealTimeIntelligentMonitoringServerTests
com.xms.framework.monitoring.integration.tests.RealTimeIntelligentMonitoringServerTests
java.lang.RuntimeException: java.lang.IllegalStateException: No Session opened for this thread
	at org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:280)
	at com.xms.framework.monitoring.integration.MonitoringSystemInitializer.initIsft(MonitoringSystemInitializer.java:64)
	at com.xms.framework.monitoring.integration.MonitoringIntegTestAbstract.initClass(MonitoringIntegTestAbstract.java:14)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: No Session opened for this thread
	at org.apache.isis.core.runtime.system.context.IsisContext.getSession(IsisContext.java:421)
	at org.apache.isis.core.runtime.system.context.IsisContext.getPersistenceSession(IsisContext.java:449)
	at org.apache.isis.core.runtime.system.context.IsisContext.getTransactionManager(IsisContext.java:478)
	at com.xms.framework.common.domain.model.AbstractXMSDomainObjectRepositoryAndFactory.findByPropMultiTenant(AbstractXMSDomainObjectRepositoryAndFactory.java:419)
	at com.xms.framework.common.domain.model.AbstractXMSDomainObjectRepositoryAndFactory.findByProp(AbstractXMSDomainObjectRepositoryAndFactory.java:413)
	at com.xms.framework.risk.domain.model.RiskMatrices.theISO27005_E1Matrix(RiskMatrices.java:39)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.initializeGlobals(RealTimeIntelligentMonitoringServer.java:201)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.createKnowledgeSession(RealTimeIntelligentMonitoringServer.java:177)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.singletonKnowledgeSession(RealTimeIntelligentMonitoringServer.java:48)
	at com.xms.framework.monitoring.services.RealTimeIntelligentMonitoringServer.init(RealTimeIntelligentMonitoringServer.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.isis.core.commons.lang.MethodExtensions.invoke(MethodExtensions.java:50)
	at org.apache.isis.core.metamodel.specloader.ServiceInitializer.postConstruct(ServiceInitializer.java:144)
	at org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.initServices(ObjectReflectorDefault.java:379)
	at org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.initAndValidate(ObjectReflectorDefault.java:281)
	at org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.init(ObjectReflectorDefault.java:246)
	at org.apache.isis.core.runtime.system.session.IsisSessionFactoryDefault.init(IsisSessionFactoryDefault.java:218)
	at org.apache.isis.core.runtime.system.IsisSystemFixturesHookAbstract.init(IsisSystemFixturesHookAbstract.java:133)
	at org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:295)
	at org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:278)
	... 17 more




> Services still not injected when entering @PostConstruct methods on a Service
> -----------------------------------------------------------------------------
>
>                 Key: ISIS-597
>                 URL: https://issues.apache.org/jira/browse/ISIS-597
>             Project: Isis
>          Issue Type: Improvement
>          Components: Core, Objectstore: JDO
>    Affects Versions: objectstore-jdo-1.3.0, core-1.3.0
>            Reporter: Oscar Bou
>            Assignee: Dan Haywood
>             Fix For: objectstore-jdo-1.4.0, core-1.4.0
>
>
> Methods annotated with @PostConstruct are invoked before their objects being injected.
> Steps to reproduce:
> As per [1], create a method on a service annotated with @PostConstruct, like this one:
> @PostConstruct
>    public void init(final Map<?, ?> props) {
> 	server.setGlobal("eventOccurrences", this.eventOccurrences);
> 	
>    }
>    ....
>    // {{ injected: EventOccurrences
>    private EventOccurrences eventOccurrences;
>    public final void injectEventOccurrences(final EventOccurrences eventOccurrences) {
>        this.eventOccurrences = eventOccurrences;
>    }
>    // }}
> The problem is that when the execution arrives to:
>     server.setGlobal("eventOccurrences", this.eventOccurrences);
> this.eventOccurrences is still null... So it has not yet been injected (or instantiated).
> [1] http://isis.apache.org/core/services/initializing-services.html



--
This message was sent by Atlassian JIRA
(v6.1#6144)