You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by pa...@apache.org on 2013/11/11 09:36:23 UTC
[3/3] git commit: Merged pull request #50
Merged pull request #50
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/62fed8f5
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/62fed8f5
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/62fed8f5
Branch: refs/heads/wicket-6.x
Commit: 62fed8f5fd9c6fa428c09a914ab159fd1aa62662
Parents: 92a5bdb
Author: John Sarman <jo...@gmail.com>
Authored: Tue Jul 16 13:06:10 2013 -0400
Committer: Emond Papegaaij <em...@topicus.nl>
Committed: Mon Nov 11 09:35:13 2013 +0100
----------------------------------------------------------------------
.../apache/wicket/cdi/AbstractCdiContainer.java | 30 +-
.../org/apache/wicket/cdi/AbstractInjector.java | 37 +-
.../apache/wicket/cdi/ApplicationQualifier.java | 44 ++
.../main/java/org/apache/wicket/cdi/Auto.java | 11 +-
.../org/apache/wicket/cdi/BehaviorInjector.java | 8 +-
.../org/apache/wicket/cdi/CdiConfiguration.java | 514 +++++++++++++++----
.../apache/wicket/cdi/CdiShutdownCleaner.java | 6 +-
.../wicket/cdi/CdiWebApplicationFactory.java | 207 ++++++++
.../org/apache/wicket/cdi/CdiWicketFilter.java | 48 ++
.../apache/wicket/cdi/ComponentInjector.java | 9 +-
.../wicket/cdi/ConfigurationParameters.java | 161 ++++++
.../cdi/ConversationExpiredException.java | 2 +-
.../wicket/cdi/ConversationExpiryChecker.java | 24 +-
.../apache/wicket/cdi/ConversationManager.java | 123 +++++
.../wicket/cdi/ConversationPropagation.java | 88 ++--
.../wicket/cdi/ConversationPropagator.java | 346 +++++++------
.../org/apache/wicket/cdi/Conversational.java | 41 ++
.../wicket/cdi/ConversationalComponent.java | 3 +-
.../java/org/apache/wicket/cdi/DetachEvent.java | 3 +-
.../apache/wicket/cdi/DetachEventEmitter.java | 13 +-
.../cdi/ICdiAwareRequestCycleListener.java | 39 --
.../wicket/cdi/IConversationPropagation.java | 15 +-
.../wicket/cdi/INonContextualManager.java | 11 +-
.../java/org/apache/wicket/cdi/IgnoreList.java | 11 +-
.../org/apache/wicket/cdi/NonContextual.java | 20 +-
.../apache/wicket/cdi/NonContextualManager.java | 7 +-
.../java/org/apache/wicket/cdi/Propagation.java | 8 +-
.../org/apache/wicket/cdi/SessionInjector.java | 3 +-
.../java/org/apache/wicket/cdi/WicketApp.java | 49 ++
.../apache/wicket/cdi/AbstractInjectorTest.java | 57 ++
.../wicket/cdi/ApacheLicenceHeaderTest.java | 2 +-
.../apache/wicket/cdi/CdiConfigurationTest.java | 211 +++++++-
.../wicket/cdi/ComponentInjectorTest.java | 102 ----
.../wicket/cdi/ConversationManagerTest.java | 92 ++++
.../wicket/cdi/ConversationPropagatorTest.java | 211 ++++++++
.../org/apache/wicket/cdi/MockCdiContainer.java | 33 +-
.../apache/wicket/cdi/WicketCdiTestCase.java | 97 +++-
.../wicket/cdi/testapp/TestApplication.java | 11 +-
.../cdi/testapp/TestCdiAdditionApplication.java | 58 +++
.../wicket/cdi/testapp/TestCdiApplication.java | 58 +++
.../cdi/testapp/TestConversationBean.java | 8 +
.../cdi/testapp/TestConversationPage.html | 2 +-
.../cdi/testapp/TestConversationPage.java | 28 +-
.../cdi/testapp/TestConversationalPage.html | 12 +
.../cdi/testapp/TestConversationalPage.java | 84 +++
.../testapp/TestNonAutoConversationalPage.html | 12 +
.../testapp/TestNonAutoConversationalPage.java | 92 ++++
.../cdi/testapp/TestNonConversationalPage.html | 11 +
.../cdi/testapp/TestNonConversationalPage.java | 59 +++
.../wicket/cdi/util/tester/CdiWicketTester.java | 137 +++++
.../cdi/util/tester/ConfigurationFilter.java | 38 ++
.../wicket/cdi/util/tester/ContextManager.java | 98 ++++
.../cdi/util/tester/FilterConfigProducer.java | 62 +++
.../cdi/util/tester/TestBehaviorInjector.java | 50 ++
.../cdi/util/tester/TestCdiConfiguration.java | 87 ++++
.../cdi/util/tester/TestComponentInjector.java | 50 ++
.../cdi/util/tester/TestFilterConfig.java | 89 ++++
.../src/test/java/simplelogger.properties | 1 +
.../wicket-cdi-1.1/wicket-cdi-1.1-weld/pom.xml | 137 ++---
.../wicket/cdi/weld/WeldCdiContainer.java | 54 +-
.../cdi/weld/ApacheLicenceHeaderTest.java | 2 +-
61 files changed, 3197 insertions(+), 729 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java
index f30666c..48f94bc 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractCdiContainer.java
@@ -16,45 +16,45 @@
*/
package org.apache.wicket.cdi;
+import javax.enterprise.context.Conversation;
import javax.servlet.http.HttpServletRequest;
+
import org.apache.wicket.Page;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.util.lang.Args;
/**
* Provides access to CDI features from inside a Wicket request
- *
+ *
* @author igor
- *
*/
public abstract class AbstractCdiContainer
{
/**
- * Deactivates conversational context
- *
- * @param cycle
- */
- public abstract void deactivateConversationalContext(RequestCycle cycle);
-
- /**
* Activates the conversational context and starts the conversation with the specified cid
- *
+ *
* @param cycle
* @param cid
*/
public abstract void activateConversationalContext(RequestCycle cycle, String cid);
+ /**
+ * Retrieve the current conversation associated with the ConversationContext
+ *
+ * @return The current Conversation attached to the current Conversation Context
+ */
+ public abstract Conversation getCurrentConversation();
+
protected HttpServletRequest getRequest(RequestCycle cycle)
{
- return (HttpServletRequest)cycle.getRequest().getContainerRequest();
+ return (HttpServletRequest) cycle.getRequest().getContainerRequest();
}
/**
* Retrieves a conversation id, if any, that is associated with a {@link Page} instance
- *
- * @param page
- * page instance
+ *
+ * @param page page instance
* @return conversation id, if any
*/
public String getConversationMarker(Page page)
@@ -66,7 +66,7 @@ public abstract class AbstractCdiContainer
* Removes conversation marker from the page instance which prevents the conversation from
* propagating to the page. This method should usually be called from page's {@code onDetach()}
* method.
- *
+ *
* @param page
*/
public void removeConversationMarker(Page page)
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
index a9a528b..bec113a 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
@@ -18,6 +18,7 @@ package org.apache.wicket.cdi;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,21 +27,27 @@ import org.slf4j.LoggerFactory;
*
* @author igor
*/
-class AbstractInjector <T>
+public class AbstractInjector<T>
{
-
+
private static final Logger LOG = LoggerFactory.getLogger(AbstractInjector.class);
@Inject
+ AbstractCdiContainer cdiContainer;
+
+ @Inject
INonContextualManager nonContextualManager;
- @Inject
+ @Inject
+ CdiConfiguration cdiConfiguration;
+
+ @Inject
@IgnoreList
Instance<String[]> ignorePackages;
protected void postConstruct(T instance)
{
- if(!ignore(instance.getClass()))
+ if (!ignore(instance.getClass()))
{
nonContextualManager.postConstruct(instance);
}
@@ -48,33 +55,31 @@ class AbstractInjector <T>
protected void inject(T instance)
{
-
- if(!ignore(instance.getClass()))
+
+ if (!ignore(instance.getClass()))
{
nonContextualManager.inject(instance);
}
}
-
-
- private boolean ignore(Class<?> instanceClass)
+
+ protected boolean ignore(Class<?> instanceClass)
{
String packageName = instanceClass.getPackage().getName();
- for(String ignore:ignorePackages.get())
+ for (String ignore : ignorePackages.get())
{
- if(packageName.contains(ignore))
+
+ if (instanceClass.getName().equals(ignore) || packageName.contains(ignore))
{
- LOG.debug("Skipping {} which is in a package to ignore {}",instanceClass,packageName);
+ LOG.debug("Skipping {} which is set to ignore {}", instanceClass, packageName);
return true;
}
- }
-
+ }
return false;
-
}
public String[] getIgnorePackages()
{
return ignorePackages.get();
}
-
+
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java
new file mode 100644
index 0000000..d62681f
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ApplicationQualifier.java
@@ -0,0 +1,44 @@
+/*
+ * 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.wicket.cdi;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+/**
+ * Allows for Programmatic lookup of WebApplications based on the Named Annotation.
+ *
+ * @author jsarman
+ */
+public class ApplicationQualifier extends AnnotationLiteral<WicketApp> implements WicketApp
+{
+ private static final long serialVersionUID = 1L;
+
+ private String value;
+
+ public ApplicationQualifier(String value)
+ {
+ super();
+ this.value = value;
+ }
+
+ @Override
+ public String value()
+ {
+ return value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java
index 65a7abf..384c775 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Auto.java
@@ -21,17 +21,18 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+
import javax.inject.Qualifier;
/**
- * Qualifier for injecting the Automatic Conversation begin boolean
- *
+ * Qualifier for injecting the Automatic Conversation begin boolean
+ *
* @author jsarman
*/
@Qualifier
-@Target( { ElementType.TYPE,ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
-public @interface Auto
+public @interface Auto
{
-
+
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
index 372e74d..f163c3a 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
@@ -17,19 +17,19 @@
package org.apache.wicket.cdi;
import javax.enterprise.context.ApplicationScoped;
+
import org.apache.wicket.IBehaviorInstantiationListener;
import org.apache.wicket.behavior.Behavior;
/**
* Injects components with CDI dependencies
- *
+ *
* @author igor
- *
*/
@ApplicationScoped
-class BehaviorInjector extends AbstractInjector<Behavior> implements IBehaviorInstantiationListener
+public class BehaviorInjector extends AbstractInjector<Behavior> implements IBehaviorInstantiationListener
{
-
+
@Override
public void onInstantiation(Behavior behavior)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
index 0c2ef3e..dc23e1e 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
@@ -18,52 +18,59 @@ package org.apache.wicket.cdi;
import java.util.Arrays;
import java.util.Iterator;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.Map;
+import java.util.TreeMap;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
import org.apache.wicket.Application;
+import org.apache.wicket.Component;
+import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.application.IComponentOnBeforeRenderListener;
+import org.apache.wicket.request.IRequestHandler;
+import org.apache.wicket.request.Url;
+import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
+import org.apache.wicket.request.cycle.IRequestCycleListener;
+import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.cycle.RequestCycleListenerCollection;
+import org.apache.wicket.util.lang.Args;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Configures CDI integration
- *
+ *
* @author igor
+ * @author jsarman
*/
@ApplicationScoped
public class CdiConfiguration
{
- private static final String[] defaultIgnoredPackages = new String[]
- {
- "org.apache.wicket.markup",
- "org.apache.wicket.protocol.http",
- "org.apache.wicket.behavior",
- };
-
- private IConversationPropagation propagation = ConversationPropagation.NONBOOKMARKABLE;
+ private static final Logger logger = LoggerFactory.getLogger(CdiConfiguration.class);
+ private static final String[] defaultIgnoredPackages = new String[] {
+ "org.apache.wicket.markup", "org.apache.wicket.protocol.http",
+ "org.apache.wicket.behavior", };
@Inject
- BeanManager beanManager;
+ AbstractCdiContainer container;
@Inject
INonContextualManager nonContextualManager;
@Inject
- Instance<ConversationPropagator> conversationPropagatorSource;
+ ConversationPropagator conversationPropagator;
@Inject
- Instance<ConversationExpiryChecker> conversationExpiryCheckerSource;
+ ConversationExpiryChecker conversationExpiryChecker;
@Inject
- Instance<DetachEventEmitter> detachEventEmitterSource;
+ DetachEventEmitter detachEventEmitter;
@Inject
BehaviorInjector behaviorInjector;
@@ -74,197 +81,407 @@ public class CdiConfiguration
@Inject
SessionInjector sessionInjector;
- private boolean injectComponents = true;
- private boolean injectApplication = true;
- private boolean injectSession = true;
- private boolean injectBehaviors = true;
- private boolean autoConversationManagement = false;
- private boolean configured = false;
- private Set<String> ignoredPackages;
+ @Inject
+ ConversationManager conversationManager;
+
+ protected Map<String, ConfigurationParameters> parameters;
+
+ /**
+ * Not intended for public use. Use {@link #get()}
+ */
+ public CdiConfiguration()
+ {
+ }
+
@PostConstruct
public void init()
{
- ignoredPackages = new TreeSet<String>();
- ignoredPackages.addAll(Arrays.asList(defaultIgnoredPackages));
+ parameters = new TreeMap<String, ConfigurationParameters>();
+ }
+
+ public boolean isInjectComponents()
+ {
+ return getApplicationParameters().isInjectComponents();
}
/**
- * Gets the configured bean manager
- *
- * @return bean manager or {@code null} if none
+ * Flag to set if ComponentInjection is enabled.
+ * <p/>
+ * This method will throw IllegalStateException if called after configured.
+ *
+ * @param injectComponents
+ * @return {@code this} for easy chaining
+ * @deprecated Application Level Configuration replaced with
+ * {@link CdiWicketFilter}
*/
- public BeanManager getBeanManager()
+ @Deprecated
+ public CdiConfiguration setInjectComponents(boolean injectComponents)
{
- return beanManager;
+ ConfigurationParameters params = getApplicationParameters();
+ if (params.isConfigured())
+ {
+ throw new IllegalStateException(
+ "Component Injection can only be changed before configure is called");
+ }
+ params.setInjectComponents(injectComponents);
+ return this;
}
- public
- @Produces
- @Propagation
- IConversationPropagation getPropagation()
+ public boolean isInjectApplication()
{
- return propagation;
+ return getApplicationParameters().isInjectApplication();
}
/**
- * Checks if auto conversation management is enabled. See
- * {@link #setAutoConversationManagement(boolean)} for details.
+ * Flag to set if ApplicationInjection is enabled.
+ * <p/>
+ * This method will throw IllegalStateException if called after configured.
+ *
+ * @param injectApplication
+ * @return {@code this} for easy chaining
+ * @deprecated Application Level Configuration replaced with
+ * {@link CdiWicketFilter}
*/
- public
- @Produces
- @Auto
- Boolean isAutoConversationManagement()
+ @Deprecated
+ public CdiConfiguration setInjectApplication(boolean injectApplication)
+ {
+ ConfigurationParameters params = getApplicationParameters();
+ if (params.isConfigured())
+ {
+ throw new IllegalStateException(
+ "Application Injection can only be changed before configure is called");
+ }
+ params.setInjectApplication(injectApplication);
+ return this;
+ }
+
+ public boolean isInjectSession()
{
- return autoConversationManagement;
+ return getApplicationParameters().isInjectSession();
}
/**
- * Toggles automatic conversation management feature.
- * <p/>
- * Automatic conversation management controls the lifecycle of the conversation based on
- * presence of components implementing the {@link ConversationalComponent} interface. If such
- * components are found in the page a conversation is marked persistent, and if they are not the
- * conversation is marked transient. This greatly simplifies the management of conversation
- * lifecycle.
+ * Flag to set if SessionInjection is enabled.
* <p/>
- * Sometimes it is necessary to manually control the application. For these cases, once a
- * conversation is started {@link AutoConversation} bean can be used to mark the conversation as
- * manually-managed.
- *
- * @param enabled
+ * This method will throw IllegalStateException if called after configured.
+ *
+ * @param injectSession
* @return {@code this} for easy chaining
+ * @deprecated Application Level Configuration replaced with
+ * {@link CdiWicketFilter}
*/
- public CdiConfiguration setAutoConversationManagement(boolean enabled)
+ @Deprecated
+ public CdiConfiguration setInjectSession(boolean injectSession)
{
- autoConversationManagement = enabled;
+ ConfigurationParameters params = getApplicationParameters();
+ if (params.isConfigured())
+ {
+ throw new IllegalStateException(
+ "Session Injection can only be changed before configure is called");
+ }
+ params.setInjectSession(injectSession);
return this;
}
- public CdiConfiguration setPropagation(IConversationPropagation propagation)
+ public boolean isInjectBehaviors()
{
- this.propagation = propagation;
- return this;
+ return getApplicationParameters().isInjectBehaviors();
}
- public INonContextualManager getNonContextualManager()
+ /**
+ * Flag to set if BehaviorInjection is enabled.
+ * <p/>
+ * This method will throw IllegalStateException if called after configured.
+ *
+ * @param injectBehaviors
+ * @return {@code this} for easy chaining
+ * @deprecated Application Level Configuration replaced with
+ * {@link CdiWicketFilter}
+ */
+ @Deprecated
+ public CdiConfiguration setInjectBehaviors(boolean injectBehaviors)
{
- return nonContextualManager;
+ ConfigurationParameters params = getApplicationParameters();
+ if (params.isConfigured())
+ {
+ throw new IllegalStateException(
+ "Behavior Injection can only be changed before configure is called");
+ }
+ params.setInjectBehaviors(injectBehaviors);
+ return this;
}
- public boolean isInjectComponents()
+ public @Produces
+ @Propagation
+ IConversationPropagation getPropagation()
{
- return injectComponents;
+ return getApplicationParameters().getPropagation();
}
- public CdiConfiguration setInjectComponents(boolean injectComponents)
+
+ public @Produces
+ @Auto
+ Boolean isAutoConversationManagement()
{
- this.injectComponents = injectComponents;
- return this;
+ return getApplicationParameters().isAutoConversationManagement();
}
- public boolean isInjectApplication()
+ /**
+ * Toggles automatic conversation management feature.
+ * <p/>
+ * Automatic conversation management controls the lifecycle of the
+ * conversation based on presence of components implementing the
+ * {@link ConversationalComponent} interface. If such components are found
+ * in the page a conversation is marked persistent, and if they are not the
+ * conversation is marked transient. This greatly simplifies the management
+ * of conversation lifecycle.
+ * <p/>
+ * ConversationManagement can also be enable per Conversation after
+ * configured. Once the CdiConfiguration is configured this call is passed
+ * to {@link ConversationManager#setManageConversation(java.lang.Boolean) }
+ * for the ConversationManager in the current ConversationScope. This allows
+ * for ConversationManagement per active Conversation.
+ * <p/>
+ *
+ * @param enabled
+ * @return {@code this} for easy chaining
+ */
+ public CdiConfiguration setAutoConversationManagement(boolean enabled)
{
- return injectApplication;
+ ConfigurationParameters params = getApplicationParameters();
+ if (params.isConfigured())
+ {
+ if (container.getCurrentConversation().isTransient())
+ {
+ logger.warn("Not setting AutoConversationManagement because the conversation context is transient.");
+ return this;
+ }
+ conversationManager.setManageConversation(enabled);
+ }
+ else
+ {
+ params.setAutoConversationManagement(enabled);
+ }
+ return this;
}
- public CdiConfiguration setInjectApplication(boolean injectApplication)
+ /**
+ * Method to set the ConversationPropagation.
+ * <p/>
+ *
+ * @param propagation
+ * @return {@code this} for easy chaining
+ */
+ public CdiConfiguration setPropagation(IConversationPropagation propagation)
{
- this.injectApplication = injectApplication;
+ Args.notNull(propagation, "propagation");
+
+ ConfigurationParameters params = getApplicationParameters();
+ if (params.isConfigured())
+ {
+ if (container.getCurrentConversation().isTransient())
+ {
+ logger.warn("Not setting propagation because the conversation context is transient.");
+ return this;
+ }
+ conversationManager.setPropagation(propagation);
+ }
+ else
+ {
+ params.setPropagation(propagation);
+ }
return this;
}
- public boolean isInjectSession()
+ public INonContextualManager getNonContextualManager()
{
- return injectSession;
+ return nonContextualManager;
}
- public CdiConfiguration setInjectSession(boolean injectSession)
+ /**
+ * @return true if configured for Application
+ */
+ public boolean isConfigured()
{
- this.injectSession = injectSession;
- return this;
+ return getApplicationParameters().isConfigured();
}
- public boolean isInjectBehaviors()
+ public @Produces
+ @IgnoreList
+ String[] getPackagesToIgnore()
{
- return injectBehaviors;
+ ConfigurationParameters params = getApplicationParameters();
+
+ String[] ignore = new String[params.getIgnoredPackages().size()];
+ return params.getIgnoredPackages().toArray(ignore);
}
- public CdiConfiguration setInjectBehaviors(boolean injectBehaviors)
+ /**
+ * Allows for addition of individual classes to be ignored during injection.
+ *
+ * @param classes
+ * @return {@code this} for easy chaining
+ */
+ public CdiConfiguration addClassesToIgnore(Class<?>... classes)
{
- this.injectBehaviors = injectBehaviors;
+ if (classes != null && classes.length > 0)
+ {
+ ConfigurationParameters params = getApplicationParameters();
+ for (Class<?> clazz : classes)
+ {
+ params.getIgnoredPackages().add(clazz.getName());
+ }
+ }
return this;
}
- public
- @Produces
- @IgnoreList
- String[] getPackagesToIgnore()
+ /**
+ * Remove one or more Classes from Ignore list
+ *
+ * @param classes
+ * @return {@code this} for easy chaining
+ */
+ public CdiConfiguration removeClassesToIgnore(Class<?>... classes)
{
- String[] ignore = new String[ignoredPackages.size()];
- return ignoredPackages.toArray(ignore);
+ if (classes != null && classes.length > 0)
+ {
+ ConfigurationParameters params = getApplicationParameters();
+ for (Class<?> clazz : classes)
+ {
+ params.getIgnoredPackages().remove(clazz.getName());
+ }
+ }
+ return this;
}
+ /**
+ * Allows for addition of one or more packages to be ignored during
+ * injection.
+ *
+ * @param packageNames
+ * @return {@code this} for easy chaining
+ */
public CdiConfiguration addPackagesToIgnore(String... packageNames)
{
- ignoredPackages.addAll(Arrays.asList(packageNames));
+ if (packageNames != null && packageNames.length > 0)
+ {
+ getApplicationParameters().getIgnoredPackages().addAll(Arrays.asList(packageNames));
+ }
return this;
}
+ /**
+ * Remove one or more Package from Ignore list
+ *
+ * @param packageNames
+ * @return {@code this} for easy chaining
+ */
public CdiConfiguration removePackagesToIgnore(String... packageNames)
{
- ignoredPackages.removeAll(Arrays.asList(packageNames));
+ if (packageNames != null && packageNames.length > 0)
+ {
+ getApplicationParameters().getIgnoredPackages().removeAll(Arrays.asList(packageNames));
+ }
return this;
}
+ protected ConfigurationParameters getApplicationParameters()
+ {
+ ConfigurationParameters params = parameters.get(Application.get().getApplicationKey());
+ if (params == null)
+ {
+ try
+ {
+ Application app = Application.get();
+ if (app.getApplicationKey() == null)
+ {
+ throw new WicketRuntimeException();
+ }
+ params = new ConfigurationParameters();
+ parameters.put(app.getApplicationKey(), params);
+ }
+ catch (WicketRuntimeException wre)
+ {
+ throw new IllegalStateException("Application is not ready.");
+ }
+ }
+ return params;
+ }
+
/**
- * Configures the specified application
- *
+ * Configures the specified application. This method allows for
+ * CdiConfiguration to be setup at the Application Level. Use the
+ * {@link CdiWicketFilter} as the filterClass or add the
+ * {@link CdiWebApplicationFactory} to the Standard WicketFilter with
+ * init-param applicationFactoryClassName for setup during Application
+ * Initialization. This allows for Injected classes in the WebApplication to
+ * be ready before init() is called.
+ *
* @param application
* @return
+ * @deprecated Application Level Configuration replaced with
+ * {@link CdiWicketFilter}
*/
- public synchronized void configure(Application application)
+ @Deprecated
+ public void configure(Application application)
+ {
+ ConfigurationParameters params = getApplicationParameters();
+ configure(application.getApplicationKey(), application, params);
+ }
+
+ protected synchronized void configure(String appKey, Application application,
+ ConfigurationParameters params)
{
- if (configured)
+
+ if (parameters.containsKey(appKey))
+ {
+ params = parameters.get(appKey);
+ if (params.isConfigured())
+ {
+ throw new IllegalStateException("Cannot configure CdiConfiguration multiple times");
+ }
+ }
+ else
{
- throw new IllegalStateException("Cannot configure CdiConfiguration multiple times");
+ parameters.put(appKey, params);
}
+ params.getIgnoredPackages().addAll(Arrays.asList(defaultIgnoredPackages));
+
RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
application.getRequestCycleListeners().add(listeners);
// enable conversation propagation
- if (getPropagation() != ConversationPropagation.NONE)
+ if (params.getPropagation() != ConversationPropagation.NONE)
{
- listeners.add(conversationPropagatorSource.get());
- application.getComponentPreOnBeforeRenderListeners().add(
- conversationExpiryCheckerSource.get());
+ enablePropagation(params, application);
}
// enable detach event
- listeners.add(detachEventEmitterSource.get());
+ listeners.add(detachEventEmitter);
// inject application instance
- if (isInjectApplication())
+ if (params.isInjectApplication())
{
nonContextualManager.postConstruct(application);
}
// enable injection of various framework components
- if (isInjectSession())
+ if (params.isInjectSession())
{
application.getSessionListeners().add(sessionInjector);
}
- if (isInjectComponents())
+ if (params.isInjectComponents())
{
application.getComponentInstantiationListeners().add(componentInjector);
}
- if (isInjectBehaviors())
+ if (params.isInjectBehaviors())
{
application.getBehaviorInstantiationListeners().add(behaviorInjector);
}
@@ -272,12 +489,18 @@ public class CdiConfiguration
// enable cleanup
application.getApplicationListeners().add(
- new CdiShutdownCleaner(isInjectApplication()));
+ new CdiShutdownCleaner(params.isInjectApplication()));
- configured = true;
+ params.setConfigured(true);
}
+ /**
+ * Convenience Method to get an Injected Instance of CdiConfiguration
+ * programmatically.
+ *
+ * @return
+ */
@SuppressWarnings("unchecked")
public static CdiConfiguration get()
{
@@ -287,9 +510,90 @@ public class CdiConfiguration
{
throw new IllegalStateException("CDI BeanManager cannot find CdiConfiguration");
}
- Bean<CdiConfiguration> bean = (Bean<CdiConfiguration>) iter.next();
+ Bean<CdiConfiguration> bean = (Bean<CdiConfiguration>)iter.next();
CreationalContext<CdiConfiguration> ctx = beanManager.createCreationalContext(bean);
- return (CdiConfiguration) beanManager.getReference(bean, CdiConfiguration.class, ctx);
+ return (CdiConfiguration)beanManager.getReference(bean, CdiConfiguration.class, ctx);
+ }
+
+ private void enablePropagation(ConfigurationParameters params, Application application)
+ {
+ disablePropagation(params); // Force remove active listeners if any
+ IRequestCycleListener requestCycleListener = conversationPropagator;// new
+ // RequestCycleListenerWrapper();
+ application.getRequestCycleListeners().add(requestCycleListener);
+ params.setActiveRequestCycleListener(requestCycleListener);
+
+ IComponentOnBeforeRenderListener componentOnBeforeRenderListener = new ComponentOnBeforeRenderListenerWrapper();
+ application.getComponentPreOnBeforeRenderListeners().add(componentOnBeforeRenderListener);
+ params.setActiveComponentOnBeforeRenderListener(componentOnBeforeRenderListener);
+ }
+
+ private void disablePropagation(ConfigurationParameters params)
+ {
+ IRequestCycleListener requestCycleListener = params.getActiveRequestCycleListener();
+ if (requestCycleListener != null)
+ {
+ Application.get().getRequestCycleListeners().remove(requestCycleListener);
+ params.setActiveRequestCycleListener(null);
+ }
+ IComponentOnBeforeRenderListener componentOnBeforeRenderListener = params
+ .getActiveComponentOnBeforeRenderListener();
+ if (componentOnBeforeRenderListener != null)
+ {
+ Application.get().getComponentPreOnBeforeRenderListeners()
+ .remove(componentOnBeforeRenderListener);
+ params.setActiveComponentOnBeforeRenderListener(null);
+ }
+ }
+
+ /**
+ * Wrapper for the Current ConversationPropagator which allows the removal
+ * of the listener.
+ */
+ class RequestCycleListenerWrapper extends AbstractRequestCycleListener
+ {
+
+ @Override
+ public void onEndRequest(RequestCycle cycle)
+ {
+ conversationPropagator.onEndRequest(cycle);
+ }
+
+ @Override
+ public void onRequestHandlerScheduled(RequestCycle cycle, IRequestHandler handler)
+ {
+ conversationPropagator.onRequestHandlerScheduled(cycle, handler);
+ }
+
+ @Override
+ public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
+ {
+ conversationPropagator.onRequestHandlerResolved(cycle, handler);
+ }
+
+ @Override
+ public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler)
+ {
+ conversationPropagator.onRequestHandlerExecuted(cycle, handler);
+ }
+
+ @Override
+ public void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url)
+ {
+ conversationPropagator.onUrlMapped(cycle, handler, url);
+ }
+
+ }
+
+ class ComponentOnBeforeRenderListenerWrapper implements IComponentOnBeforeRenderListener
+ {
+
+ @Override
+ public void onBeforeRender(Component component)
+ {
+ conversationExpiryChecker.onBeforeRender(component);
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
index 38c5351..676c346 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
@@ -21,16 +21,16 @@ import org.apache.wicket.IApplicationListener;
/**
* Listens to application shutdown and cleans up
- *
+ *
* @author igor
*/
class CdiShutdownCleaner implements IApplicationListener
{
-
+
private final boolean preDestroyApplication;
public CdiShutdownCleaner(boolean preDestroyApplication)
- {
+ {
this.preDestroyApplication = preDestroyApplication;
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java
new file mode 100644
index 0000000..09c1b0e
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWebApplicationFactory.java
@@ -0,0 +1,207 @@
+/*
+ * 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.wicket.cdi;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.inject.Inject;
+import javax.servlet.FilterConfig;
+
+import org.apache.wicket.protocol.http.ContextParamWebApplicationFactory;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.protocol.http.WicketFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * WebApplicationFactory designed for CDI Injection.
+ * <p/>
+ * This class can be added to the default WicketFilter by setting the init-param
+ * 'applicationFactoryClassName' with this classes fully qualified path. In this
+ * case the applicationClassName init-param is required. The CdiConfiguration is
+ * automatically configured and the Application class is postConstructed, unless
+ * overriding with the enableApplicationInjection init-param.
+ * <p/>
+ * This class is also used by CdiWicketFilter. When using CdiWicketFilter you do
+ * not need to use the applicationClassName init-param. CdiWicketFilter uses the
+ * Injected CdiWebApplicationFactory. When createApplication is called a
+ * WebApplication Instance iterator is searched to find the proper
+ * WebApplication. Search works by first looking up the init-param
+ * applicationName. If this is found then the WebApplication annotated with
+ * {@link WicketApp}('someApp') is selected. This allows for multiple
+ * WebApplications to exist in the classloader. If multiple WebApplication are
+ * in the classloader then the use of {@link WicketApp} is required. If the
+ * init-param applicationName is not set then the classloader is searched to
+ * verify there is only one WebApplication. If there is only one WebApplication
+ * then it is used. If there are no WebApplications or multiple Applications
+ * without applicationName being set then an exception will be thrown. When
+ * using CdiWicketFilter the Application is always Injected. When using this in
+ * a EE container like glassfish the {@link WicketApp} is required to let EE
+ * container manage the object.
+ *
+ * @author jsarman
+ */
+@ApplicationScoped
+public class CdiWebApplicationFactory extends ContextParamWebApplicationFactory
+{
+
+ private final static Logger log = LoggerFactory.getLogger(CdiWebApplicationFactory.class);
+ static final String WICKET_APP_NAME = "applicationName";
+ static final String INJECT_APP = "enableApplicationInjection";
+ static final String INJECT_COMPONENT = "enableComponentInjection";
+ static final String INJECT_SESSION = "enableSessionInjection";
+ static final String INJECT_BEHAVIOR = "enableBehaviorInjecion";
+ static final String AUTO_CONVERSATION = "enableAutoConversationManagement";
+ static final String PROPAGATION = "initialConversationPropagation";
+ @Inject
+ @Any
+ Instance<WebApplication> applications;
+ private boolean overrideApplicationInjection;
+
+ public CdiWebApplicationFactory()
+ {
+ }
+
+ @Override
+ public WebApplication createApplication(WicketFilter filter)
+ {
+
+ WebApplication application;
+ if (applications == null)
+ {
+ application = super.createApplication(filter);
+ }
+ else
+ {
+ String appName = filter.getFilterConfig().getInitParameter(WICKET_APP_NAME);
+ if (appName != null)
+ {
+ try
+ {
+ ApplicationQualifier qualifier = new ApplicationQualifier(appName);
+ application = applications.select(qualifier).get();
+ log.info("Found WicketApp('{}') annotated WebApplication: {} ", appName,
+ application.getClass());
+ }
+ catch (IllegalArgumentException iae)
+ {
+ log.error(
+ "The init param {} set to {} is either has no @Named parameter or duplicates.",
+ WICKET_APP_NAME, appName);
+ throw iae;
+ }
+ catch (UnsatisfiedResolutionException ure)
+ {
+ log.error(
+ "The init param {} set to {} requires a WebApplication to be annotated with @Named(\"{}\").",
+ new Object[] { WICKET_APP_NAME, appName, appName });
+ throw ure;
+ }
+ }
+ else
+ {
+ Iterator<WebApplication> possibleApps = applications.iterator();
+ try
+ {
+ application = possibleApps.next();
+ }
+ catch (NoSuchElementException nsee)
+ {
+ log.error("The classLoader does not contain any WebApplications. Please create a WebApplication.");
+ throw new RuntimeException("Missing WebApplication");
+ }
+ if (possibleApps.hasNext())
+ {
+ log.error(
+ "Multiple WebApplications are in the classloader. This requires using @Named parameter on WebApplication"
+ + " and setting the init-param {} with the matching name in web.xml",
+ WICKET_APP_NAME);
+ throw new IllegalArgumentException("Missing init-param " + WICKET_APP_NAME
+ + " to match against multiple WebApplications in classLoader. ");
+ }
+ log.info("Found Single WebApplication: {}", application.getClass());
+ }
+ overrideApplicationInjection = true; // Already injected so don't
+ // let CdiConfiguration
+ // reinject it.
+ }
+
+ ConfigurationParameters parameters = buildParameters(filter.getFilterConfig());
+ CdiConfiguration.get().configure(filter.getFilterConfig().getFilterName(), application,
+ parameters);
+ return application;
+ }
+
+ private ConfigurationParameters buildParameters(FilterConfig filterConfig)
+ {
+ ConfigurationParameters parameters = new ConfigurationParameters();
+ if (!overrideApplicationInjection)
+ {
+ final String injectApp = filterConfig.getInitParameter(INJECT_APP);
+
+ if (injectApp != null)
+ {
+ parameters.setInjectApplication(Boolean.parseBoolean(injectApp));
+ }
+ }
+ else
+ {
+ parameters.setInjectApplication(false);
+ }
+ final String injectComponent = filterConfig.getInitParameter(INJECT_COMPONENT);
+ if (injectComponent != null)
+ {
+ parameters.setInjectComponents(Boolean.parseBoolean(injectComponent));
+ }
+ final String injectSession = filterConfig.getInitParameter(INJECT_SESSION);
+ if (injectSession != null)
+ {
+ parameters.setInjectSession(Boolean.parseBoolean(injectSession));
+ }
+ final String injectBehavior = filterConfig.getInitParameter(INJECT_BEHAVIOR);
+ if (injectBehavior != null)
+ {
+ parameters.setInjectBehaviors(Boolean.parseBoolean(injectBehavior));
+ }
+ final String autoConversation = filterConfig.getInitParameter(AUTO_CONVERSATION);
+ if (autoConversation != null)
+ {
+ parameters.setAutoConversationManagement(Boolean.parseBoolean(autoConversation));
+ }
+ final String propagation = filterConfig.getInitParameter(PROPAGATION);
+ if (propagation != null)
+ {
+ try
+ {
+ parameters.setPropagation(ConversationPropagation.valueOf(propagation));
+ }
+ catch (IllegalArgumentException iae)
+ {
+ log.warn("Init Param {} = {} is not a valid propagation type. Using Default {}",
+ new Object[] { PROPAGATION, propagation,
+ parameters.getPropagation().toString() });
+ }
+ }
+
+ return parameters;
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java
new file mode 100644
index 0000000..5803865
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/CdiWicketFilter.java
@@ -0,0 +1,48 @@
+/*
+ * 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.wicket.cdi;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.protocol.http.IWebApplicationFactory;
+import org.apache.wicket.protocol.http.WicketFilter;
+
+/**
+ * CdiWicketFilter is a Cdi Enabled version of WicketFilter. It uses the Managed Version of
+ * {@link CdiWebApplicationFactory} therefore the WebApplication is also Managed via the Cdi container.
+ *
+ * @author jsarman
+ */
+
+public class CdiWicketFilter extends WicketFilter
+{
+
+ @Inject
+ CdiWebApplicationFactory applicationFactory;
+
+ public CdiWicketFilter()
+ {
+ }
+
+
+ @Override
+ protected IWebApplicationFactory getApplicationFactory()
+ {
+ return applicationFactory;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
index ab620bb..79e4b78 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
@@ -23,17 +23,16 @@ import org.apache.wicket.application.IComponentInstantiationListener;
/**
* Injects components with CDI dependencies
- *
+ *
* @author igor
- *
*/
@ApplicationScoped
-class ComponentInjector extends AbstractInjector<Component> implements IComponentInstantiationListener
+public class ComponentInjector extends AbstractInjector<Component> implements IComponentInstantiationListener
{
@Override
public void onInstantiation(Component component)
- {
- inject(component);
+ {
+ inject(component);
}
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java
new file mode 100644
index 0000000..0165d2a
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConfigurationParameters.java
@@ -0,0 +1,161 @@
+/*
+ * 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.wicket.cdi;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.wicket.application.IComponentOnBeforeRenderListener;
+import org.apache.wicket.request.cycle.IRequestCycleListener;
+
+/**
+ * Simple POJO bean for storing the initial configuration parameters as well as
+ * the state of the dynamic variables used by {@link CdiConfiguration}.
+ *
+ * @author jsarman
+ */
+public class ConfigurationParameters implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private IConversationPropagation propagation = ConversationPropagation.NONBOOKMARKABLE;
+ private boolean injectComponents = true;
+ private boolean injectApplication = true;
+ private boolean injectSession = true;
+ private boolean injectBehaviors = true;
+ private boolean autoConversationManagement = false;
+ private boolean configured = false;
+
+ private Set<String> ignoredPackages = new TreeSet<String>();
+ private IRequestCycleListener activeRequestCycleListener;
+ private IComponentOnBeforeRenderListener activeComponentOnBeforeRenderListener;
+
+ public ConfigurationParameters()
+ {
+
+ }
+
+
+ public IConversationPropagation getPropagation()
+ {
+ return propagation;
+ }
+
+ ConfigurationParameters setPropagation(IConversationPropagation propagation)
+ {
+ this.propagation = propagation;
+ return this;
+ }
+
+
+ public boolean isInjectComponents()
+ {
+ return injectComponents;
+ }
+
+ ConfigurationParameters setInjectComponents(boolean injectComponents)
+ {
+ this.injectComponents = injectComponents;
+ return this;
+ }
+
+ public boolean isInjectApplication()
+ {
+ return injectApplication;
+ }
+
+ ConfigurationParameters setInjectApplication(boolean injectApplication)
+ {
+ this.injectApplication = injectApplication;
+ return this;
+ }
+
+ public boolean isInjectSession()
+ {
+ return injectSession;
+ }
+
+ ConfigurationParameters setInjectSession(boolean injectSession)
+ {
+ this.injectSession = injectSession;
+ return this;
+ }
+
+ public boolean isInjectBehaviors()
+ {
+ return injectBehaviors;
+ }
+
+ ConfigurationParameters setInjectBehaviors(boolean injectBehaviors)
+ {
+ this.injectBehaviors = injectBehaviors;
+ return this;
+ }
+
+ public boolean isAutoConversationManagement()
+ {
+ return autoConversationManagement;
+ }
+
+ ConfigurationParameters setAutoConversationManagement(boolean autoConversationManagement)
+ {
+ this.autoConversationManagement = autoConversationManagement;
+ return this;
+ }
+
+ public Set<String> getIgnoredPackages()
+ {
+ return ignoredPackages;
+ }
+
+ void setIgnoredPackages(Set<String> ignoredPackages)
+ {
+ this.ignoredPackages = ignoredPackages;
+ }
+
+ IRequestCycleListener getActiveRequestCycleListener()
+ {
+ return activeRequestCycleListener;
+ }
+
+ void setActiveRequestCycleListener(IRequestCycleListener activeRequestCycleListener)
+ {
+ this.activeRequestCycleListener = activeRequestCycleListener;
+ }
+
+ IComponentOnBeforeRenderListener getActiveComponentOnBeforeRenderListener()
+ {
+ return activeComponentOnBeforeRenderListener;
+ }
+
+ void setActiveComponentOnBeforeRenderListener(IComponentOnBeforeRenderListener activeComponentOnBeforeRenderListener)
+ {
+ this.activeComponentOnBeforeRenderListener = activeComponentOnBeforeRenderListener;
+ }
+
+ public boolean isConfigured()
+ {
+ return configured;
+ }
+
+ void setConfigured(boolean configured)
+ {
+ this.configured = configured;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
index ab62ff0..2b3e696 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
@@ -28,7 +28,7 @@ public class ConversationExpiredException extends RuntimeException
private final IRequestHandler handler;
public ConversationExpiredException(Throwable cause, String cid, Page page,
- IRequestHandler handler)
+ IRequestHandler handler)
{
super(cause);
this.cid = cid;
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
index b8c7871..989e344 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
@@ -17,9 +17,9 @@
package org.apache.wicket.cdi;
import java.io.Serializable;
+
+import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Conversation;
-import javax.enterprise.context.ConversationScoped;
-import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import org.apache.wicket.Component;
@@ -34,28 +34,24 @@ import org.slf4j.LoggerFactory;
/**
* Checks for conversation expiration during page render and throws a
* {@link ConversationExpiredException} when an expired conversation is detected.
- *
+ * <p/>
* For example a link that calls {@link Conversation#end()} but does not redirect to a
* non-conversation-dependent page will be caught by this listener.
- *
+ *
* @author igor
- *
*/
-@ConversationScoped
+@ApplicationScoped
public class ConversationExpiryChecker implements IComponentOnBeforeRenderListener, Serializable
{
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(ConversationExpiryChecker.class);
-
- @Inject
- Instance<AbstractCdiContainer> containerSource;
@Inject
- private Conversation conversation;
+ AbstractCdiContainer container;
public ConversationExpiryChecker()
{
-
+
}
@Override
@@ -64,12 +60,12 @@ public class ConversationExpiryChecker implements IComponentOnBeforeRenderListen
if (component instanceof Page || RequestCycle.get().find(AjaxRequestTarget.class) != null)
{
Page page = component.getPage();
- String cid = containerSource.get().getConversationMarker(page);
- if (cid != null && !Objects.isEqual(conversation.getId(), cid))
+ String cid = container.getConversationMarker(page);
+ if (cid != null && !Objects.isEqual(container.getCurrentConversation().getId(), cid))
{
logger.info("Conversation {} has expired for {}", cid, page);
throw new ConversationExpiredException(null, cid, page, RequestCycle.get()
- .getActiveRequestHandler());
+ .getActiveRequestHandler());
}
}
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java
new file mode 100644
index 0000000..d7b2885
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationManager.java
@@ -0,0 +1,123 @@
+/*
+ * 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.wicket.cdi;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.Conversation;
+import javax.enterprise.context.ConversationScoped;
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author jsarman
+ */
+@ConversationScoped
+public class ConversationManager implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = LoggerFactory.getLogger(ConversationManager.class);
+
+ @Inject
+ AbstractCdiContainer container;
+
+ @Inject
+ @Auto
+ Boolean globalAuto;
+
+ @Inject
+ @Propagation
+ IConversationPropagation globalPropagation;
+
+ IConversationPropagation propagation;
+ Boolean manageConversation;
+
+ boolean terminateConversation;
+
+ @PostConstruct
+ public void init()
+ {
+ logger.debug("Starting new Conversation manager for id = {}", getConversation().getId());
+ propagation = globalPropagation;
+ manageConversation = globalAuto;
+ logger.debug("Setting initial values to auto = {} prop = {}", manageConversation, propagation);
+ }
+
+ private Conversation getConversation()
+ {
+ return container.getCurrentConversation();
+ }
+
+ public IConversationPropagation getPropagation()
+ {
+ return propagation;
+ }
+
+ public void setPropagation(IConversationPropagation propagation)
+ {
+ if (propagation == null)
+ {
+ throw new IllegalArgumentException("Propagation cannot be null");
+ }
+ if (this.propagation == propagation)
+ {
+ return;
+ }
+
+ logger.debug("Changing conversation dependent propagation to {} for id = {}",
+ propagation, getConversation().getId());
+
+ this.propagation = propagation;
+ }
+
+ public Boolean getManageConversation()
+ {
+ return manageConversation;
+ }
+
+ public void setManageConversation(boolean manageConversation)
+ {
+ if (this.manageConversation == manageConversation)
+ {
+ return;
+ }
+ logger.debug("Setting conversation dependent manageConversation to {} for id = {} ",
+ manageConversation, getConversation().getId());
+
+ this.manageConversation = manageConversation;
+ }
+
+ void cancelConversationEnd()
+ {
+ terminateConversation = false;
+ }
+
+ void scheduleConversationEnd()
+ {
+ terminateConversation = true;
+ }
+
+ boolean isConversationScheduledForEnd()
+ {
+ return terminateConversation;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
index e9ef296..e59953d 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
@@ -16,62 +16,66 @@
*/
package org.apache.wicket.cdi;
-import javax.enterprise.context.ConversationScoped;
+
import org.apache.wicket.Page;
import org.apache.wicket.request.IRequestHandler;
/**
* Various modes of propagating persistent conversations across requests.
- *
- * @see ConversationScoped
- *
+ *
* @author igor
*/
-public enum ConversationPropagation implements IConversationPropagation {
- /** No conversational propagation takes place */
- NONE {
- @Override
- public boolean propagatesViaPage(Page page, IRequestHandler handler)
- {
- return false;
- }
+public enum ConversationPropagation implements IConversationPropagation
+{
+ /**
+ * No conversational propagation takes place
+ */
+ NONE
+ {
+ @Override
+ public boolean propagatesViaPage(Page page, IRequestHandler handler)
+ {
+ return false;
+ }
- @Override
- public boolean propagatesViaParameters(IRequestHandler handler)
- {
- return false;
- }
- },
+ @Override
+ public boolean propagatesViaParameters(IRequestHandler handler)
+ {
+ return false;
+ }
+ },
/**
* Persistent conversations are propagated between non-bookmarkable pages only
*/
- NONBOOKMARKABLE {
- @Override
- public boolean propagatesViaPage(Page page, IRequestHandler handler)
- {
- return true;
- }
+ NONBOOKMARKABLE
+ {
+ @Override
+ public boolean propagatesViaPage(Page page, IRequestHandler handler)
+ {
+ return true;
+ }
- @Override
- public boolean propagatesViaParameters(IRequestHandler handler)
- {
- return false;
- }
- },
+ @Override
+ public boolean propagatesViaParameters(IRequestHandler handler)
+ {
+ return false;
+ }
+ },
/**
* Persistent conversations are propagated between bookmarkable and non-bookmarkable pages
*/
- ALL {
- @Override
- public boolean propagatesViaPage(Page page, IRequestHandler handler)
- {
- return true;
- }
+ ALL
+ {
+ @Override
+ public boolean propagatesViaPage(Page page, IRequestHandler handler)
+ {
+ return true;
+ }
- @Override
- public boolean propagatesViaParameters(IRequestHandler handler)
- {
- return true;
- }
- };
+ @Override
+ public boolean propagatesViaParameters(IRequestHandler handler)
+ {
+ return true;
+ }
+ };
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
index 94991b4..7833cf7 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
@@ -16,13 +16,12 @@
*/
package org.apache.wicket.cdi;
-import java.io.Serializable;
+
+import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Conversation;
-import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.NonexistentConversationException;
-import javax.enterprise.inject.Instance;
import javax.inject.Inject;
-import org.apache.wicket.Application;
+
import org.apache.wicket.Component;
import org.apache.wicket.MetaDataKey;
import org.apache.wicket.Page;
@@ -35,7 +34,6 @@ import org.apache.wicket.request.IRequestHandlerDelegate;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.component.IRequestablePage;
import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
-import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.handler.resource.ResourceReferenceRequestHandler;
import org.apache.wicket.request.mapper.parameter.PageParameters;
@@ -49,77 +47,60 @@ import org.slf4j.LoggerFactory;
/**
* A request cycle listener that takes care of propagating persistent conversations.
- *
- * @see ConversationScoped
- *
+ *
* @author igor
*/
-@ConversationScoped
-public class ConversationPropagator extends AbstractRequestCycleListener implements Serializable
+@ApplicationScoped
+public class ConversationPropagator extends AbstractRequestCycleListener
{
- private static final long serialVersionUID = 1L;
+
private static final Logger logger = LoggerFactory.getLogger(ConversationPropagator.class);
private static final MetaDataKey<String> CID_KEY = ConversationIdMetaKey.INSTANCE;
- private static final MetaDataKey<Boolean> CONVERSATION_STARTED_KEY = new MetaDataKey<Boolean>()
- {
- private static final long serialVersionUID = 1L;
- };
-
static final String CID_ATTR = "cid";
-
- @Inject
- Instance<AbstractCdiContainer> containerSource;
- /** propagation mode to use */
- @Propagation
@Inject
- Instance<IConversationPropagation> propagationSource;
-
- @Auto
+ CdiConfiguration cdiConfiguration;
+
@Inject
- Instance<Boolean> auto;
+ AbstractCdiContainer container;
@Inject
- Conversation conversation_;
+ ConversationManager conversationManager;
- /**
- * Constructor
- *
- * @param container
- * @param propagation
- */
- public ConversationPropagator()
- {
- }
-
- private Conversation getConversation(RequestCycle cycle)
+ private Conversation getConversation()
{
- return Boolean.TRUE.equals(cycle.getMetaData(CONVERSATION_STARTED_KEY)) ? conversation_
- : null;
+ return container.getCurrentConversation();
}
@Override
public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
{
+ Conversation conversation = getConversation();
+ logger.debug("In onRequestHandlerResolved id = {}", conversation.getId());
String cid = cycle.getRequest().getRequestParameters().getParameterValue(CID_ATTR).toString();
Page page = getPage(handler);
- if (cid == null && page != null)
+ if (page == null)
+ {
+ return;
+ }
+
+ if (cid == null)
{
cid = page.getMetaData(CID_KEY);
}
- Conversation current = getConversation(cycle);
- if (current != null && !Objects.isEqual(current.getId(), cid))
+
+ if (cid != null && !conversation.isTransient() && !Objects.isEqual(conversation.getId(), cid))
{
logger.info("Conversation {} has expired for {}", cid, page);
throw new ConversationExpiredException(null, cid, page, handler);
}
- activateConversationIfNeeded(cycle, handler, cid);
+ activateConversationIfNeeded(page, cycle, handler, cid);
}
@Override
@@ -130,18 +111,18 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
if (ex instanceof StalePageException)
{
- IRequestablePage requestable = ((StalePageException)ex).getPage();
+ IRequestablePage requestable = ((StalePageException) ex).getPage();
if (requestable instanceof Page)
{
- String cid = containerSource.get().getConversationMarker((Page)requestable);
+ Page page = (Page) requestable;
+ String cid = container.getConversationMarker(page);
if (cid != null)
{
try
{
- activateConversationIfNeeded(cycle, null, cid);
+ activateConversationIfNeeded(page, cycle, null, cid);
return null;
- }
- catch (ConversationExpiredException e)
+ } catch (ConversationExpiredException e)
{
// ignore, we will start a new one below
}
@@ -149,59 +130,42 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
}
}
- activateConversationIfNeeded(cycle, null, null);
+ activateConversationIfNeeded(null, cycle, null, null);
return null;
}
- private void activateConversationIfNeeded(RequestCycle cycle, IRequestHandler handler,
- String cid)
+ private void activateConversationIfNeeded(Page page, RequestCycle cycle, IRequestHandler handler,
+ String cid)
{
- Conversation current = getConversation(cycle);
-
- if (current != null || !activateForHandler(handler))
+ if (!activateForHandler(handler))
{
return;
}
- logger.debug("Activating conversation {}", cid);
-
try
{
- containerSource.get().activateConversationalContext(cycle, cid);
- fireOnAfterConversationStarted(cycle);
- }
- catch (NonexistentConversationException e)
+ Conversation conversation = getConversation();
+
+ if (!(conversation.isTransient() && cid == null))
+ {
+ logger.debug("Activating conversation {}", cid);
+ container.activateConversationalContext(cycle, cid);
+ }
+
+ } catch (NonexistentConversationException e)
{
logger.info("Unable to restore conversation with id {}", cid, e.getMessage());
logger.debug("Unable to restore conversation", e);
- fireOnAfterConversationStarted(cycle);
throw new ConversationExpiredException(e, cid, getPage(handler), handler);
}
- cycle.setMetaData(CONVERSATION_STARTED_KEY, true);
- }
-
- private void fireOnAfterConversationStarted(RequestCycle cycle)
- {
- for (IRequestCycleListener listener : Application.get().getRequestCycleListeners())
- {
- if (listener instanceof ICdiAwareRequestCycleListener)
- {
- ((ICdiAwareRequestCycleListener)listener).onAfterConversationActivated(cycle);
- }
- }
}
@Override
public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler)
{
- Conversation conversation = getConversation(cycle);
-
- if (conversation == null)
- {
- return;
- }
-
+ Conversation conversation = getConversation();
+ logger.debug("In onRequestHandlerExecuted id = {}", conversation.getId());
Page page = getPage(handler);
if (page == null)
@@ -209,15 +173,17 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
return;
}
- // apply auto semantics
-
- autoEndIfNecessary(page, handler, conversation);
- autoBeginIfNecessary(page, handler, conversation);
-
- if (propagationSource.get().propagatesViaPage(page, handler))
+ if (autoEndIfNecessary(page, handler, conversation))
+ {
+ container.activateConversationalContext(cycle, null);
+ } else
+ {
+ autoBeginIfNecessary(page, handler);
+ }
+ if (getPropagation().propagatesViaPage(page, handler))
{
// propagate a conversation across non-bookmarkable page instances
- setConversationOnPage(conversation, page);
+ setConversationOnPage(page);
}
}
@@ -226,113 +192,121 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
{
// propagate current non-transient conversation to the newly scheduled page
- Conversation conversation = getConversation(cycle);
-
- if (conversation == null || conversation.isTransient())
+ Conversation conversation = getConversation();
+ logger.debug("In onRequestHandlerScheduled id = {}", conversation.getId());
+ if (conversation.isTransient())
{
return;
}
-
+ boolean propagated = false;
Page page = getPage(handler);
if (page != null)
{
- if (propagationSource.get().propagatesViaPage(page, handler))
+ if (getPropagation().propagatesViaPage(page, handler))
{
// propagate a conversation across non-bookmarkable page instances
- setConversationOnPage(conversation, page);
+ setConversationOnPage(page);
+ propagated = true;
}
}
- if (propagationSource.get().propagatesViaParameters(handler))
+ if (getPropagation().propagatesViaParameters(handler))
{
// propagate cid to a scheduled bookmarkable page
logger.debug(
- "Propagating non-transient conversation {} via page parameters of handler {}",
- conversation.getId(), handler);
+ "Propagating non-transient conversation {} via page parameters of handler {}",
+ conversation.getId(), handler);
PageParameters parameters = getPageParameters(handler);
if (parameters != null)
{
parameters.set(CID_ATTR, conversation.getId());
+ propagated = true;
}
}
+ if (!propagated && getAuto())
+ {
+ getConversationManager().scheduleConversationEnd();
+ }
}
- protected void setConversationOnPage(Conversation conversation, Page page)
+ protected void setConversationOnPage(Page page)
{
- if (conversation == null || conversation.isTransient())
+ Conversation conversation = getConversation();
+ if (conversation.isTransient())
{
- logger.debug("Detaching transient conversation {} via meta of page instance {}",
- (conversation == null ? "null" : conversation.getId()), page);
-
- page.setMetaData(CID_KEY, null);
- }
- else
+ clearConversationOnPage(page);
+ } else
{
logger.debug("Propagating non-transient conversation {} via meta of page instance {}",
- conversation.getId(), page);
+ conversation.getId(), page);
page.setMetaData(CID_KEY, conversation.getId());
}
}
+ protected void clearConversationOnPage(Page page)
+ {
+ Conversation conversation = getConversation();
+ logger.debug("Detaching transient conversation {} via meta of page instance {}",
+ conversation.getId(), page);
+
+ page.setMetaData(CID_KEY, null);
+ }
+
@Override
public void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url)
{
+ Conversation conversation = getConversation();
+ logger.debug("In onUrlMapped id = {}", conversation.getId());
// no need to propagate the conversation to packaged resources, they should never change
if (handler instanceof ResourceReferenceRequestHandler)
{
- if (((ResourceReferenceRequestHandler)handler).getResourceReference() instanceof PackageResourceReference)
+ if (((ResourceReferenceRequestHandler) handler).getResourceReference() instanceof PackageResourceReference)
{
return;
}
}
- Conversation conversation = getConversation(cycle);
- if (conversation == null || conversation.isTransient())
+ if (conversation.isTransient())
{
return;
}
- if (propagationSource.get().propagatesViaParameters(handler))
+ if (getPropagation().propagatesViaParameters(handler))
{
// propagate cid to bookmarkable pages via urls
logger.debug("Propagating non-transient conversation {} via url", conversation.getId());
url.setQueryParameter(CID_ATTR, conversation.getId());
- }
- }
-
- @Override
- public void onDetach(RequestCycle cycle)
- {
- Conversation conversation = getConversation(cycle);
- if (conversation != null)
+ } else
{
- logger.debug("Deactivating conversation {}", conversation.getId());
-
- for (IRequestCycleListener listener : Application.get().getRequestCycleListeners())
+ //we did not propagate.
+ //Cancel scheduled conversation end if page is auto.
+ Page page = getPage(handler);
+ if (page != null)
{
- if (listener instanceof ICdiAwareRequestCycleListener)
+ Conversational annotation = page.getClass().getAnnotation(Conversational.class);
+ if (annotation != null)
{
- ((ICdiAwareRequestCycleListener)listener).onBeforeConversationDeactivated(cycle);
+ if (annotation.auto() && getConversationManager().isConversationScheduledForEnd())
+ {
+ getConversationManager().cancelConversationEnd(); //was scheduled to end but next page is auto
+ }
}
}
- containerSource.get().deactivateConversationalContext(cycle);
-
- cycle.setMetaData(CONVERSATION_STARTED_KEY, null);
}
}
/**
- * Determines whether or not a conversation should be activated fro the specified handler. This
+ * Determines whether or not a conversation should be activated for the specified handler. This
* method is used to filter out conversation activation for utility handlers such as the
* {@link BufferedResponseRequestHandler}
- *
+ *
* @param handler
* @return {@code true} iff a conversation should be activated
*/
@@ -349,40 +323,68 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
return true;
}
- protected void autoBeginIfNecessary(Page page, IRequestHandler handler,
- Conversation conversation)
+ protected void autoBeginIfNecessary(Page page, IRequestHandler handler)
{
- if (!auto.get() || conversation == null || !conversation.isTransient() || page == null ||
- !propagationSource.get().propagatesViaPage(page, handler) || !hasConversationalComponent(page))
+
+ if (page == null)
{
return;
}
- // auto activate conversation
+ Conversational annotation = page.getClass().getAnnotation(Conversational.class);
- conversation.begin();
+ boolean auto = getAuto();
+ auto |= annotation == null ? false : annotation.auto();
- logger.debug("Auto-began conversation {} for page {}", conversation.getId(), page);
- }
-
- protected void autoEndIfNecessary(Page page, IRequestHandler handler, Conversation conversation)
- {
- if (!auto.get() || conversation == null || conversation.isTransient() || page == null ||
- !propagationSource.get().propagatesViaPage(page, handler) || hasConversationalComponent(page))
+ // possibly changing propagation and auto is not set
+ if (annotation == null && !auto)
{
return;
}
- // auto de-activate conversation
-
- String cid = conversation.getId();
+ if (getConversation().isTransient())
+ {
+ if (auto)
+ {
+ getConversation().begin();
+ logger.debug("Auto-began conversation {} for page {}", getConversation().getId(), page);
+ }
+ }
+ ConversationPropagation prop = annotation != null ? annotation.prop() : getPropagation();
+ // The conversationManager is attached to a conversation so update
+ if (!getConversation().isTransient())
+ {
+ getConversationManager().setPropagation(prop);
+ getConversationManager().setManageConversation(auto);
+ } else
+ {
+ if (prop != getPropagation())
+ {
+ logger.info("Not setting propagation to {} because no conversation is started.",
+ prop);
+ }
+ }
+ }
- conversation.end();
+ protected boolean autoEndIfNecessary(Page page, IRequestHandler handler, Conversation conversation)
+ {
+ if (page == null || conversation.isTransient())
+ {
+ return false;
+ }
- logger.debug("Auto-ended conversation {} for page {}", cid, page);
+ boolean endConversation = getConversationManager().isConversationScheduledForEnd();
+ if (endConversation)
+ {
+ String cid = conversation.getId();
+ getConversation().end();
+ logger.debug("Auto-ended conversation {} for page {}", cid, page);
+ }
+ return endConversation;
}
+ // Currently not being used will reinvestigate this concept.
protected boolean hasConversationalComponent(Page page)
{
Boolean hasConversational = Visits.visit(page, new IVisitor<Component, Boolean>()
@@ -390,7 +392,8 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
@Override
public void component(Component object, IVisit<Boolean> visit)
{
- if (object instanceof ConversationalComponent)
+ Conversational annotation = object.getClass().getAnnotation(Conversational.class);
+ if (annotation != null)
{
visit.stop(true);
}
@@ -402,7 +405,7 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
/**
* Resolves a page instance from the request handler iff the page instance is already created
- *
+ *
* @param handler
* @return page or {@code null} if none
*/
@@ -410,15 +413,15 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
{
while (handler instanceof IRequestHandlerDelegate)
{
- handler = ((IRequestHandlerDelegate)handler).getDelegateHandler();
+ handler = ((IRequestHandlerDelegate) handler).getDelegateHandler();
}
if (handler instanceof IPageRequestHandler)
{
- IPageRequestHandler pageHandler = (IPageRequestHandler)handler;
+ IPageRequestHandler pageHandler = (IPageRequestHandler) handler;
if (pageHandler.isPageInstanceCreated())
{
- return (Page)pageHandler.getPage();
+ return (Page) pageHandler.getPage();
}
}
return null;
@@ -426,7 +429,7 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
/**
* Resolves page parameters from a request handler
- *
+ *
* @param handler
* @return page parameters or {@code null} if none
*/
@@ -434,18 +437,41 @@ public class ConversationPropagator extends AbstractRequestCycleListener impleme
{
if (handler instanceof IPageClassRequestHandler)
{
- IPageClassRequestHandler pageHandler = (IPageClassRequestHandler)handler;
+ IPageClassRequestHandler pageHandler = (IPageClassRequestHandler) handler;
return pageHandler.getPageParameters();
}
return null;
}
- Boolean getAuto() {
- return auto.get();
- }
-
- ConversationPropagation getPropagation() {
- return (ConversationPropagation)propagationSource.get();
- }
-
+ ConversationManager getConversationManager()
+ {
+ if (getConversation().isTransient())
+ {
+ logger.warn("Accessing Conversation Manager from transient Conversation Context");
+ }
+ return conversationManager;
+ }
+
+ Boolean getAuto()
+ {
+ if (getConversation().isTransient())
+ {
+ logger.debug("Getting Global Auto setting");
+ return cdiConfiguration.isAutoConversationManagement();
+ }
+ logger.debug("Getting Auto setting for conversation = {}", getConversation().getId());
+ return getConversationManager().getManageConversation();
+ }
+
+ ConversationPropagation getPropagation()
+ {
+ if (getConversation().isTransient())
+ {
+ logger.debug("Getting global Propagation {}.", cdiConfiguration.getPropagation());
+ return (ConversationPropagation) cdiConfiguration.getPropagation();
+ }
+ logger.debug("Propagation is set to {} with id = {}", getConversationManager().getPropagation(), getConversation().getId());
+ return (ConversationPropagation) getConversationManager().getPropagation();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Conversational.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Conversational.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Conversational.java
new file mode 100644
index 0000000..ec5e5e9
--- /dev/null
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/Conversational.java
@@ -0,0 +1,41 @@
+/*
+ * 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.wicket.cdi;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.Typed;
+
+import org.apache.wicket.Page;
+
+/**
+ * @author jsarman
+ */
+@Documented
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Typed(Page.class)
+public @interface Conversational
+{
+ ConversationPropagation prop() default ConversationPropagation.NONBOOKMARKABLE;
+
+ boolean auto() default true;
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java
index e041a87..2230435 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java
@@ -21,9 +21,10 @@ package org.apache.wicket.cdi;
* management feature ({@link CdiConfiguration#setAutoConversationManagement(boolean)}) to
* automatically begin and end conversations based on the presence of these components in the
* component hierarchy of pages (can be applied to the page itself).
- *
+ *
* @author igor
*/
+@Conversational
public interface ConversationalComponent
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/62fed8f5/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEvent.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEvent.java b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEvent.java
index ac99ec3..531e617 100644
--- a/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEvent.java
+++ b/wicket-experimental/wicket-cdi-1.1/wicket-cdi-1.1-core/src/main/java/org/apache/wicket/cdi/DetachEvent.java
@@ -18,9 +18,8 @@ package org.apache.wicket.cdi;
/**
* Fired when request cycle is detached
- *
+ *
* @author igor
- *
*/
public class DetachEvent
{