Skip to content

Commit

Permalink
[WABs, tests] Working tests for listener invocation order. Additional…
Browse files Browse the repository at this point in the history
… compatibility bundles
  • Loading branch information
grgrzybek committed Jul 6, 2021
1 parent 5e555f6 commit dac8317
Show file tree
Hide file tree
Showing 42 changed files with 708 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -226,7 +227,7 @@ public String toString() {
/**
* <p>A {@link BundleWebApplication} can be started only once. Even if "Figure 128.2 State diagram Web Application"
* shows that WAB * can go from UNDEPLOYED to DEPLOYING state, we're using
* {@link org.apache.felix.utils.extender.AbstractExtender#destroyExtension}, so what will be started after
* {@code org.apache.felix.utils.extender.AbstractExtender#destroyExtension}, so what will be started after
* undeployment is a new instance of {@link BundleWebApplication}. Again it's important to distinguish
* {@link BundleWebApplication.State} and {@link WebApplicationEvent.State}.</p>
*
Expand Down Expand Up @@ -1172,6 +1173,8 @@ private void buildModel() {
// very important step - we pass a classloader, which contains reachable bundles - bundles discovered when
// WAB's metadata was parsed/processed
ocm.setClassLoader(this.classLoader);
// this is important - we should be able to reference the context by path (not by name)
ocm.getContextRegistrationProperties().put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, this.contextPath);

// this is the best place to think about how to reference the underlying "context"
// in HttpService and Whiteboard scenarios.
Expand Down Expand Up @@ -1256,8 +1259,11 @@ private void buildModel() {
// 1.4. Context initial parameters
ocm.getContextParams().putAll(mainWebXml.getContextParams());
// TODO: do it consistently using runtime configuration of temp directory
ocm.getInitialContextAttributes().put(ServletContext.TEMPDIR,
new File(System.getProperty("java.io.tmpdir"), ocm.getTemporaryLocation()));
File tmpLocation = new File(System.getProperty("java.io.tmpdir"), ocm.getTemporaryLocation());
if (!tmpLocation.mkdirs()) {
LOG.warn("Can't create temporary directory for {}: {}", ocm, tmpLocation.getAbsolutePath());
}
ocm.getInitialContextAttributes().put(ServletContext.TEMPDIR, tmpLocation);

wabBatch.addOsgiContextModel(ocm, scm);
wabBatch.associateOsgiContextModel(httpContext, ocm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ public void initialize(WebXml mainWebXml, OsgiServletContextClassLoader wabClass
orderedFragments.put(fragment.getJarName(), fragment);
}

List<String> orderedLibsAttribute = (List<String>) context.getAttribute(ServletContext.ORDERED_LIBS);
orderedLibs = orderedLibsAttribute == null ? Collections.emptyList() : orderedLibsAttribute;
orderedLibs = (List<String>) context.getAttribute(ServletContext.ORDERED_LIBS);

// After collecting the bundles associated with ordered web fragments, we can finish the "construction"
// of WAB's classloader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ public List<OsgiContextModel> resolveContexts(Bundle bundle, Filter selector) {
// to work, we're explicitly skipping "shared" contexts - user will still be able to use such shared
// HttpService contexts (specific to Pax Web), but with more effort.
for (OsgiContextModel model : getBundleApplication(bundle).getWebContainerOsgiContextModels()) {
if (!model.isShared() && selector.matchCase(model.getContextRegistrationProperties())) {
if ((!model.isShared() || model.isWab())
&& selector.matchCase(model.getContextRegistrationProperties())) {
targetContexts.add(model);
}
}
Expand Down Expand Up @@ -396,6 +397,7 @@ private void reRegisterWebElements() {
// 1. unregistration because of no matching contexts
// TODO: DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
if (newMatching.size() == 0) {
LOG.debug("Unregistering {} because its context selection filter doesn't match any context", webElement);
if (view != null) {
webElement.unregister(view);
}
Expand All @@ -407,6 +409,7 @@ private void reRegisterWebElements() {
// TODO: get rid of existing DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
if (oldMatching.size() == 0) {
webElement.changeContextModels(newMatching);
LOG.debug("Registering {} because its context selection filter started matching existing contexts", webElement);
if (view != null) {
webElement.register(view);
}
Expand All @@ -427,10 +430,12 @@ private void reRegisterWebElements() {
// so it's really easier - FULLY unregister the element from all current contexts and then
// register to all the new contexts
if (view != null) {
LOG.debug("Unregistering {} because its context selection filter matched new set of contexts", webElement);
webElement.unregister(view);
}
webElement.changeContextModels(newMatching);
if (view != null) {
LOG.debug("Registering {} again after its context selection filter matched new set of contexts", webElement);
webElement.register(view);
}
}
Expand Down Expand Up @@ -490,7 +495,7 @@ private BundleWhiteboardApplication getBundleApplication(final Bundle bundle) {

/**
* This method is invoked after checking that element model {@link ElementModel#isValid() is valid}.
* @param httpServiceRuntime
* @param webElement
*/
public void configureDTOs(ElementModel<?, ?> webElement) {
// TODO: could result in DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
Expand All @@ -499,21 +504,21 @@ public void configureDTOs(ElementModel<?, ?> webElement) {

/**
* This method is invoked after checking that element model {@link ElementModel#isValid() is not valid}.
* @param httpServiceRuntime
* @param webElement
*/
public void configureFailedDTOs(ElementModel<?, ?> webElement) {
}

/**
* This method is invoked after checking that context model {@link OsgiContextModel#isValid() is valid}.
* @param httpServiceRuntime
* @param webContext
*/
public void configureDTOs(OsgiContextModel webContext) {
}

/**
* This method is invoked after checking that context model {@link OsgiContextModel#isValid() is not valid}.
* @param httpServiceRuntime
* @param webContext
*/
public void configureFailedDTOs(OsgiContextModel webContext) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<parent>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility</artifactId>
<artifactId>pax-web-fragments</artifactId>
<version>8.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<parent>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility</artifactId>
<artifactId>pax-web-fragments</artifactId>
<version>8.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down Expand Up @@ -61,12 +61,12 @@
version:List<Version>="2.0,1.2,1.1,1.0"
]]></Provide-Capability>
<Require-Capability><![CDATA[
osgi.serviceloader;filter:="(osgi.serviceloader=javax.enterprise.inject.se.SeContainerInitializer)";cardinality:=multiple,
osgi.serviceloader;filter:="(osgi.serviceloader=javax.enterprise.inject.spi.CDIProvider)";cardinality:=multiple,
osgi.extender;filter:="(osgi.extender=osgi.serviceloader.processor)",
osgi.contract;osgi.contract=JavaEL;filter:="(&(osgi.contract=JavaEL)(version=2.2.0))",
osgi.contract;osgi.contract=JavaInterceptor;filter:="(&(osgi.contract=JavaInterceptor)(version=1.2.0))",
osgi.contract;osgi.contract=JavaInject;filter:="(&(osgi.contract=JavaInject)(version=1.0.0))"
osgi.serviceloader;filter:="(osgi.serviceloader=javax.enterprise.inject.se.SeContainerInitializer)";cardinality:=multiple;resolution:=optional,
osgi.serviceloader;filter:="(osgi.serviceloader=javax.enterprise.inject.spi.CDIProvider)";cardinality:=multiple;resolution:=optional,
osgi.extender;filter:="(osgi.extender=osgi.serviceloader.processor)";resolution:=optional,
osgi.contract;osgi.contract=JavaEL;filter:="(&(osgi.contract=JavaEL)(version=2.2.0))";resolution:=optional,
osgi.contract;osgi.contract=JavaInterceptor;filter:="(&(osgi.contract=JavaInterceptor)(version=1.2.0))";resolution:=optional,
osgi.contract;osgi.contract=JavaInject;filter:="(&(osgi.contract=JavaInject)(version=1.0.0))";resolution:=optional
]]></Require-Capability>
<!-- <Require-Capability><![CDATA[-->
<!-- osgi.serviceloader;filter:="(osgi.serviceloader=javax.enterprise.inject.se.SeContainerInitializer)";cardinality:=multiple,-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<parent>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility</artifactId>
<artifactId>pax-web-fragments</artifactId>
<version>8.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<parent>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility</artifactId>
<artifactId>pax-web-fragments</artifactId>
<version>8.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<parent>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility</artifactId>
<artifactId>pax-web-fragments</artifactId>
<version>8.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
Expand Down
70 changes: 70 additions & 0 deletions pax-web-fragments/pax-web-fragment-myfaces-spifly/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2020 OPS4J.
Licensed 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.ops4j.pax.web</groupId>
<artifactId>pax-web-fragments</artifactId>
<version>8.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-fragment-myfaces-spifly</artifactId>
<packaging>bundle</packaging>

<name>OPS4J Pax Web - myfaces-impl SPI-FLY integration </name>

<description>
This fragment bundle adds SPI-FLY requirements to myfaces-impl so it can be detected as CDI extension
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Fragment-Host>org.apache.myfaces.core.impl</Fragment-Host>
<Require-Capability><![CDATA[
osgi.extender;filter:="(&(osgi.extender=osgi.serviceloader.registrar)(version>=1.0)(!(version>=2.0)))"
]]></Require-Capability>
<Provide-Capability>
osgi.serviceloader;osgi.serviceloader=javax.enterprise.inject.spi.Extension;aries.cdi.extension.mode=implicit
</Provide-Capability>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>

<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-impl</artifactId>
</dependency>

</dependencies>

</project>
10 changes: 8 additions & 2 deletions pax-web-compatibility/pom.xml → pax-web-fragments/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@
</parent>

<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility</artifactId>
<artifactId>pax-web-fragments</artifactId>
<packaging>pom</packaging>

<name>OPS4J Pax Web - Compatibility bundles</name>
<name>OPS4J Pax Web - support bundles</name>

<modules>
<!--
These are fragments that either export older versions of some packages or add osgi.contracts to
JakartaEE _canonical_ API jars
-->
<module>pax-web-compatibility-cdi12</module>
<module>pax-web-compatibility-servlet31</module>
<module>pax-web-compatibility-el2</module>
<module>pax-web-compatibility-interceptor12</module>
<module>pax-web-compatibility-annotation13</module>
<!-- These are other support fragments -->
<module>pax-web-fragment-myfaces-spifly</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,10 @@ protected Option[] myfaces() {
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.ops4j.pax.web", "pax-web-compatibility-interceptor12")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 2).noStart(),
// it has to be CDI 1.2 for Myfaces 2.3.x
mavenBundle("javax.enterprise", "cdi-api")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("jakarta.enterprise", "jakarta.enterprise.cdi-api")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1).noStart(),
mavenBundle("org.ops4j.pax.web", "pax-web-compatibility-cdi12")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 2).noStart(),
mavenBundle("commons-collections", "commons-collections")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("commons-beanutils", "commons-beanutils")
Expand Down Expand Up @@ -491,6 +492,8 @@ protected Option[] ariesCdiAndMyfaces(String containerCdiArtifact) {
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.apache.myfaces.core", "myfaces-impl")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.ops4j.pax.web", "pax-web-fragment-myfaces-spifly")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 2).noStart(),

// These 4 would be required because of osgi.contract capabilities. But Pax Web provides proper
// compatibility bundles that fix _canonical_ jakarta API bundles
Expand Down Expand Up @@ -529,6 +532,8 @@ protected Option[] ariesCdiAndMyfaces(String containerCdiArtifact) {
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.apache.aries.cdi", "org.apache.aries.cdi.extension.servlet.weld")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.apache.aries.cdi", "org.apache.aries.cdi.extension.el.jsp")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.apache.aries.cdi", "org.apache.aries.cdi.extra")
.versionAsInProject().startLevel(START_LEVEL_TEST_BUNDLE - 1),
mavenBundle("org.jboss.weld", "weld-osgi-bundle")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility-annotation13</artifactId>
</dependency>
<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-fragment-myfaces-spifly</artifactId>
</dependency>

<!-- pax-web war samples -->

Expand Down Expand Up @@ -436,6 +440,10 @@
<groupId>org.apache.aries.cdi</groupId>
<artifactId>org.apache.aries.cdi.extra</artifactId>
</dependency>
<dependency>
<groupId>org.apache.aries.cdi</groupId>
<artifactId>org.apache.aries.cdi.extension.el.jsp</artifactId>
</dependency>

<dependency>
<groupId>org.apache.aries.spifly</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.ops4j.pax.web.itest.jetty.war.jsf;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
Expand All @@ -29,15 +28,16 @@
import static org.ops4j.pax.exam.OptionUtils.combine;

@RunWith(PaxExam.class)
public class WarJsfCdiIntegrationTest extends AbstractWarJsfCdiIntegrationTest {
public class WarJSFCdiIntegrationTest extends AbstractWarJsfCdiIntegrationTest {

private Bundle wab;

@Configuration
public Option[] configure() {
Option[] serverOptions = combine(baseConfigure(), paxWebJetty());
Option[] osgiOptions = combine(serverOptions, configAdmin());
Option[] jspOptions = combine(osgiOptions, paxWebJsp());
Option[] whiteboardOptions = combine(osgiOptions, paxWebExtenderWhiteboard());
Option[] jspOptions = combine(whiteboardOptions, paxWebJsp());
Option[] cdiOptions = combine(jspOptions, ariesCdiAndMyfaces(containerSpecificCdiBundle()));
return combine(cdiOptions, paxWebExtenderWar());
}
Expand Down
4 changes: 2 additions & 2 deletions pax-web-itest/pax-web-itest-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<include>**/*IntegrationTest.java</include>
</includes>
<excludes>
<exclude>**/WarJsfCdiIntegrationTest.java</exclude>
<exclude>**/WarJSFCdiIntegrationTest.java</exclude>
</excludes>
<systemPropertyVariables>
<!--
Expand Down Expand Up @@ -143,7 +143,7 @@
<exclude>**/*</exclude>
</excludes>
<includes>
<include>**/WarJsfCdiIntegrationTest.java</include>
<include>**/WarJSFCdiIntegrationTest.java</include>
</includes>
<classpathDependencyExcludes>
<!-- This includes osgi.core R6 -->
Expand Down
5 changes: 5 additions & 0 deletions pax-web-itest/pax-web-itest-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-compatibility-annotation13</artifactId>
</dependency>

<!-- pax-web internal samples -->

<dependency>
Expand Down
Loading

0 comments on commit dac8317

Please sign in to comment.