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 2019/01/28 18:52:13 UTC
[isis] branch 2033-IoC updated: ISIS-2033: utilizes the Seam-SPI to
provide a ConversationContext
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 2033-IoC
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/2033-IoC by this push:
new 0fa82f2 ISIS-2033: utilizes the Seam-SPI to provide a ConversationContext
0fa82f2 is described below
commit 0fa82f278f1735850da2dc67e5770b2f252df7b8
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Jan 28 19:52:05 2019 +0100
ISIS-2033: utilizes the Seam-SPI to provide a ConversationContext
disables the ConversationContextServiceWeld, as introduced prior
Task-Url: https://issues.apache.org/jira/browse/ISIS-2033
---
.../org/apache/isis/config/AppConfigLocator.java | 2 +
.../isis/core/metamodel/services/ServiceUtil.java | 19 ++++-
core/plugins/ioc-weld/pom.xml | 30 ++++++--
.../isis/core/plugins/ioc/weld/WeldFactory.java | 5 ++
.../ConversationContextServiceWeld.java | 21 +++++-
.../SeamConversationContextSupport.java | 80 ++++++++++++++++++++++
...s.seam.conversation.spi.SeamConversationContext | 1 +
.../runtime/system/session/IsisSessionFactory.java | 3 +-
.../system/session/IsisSessionFactoryBuilder.java | 3 -
.../integration/wicket/WebRequestCycleForIsis.java | 27 +++-----
10 files changed, 158 insertions(+), 33 deletions(-)
diff --git a/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java b/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java
index ddf44b1..f469a07 100644
--- a/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java
+++ b/core/config/src/main/java/org/apache/isis/config/AppConfigLocator.java
@@ -80,6 +80,8 @@ public final class AppConfigLocator {
"org.apache.isis.applib.services.homepage.HomePageProviderService"
+ //"org.jboss.seam.conversation.spi.SeamConversationContext"
+
));
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServiceUtil.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServiceUtil.java
index 4f7989d..61bdaa8 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServiceUtil.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/ServiceUtil.java
@@ -70,12 +70,27 @@ public final class ServiceUtil {
return normalize(implementedTypes.iterator().next());
}
+ // try to get a name from injection points
+ final Set<Class<?>> requiredTypes = serviceBean.getInjectionPoints().stream()
+ .map(ip->ip.getType())
+ .filter(type->!type.getTypeName().equals(Object.class.getTypeName()))
+ .filter(type->!type.getTypeName().equals(Serializable.class.getTypeName()))
+ .filter(type->type instanceof Class)
+ .map(type->(Class<?>) type)
+ .collect(Collectors.toSet());
+
+ if(requiredTypes.size()==1) {
+ // we found a unique required type as defined by injection points for this bean
+ return normalize(requiredTypes.iterator().next());
+ }
+
throw _Exceptions.unrecoverable(
- String.format("could not extract a service id from the given bean '%s', "
- + "it should be one of '%s' from types %s",
+ String.format("Could not extract a service id from the given bean '%s', "
+ + "implementedTypes='%s' requiredTypes='%s' from types %s.",
serviceBean,
implementedTypes,
+ requiredTypes,
serviceBean.getTypes()));
diff --git a/core/plugins/ioc-weld/pom.xml b/core/plugins/ioc-weld/pom.xml
index 06180d6..593403a 100644
--- a/core/plugins/ioc-weld/pom.xml
+++ b/core/plugins/ioc-weld/pom.xml
@@ -59,7 +59,7 @@
</build>
<dependencies>
-
+
<!-- compile dependencies -->
<dependency>
@@ -67,11 +67,29 @@
<artifactId>isis-core-commons</artifactId>
<scope>compile</scope>
</dependency>
-
- <dependency>
- <groupId>org.jboss.weld.se</groupId>
- <artifactId>weld-se-shaded</artifactId>
- </dependency>
+
+ <dependency>
+ <groupId>org.jboss.weld.se</groupId>
+ <artifactId>weld-se-shaded</artifactId>
+ </dependency>
+
+ <!-- in order to provide a ConversationContext for Wicket -->
+ <dependency>
+ <groupId>org.jboss.seam.conversation</groupId>
+ <artifactId>seam-conversation-spi</artifactId>
+ <version>3.0.0.Final</version>
+ </dependency>
+<!-- <dependency> -->
+<!-- <groupId>org.jboss.seam.conversation</groupId> -->
+<!-- <artifactId>seam-conversation-weld</artifactId> -->
+<!-- <version>3.0.0.Final</version> -->
+<!-- </dependency> -->
+ <dependency>
+ <groupId>org.jboss.weld.module</groupId>
+ <artifactId>weld-web</artifactId>
+ <version>3.0.5.Final</version>
+ </dependency>
+
</dependencies>
diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/WeldFactory.java b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/WeldFactory.java
index 6c8ff03..a13fd51 100644
--- a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/WeldFactory.java
+++ b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/WeldFactory.java
@@ -55,6 +55,9 @@ public class WeldFactory {
//FIXME [2033] this is just for PoC, don't hardcode this here !? ...
"org.apache.isis.core.plugins.ioc.weld.WeldFactory",
+ "org.jboss.seam.conversation.spi.SeamConversationContext",
+
+ "org.jboss.weld.module.web.WeldWebModule",
"domainapp.application.HelloWorldAppManifest", // specific to the app
@@ -77,6 +80,8 @@ public class WeldFactory {
stream(additionalPackages)
.forEach(p->probe.println("scanning additionalPackage %s", p));
+ System.setProperty("seam.conversation.disable.noop", Boolean.TRUE.toString());
+
boolean scanRecursively = true;
Weld builder = new Weld()
diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/scopes/conversation/ConversationContextServiceWeld.java b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/scopes/conversation/ConversationContextServiceWeld.java
index 64041af..99e306f 100644
--- a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/scopes/conversation/ConversationContextServiceWeld.java
+++ b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/scopes/conversation/ConversationContextServiceWeld.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.apache.isis.core.plugins.ioc.weld.scopes.conversation;
import static org.apache.isis.commons.internal.base._With.requiresNotEmpty;
@@ -18,8 +34,9 @@ import org.jboss.weld.context.bound.MutableBoundRequest;
import lombok.val;
-@Singleton @Alternative @Priority(10)
-public class ConversationContextServiceWeld implements ConversationContextService {
+//@Singleton @Alternative @Priority(10)
+@Deprecated //TODO [2033] not needed, since we are using seam SPI
+class ConversationContextServiceWeld implements ConversationContextService {
private final static String TRANSIENT_CID = null;
diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/scopes/conversation/SeamConversationContextSupport.java b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/scopes/conversation/SeamConversationContextSupport.java
new file mode 100644
index 0000000..db5840e
--- /dev/null
+++ b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/scopes/conversation/SeamConversationContextSupport.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.core.plugins.ioc.weld.scopes.conversation;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.commons.internal.cdi._CDI;
+import org.jboss.seam.conversation.spi.SeamConversationContext;
+import org.jboss.weld.context.http.HttpConversationContext;
+
+import lombok.val;
+
+public class SeamConversationContextSupport implements SeamConversationContext<HttpServletRequest> {
+
+ @Override
+ public SeamConversationContext<HttpServletRequest> associate(HttpServletRequest request) {
+ httpConversationContext().associate(request);
+ return this;
+ }
+
+ @Override
+ public SeamConversationContext<HttpServletRequest> activate(String conversationId) {
+
+ val cid = conversationId!=null && !_Strings.isEmpty(conversationId)
+ ? conversationId
+ : null;
+
+ httpConversationContext().activate(cid);
+ return this;
+ }
+
+ @Override
+ public SeamConversationContext<HttpServletRequest> invalidate() {
+ httpConversationContext().invalidate();
+ return this;
+ }
+
+ @Override
+ public SeamConversationContext<HttpServletRequest> deactivate() {
+ httpConversationContext().deactivate();
+ return this;
+ }
+
+ @Override
+ public SeamConversationContext<HttpServletRequest> dissociate(HttpServletRequest request) {
+ httpConversationContext().dissociate(request);
+ return this;
+ }
+
+ // -- STUPID HACK
+
+ protected void doAssociate(HttpServletRequest nop) {
+
+ }
+
+ // -- HELPER
+
+ private HttpConversationContext httpConversationContext() {
+ return _CDI.getManagedBean(HttpConversationContext.class).get();
+ }
+
+
+
+
+}
diff --git a/core/plugins/ioc-weld/src/main/resources/META-INF/services/org.jboss.seam.conversation.spi.SeamConversationContext b/core/plugins/ioc-weld/src/main/resources/META-INF/services/org.jboss.seam.conversation.spi.SeamConversationContext
new file mode 100644
index 0000000..320c1b6
--- /dev/null
+++ b/core/plugins/ioc-weld/src/main/resources/META-INF/services/org.jboss.seam.conversation.spi.SeamConversationContext
@@ -0,0 +1 @@
+org.apache.isis.core.plugins.ioc.weld.scopes.conversation.SeamConversationContextSupport
\ No newline at end of file
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
index a2ee3bf..c4d2e0a 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
@@ -83,7 +83,8 @@ public interface IsisSessionFactory {
* @param authenticationSession
*/
public default void doInSession(final Runnable runnable, final AuthenticationSession authenticationSession) {
- doInSession(runnable, authenticationSession);
+ final Callable<Void> callable = ()->{runnable.run(); return null;};
+ doInSession(callable, authenticationSession);
}
/**
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
index 9af5cb9..daa47a9 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
@@ -36,8 +36,6 @@ import org.apache.isis.core.commons.lang.ListExtensions;
import org.apache.isis.core.metamodel.IsisJdoRuntimePlugin;
import org.apache.isis.core.metamodel.facetapi.MetaModelRefiner;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
-import org.apache.isis.core.metamodel.specloader.validator.MetaModelDeficiencies;
-import org.apache.isis.core.metamodel.specloader.validator.MetaModelInvalidException;
import org.apache.isis.core.runtime.system.IsisSystemException;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.internal.IsisLocaleInitializer;
@@ -51,7 +49,6 @@ import org.apache.isis.schema.utils.ChangesDtoUtils;
import org.apache.isis.schema.utils.CommandDtoUtils;
import org.apache.isis.schema.utils.InteractionDtoUtils;
-import lombok.val;
import lombok.extern.slf4j.Slf4j;
@Slf4j
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 836f5a4..64766e2 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
@@ -95,19 +95,10 @@ public class WebRequestCycleForIsis implements IRequestCycleListener {
private _Lazy<RequestContextService> requestContextService = _Lazy.of(()->
_CDI.getSingleton(RequestContextService.class));
- private _Lazy<ConversationContextService> conversationContextService = _Lazy.of(()->
- _CDI.getSingleton(ConversationContextService.class));
-
public final static MetaDataKey<RequestContextHandle> REQUEST_CONTEXT_HANDLE_KEY
= new MetaDataKey<RequestContextHandle>() {
private static final long serialVersionUID = 1L; };
- public final static MetaDataKey<ConversationContextHandle> CONVERSATION_CONTEXT_HANDLE_KEY
- = new MetaDataKey<ConversationContextHandle>() {
- private static final long serialVersionUID = 1L; };
-
-
-
@Override
public synchronized void onBeginRequest(RequestCycle requestCycle) {
@@ -118,13 +109,11 @@ public class WebRequestCycleForIsis implements IRequestCycleListener {
// retrieved later at 'onEndRequest'
val requestContextHandle = requestContextService.get().startRequest();
if(requestContextHandle!=null) {
- requestCycle.setMetaData(REQUEST_CONTEXT_HANDLE_KEY, requestContextHandle);
- }
-
- val conversationContextService = conversationContextService.get().startTransientConversation();
- if(conversationContextService!=null) {
- requestCycle.setMetaData(CONVERSATION_CONTEXT_HANDLE_KEY, conversationContextService);
- }
+ requestCycle.setMetaData(REQUEST_CONTEXT_HANDLE_KEY, requestContextHandle);
+ probe.println("request context created");
+ } else {
+ probe.println("no request context created");
+ }
if (!Session.exists()) {
@@ -229,10 +218,10 @@ public class WebRequestCycleForIsis implements IRequestCycleListener {
}
// detach the current @RequestScope, if any
- RequestContextService.closeHandle(requestCycle.getMetaData(REQUEST_CONTEXT_HANDLE_KEY));
+ val handle = requestCycle.getMetaData(REQUEST_CONTEXT_HANDLE_KEY);
+ requestCycle.setMetaData(REQUEST_CONTEXT_HANDLE_KEY, null);
+ //RequestContextService.closeHandle(handle); //FIXME [2033] too early, as of commented out ... memory leak
- // detach the current @ConversationScope, if any
- ConversationContextService.closeHandle(requestCycle.getMetaData(CONVERSATION_CONTEXT_HANDLE_KEY));
}