WICKET-6581 Module wicket-cdi-1.1 migrated to CDI 2 and name changed to wicket-cdi. Solved dependecy problems with weld versions.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/057c402b Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/057c402b Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/057c402b Branch: refs/heads/master Commit: 057c402b473bcb027176d60710e5aadfa9c7f55e Parents: 056d726 Author: Andrea Del Bene <[email protected]> Authored: Mon Sep 24 21:21:29 2018 +0200 Committer: Andrea Del Bene <[email protected]> Committed: Mon Sep 24 22:06:53 2018 +0200 ---------------------------------------------------------------------- pom.xml | 42 +-- .../testing/WicketJavaEEApplication.java | 6 +- wicket-cdi-1.1/pom.xml | 93 ------ .../org/apache/wicket/cdi/AbstractInjector.java | 39 --- .../org/apache/wicket/cdi/AutoConversation.java | 50 --- .../wicket/cdi/AutoConversationManager.java | 121 ------- .../apache/wicket/cdi/BeanManagerLookup.java | 128 ------- .../org/apache/wicket/cdi/BehaviorInjector.java | 42 --- .../org/apache/wicket/cdi/CdiConfiguration.java | 126 ------- .../apache/wicket/cdi/CdiShutdownCleaner.java | 39 --- .../apache/wicket/cdi/ComponentInjector.java | 43 --- .../cdi/ConversationExpiredException.java | 52 --- .../wicket/cdi/ConversationExpiryChecker.java | 70 ---- .../wicket/cdi/ConversationPropagation.java | 62 ---- .../wicket/cdi/ConversationPropagator.java | 291 ---------------- .../wicket/cdi/ConversationalComponent.java | 30 -- .../java/org/apache/wicket/cdi/DetachEvent.java | 28 -- .../apache/wicket/cdi/DetachEventEmitter.java | 75 ----- .../cdi/ICdiAwareRequestCycleListener.java | 41 --- .../wicket/cdi/IConversationPropagation.java | 47 --- .../org/apache/wicket/cdi/NonContextual.java | 164 --------- .../org/apache/wicket/cdi/SessionInjector.java | 42 --- .../src/main/resources/META-INF/beans.xml | 4 - .../wicket/cdi/ApacheLicenceHeaderTest.java | 42 --- .../apache/wicket/cdi/CdiConfigurationTest.java | 68 ---- .../org/apache/wicket/cdi/CdiWicketTester.java | 129 ------- .../org/apache/wicket/cdi/ContextManager.java | 106 ------ .../wicket/cdi/ConversationPropagatorTest.java | 202 ----------- .../apache/wicket/cdi/WicketCdiTestCase.java | 185 ----------- .../apache/wicket/cdi/testapp/TestAppScope.java | 40 --- .../wicket/cdi/testapp/TestApplication.java | 39 --- .../wicket/cdi/testapp/TestCdiApplication.java | 54 --- .../cdi/testapp/TestConversationBean.java | 56 ---- .../cdi/testapp/TestConversationPage.html | 12 - .../cdi/testapp/TestConversationPage.java | 84 ----- .../cdi/testapp/TestConversationalPage.html | 12 - .../cdi/testapp/TestConversationalPage.java | 78 ----- .../cdi/testapp/TestNonConversationalPage.html | 11 - .../cdi/testapp/TestNonConversationalPage.java | 55 --- .../org/apache/wicket/cdi/testapp/TestPage.html | 10 - .../org/apache/wicket/cdi/testapp/TestPage.java | 40 --- .../wicket/cdi/testapp/TestQualifier.java | 35 -- .../src/test/java/simplelogger.properties | 1 - wicket-cdi/pom.xml | 35 +- .../org/apache/wicket/cdi/AbstractInjector.java | 12 +- .../org/apache/wicket/cdi/AutoConversation.java | 7 +- .../wicket/cdi/AutoConversationManager.java | 121 +++++++ .../apache/wicket/cdi/BeanManagerLookup.java | 128 +++++++ .../org/apache/wicket/cdi/BehaviorInjector.java | 7 +- .../org/apache/wicket/cdi/CdiConfiguration.java | 184 +++------- .../org/apache/wicket/cdi/CdiContainer.java | 167 ---------- .../apache/wicket/cdi/CdiShutdownCleaner.java | 20 +- .../apache/wicket/cdi/ComponentInjector.java | 5 +- .../cdi/ConversationExpiredException.java | 3 +- .../wicket/cdi/ConversationExpiryChecker.java | 22 +- .../wicket/cdi/ConversationIdMetaKey.java | 24 -- .../wicket/cdi/ConversationPropagation.java | 32 +- .../wicket/cdi/ConversationPropagator.java | 312 ++++------------- .../wicket/cdi/ConversationalComponent.java | 10 +- .../apache/wicket/cdi/DetachEventEmitter.java | 11 +- .../wicket/cdi/IConversationPropagation.java | 32 +- .../wicket/cdi/INonContextualManager.java | 55 --- .../org/apache/wicket/cdi/NonContextual.java | 332 +++++++++---------- .../apache/wicket/cdi/NonContextualManager.java | 78 ----- .../org/apache/wicket/cdi/SessionInjector.java | 5 +- .../src/main/resources/META-INF/beans.xml | 4 + .../wicket/cdi/ApacheLicenceHeaderTest.java | 6 +- .../apache/wicket/cdi/CdiConfigurationTest.java | 68 ++++ .../org/apache/wicket/cdi/CdiWicketTester.java | 129 +++++++ .../org/apache/wicket/cdi/ContextManager.java | 106 ++++++ .../wicket/cdi/ConversationPropagatorTest.java | 202 +++++++++++ .../apache/wicket/cdi/WicketCdiTestCase.java | 185 +++++++++++ .../apache/wicket/cdi/testapp/TestAppScope.java | 40 +++ .../wicket/cdi/testapp/TestApplication.java | 39 +++ .../wicket/cdi/testapp/TestCdiApplication.java | 54 +++ .../cdi/testapp/TestConversationBean.java | 56 ++++ .../cdi/testapp/TestConversationPage.html | 12 + .../cdi/testapp/TestConversationPage.java | 84 +++++ .../cdi/testapp/TestConversationalPage.html | 12 + .../cdi/testapp/TestConversationalPage.java | 78 +++++ .../cdi/testapp/TestNonConversationalPage.html | 11 + .../cdi/testapp/TestNonConversationalPage.java | 55 +++ .../org/apache/wicket/cdi/testapp/TestPage.html | 10 + .../org/apache/wicket/cdi/testapp/TestPage.java | 40 +++ .../wicket/cdi/testapp/TestQualifier.java | 35 ++ .../src/test/java/simplelogger.properties | 1 + wicket-examples/pom.xml | 4 +- wicket-ioc/pom.xml | 9 +- 88 files changed, 1858 insertions(+), 3878 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index da33efc..935278b 100644 --- a/pom.xml +++ b/pom.xml @@ -108,7 +108,6 @@ <module>testing/wicket-arquillian</module> <module>wicket-native-websocket</module> <module>wicket-bean-validation</module> - <module>wicket-cdi-1.1</module> <module>wicket-user-guide</module> </modules> <properties> @@ -294,12 +293,6 @@ </dependency> <dependency> <groupId>org.apache.wicket</groupId> - <artifactId>wicket-cdi-1.1</artifactId> - <version>9.0.0-SNAPSHOT</version> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.apache.wicket</groupId> <artifactId>wicket-core</artifactId> <version>9.0.0-SNAPSHOT</version> <type>jar</type> @@ -418,34 +411,19 @@ <type>jar</type> </dependency> <dependency> - <groupId>org.jboss.weld</groupId> - <artifactId>weld-api</artifactId> - <version>3.0.SP4</version> - </dependency> - <dependency> - <groupId>org.jboss.weld</groupId> - <artifactId>weld-core</artifactId> - <version>2.4.7.Final</version> - </dependency> - <dependency> - <groupId>org.jboss.weld</groupId> - <artifactId>weld-core-impl</artifactId> - <version>3.0.5.Final</version> - </dependency> - <dependency> - <groupId>org.jboss.weld</groupId> - <artifactId>weld-spi</artifactId> - <version>3.0.SP4</version> - </dependency> - <dependency> <groupId>org.jboss.weld.module</groupId> <artifactId>weld-web</artifactId> <version>3.0.4.Final</version> </dependency> <dependency> - <groupId>org.jboss.weld.servlet</groupId> - <artifactId>weld-servlet</artifactId> - <version>2.4.2.SP1</version> + <groupId>org.jboss.weld.se</groupId> + <artifactId>weld-se-core</artifactId> + <version>3.0.4.Final</version> + </dependency> + <dependency> + <groupId>org.jboss.weld.servlet</groupId> + <artifactId>weld-servlet-core</artifactId> + <version>3.0.4.Final</version> </dependency> <dependency> <groupId>org.objenesis</groupId> @@ -578,7 +556,7 @@ <dependency> <groupId>org.jglue.cdi-unit</groupId> <artifactId>cdi-unit</artifactId> - <version>4.0.2</version> + <version>4.1.0</version> <scope>test</scope> </dependency> <dependency> @@ -1003,7 +981,7 @@ <includes> <include>**/*Test.java</include> </includes> - <argLine>--add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-modules=ALL-SYSTEM</argLine> + </configuration> <dependencies> <dependency> http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/testing/wicket-arquillian/src/main/java/org/apache/wicket/arquillian/testing/WicketJavaEEApplication.java ---------------------------------------------------------------------- diff --git a/testing/wicket-arquillian/src/main/java/org/apache/wicket/arquillian/testing/WicketJavaEEApplication.java b/testing/wicket-arquillian/src/main/java/org/apache/wicket/arquillian/testing/WicketJavaEEApplication.java index 6dc0c93..13f57bf 100644 --- a/testing/wicket-arquillian/src/main/java/org/apache/wicket/arquillian/testing/WicketJavaEEApplication.java +++ b/testing/wicket-arquillian/src/main/java/org/apache/wicket/arquillian/testing/WicketJavaEEApplication.java @@ -60,8 +60,10 @@ public class WicketJavaEEApplication extends WebApplication { initResourceFinder(); // Configure CDI, disabling Conversations as we aren't using them - new CdiConfiguration(bm).setPropagation(ConversationPropagation.NONE).configure(this); - + CdiConfiguration cdiConfiguration = new CdiConfiguration(); + cdiConfiguration.setPropagation(ConversationPropagation.NONE).configure(this); + cdiConfiguration.setFallbackBeanManager(bm); + // Mount the InsertContact page at /insert mountPage("/insert", InsertContact.class); } http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/pom.xml b/wicket-cdi-1.1/pom.xml deleted file mode 100644 index 18448d4..0000000 --- a/wicket-cdi-1.1/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-parent</artifactId> - <version>9.0.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>wicket-cdi-1.1</artifactId> - <packaging>bundle</packaging> - <name>Wicket CDI 1.1</name> - <description> - Provides integration between Wicket and CDI containers. Enables injection of - components and behaviors, as well as other non-contextual object instances. - Also enables propagation of conversations between wicket artifacts such as pages - and resources. - </description> - <dependencyManagement> - <dependencies> - <!-- local management because we can only define one GAV in the parent --> - <dependency> - <groupId>javax.enterprise</groupId> - <artifactId>cdi-api</artifactId> - <version>1.1</version> - <scope>provided</scope> - </dependency> - </dependencies> - </dependencyManagement> - <dependencies> - <dependency> - <groupId>javax.enterprise</groupId> - <artifactId>cdi-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-core</artifactId> - </dependency> - <dependency> - <groupId>org.jboss.weld</groupId> - <artifactId>weld-core</artifactId> - </dependency> - <dependency> - <groupId>org.jboss.weld</groupId> - <artifactId>weld-spi</artifactId> - </dependency> - <dependency> - <groupId>org.jboss.weld.module</groupId> - <artifactId>weld-web</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.jboss.weld.se</groupId> - <artifactId>weld-se</artifactId> - </dependency> - <dependency> - <groupId>org.jglue.cdi-unit</groupId> - <artifactId>cdi-unit</artifactId> - </dependency> - </dependencies> - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-enforcer-plugin</artifactId> - <configuration> - <skip>true</skip> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> -</project> http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java deleted file mode 100644 index cf8d67f..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AbstractInjector.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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; - -/** - * Base class for injectors - * - * @author igor - */ -class AbstractInjector -{ - public AbstractInjector() - { - } - - protected <T> void postConstruct(T instance) - { - NonContextual.of(instance).postConstruct(instance); - } - - protected <T> void inject(T instance) - { - NonContextual.of(instance).inject(instance); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java deleted file mode 100644 index 90f5e19..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.context.ConversationScoped; - -import org.apache.wicket.util.io.IClusterable; - -/** - * A bean that can be used to override whether the lifecycle of the conversation - * should be managed automatically or not. - * - * @author igor - */ -@ConversationScoped -public class AutoConversation implements IClusterable -{ - private static final long serialVersionUID = 1L; - - private boolean automatic; - - public AutoConversation() - { - automatic = false; - } - - public void setAutomatic(boolean automatic) - { - this.automatic = automatic; - } - - public boolean isAutomatic() - { - return automatic; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java deleted file mode 100644 index 4aedb48..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.context.Conversation; -import javax.inject.Inject; - -import org.apache.wicket.Component; -import org.apache.wicket.Page; -import org.apache.wicket.application.IComponentOnBeforeRenderListener; -import org.apache.wicket.request.IRequestHandler; -import org.apache.wicket.request.cycle.RequestCycle; -import org.apache.wicket.util.visit.IVisit; -import org.apache.wicket.util.visit.IVisitor; -import org.apache.wicket.util.visit.Visits; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Automatically starts and ends conversations for pages with a - * {@link ConversationalComponent}. - * - * @author papegaaij - */ -public class AutoConversationManager implements IComponentOnBeforeRenderListener -{ - private static final Logger logger = LoggerFactory.getLogger(AutoConversationManager.class); - - @Inject - private Conversation conversation; - - @Inject - private AutoConversation autoConversation; - - private IConversationPropagation propagation; - - public AutoConversationManager(IConversationPropagation propagation) - { - NonContextual.of(AutoConversationManager.class).inject(this); - this.propagation = propagation; - } - - @Override - public void onBeforeRender(Component component) - { - if (component instanceof Page) - { - Page page = (Page)component; - IRequestHandler activeRequestHandler = page.getRequestCycle().getActiveRequestHandler(); - autoEndIfNecessary(page, activeRequestHandler); - autoBeginIfNecessary(page, activeRequestHandler); - } - } - - protected void autoBeginIfNecessary(Page page, IRequestHandler handler) - { - if (conversation == null || !conversation.isTransient() || page == null - || !hasConversationalComponent(page) || !propagation.propagatesVia(handler, page)) - { - return; - } - - // auto activate conversation - - conversation.begin(); - autoConversation.setAutomatic(true); - - logger.debug("Auto-began conversation '{}' for page '{}'", conversation.getId(), page); - } - - protected void autoEndIfNecessary(Page page, IRequestHandler handler) - { - if (conversation == null || conversation.isTransient() || page == null - || hasConversationalComponent(page) || !propagation.propagatesVia(handler, page) - || autoConversation.isAutomatic() == false) - { - return; - } - - // auto de-activate conversation - - String cid = conversation.getId(); - - autoConversation.setAutomatic(false); - conversation.end(); - ConversationPropagator.removeConversationIdFromPage(page); - - logger.debug("Auto-ended conversation '{}' for page '{}'", cid, page); - } - - protected boolean hasConversationalComponent(Page page) - { - Boolean hasConversational = Visits.visit(page, new IVisitor<Component, Boolean>() - { - @Override - public void component(Component object, IVisit<Boolean> visit) - { - if (object instanceof ConversationalComponent) - { - visit.stop(true); - } - } - }); - - return hasConversational == null ? false : hasConversational; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java deleted file mode 100644 index f44e513..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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.inject.spi.BeanManager; -import javax.enterprise.inject.spi.CDI; -import javax.naming.InitialContext; -import javax.naming.NamingException; - -import org.apache.wicket.Application; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Defines several strategies for looking up a CDI BeanManager in a portable - * way. The following strategies are tried (in order): - * <ul> - * <li>JNDI under java:comp/BeanManager (default location)</li> - * <li>JNDI under java:comp/env/BeanManager (for servlet containers like Tomcat - * and Jetty)</li> - * <li>CDI.current().getBeanManager() (portable lookup)</li> - * <li>{@linkplain CdiConfiguration#getFallbackBeanManager() Fallback}</li> - * </ul> - * - * The last successful lookup strategy is saved and tried first next time. - * - * @author papegaaij - */ -public final class BeanManagerLookup -{ - private static final Logger log = LoggerFactory.getLogger(BeanManagerLookup.class); - - private enum BeanManagerLookupStrategy { - JNDI { - @Override - public BeanManager lookup() - { - try - { - return InitialContext.doLookup("java:comp/BeanManager"); - } - catch (NamingException e) - { - return null; - } - } - }, - JNDI_ENV { - @Override - public BeanManager lookup() - { - try - { - return InitialContext.doLookup("java:comp/env/BeanManager"); - } - catch (NamingException e) - { - return null; - } - } - }, - CDI_PROVIDER { - @Override - public BeanManager lookup() - { - try - { - return CDI.current().getBeanManager(); - } - catch (Exception e) - { - log.debug(e.getMessage(), e); - return null; - } - } - }, - FALLBACK { - @Override - public BeanManager lookup() - { - return CdiConfiguration.get(Application.get()).getFallbackBeanManager(); - } - }; - - public abstract BeanManager lookup(); - } - - private static BeanManagerLookupStrategy lastSuccessful = BeanManagerLookupStrategy.JNDI; - - private BeanManagerLookup() - { - } - - public static BeanManager lookup() - { - BeanManager ret = lastSuccessful.lookup(); - if (ret != null) - return ret; - - for (BeanManagerLookupStrategy curStrategy : BeanManagerLookupStrategy.values()) - { - ret = curStrategy.lookup(); - if (ret != null) - { - lastSuccessful = curStrategy; - return ret; - } - } - - throw new IllegalStateException( - "No BeanManager found via the CDI provider and no fallback specified. Check your " - + "CDI setup or specify a fallback BeanManager in the CdiConfiguration."); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java deleted file mode 100644 index 15979f6..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 org.apache.wicket.IBehaviorInstantiationListener; -import org.apache.wicket.behavior.Behavior; - -/** - * Injects components with CDI dependencies - * - * @author igor - * - */ -public class BehaviorInjector extends AbstractInjector implements IBehaviorInstantiationListener -{ - /** - * Constructor - */ - public BehaviorInjector() - { - } - - @Override - public void onInstantiation(Behavior behavior) - { - inject(behavior); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java deleted file mode 100644 index 30778aa..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.inject.spi.BeanManager; - -import org.apache.wicket.Application; -import org.apache.wicket.MetaDataKey; -import org.apache.wicket.request.cycle.RequestCycleListenerCollection; - -/** - * Configures CDI integration - * - * @author igor - * - */ -public class CdiConfiguration -{ - private static final MetaDataKey<CdiConfiguration> CDI_CONFIGURATION_KEY = new MetaDataKey<CdiConfiguration>() - { - private static final long serialVersionUID = 1L; - }; - - private IConversationPropagation propagation = ConversationPropagation.NONBOOKMARKABLE; - - private BeanManager fallbackBeanManager; - - /** - * Constructor - */ - public CdiConfiguration() - { - } - - public IConversationPropagation getPropagation() - { - return propagation; - } - - public CdiConfiguration setPropagation(IConversationPropagation propagation) - { - this.propagation = propagation; - return this; - } - - public BeanManager getFallbackBeanManager() - { - return fallbackBeanManager; - } - - /** - * Sets a BeanManager that should be used if all strategies to lookup a - * BeanManager fail. This can be used in scenarios where you do not have - * JNDI available and do not want to bootstrap the CDI provider. It should - * be noted that the fallback BeanManager can only be used within the - * context of a Wicket application (ie. Application.get() should return the - * application that was configured with this CdiConfiguration). - * - * @param fallbackBeanManager - * @return this instance - */ - public CdiConfiguration setFallbackBeanManager(BeanManager fallbackBeanManager) - { - this.fallbackBeanManager = fallbackBeanManager; - return this; - } - - /** - * Configures the specified application - * - * @param application - */ - public void configure(Application application) - { - if (application.getMetaData(CDI_CONFIGURATION_KEY) != null) - { - throw new IllegalStateException("Cdi already configured for this application"); - } - application.setMetaData(CDI_CONFIGURATION_KEY, this); - - RequestCycleListenerCollection listeners = new RequestCycleListenerCollection(); - application.getRequestCycleListeners().add(listeners); - - // enable conversation propagation - if (getPropagation() != ConversationPropagation.NONE) - { - listeners.add(new ConversationPropagator(application, getPropagation())); - application.getComponentPreOnBeforeRenderListeners().add( - new AutoConversationManager(getPropagation())); - application.getComponentPreOnBeforeRenderListeners().add( - new ConversationExpiryChecker()); - } - - // enable detach event - listeners.add(new DetachEventEmitter()); - - NonContextual.of(application).postConstruct(application); - - // enable injection of various framework components - application.getSessionListeners().add(new SessionInjector()); - application.getComponentInstantiationListeners().add(new ComponentInjector()); - application.getBehaviorInstantiationListeners().add(new BehaviorInjector()); - - // enable cleanup - application.getApplicationListeners().add(new CdiShutdownCleaner()); - } - - public static CdiConfiguration get(Application application) - { - return application.getMetaData(CDI_CONFIGURATION_KEY); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java deleted file mode 100644 index 25c29dd..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 org.apache.wicket.Application; -import org.apache.wicket.IApplicationListener; - -/** - * Listens to application shutdown and cleans up - * - * @author igor - */ -class CdiShutdownCleaner implements IApplicationListener -{ - public CdiShutdownCleaner() - { - } - - @Override - public void onBeforeDestroyed(Application application) - { - NonContextual.of(application).preDestroy(application); - NonContextual.undeploy(); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java deleted file mode 100644 index 65a4879..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ComponentInjector.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 org.apache.wicket.Component; -import org.apache.wicket.application.IComponentInstantiationListener; - -/** - * Injects components with CDI dependencies - * - * @author igor - * - */ -class ComponentInjector extends AbstractInjector implements IComponentInstantiationListener -{ - /** - * Constructor - */ - public ComponentInjector() - { - } - - @Override - public void onInstantiation(Component component) - { - inject(component); - } - -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java deleted file mode 100644 index 16df7b1..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 org.apache.wicket.Page; -import org.apache.wicket.request.IRequestHandler; - -public class ConversationExpiredException extends RuntimeException -{ - private static final long serialVersionUID = 1L; - private String cid; - private Page page; - private IRequestHandler handler; - - public ConversationExpiredException(Throwable cause, String cid, Page page, - IRequestHandler handler) - { - super(cause); - this.cid = cid; - this.page = page; - this.handler = handler; - } - - public String getCid() - { - return cid; - } - - public Page getPage() - { - return page; - } - - public IRequestHandler getHandler() - { - return handler; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java deleted file mode 100644 index 3e2bc94..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.context.Conversation; -import javax.inject.Inject; - -import org.apache.wicket.Component; -import org.apache.wicket.Page; -import org.apache.wicket.application.IComponentOnBeforeRenderListener; -import org.apache.wicket.core.request.handler.IPartialPageRequestHandler; -import org.apache.wicket.request.cycle.RequestCycle; -import org.apache.wicket.util.lang.Objects; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Checks for conversation expiration during page render and throws a - * {@link ConversationExpiredException} when an expired conversation is - * detected. - * - * 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 - * - */ -public class ConversationExpiryChecker implements IComponentOnBeforeRenderListener -{ - private static final Logger logger = LoggerFactory.getLogger(ConversationExpiryChecker.class); - - @Inject - private Conversation conversation; - - public ConversationExpiryChecker() - { - NonContextual.of(ConversationExpiryChecker.class).inject(this); - } - - @Override - public void onBeforeRender(Component component) - { - if (component instanceof Page || RequestCycle.get().find(IPartialPageRequestHandler.class).isPresent()) - { - Page page = component.getPage(); - String cid = ConversationPropagator.getConversationIdFromPage(page); - if (cid != null && !Objects.isEqual(conversation.getId(), cid)) - { - logger.info("Conversation {} has expired for {}", cid, page); - throw new ConversationExpiredException(null, cid, page, RequestCycle.get() - .getActiveRequestHandler()); - } - } - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java deleted file mode 100644 index 3c1eb89..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.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 propagatesVia(IRequestHandler handler, Page page) - { - return false; - } - }, - /** - * Pesistent conversations are propagated between non-bookmarkable pages - * only - */ - NONBOOKMARKABLE { - @Override - public boolean propagatesVia(IRequestHandler handler, Page page) - { - return page != null; - } - }, - /** - * Persistent conversations are propagated between bookmarkable and - * non-bookmarkable pages - */ - ALL { - @Override - public boolean propagatesVia(IRequestHandler handler, Page page) - { - return true; - } - }; -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java deleted file mode 100644 index 613f6a5..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * 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.context.ContextNotActiveException; -import javax.enterprise.context.Conversation; -import javax.enterprise.context.ConversationScoped; -import javax.inject.Inject; - -import org.apache.wicket.Application; -import org.apache.wicket.MetaDataKey; -import org.apache.wicket.Page; -import org.apache.wicket.core.request.handler.BufferedResponseRequestHandler; -import org.apache.wicket.core.request.handler.IPageClassRequestHandler; -import org.apache.wicket.core.request.handler.IPageRequestHandler; -import org.apache.wicket.request.IRequestHandler; -import org.apache.wicket.request.IRequestHandlerDelegate; -import org.apache.wicket.request.Url; -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; -import org.apache.wicket.request.resource.PackageResourceReference; -import org.apache.wicket.util.lang.Args; -import org.apache.wicket.util.lang.Classes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A request cycle listener that takes care of propagating persistent - * conversations. - * - * @see ConversationScoped - * - * @author igor - */ -public class ConversationPropagator implements IRequestCycleListener -{ - private static final Logger logger = LoggerFactory.getLogger(ConversationPropagator.class); - - private static final MetaDataKey<Boolean> CONVERSATION_STARTED_KEY = new MetaDataKey<Boolean>() - { - private static final long serialVersionUID = 1L; - }; - - private static final MetaDataKey<String> CONVERSATION_ID_KEY = new MetaDataKey<String>() - { - private static final long serialVersionUID = 1L; - }; - - public static final String CID = "cid"; - - /** propagation mode to use */ - private final IConversationPropagation propagation; - - private final Application application; - - @Inject - private Conversation conversation; - - /** - * Constructor - * - * @param application - * @param propagation - */ - public ConversationPropagator(Application application, IConversationPropagation propagation) - { - Args.notNull(application, "application"); - Args.notNull(propagation, "propagation"); - - if (propagation == ConversationPropagation.NONE) - { - throw new IllegalArgumentException( - "If propagation is NONE do not set up the propagator"); - } - - this.application = application; - this.propagation = propagation; - - NonContextual.of(ConversationPropagator.class).postConstruct(this); - } - - public IConversationPropagation getPropagation() - { - return propagation; - } - - @Override - public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler) - { - if (activateForHandler(handler)) - { - logger.debug("Activating conversation {}", conversation.getId()); - fireOnAfterConversationStarted(cycle); - } - } - - private void fireOnAfterConversationStarted(RequestCycle cycle) - { - cycle.setMetaData(CONVERSATION_STARTED_KEY, true); - for (IRequestCycleListener listener : application.getRequestCycleListeners()) - { - if (listener instanceof ICdiAwareRequestCycleListener) - { - ((ICdiAwareRequestCycleListener)listener).onAfterConversationActivated(cycle); - } - } - } - - @Override - public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler) - { - // propagate current non-transient conversation to the newly scheduled - // page - try - { - if (conversation.isTransient()) - { - return; - } - } catch (ContextNotActiveException cnax) - { - logger.debug("There is no active context for the requested scope!", cnax); - return; - } - - if (propagation.propagatesVia(handler, getPage(handler))) - { - logger.debug( - "Propagating non-transient conversation {} via page parameters of handler {}", - conversation.getId(), handler); - - PageParameters parameters = getPageParameters(handler); - if (parameters != null) - { - parameters.set(CID, conversation.getId()); - markPageWithConversationId(handler, conversation.getId()); - } - } - } - - - @Override - public void onUrlMapped(RequestCycle cycle, IRequestHandler handler, Url url) - { - // no need to propagate the conversation to packaged resources, they - // should never change - if (handler instanceof ResourceReferenceRequestHandler) - { - if (((ResourceReferenceRequestHandler)handler).getResourceReference() instanceof PackageResourceReference) - { - return; - } - } - - if (conversation.isTransient()) - { - return; - } - - if (propagation.propagatesVia(handler, getPage(handler))) - { - logger.debug("Propagating non-transient conversation {} via url", conversation.getId()); - url.setQueryParameter(CID, conversation.getId()); - markPageWithConversationId(handler, conversation.getId()); - } - } - - @Override - public void onDetach(RequestCycle cycle) - { - if (!Boolean.TRUE.equals(cycle.getMetaData(CONVERSATION_STARTED_KEY))) - { - return; - } - - logger.debug("Deactivating conversation {}", conversation.getId()); - for (IRequestCycleListener listener : application.getRequestCycleListeners()) - { - if (listener instanceof ICdiAwareRequestCycleListener) - { - ((ICdiAwareRequestCycleListener)listener).onBeforeConversationDeactivated(cycle); - } - } - } - - /** - * Determines whether or not a conversation should be activated fro 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 - */ - protected boolean activateForHandler(IRequestHandler handler) - { - if (handler != null) - { - String handlerClassName = Classes.name(handler.getClass()); - - if (handler instanceof BufferedResponseRequestHandler) - { - // we do not care about pages that are being rendered from a buffer - return false; - } else if ("org.apache.wicket.protocol.ws.api.WebSocketMessageBroadcastHandler".equals(handlerClassName)) - { - return false; - } else if ("org.apache.wicket.protocol.ws.api.WebSocketRequestHandler".equals(handlerClassName)) { - // injection is not supported in web sockets communication - return false; - } - } - return true; - } - - public static void markPageWithConversationId(IRequestHandler handler, String cid) - { - Page page = getPage(handler); - if (page != null) - { - page.setMetaData(CONVERSATION_ID_KEY, cid); - } - } - - public static String getConversationIdFromPage(Page page) - { - return page.getMetaData(CONVERSATION_ID_KEY); - } - - public static void removeConversationIdFromPage(Page page) - { - page.setMetaData(CONVERSATION_ID_KEY, null); - } - - /** - * Resolves a page instance from the request handler iff the page instance - * is already created - * - * @param handler - * @return page or {@code null} if none - */ - public static Page getPage(IRequestHandler handler) - { - while (handler instanceof IRequestHandlerDelegate) - { - handler = ((IRequestHandlerDelegate)handler).getDelegateHandler(); - } - - if (handler instanceof IPageRequestHandler) - { - IPageRequestHandler pageHandler = (IPageRequestHandler)handler; - if (pageHandler.isPageInstanceCreated()) - { - return (Page)pageHandler.getPage(); - } - } - return null; - } - - /** - * Resolves page parameters from a request handler - * - * @param handler - * @return page parameters or {@code null} if none - */ - protected PageParameters getPageParameters(IRequestHandler handler) - { - if (handler instanceof IPageClassRequestHandler) - { - IPageClassRequestHandler pageHandler = (IPageClassRequestHandler)handler; - return pageHandler.getPageParameters(); - } - return null; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java deleted file mode 100644 index 16d9fc1..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ConversationalComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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; - -/** - * Marks a component that requires a conversation. This marker is used by the - * automatic conversation management feature 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 - */ -public interface ConversationalComponent -{ -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java deleted file mode 100644 index ac99ec3..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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; - -/** - * Fired when request cycle is detached - * - * @author igor - * - */ -public class DetachEvent -{ - -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java deleted file mode 100644 index b141236..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/DetachEventEmitter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.event.Event; -import javax.inject.Inject; - -import org.apache.wicket.MetaDataKey; -import org.apache.wicket.request.IRequestHandler; -import org.apache.wicket.request.cycle.IRequestCycleListener; -import org.apache.wicket.request.cycle.RequestCycle; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Request cycle listener that fires the {@link DetachEvent} event - * - * @author igor - * - */ -public class DetachEventEmitter implements IRequestCycleListener -{ - private static final Logger logger = LoggerFactory.getLogger(DetachEventEmitter.class); - - private static final MetaDataKey<Boolean> DETACH_SCHEDULED_KEY = new MetaDataKey<Boolean>() - { - private static final long serialVersionUID = 1L; - }; - - @Inject - Event<DetachEvent> detachEvent; - - /** - * Constructor - */ - public DetachEventEmitter() - { - NonContextual.of(DetachEventEmitter.class).postConstruct(this); - } - - @Override - public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler) - { - // this is a wicket request, schedule detach event to be fired - - cycle.setMetaData(DETACH_SCHEDULED_KEY, true); - } - - @Override - public void onDetach(RequestCycle cycle) - { - if (Boolean.TRUE.equals(cycle.getMetaData(DETACH_SCHEDULED_KEY))) - { - logger.debug("Firing Detach event {}", cycle.getRequest().getUrl()); - - detachEvent.fire(new DetachEvent()); - - cycle.setMetaData(DETACH_SCHEDULED_KEY, null); - } - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java deleted file mode 100644 index a577954..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/ICdiAwareRequestCycleListener.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 org.apache.wicket.request.cycle.IRequestCycleListener; -import org.apache.wicket.request.cycle.RequestCycle; - -public interface ICdiAwareRequestCycleListener extends IRequestCycleListener -{ - /** - * Called right after a conversation context for this request is activated - * - * @param cycle - * request cycle - */ - default void onAfterConversationActivated(RequestCycle cycle) - {} - - /** - * Called right before the current conversation context is deactivated - * - * @param cycle - * request cycle - */ - default void onBeforeConversationDeactivated(RequestCycle cycle) - {} -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java deleted file mode 100644 index b9eb1e3..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/IConversationPropagation.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 org.apache.wicket.Page; -import org.apache.wicket.core.request.handler.IPageRequestHandler; -import org.apache.wicket.request.IRequestHandler; - -/** - * A strategy that specifies how conversations should be propagated between - * pages/resources. {@link ConversationPropagation} provides sensible default - * implementations of this interface. - * - * @author papegaaij - */ -@FunctionalInterface -public interface IConversationPropagation -{ - /** - * Indicates if the conversation should be propagated via url-parameters for - * the given request handler and page (if any). A conversation is always - * propagated via the cid query parameter. - * - * @param handler - * The current request handler - * @param page - * The page associated with the request handler, or null if the - * handler is not an {@link IPageRequestHandler}. - * @return true if the conversation should be propagated for the given - * request handler. - */ - boolean propagatesVia(IRequestHandler handler, Page page); -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java deleted file mode 100644 index b596f53..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/NonContextual.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * 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.Collections; -import java.util.Map; -import java.util.WeakHashMap; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.enterprise.context.spi.CreationalContext; -import javax.enterprise.inject.spi.AnnotatedType; -import javax.enterprise.inject.spi.BeanManager; -import javax.enterprise.inject.spi.InjectionTarget; - -import org.apache.wicket.util.collections.ClassMetaCache; - -/** - * Manages lifecycle of non-contextual (non-CDI-managed) objects - * - * @param <T> - * @author igor - */ -public class NonContextual<T> -{ - private static final Object lock = new Object(); - private static volatile Map<BeanManager, ClassMetaCache<NonContextual<?>>> cache = Collections - .emptyMap(); - - final InjectionTarget<T> it; - - /** - * Undeploys the looked up bean manager from cache - */ - public static void undeploy() - { - if (cache.containsKey(BeanManagerLookup.lookup())) - { - synchronized (lock) - { - // copy-on-write the cache - Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>( - cache); - newCache.remove(BeanManagerLookup.lookup()); - cache = Collections.unmodifiableMap(newCache); - } - } - } - - /** - * Convenience factory method for an instance, see {@link #of(Class). - * - * @param <T> - * @param clazz - * @return The NonContextual for the instance's class - */ - @SuppressWarnings("unchecked") - public static <T> NonContextual<T> of(T t) { - // cast is necessary for Eclipse compiler :/ - return (NonContextual<T>)of(t.getClass()); - } - - /** - * Factory method for creating non-contextual instances - * - * @param <T> - * @param clazz - * @return The NonContextual for the given class - */ - public static <T> NonContextual<T> of(Class<? extends T> clazz) - { - ClassMetaCache<NonContextual<?>> meta = getCache(); - - @SuppressWarnings("unchecked") - NonContextual<T> nc = (NonContextual<T>)meta.get(clazz); - - if (nc == null) - { - nc = new NonContextual<T>(clazz); - meta.put(clazz, nc); - } - return nc; - } - - private static ClassMetaCache<NonContextual<?>> getCache() - { - ClassMetaCache<NonContextual<?>> meta = cache.get(BeanManagerLookup.lookup()); - if (meta == null) - { - synchronized (lock) - { - BeanManager manager = BeanManagerLookup.lookup(); - meta = cache.get(manager); - if (meta == null) - { - meta = new ClassMetaCache<NonContextual<?>>(); - - // copy-on-write the cache - Map<BeanManager, ClassMetaCache<NonContextual<?>>> newCache = new WeakHashMap<BeanManager, ClassMetaCache<NonContextual<?>>>( - cache); - newCache.put(manager, meta); - cache = Collections.unmodifiableMap(newCache); - } - } - } - return meta; - } - - @SuppressWarnings("unchecked") - private NonContextual(Class<? extends T> clazz) - { - BeanManager manager = BeanManagerLookup.lookup(); - AnnotatedType<? extends T> type = manager.createAnnotatedType(clazz); - this.it = (InjectionTarget<T>)manager.createInjectionTarget(type); - } - - /** - * Injects the instance and calls any {@link PostConstruct} methods - * - * @param instance - */ - public void postConstruct(T instance) - { - CreationalContext<T> cc = BeanManagerLookup.lookup().createCreationalContext(null); - it.inject(instance, cc); - it.postConstruct(instance); - } - - /** - * Injects the instance - * - * @param instance - */ - public void inject(T instance) - { - CreationalContext<T> cc = BeanManagerLookup.lookup().createCreationalContext(null); - it.inject(instance, cc); - } - - /** - * Calls any {@link PreDestroy} methods and destroys any injected - * dependencies that need to be destroyed. - * - * @param instance - */ - public void preDestroy(T instance) - { - it.preDestroy(instance); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java b/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java deleted file mode 100644 index a6fb4d2..0000000 --- a/wicket-cdi-1.1/src/main/java/org/apache/wicket/cdi/SessionInjector.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 org.apache.wicket.ISessionListener; -import org.apache.wicket.Session; - -/** - * Injects components with CDI dependencies - * - * @author igor - * - */ -class SessionInjector extends AbstractInjector implements ISessionListener -{ - /** - * Constructor - */ - public SessionInjector() - { - } - - @Override - public void onCreated(Session session) - { - postConstruct(session); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml b/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml deleted file mode 100644 index 6a2f1ec..0000000 --- a/wicket-cdi-1.1/src/main/resources/META-INF/beans.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" - version="1.1" bean-discovery-mode="annotated" /> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java deleted file mode 100644 index 3a3f7bf..0000000 --- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ApacheLicenceHeaderTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.Arrays; - -import org.apache.wicket.util.license.ApacheLicenseHeaderTestCase; - -/** - * Test that the license headers are in place in this project. The tests are run - * from {@link ApacheLicenseHeaderTestCase}, but you can add project specific - * tests here if needed. - * - * @author Frank Bille Jensen (frankbille) - */ -public class ApacheLicenceHeaderTest extends ApacheLicenseHeaderTestCase -{ - /** - * Construct. - */ - public ApacheLicenceHeaderTest() - { - xmlIgnore.add(".settings"); - xmlIgnore.add("src/main/resources/META-INF/beans.xml"); - xmlIgnore.add("src/test/java/simplelogger.properties"); - xmlPrologIgnore = Arrays.asList("src"); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java deleted file mode 100644 index 723db16..0000000 --- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiConfigurationTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 org.apache.wicket.cdi.testapp.TestConversationPage; -import org.apache.wicket.cdi.testapp.TestPage; -import org.apache.wicket.util.tester.WicketTester; -import org.junit.Test; - -/** - * @author jsarman - */ -public class CdiConfigurationTest extends WicketCdiTestCase -{ - @Test - public void testApplicationScope() - { - configure(new CdiConfiguration()); - tester.startPage(TestPage.class); - tester.assertLabel("appscope", "Test ok"); - } - - @Test - public void testConversationScope() - { - configure(new CdiConfiguration()); - tester.startPage(TestConversationPage.class); - for (int i = 0; i < 20; i++) - { - tester.assertCount(i); - tester.clickLink("increment"); - } - } - - @Test(expected = Exception.class) - public void testConfigureTwice() - { - configure(new CdiConfiguration()); - new CdiConfiguration().configure(tester.getApplication()); - } - - @Test - public void testApplicationLevelConfiguration() - { - WicketTester tester = new WicketTester(); - CdiConfiguration config = new CdiConfiguration(); - for (ConversationPropagation cp : ConversationPropagation.values()) - { - config.setPropagation(cp); - assertEquals(cp, config.getPropagation()); - } - config.configure(tester.getApplication()); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java deleted file mode 100644 index 275a9bc..0000000 --- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/CdiWicketTester.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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 static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.annotation.PreDestroy; -import javax.inject.Inject; - -import org.apache.wicket.Page; -import org.apache.wicket.protocol.http.WebApplication; -import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; -import org.apache.wicket.request.IRequestHandler; -import org.apache.wicket.request.Url; -import org.apache.wicket.util.tester.WicketTester; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author jsarman - */ -public class CdiWicketTester extends WicketTester -{ - private static final Pattern COUNT_PATTERN = Pattern.compile("COUNT=x([0-9]+)x"); - private static final Logger logger = LoggerFactory.getLogger(CdiWicketTester.class); - - @Inject - ContextManager contextManager; - - public CdiWicketTester(WebApplication app) - { - super(app); - NonContextual.of(CdiWicketTester.class).inject(this); - getHttpSession().setTemporary(false); - } - - /** - * Process the request by first activating the contexts on initial call. - * This call is called recursively in the super class so keep track of the - * topmost call and only activate and deactivate the contexts during that - * time. - * - * @param forcedRequest - * @param forcedRequestHandler - * @param redirect - * @return - */ - @Override - protected boolean processRequest(final MockHttpServletRequest forcedRequest, - final IRequestHandler forcedRequestHandler, final boolean redirect) - { - if (getLastRequest() != null) - { - contextManager.deactivateContexts(); - } - contextManager.activateContexts(forcedRequest == null ? getRequest() : forcedRequest); - return super.processRequest(forcedRequest, forcedRequestHandler, redirect); - } - - @Override - public Url urlFor(IRequestHandler handler) - { - Url ret = super.urlFor(handler); - final CdiConfiguration configuration = CdiConfiguration.get(getApplication()); - Page page = ConversationPropagator.getPage(handler); - if (configuration.getPropagation().propagatesVia(handler, page)) - { - if (page != null) - { - String cid = ConversationPropagator.getConversationIdFromPage(page); - ret.addQueryParameter(ConversationPropagator.CID, cid); - } - } - return ret; - } - - @PreDestroy - public void finish() - { - try - { - logger.debug("Destroying Cdi Wicket Tester"); - if (getLastRequest() != null) - { - contextManager.deactivateContexts(); - } - contextManager.destroy(); - destroy(); - } - catch (Throwable t) - { - } - } - - /** - * Asserts that the response contains the right count. This can only be done - * by parsing the markup because models only contain valid values during a - * request, not after. - * - * @param count - * TODO - */ - public void assertCount(int count) - { - assertTrue("Response does not contain a count", - getLastResponseAsString().contains("COUNT=x")); - Matcher matcher = COUNT_PATTERN.matcher(getLastResponseAsString()); - assertTrue(matcher.find()); - assertEquals(Integer.toString(count), matcher.group(1)); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ContextManager.java ---------------------------------------------------------------------- diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ContextManager.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ContextManager.java deleted file mode 100644 index ee92367..0000000 --- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ContextManager.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.annotation.PostConstruct; -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.spi.BeanManager; -import javax.inject.Inject; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; - -import org.jboss.weld.bean.builtin.BeanManagerProxy; -import org.jboss.weld.servlet.HttpContextLifecycle; -import org.jboss.weld.servlet.spi.helpers.AcceptingHttpContextActivationFilter; -import org.jglue.cdiunit.internal.CdiUnitInitialListenerImpl; -import org.jglue.cdiunit.internal.servlet.LifecycleAwareRequest; - -/** - * @author jsarman - */ -@ApplicationScoped -public class ContextManager -{ - private HttpServletRequest currentRequest; - - @Inject - private BeanManager beanManager; - - private HttpContextLifecycle lifecycle; - - private HttpSession currentSession; - - @PostConstruct - public void setup() - { - try - { - lifecycle = new HttpContextLifecycle(BeanManagerProxy.unwrap(beanManager), - AcceptingHttpContextActivationFilter.INSTANCE, true, true, false, true); - } - catch (NoSuchMethodError e) - { - try - { - lifecycle = HttpContextLifecycle.class.getConstructor(BeanManager.class, - AcceptingHttpContextActivationFilter.class).newInstance( - BeanManagerProxy.unwrap(beanManager), - AcceptingHttpContextActivationFilter.INSTANCE); - } - catch (Exception e1) - { - throw new RuntimeException(e1); - } - } - lifecycle.setConversationActivationEnabled(true); - } - - public void activateContexts(HttpServletRequest request) - { - if (currentRequest != null) - return; - - currentRequest = new LifecycleAwareRequest(new CdiUnitInitialListenerImpl(), request); - lifecycle.requestInitialized(currentRequest, null); - } - - public void deactivateContexts() - { - lifecycle.requestDestroyed(currentRequest); - currentSession = currentRequest.getSession(false); - currentRequest = null; - } - - public void destroy() - { - if (currentRequest != null) - { - currentSession = currentRequest.getSession(false); - } - - if (currentSession != null) - { - lifecycle.sessionDestroyed(currentSession); - currentSession = null; - } - } - - public boolean isRequestActive() - { - return currentRequest != null; - } -}
