You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2018/09/24 20:09:38 UTC
[2/3] wicket git commit: WICKET-6581 Module wicket-cdi-1.1 migrated
to CDI 2 and name changed to wicket-cdi. Solved dependecy problems with weld
versions.
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
deleted file mode 100644
index 945c9cf..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/ConversationPropagatorTest.java
+++ /dev/null
@@ -1,202 +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.cdi.testapp.TestConversationPage;
-import org.apache.wicket.cdi.testapp.TestConversationalPage;
-import org.apache.wicket.core.request.mapper.MountedMapper;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.hamcrest.CoreMatchers;
-import org.junit.Test;
-
-/**
- * @author jsarman
- */
-public class ConversationPropagatorTest extends WicketCdiTestCase
-{
- @Inject
- Conversation conversation;
-
- @Test
- public void testAutoConversationNonBookmarkable()
- {
- configure(new CdiConfiguration());
-
- tester.startPage(TestConversationalPage.class);
- int i;
- for (i = 0; i < 3; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- tester.clickLink("next");
- for (; i < 6; i++)
- {
- tester.clickLink("increment");
- tester.assertCount(1);
- }
- }
-
- @Test
- public void testAutoConversationBookmarkable()
- {
- configure(new CdiConfiguration());
-
- tester.startPage(TestConversationalPage.class,
- new PageParameters().add("pageType", "bookmarkable"));
-
- int i;
- for (i = 0; i < 3; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- tester.clickLink("next");
- for (i = 0; i < 3; i++)
- {
- tester.clickLink("increment");
- tester.assertCount(1);
- }
- }
-
- @Test
- public void testPropagationAllNonBookmarkable()
- {
- configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL));
-
- tester.startPage(TestConversationPage.class);
- int i;
- for (i = 0; i < 3; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- tester.clickLink("next");
- for (; i < 6; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- }
-
- @Test
- public void testPropagationAllHybrid()
- {
- configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL));
- tester.getApplication().getRootRequestMapperAsCompound().add(new MountedMapper("segment/${pageType}", TestConversationPage.class));
-
- tester.startPage(TestConversationPage.class, new PageParameters().add("pageType", "hybrid"));
-
- int i;
- for (i = 0; i < 3; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- tester.clickLink("next");
- for (; i < 6; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- }
-
- /**
- * https://issues.apache.org/jira/browse/WICKET-6257
- */
- @Test
- public void testPropagationAllHybridRefresh()
- {
- configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL));
- tester.getApplication().getRootRequestMapperAsCompound().add(new MountedMapper("segment/${pageType}", TestConversationPage.class));
-
- tester.startPage(TestConversationPage.class, new PageParameters().add("pageType", "hybrid"));
-
- String pageId = tester.getLastRenderedPage().getId();
- String cid = conversation.getId();
-
- tester.executeUrl("segment/hybrid?"+pageId+"&cid="+cid);
-
- assertThat(tester.getLastRenderedPage().getId(), CoreMatchers.is(pageId));
- }
-
- @Test
- public void testPropagationAllBookmarkable()
- {
- configure(new CdiConfiguration().setPropagation(ConversationPropagation.ALL));
-
- tester.startPage(TestConversationPage.class,
- new PageParameters().add("pageType", "bookmarkable"));
- int i;
- for (i = 0; i < 3; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- tester.clickLink("next");
- for (; i < 6; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- }
-
- @Test
- public void testPropagationNonBookmarkable()
- {
- configure(new CdiConfiguration());
-
- tester.startPage(TestConversationPage.class,
- new PageParameters().add("pageType", "bookmarkable"));
- int i;
- for (i = 0; i < 3; i++)
- {
- tester.assertCount(i);
- tester.clickLink("increment");
- }
- tester.clickLink("next");
- for (; i < 6; i++)
- {
- tester.clickLink("increment");
- tester.assertCount(1);
- }
- }
-
- @Test
- public void testPropagationNone()
- {
- configure(new CdiConfiguration().setPropagation(ConversationPropagation.NONE));
-
- tester.startPage(TestConversationPage.class);
- int i;
- for (i = 0; i < 3; i++)
- {
- tester.clickLink("increment");
- tester.assertCount(1);
- }
- tester.clickLink("next");
- for (; i < 6; i++)
- {
- tester.clickLink("increment");
- tester.assertCount(1);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
deleted file mode 100644
index 3f82075..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/WicketCdiTestCase.java
+++ /dev/null
@@ -1,185 +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.inject.Inject;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.Page;
-import org.apache.wicket.ThreadContext;
-import org.apache.wicket.behavior.AbstractAjaxBehavior;
-import org.apache.wicket.cdi.testapp.TestAppScope;
-import org.apache.wicket.cdi.testapp.TestCdiApplication;
-import org.apache.wicket.cdi.testapp.TestConversationBean;
-import org.apache.wicket.mock.MockApplication;
-import org.apache.wicket.protocol.http.WebApplication;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.util.tester.WicketTester;
-import org.jglue.cdiunit.AdditionalClasses;
-import org.jglue.cdiunit.CdiRunner;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-
-/**
- * @author jsarman
- */
-@RunWith(CdiRunner.class)
-@AdditionalClasses({ CdiWicketTester.class, BehaviorInjector.class, CdiConfiguration.class,
- CdiShutdownCleaner.class, ComponentInjector.class, ConversationExpiryChecker.class,
- ConversationPropagator.class, DetachEventEmitter.class, SessionInjector.class,
- TestAppScope.class, TestConversationBean.class, TestCdiApplication.class,
- AutoConversation.class })
-public abstract class WicketCdiTestCase extends Assert
-{
- @Inject
- private ContextManager contextManager;
- /** */
- protected CdiWicketTester tester;
-
- protected CdiWicketTester newWicketTester(WebApplication app)
- {
- return new CdiWicketTester(app);
- }
-
- public void configure(CdiConfiguration configuration)
- {
- configuration.configure(tester.getApplication());
- }
-
- @After
- public void end()
- {
- if (contextManager.isRequestActive())
- {
- contextManager.deactivateContexts();
- contextManager.destroy();
- }
- }
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- @Before
- public void commonBefore()
- {
- // make sure no leaked threadlocals are present
- ThreadContext.detach();
-
- WebApplication application = newApplication();
- tester = newWicketTester(application);
- }
-
- /**
- * @return the application that should be used for the test
- */
- protected WebApplication newApplication()
- {
- return new MockApplication();
- }
-
- /**
- *
- */
- @After
- public void commonAfter()
- {
- tester.destroy();
- }
-
- /**
- * Use <code>-Dwicket.replace.expected.results=true</code> to automatically
- * replace the expected output file.
- *
- * @param <T>
- *
- * @param pageClass
- * @param filename
- * @throws Exception
- */
- protected <T extends Page> void executeTest(final Class<T> pageClass, final String filename)
- throws Exception
- {
- tester.executeTest(getClass(), pageClass, filename);
- }
-
- /**
- * Use <code>-Dwicket.replace.expected.results=true</code> to automatically
- * replace the expected output file.
- *
- * @param page
- * @param filename
- * @throws Exception
- */
- protected void executeTest(final Page page, final String filename) throws Exception
- {
- tester.executeTest(getClass(), page, filename);
- }
-
- /**
- * Use <code>-Dwicket.replace.expected.results=true</code> to automatically
- * replace the expected output file.
- *
- * @param <T>
- *
- * @param pageClass
- * @param parameters
- * @param filename
- * @throws Exception
- */
- protected <T extends Page> void executeTest(final Class<T> pageClass,
- PageParameters parameters, final String filename) throws Exception
- {
- tester.executeTest(getClass(), pageClass, parameters, filename);
- }
-
- /**
- *
- * @param component
- * @param filename
- * @throws Exception
- */
- protected void executeListener(final Component component, final String filename)
- throws Exception
- {
- tester.executeListener(getClass(), component, filename);
- }
-
- /**
- *
- * @param behavior
- * @param filename
- * @throws Exception
- */
- protected void executeBehavior(final AbstractAjaxBehavior behavior, final String filename)
- throws Exception
- {
- tester.executeBehavior(getClass(), behavior, filename);
- }
-
- /**
- * Returns the current Maven build directory taken from the <tt>basedir</tt>
- * system property, or null if not set
- *
- * @return path with a trailing slash
- */
- public String getBasedir()
- {
- return WicketTester.getBasedir();
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
deleted file mode 100644
index b36f8a7..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestAppScope.java
+++ /dev/null
@@ -1,40 +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.testapp;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.Produces;
-
-/**
- * @author jsarman
- */
-@ApplicationScoped
-public class TestAppScope
-{
-
- public String test()
- {
- return "Test ok";
- }
-
- public @Produces
- @TestQualifier
- String testString()
- {
- return "Test String";
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.java
deleted file mode 100644
index 7b82203..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestApplication.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.testapp;
-
-import org.apache.wicket.Page;
-import org.apache.wicket.protocol.http.WebApplication;
-
-/**
- * @author jsarman
- */
-public class TestApplication extends WebApplication
-{
-
- @Override
- public Class<? extends Page> getHomePage()
- {
- return TestPage.class;
- }
-
- @Override
- protected void init()
- {
- super.init();
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
deleted file mode 100644
index 1bd8656..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestCdiApplication.java
+++ /dev/null
@@ -1,54 +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.testapp;
-
-import javax.inject.Inject;
-
-import org.apache.wicket.Page;
-import org.apache.wicket.cdi.CdiConfiguration;
-import org.apache.wicket.protocol.http.WebApplication;
-
-/**
- * @author jsarman
- */
-public class TestCdiApplication extends WebApplication
-{
-
- @Inject
- @TestQualifier
- String testString;
-
-
- @Override
- public Class<? extends Page> getHomePage()
- {
- return TestPage.class;
- }
-
- @Override
- protected void init()
- {
- super.init();
- new CdiConfiguration().configure(this);
- }
-
- public String getInjectedTestString()
- {
- return testString;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
deleted file mode 100644
index 140ecdb..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationBean.java
+++ /dev/null
@@ -1,56 +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.testapp;
-
-import java.io.Serializable;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.enterprise.context.ConversationScoped;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author jsarman
- */
-@ConversationScoped
-public class TestConversationBean implements Serializable
-{
- private static final long serialVersionUID = 1L;
-
- private static final Logger logger = LoggerFactory.getLogger(TestConversationBean.class);
-
- private AtomicInteger counter = new AtomicInteger();
-
- public int getCount()
- {
- logger.debug("Count = {}", counter.get());
- return counter.get();
- }
-
- public String getCountStr()
- {
- return "COUNT=x" + getCount() + "x";
- }
-
- public void increment()
- {
-
- counter.incrementAndGet();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
deleted file mode 100644
index e7f3de7..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<!DOCTYPE html>
-<html xmlns:wicket>
-<head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-</head>
-<body>
-<span wicket:id="count">100</span>
-<a wicket:id="increment">increment</a>
-<a wicket:id="next">Reset</a>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
deleted file mode 100644
index c6cc8bc..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationPage.java
+++ /dev/null
@@ -1,84 +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.testapp;
-
-import javax.enterprise.context.Conversation;
-import javax.inject.Inject;
-
-import org.apache.wicket.markup.html.WebPage;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.model.PropertyModel;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-
-
-/**
- * @author jsarman
- */
-public class TestConversationPage extends WebPage
-{
- private static final long serialVersionUID = 1L;
-
- @Inject
- Conversation conversation;
-
- @Inject
- TestConversationBean counter;
-
- public TestConversationPage()
- {
- this(new PageParameters());
- }
-
- public TestConversationPage(final PageParameters parameters)
- {
- super(parameters);
-
- conversation.begin();
- System.out.println("Opened Conversion with id = " + conversation.getId());
-
- add(new Label("count", new PropertyModel<String>(this, "counter.countStr")));
-
- add(new Link<Void>("increment")
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick()
- {
- counter.increment();
- }
- });
- add(new Link<Void>("next")
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick()
- {
- String pageType = parameters.get("pageType").toString("nonbookmarkable");
- if ("bookmarkable".equals(pageType.toLowerCase()))
- setResponsePage(TestNonConversationalPage.class);
- else if ("hybrid".equals(pageType.toLowerCase()))
- setResponsePage(TestConversationPage.this);
- else
- setResponsePage(new TestNonConversationalPage());
- }
- });
-
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
deleted file mode 100644
index b3550f1..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<!DOCTYPE html>
-<html xmlns:wicket>
-<head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-</head>
-<body>
-<span wicket:id="count">100</span>
-<a wicket:id="increment">increment</a>
-<a wicket:id="next">next</a>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
deleted file mode 100644
index 5e41fd5..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestConversationalPage.java
+++ /dev/null
@@ -1,78 +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.testapp;
-
-import javax.inject.Inject;
-
-import org.apache.wicket.cdi.ConversationalComponent;
-import org.apache.wicket.markup.html.WebPage;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.model.PropertyModel;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author jsarman
- */
-public class TestConversationalPage extends WebPage implements ConversationalComponent
-{
- private static final long serialVersionUID = 1L;
-
- private static final Logger logger = LoggerFactory.getLogger(TestConversationPage.class);
- @Inject
- TestConversationBean counter;
-
- public TestConversationalPage()
- {
- this(new PageParameters());
- }
-
-
- public TestConversationalPage(final PageParameters pp)
- {
- logger.debug("Starting TestConversationalPage");
-
- add(new Label("count", new PropertyModel<String>(this, "counter.countStr")));
-
- add(new Link<Void>("increment")
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick()
- {
- counter.increment();
- }
- });
- add(new Link<Void>("next")
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick()
- {
- String pageType = pp.get("pageType").toString("nonbookmarkable");
- if ("bookmarkable".equals(pageType.toLowerCase()))
- setResponsePage(TestNonConversationalPage.class);
- else
- setResponsePage(new TestNonConversationalPage());
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
deleted file mode 100644
index fd58f2d..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html xmlns:wicket>
-<head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-</head>
-<body>
-<span wicket:id="count">100</span>
-<a wicket:id="increment">increment</a>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
deleted file mode 100644
index 7728e81..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestNonConversationalPage.java
+++ /dev/null
@@ -1,55 +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.testapp;
-
-import javax.inject.Inject;
-
-import org.apache.wicket.markup.html.WebPage;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.model.PropertyModel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * @author jsarman
- */
-public class TestNonConversationalPage extends WebPage
-{
- private static final long serialVersionUID = 1L;
- private static final Logger logger = LoggerFactory.getLogger(TestConversationPage.class);
- @Inject
- TestConversationBean counter;
-
- public TestNonConversationalPage()
- {
- logger.debug("Starting TestConversationalPage");
- add(new Label("count", new PropertyModel<String>(this, "counter.countStr")));
-
- add(new Link<Void>("increment")
- {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick()
- {
- counter.increment();
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html
deleted file mode 100644
index 4689c49..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<html xmlns:wicket>
-<head>
- <title></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-</head>
-<body>
-<div wicket:id="appscope">Fail</div>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java
deleted file mode 100644
index cf5108b..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestPage.java
+++ /dev/null
@@ -1,40 +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.testapp;
-
-import javax.inject.Inject;
-
-import org.apache.wicket.markup.html.WebPage;
-import org.apache.wicket.markup.html.basic.Label;
-
-/**
- * @author jsarman
- */
-public class TestPage extends WebPage
-{
- private static final long serialVersionUID = 1L;
-
- @Inject
- TestAppScope appScope;
-
- public TestPage()
- {
-
- add(new Label("appscope", appScope.test()));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java b/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java
deleted file mode 100644
index dcd0289..0000000
--- a/wicket-cdi-1.1/src/test/java/org/apache/wicket/cdi/testapp/TestQualifier.java
+++ /dev/null
@@ -1,35 +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.testapp;
-
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * @author jsarman
- */
-@Qualifier
-@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD })
-@Retention(RetentionPolicy.RUNTIME)
-public @interface TestQualifier {
-
-}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi-1.1/src/test/java/simplelogger.properties
----------------------------------------------------------------------
diff --git a/wicket-cdi-1.1/src/test/java/simplelogger.properties b/wicket-cdi-1.1/src/test/java/simplelogger.properties
deleted file mode 100644
index 17c5fe6..0000000
--- a/wicket-cdi-1.1/src/test/java/simplelogger.properties
+++ /dev/null
@@ -1 +0,0 @@
-org.slf4j.simpleLogger.log.org.apache.wicket.cdi=info
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/pom.xml
----------------------------------------------------------------------
diff --git a/wicket-cdi/pom.xml b/wicket-cdi/pom.xml
index a0cf977..29de4bb 100644
--- a/wicket-cdi/pom.xml
+++ b/wicket-cdi/pom.xml
@@ -27,7 +27,7 @@
</parent>
<artifactId>wicket-cdi</artifactId>
<packaging>bundle</packaging>
- <name>Wicket CDI Integration</name>
+ <name>Wicket CDI</name>
<description>
Provides integration between Wicket and CDI containers. Enables injection of
components and behaviors, as well as other non-contextual object instances.
@@ -55,12 +55,41 @@
<artifactId>wicket-core</artifactId>
</dependency>
<dependency>
- <groupId>org.jboss.weld</groupId>
- <artifactId>weld-core-impl</artifactId>
+ <groupId>org.jboss.weld.module</groupId>
+ <artifactId>weld-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld.se</groupId>
+ <artifactId>weld-se-core</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.jglue.cdi-unit</groupId>
+ <artifactId>cdi-unit</artifactId>
+ <exclusions>
+ <exclusion>
+ <artifactId>org.jboss.spec.javax.annotation</artifactId>
+ <groupId>jboss-annotations-api_1.2_spec</groupId>
+ </exclusion>
+ </exclusions>
+ </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/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/AbstractInjector.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
index b77aa6e..cf8d67f 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AbstractInjector.java
@@ -16,8 +16,6 @@
*/
package org.apache.wicket.cdi;
-import org.apache.wicket.util.lang.Args;
-
/**
* Base class for injectors
*
@@ -25,21 +23,17 @@ import org.apache.wicket.util.lang.Args;
*/
class AbstractInjector
{
- private final CdiContainer container;
-
- public AbstractInjector(CdiContainer container)
+ public AbstractInjector()
{
- Args.notNull(container, "container");
- this.container = container;
}
protected <T> void postConstruct(T instance)
{
- container.getNonContextualManager().postConstruct(instance);
+ NonContextual.of(instance).postConstruct(instance);
}
protected <T> void inject(T instance)
{
- container.getNonContextualManager().inject(instance);
+ NonContextual.of(instance).inject(instance);
}
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversation.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversation.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversation.java
index 0193a7d..90f5e19 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversation.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversation.java
@@ -21,15 +21,16 @@ 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. See {@link CdiConfiguration#setAutoConversationManagement(boolean)} for
- * details.
+ * 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()
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java
new file mode 100644
index 0000000..4aedb48
--- /dev/null
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/AutoConversationManager.java
@@ -0,0 +1,121 @@
+/*
+ * 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/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
new file mode 100644
index 0000000..f44e513
--- /dev/null
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/BeanManagerLookup.java
@@ -0,0 +1,128 @@
+/*
+ * 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/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
index 0ba6219..15979f6 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/BehaviorInjector.java
@@ -25,16 +25,13 @@ import org.apache.wicket.behavior.Behavior;
* @author igor
*
*/
-class BehaviorInjector extends AbstractInjector implements IBehaviorInstantiationListener
+public class BehaviorInjector extends AbstractInjector implements IBehaviorInstantiationListener
{
/**
* Constructor
- *
- * @param container
*/
- public BehaviorInjector(CdiContainer container)
+ public BehaviorInjector()
{
- super(container);
}
@Override
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
index ad369a1..30778aa 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
@@ -19,8 +19,8 @@ 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;
-import org.apache.wicket.util.lang.Args;
/**
* Configures CDI integration
@@ -30,37 +30,20 @@ import org.apache.wicket.util.lang.Args;
*/
public class CdiConfiguration
{
- private BeanManager beanManager;
+ private static final MetaDataKey<CdiConfiguration> CDI_CONFIGURATION_KEY = new MetaDataKey<CdiConfiguration>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
+
private IConversationPropagation propagation = ConversationPropagation.NONBOOKMARKABLE;
- private INonContextualManager nonContextualManager;
- private boolean injectComponents = true;
- private boolean injectApplication = true;
- private boolean injectSession = true;
- private boolean injectBehaviors = true;
- private boolean autoConversationManagement = false;
+ private BeanManager fallbackBeanManager;
/**
* Constructor
- *
- * @param beanManager
- */
- public CdiConfiguration(BeanManager beanManager)
- {
- Args.notNull(beanManager, "beanManager");
-
- this.beanManager = beanManager;
- nonContextualManager = new NonContextualManager(beanManager);
- }
-
- /**
- * Gets the configured bean manager
- *
- * @return bean manager or {@code null} if none
*/
- public BeanManager getBeanManager()
+ public CdiConfiguration()
{
- return beanManager;
}
public IConversationPropagation getPropagation()
@@ -68,96 +51,31 @@ public class CdiConfiguration
return propagation;
}
- /**
- * Checks if auto conversation management is enabled. See
- * {@link #setAutoConversationManagement(boolean)} for details.
- */
- public boolean isAutoConversationManagement()
- {
- return autoConversationManagement;
- }
-
- /**
- * Toggles automatic conversation management feature.
- *
- * 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.
- *
- * 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
- *
- * @return {@code this} for easy chaining
- */
- public CdiConfiguration setAutoConversationManagement(boolean enabled)
- {
- autoConversationManagement = enabled;
- return this;
- }
-
public CdiConfiguration setPropagation(IConversationPropagation propagation)
{
this.propagation = propagation;
return this;
}
- public INonContextualManager getNonContextualManager()
- {
- return nonContextualManager;
- }
-
- public CdiConfiguration setNonContextualManager(INonContextualManager nonContextualManager)
- {
- this.nonContextualManager = nonContextualManager;
- return this;
- }
-
- public boolean isInjectComponents()
- {
- return injectComponents;
- }
-
- public CdiConfiguration setInjectComponents(boolean injectComponents)
- {
- this.injectComponents = injectComponents;
- return this;
- }
-
- public boolean isInjectApplication()
- {
- return injectApplication;
- }
-
- public CdiConfiguration setInjectApplication(boolean injectApplication)
- {
- this.injectApplication = injectApplication;
- return this;
- }
-
- public boolean isInjectSession()
+ public BeanManager getFallbackBeanManager()
{
- return injectSession;
+ return fallbackBeanManager;
}
- public CdiConfiguration setInjectSession(boolean injectSession)
- {
- this.injectSession = injectSession;
- return this;
- }
-
- public boolean isInjectBehaviors()
- {
- return injectBehaviors;
- }
-
- public CdiConfiguration setInjectBehaviors(boolean injectBehaviors)
+ /**
+ * 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.injectBehaviors = injectBehaviors;
+ this.fallbackBeanManager = fallbackBeanManager;
return this;
}
@@ -165,18 +83,14 @@ public class CdiConfiguration
* Configures the specified application
*
* @param application
- * @return The CdiContainer
*/
- public CdiContainer configure(Application application)
+ public void configure(Application application)
{
- if (beanManager == null)
+ if (application.getMetaData(CDI_CONFIGURATION_KEY) != null)
{
- throw new IllegalStateException(
- "Configuration does not have a BeanManager instance configured");
+ throw new IllegalStateException("Cdi already configured for this application");
}
-
- CdiContainer container = new CdiContainer(beanManager, nonContextualManager);
- container.bind(application);
+ application.setMetaData(CDI_CONFIGURATION_KEY, this);
RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
application.getRequestCycleListeners().add(listeners);
@@ -184,45 +98,29 @@ public class CdiConfiguration
// enable conversation propagation
if (getPropagation() != ConversationPropagation.NONE)
{
- listeners.add(new ConversationPropagator(application, container, getPropagation(),
- autoConversationManagement));
+ listeners.add(new ConversationPropagator(application, getPropagation()));
+ application.getComponentPreOnBeforeRenderListeners().add(
+ new AutoConversationManager(getPropagation()));
application.getComponentPreOnBeforeRenderListeners().add(
- new ConversationExpiryChecker(container));
+ new ConversationExpiryChecker());
}
// enable detach event
- listeners.add(new DetachEventEmitter(container));
-
+ listeners.add(new DetachEventEmitter());
- // inject application instance
- if (isInjectApplication())
- {
- container.getNonContextualManager().postConstruct(application);
- }
+ NonContextual.of(application).postConstruct(application);
// enable injection of various framework components
-
- if (isInjectSession())
- {
- application.getSessionListeners().add(new SessionInjector(container));
- }
-
- if (isInjectComponents())
- {
- application.getComponentInstantiationListeners().add(new ComponentInjector(container));
- }
-
- if (isInjectBehaviors())
- {
- application.getBehaviorInstantiationListeners().add(new BehaviorInjector(container));
- }
+ application.getSessionListeners().add(new SessionInjector());
+ application.getComponentInstantiationListeners().add(new ComponentInjector());
+ application.getBehaviorInstantiationListeners().add(new BehaviorInjector());
// enable cleanup
-
- application.getApplicationListeners().add(
- new CdiShutdownCleaner(beanManager, isInjectApplication()));
-
- return container;
+ 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/src/main/java/org/apache/wicket/cdi/CdiContainer.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiContainer.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiContainer.java
deleted file mode 100644
index 168588d..0000000
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiContainer.java
+++ /dev/null
@@ -1,167 +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.servlet.http.HttpServletRequest;
-
-import org.apache.wicket.Application;
-import org.apache.wicket.MetaDataKey;
-import org.apache.wicket.Page;
-import org.apache.wicket.request.cycle.RequestCycle;
-import org.apache.wicket.util.lang.Args;
-import org.jboss.weld.Container;
-import org.jboss.weld.context.http.HttpConversationContext;
-
-/**
- * Provides access to CDI features from inside a Wicket request
- *
- * @author igor
- *
- */
-public class CdiContainer
-{
- private static final MetaDataKey<CdiContainer> CONTEXT_KEY = new MetaDataKey<CdiContainer>()
- {
- private static final long serialVersionUID = 1L;
- };
-
- protected final BeanManager beanManager;
- private final HttpConversationContext conversationContext;
- private final INonContextualManager nonContextualManager;
-
- /**
- * Constructor
- *
- * @param beanManager
- * bean manager
- */
- public CdiContainer(BeanManager beanManager, INonContextualManager nonContextualManager)
- {
- Args.notNull(beanManager, "beanManager");
- Args.notNull(nonContextualManager, "nonContextualManager");
-
- this.beanManager = beanManager;
- this.nonContextualManager = nonContextualManager;
-
- conversationContext = Container.instance().deploymentManager().instance().select(HttpConversationContext.class).get();
- if (conversationContext == null)
- {
- throw new IllegalStateException(
- "Could not resolve conversation context manager. Make sure a Seam-Conversation module for your CDI container implementation is included in your dependencies.");
- }
- }
-
- public INonContextualManager getNonContextualManager()
- {
- return nonContextualManager;
- }
-
- /**
- * Deactivates conversational context
- *
- * @param cycle
- */
- public void deactivateConversationalContext(RequestCycle cycle)
- {
- conversationContext.deactivate();
- conversationContext.dissociate(getRequest(cycle));
- }
-
- /**
- * Activates the conversational context and starts the conversation with the specified cid
- *
- * @param cycle
- * @param cid
- */
- public void activateConversationalContext(RequestCycle cycle, String cid)
- {
- conversationContext.associate(getRequest(cycle));
- conversationContext.activate(cid);
- }
-
- private HttpServletRequest getRequest(RequestCycle cycle)
- {
- return (HttpServletRequest)cycle.getRequest().getContainerRequest();
- }
-
- /**
- * Retrieves a conversation id, if any, that is associated with a {@link Page} instance
- *
- * @param page
- * page instance
- * @return conversation id, if any
- */
- public String getConversationMarker(Page page)
- {
- return page.getMetaData(ConversationIdMetaKey.INSTANCE);
- }
-
- /**
- * 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)
- {
- Args.notNull(page, "page");
-
- page.setMetaData(ConversationIdMetaKey.INSTANCE, null);
- page.getPageParameters().remove(ConversationPropagator.CID);
- }
-
- /**
- * Binds this container instance to the {@link Application}, making it possible to retrieve it
- * later
- *
- * @param application
- */
- protected void bind(Application application)
- {
- application.setMetaData(CONTEXT_KEY, this);
- }
-
- /**
- * Retrieves container instance stored in the application
- *
- * @param application
- * @return container instance or {@code null} if none
- */
- public static final CdiContainer get(Application application)
- {
- CdiContainer ctx = application.getMetaData(CONTEXT_KEY);
- if (ctx == null)
- {
- throw new IllegalStateException("No CDI Context bound to application");
- }
- return ctx;
- }
-
- /**
- * Retrieves container instance stored in the current thread's application
- *
- * @return container instance or {@code null} if none
- */
- public static final CdiContainer get()
- {
- return get(Application.get());
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
index aa219da..25c29dd 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiShutdownCleaner.java
@@ -16,11 +16,8 @@
*/
package org.apache.wicket.cdi;
-import javax.enterprise.inject.spi.BeanManager;
-
import org.apache.wicket.Application;
import org.apache.wicket.IApplicationListener;
-import org.apache.wicket.util.lang.Args;
/**
* Listens to application shutdown and cleans up
@@ -29,25 +26,14 @@ import org.apache.wicket.util.lang.Args;
*/
class CdiShutdownCleaner implements IApplicationListener
{
- private final BeanManager beanManager;
- private final boolean preDestroyApplication;
-
- public CdiShutdownCleaner(BeanManager beanManager, boolean preDestroyApplication)
+ public CdiShutdownCleaner()
{
- Args.notNull(beanManager, "beanManager");
-
- this.beanManager = beanManager;
- this.preDestroyApplication = preDestroyApplication;
}
@Override
public void onBeforeDestroyed(Application application)
{
- if (preDestroyApplication)
- {
- NonContextual.of(application, beanManager).preDestroy(application);
- }
- NonContextual.undeploy(beanManager);
+ NonContextual.of(application).preDestroy(application);
+ NonContextual.undeploy();
}
-
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ComponentInjector.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
index bc302ef..65a4879 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ComponentInjector.java
@@ -29,12 +29,9 @@ class ComponentInjector extends AbstractInjector implements IComponentInstantiat
{
/**
* Constructor
- *
- * @param container
*/
- public ComponentInjector(CdiContainer container)
+ public ComponentInjector()
{
- super(container);
}
@Override
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
index 7993ae4..16df7b1 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiredException.java
@@ -21,12 +21,13 @@ 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)
+ IRequestHandler handler)
{
super(cause);
this.cid = cid;
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
index 8881485..3e2bc94 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationExpiryChecker.java
@@ -30,10 +30,12 @@ import org.slf4j.LoggerFactory;
/**
* Checks for conversation expiration during page render and throws a
- * {@link ConversationExpiredException} when an expired conversation is detected.
+ * {@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.
+ * 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
*
@@ -41,17 +43,13 @@ import org.slf4j.LoggerFactory;
public class ConversationExpiryChecker implements IComponentOnBeforeRenderListener
{
private static final Logger logger = LoggerFactory.getLogger(ConversationExpiryChecker.class);
-
+
@Inject
private Conversation conversation;
- private final CdiContainer container;
-
- public ConversationExpiryChecker(CdiContainer container)
+ public ConversationExpiryChecker()
{
- this.container = container;
-
- container.getNonContextualManager().inject(this);
+ NonContextual.of(ConversationExpiryChecker.class).inject(this);
}
@Override
@@ -60,12 +58,12 @@ public class ConversationExpiryChecker implements IComponentOnBeforeRenderListen
if (component instanceof Page || RequestCycle.get().find(IPartialPageRequestHandler.class).isPresent())
{
Page page = component.getPage();
- String cid = container.getConversationMarker(page);
+ 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());
+ .getActiveRequestHandler());
}
}
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java
deleted file mode 100644
index 94cc70f..0000000
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationIdMetaKey.java
+++ /dev/null
@@ -1,24 +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.MetaDataKey;
-
-final class ConversationIdMetaKey extends MetaDataKey<String>
-{
- static final ConversationIdMetaKey INSTANCE = new ConversationIdMetaKey();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
index e70ff9c..3c1eb89 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagation.java
@@ -32,45 +32,29 @@ 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)
+ public boolean propagatesVia(IRequestHandler handler, Page page)
{
return false;
}
},
/**
- * Pesistent conversations are propagated between non-bookmarkable pages only
+ * Pesistent conversations are propagated between non-bookmarkable pages
+ * only
*/
NONBOOKMARKABLE {
@Override
- public boolean propagatesViaPage(Page page, IRequestHandler handler)
- {
- return true;
- }
-
- @Override
- public boolean propagatesViaParameters(IRequestHandler handler)
+ public boolean propagatesVia(IRequestHandler handler, Page page)
{
- return false;
+ return page != null;
}
},
/**
- * Persistent conversations are propagated between bookmarkable and non-bookmarkable pages
+ * Persistent conversations are propagated between bookmarkable and
+ * non-bookmarkable pages
*/
ALL {
@Override
- public boolean propagatesViaPage(Page page, IRequestHandler handler)
- {
- return true;
- }
-
- @Override
- public boolean propagatesViaParameters(IRequestHandler handler)
+ public boolean propagatesVia(IRequestHandler handler, Page page)
{
return true;
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/057c402b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
----------------------------------------------------------------------
diff --git a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
index 92f261c..613f6a5 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/ConversationPropagator.java
@@ -16,38 +16,33 @@
*/
package org.apache.wicket.cdi;
+import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
-import javax.enterprise.context.NonexistentConversationException;
import javax.inject.Inject;
import org.apache.wicket.Application;
-import org.apache.wicket.Component;
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.core.request.mapper.StalePageException;
import org.apache.wicket.request.IRequestHandler;
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.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.Objects;
-import org.apache.wicket.util.visit.IVisit;
-import org.apache.wicket.util.visit.IVisitor;
-import org.apache.wicket.util.visit.Visits;
+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.
+ * A request cycle listener that takes care of propagating persistent
+ * conversations.
*
* @see ConversationScoped
*
@@ -57,158 +52,67 @@ public class ConversationPropagator implements IRequestCycleListener
{
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;
};
+ private static final MetaDataKey<String> CONVERSATION_ID_KEY = new MetaDataKey<String>()
+ {
+ private static final long serialVersionUID = 1L;
+ };
public static final String CID = "cid";
- private final CdiContainer container;
-
/** propagation mode to use */
private final IConversationPropagation propagation;
private final Application application;
- private final boolean auto;
-
- @Inject
- Conversation conversation_;
-
@Inject
- AutoConversation autoConversation;
-
- /**
- * Constructor
- *
- * @param container
- * @param propagation
- */
- public ConversationPropagator(Application application, CdiContainer container,
- IConversationPropagation propagation)
- {
- this(application, container, propagation, false);
- }
-
+ private Conversation conversation;
/**
* Constructor
*
- * @param container
+ * @param application
* @param propagation
*/
- public ConversationPropagator(Application application, CdiContainer container,
- IConversationPropagation propagation, boolean auto)
+ public ConversationPropagator(Application application, IConversationPropagation propagation)
{
Args.notNull(application, "application");
- Args.notNull(container, "container");
Args.notNull(propagation, "propagation");
if (propagation == ConversationPropagation.NONE)
{
throw new IllegalArgumentException(
- "If propagation is NONE do not set up the propagator");
+ "If propagation is NONE do not set up the propagator");
}
this.application = application;
- this.container = container;
this.propagation = propagation;
- this.auto = auto;
- container.getNonContextualManager().postConstruct(this);
+ NonContextual.of(ConversationPropagator.class).postConstruct(this);
}
- private Conversation getConversation(RequestCycle cycle)
+ public IConversationPropagation getPropagation()
{
- return Boolean.TRUE.equals(cycle.getMetaData(CONVERSATION_STARTED_KEY)) ? conversation_
- : null;
+ return propagation;
}
@Override
public void onRequestHandlerResolved(RequestCycle cycle, IRequestHandler handler)
{
- String cid = cycle.getRequest().getRequestParameters().getParameterValue(CID).toString();
- Page page = getPage(handler);
-
- if (cid == null && page != null)
- {
- cid = page.getMetaData(CID_KEY);
- }
-
- Conversation current = getConversation(cycle);
- if (current != null && !Objects.isEqual(current.getId(), cid))
- {
- logger.info("Conversation {} has expired for {}", cid, page);
- throw new ConversationExpiredException(null, cid, page, handler);
- }
-
- activateConversationIfNeeded(cycle, handler, cid);
- }
-
- @Override
- public IRequestHandler onException(RequestCycle cycle, Exception ex)
- {
- // if we are handling a stale page exception then use its conversation since we are most
- // likely about to rerender it.
-
- if (ex instanceof StalePageException)
- {
- IRequestablePage requestable = ((StalePageException)ex).getPage();
- if (requestable instanceof Page)
- {
- String cid = container.getConversationMarker((Page)requestable);
- if (cid != null)
- {
- try
- {
- activateConversationIfNeeded(cycle, null, cid);
- return null;
- }
- catch (ConversationExpiredException e)
- {
- // ignore, we will start a new one below
- }
- }
- }
- }
-
- activateConversationIfNeeded(cycle, null, null);
- return null;
- }
-
- private void activateConversationIfNeeded(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
- {
- container.activateConversationalContext(cycle, cid);
+ logger.debug("Activating conversation {}", conversation.getId());
fireOnAfterConversationStarted(cycle);
}
- 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)
{
+ cycle.setMetaData(CONVERSATION_STARTED_KEY, true);
for (IRequestCycleListener listener : application.getRequestCycleListeners())
{
if (listener instanceof ICdiAwareRequestCycleListener)
@@ -221,93 +125,41 @@ public class ConversationPropagator implements IRequestCycleListener
@Override
public void onRequestHandlerExecuted(RequestCycle cycle, IRequestHandler handler)
{
- Conversation conversation = getConversation(cycle);
-
- if (conversation == null)
- {
- return;
- }
-
- Page page = getPage(handler);
-
- if (page == null)
- {
- return;
- }
-
- // apply auto semantics
-
- autoEndIfNecessary(page, handler, conversation);
- autoBeginIfNecessary(page, handler, conversation);
-
- if (propagation.propagatesViaPage(page, handler))
- {
- // propagate a conversation across non-bookmarkable page instances
- setConversationOnPage(conversation, page);
- }
- }
-
- @Override
- public void onRequestHandlerScheduled(RequestCycle cycle, IRequestHandler handler)
- {
- // propagate current non-transient conversation to the newly scheduled page
-
- Conversation conversation = getConversation(cycle);
-
- if (conversation == null || conversation.isTransient())
- {
- return;
- }
-
- Page page = getPage(handler);
- if (page != null)
+ // propagate current non-transient conversation to the newly scheduled
+ // page
+ try
{
- if (propagation.propagatesViaPage(page, handler))
+ if (conversation.isTransient())
{
- // propagate a conversation across non-bookmarkable page instances
- setConversationOnPage(conversation, page);
+ return;
}
+ } catch (ContextNotActiveException cnax)
+ {
+ logger.debug("There is no active context for the requested scope!", cnax);
+ return;
}
- if (propagation.propagatesViaParameters(handler))
+ if (propagation.propagatesVia(handler, getPage(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, conversation.getId());
+ markPageWithConversationId(handler, conversation.getId());
}
}
}
- protected void setConversationOnPage(Conversation conversation, Page page)
- {
- if (conversation == null || conversation.isTransient())
- {
- logger.debug("Detaching transient conversation {} via meta of page instance {}",
- (conversation == null ? "null" : conversation.getId()), page);
-
- page.setMetaData(CID_KEY, null);
- }
- else
- {
-
- logger.debug("Propagating non-transient conversation {} via meta of page instance {}",
- conversation.getId(), page);
-
- page.setMetaData(CID_KEY, 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
+ // no need to propagate the conversation to packaged resources, they
+ // should never change
if (handler instanceof ResourceReferenceRequestHandler)
{
if (((ResourceReferenceRequestHandler)handler).getResourceReference() instanceof PackageResourceReference)
@@ -316,47 +168,41 @@ public class ConversationPropagator implements IRequestCycleListener
}
}
- Conversation conversation = getConversation(cycle);
-
- if (conversation == null || conversation.isTransient())
+ if (conversation.isTransient())
{
return;
}
- if (propagation.propagatesViaParameters(handler))
+ if (propagation.propagatesVia(handler, getPage(handler)))
{
- // propagate cid to bookmarkable pages via urls
-
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)
{
- Conversation conversation = getConversation(cycle);
- if (conversation != null)
+ if (!Boolean.TRUE.equals(cycle.getMetaData(CONVERSATION_STARTED_KEY)))
{
- logger.debug("Deactivating conversation {}", conversation.getId());
+ return;
+ }
- for (IRequestCycleListener listener : application.getRequestCycleListeners())
+ logger.debug("Deactivating conversation {}", conversation.getId());
+ for (IRequestCycleListener listener : application.getRequestCycleListeners())
+ {
+ if (listener instanceof ICdiAwareRequestCycleListener)
{
- if (listener instanceof ICdiAwareRequestCycleListener)
- {
- ((ICdiAwareRequestCycleListener)listener).onBeforeConversationDeactivated(cycle);
- }
+ ((ICdiAwareRequestCycleListener)listener).onBeforeConversationDeactivated(cycle);
}
- container.deactivateConversationalContext(cycle);
-
- cycle.setMetaData(CONVERSATION_STARTED_KEY, null);
}
}
/**
- * 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
+ * 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
@@ -366,71 +212,45 @@ public class ConversationPropagator implements IRequestCycleListener
{
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;
}
- protected void autoBeginIfNecessary(Page page, IRequestHandler handler,
- Conversation conversation)
+ public static void markPageWithConversationId(IRequestHandler handler, String cid)
{
- if (!auto || conversation == null || !conversation.isTransient() || page == null ||
- !propagation.propagatesViaPage(page, handler) || !hasConversationalComponent(page))
+ Page page = getPage(handler);
+ if (page != null)
{
- return;
+ page.setMetaData(CONVERSATION_ID_KEY, cid);
}
-
- // 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, Conversation conversation)
+ public static String getConversationIdFromPage(Page page)
{
- if (!auto || conversation == null || conversation.isTransient() || page == null ||
- !propagation.propagatesViaPage(page, handler) || hasConversationalComponent(page) ||
- autoConversation.isAutomatic() == false)
- {
- return;
- }
-
- // auto de-activate conversation
-
- String cid = conversation.getId();
-
- autoConversation.setAutomatic(false);
- conversation.end();
-
- logger.debug("Auto-ended conversation {} for page {}", cid, page);
+ return page.getMetaData(CONVERSATION_ID_KEY);
}
-
- protected boolean hasConversationalComponent(Page page)
+ public static void removeConversationIdFromPage(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;
+ page.setMetaData(CONVERSATION_ID_KEY, null);
}
/**
- * Resolves a page instance from the request handler iff the page instance is already created
+ * Resolves a page instance from the request handler iff the page instance
+ * is already created
*
* @param handler
* @return page or {@code null} if none