Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAXWEB-993] Fix JSF-Support for Tomcat and enable Tests #89

Merged
merged 1 commit into from Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,7 +17,6 @@

import org.junit.After;
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 @@ -35,14 +34,11 @@
import java.util.regex.Pattern;

import static org.junit.Assert.fail;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.MavenUtils.asInProject;

/**
* @author Achim Nierbeck
*/
@RunWith(PaxExam.class)
@Ignore("Failes: can't find the EL factory -> [PAXWEB-929] should fix this")
public class WarJSFTCIntegrationTest extends ITestBase {

private Bundle installWarBundle;
Expand Down Expand Up @@ -96,7 +92,7 @@ public void testSlash() throws Exception {
HttpTestClientFactory.createDefaultTestClient()
.withResponseAssertion("Response must contain 'Please enter your name'",
resp -> resp.contains("Please enter your name"))
.doGETandExecuteTest("http://127.0.0.1:8282/war-jsf-sample/");
.doGETandExecuteTest("http://127.0.0.1:8282/war-jsf-sample/index.jsp");
}

@Test
Expand Down Expand Up @@ -128,7 +124,7 @@ public void testJSF() throws Exception {
logger.debug("Found ID: {}", inputID);
return true;
})
.doGETandExecuteTest("http://127.0.0.1:8282/war-jsf-sample");
.doGETandExecuteTest("http://127.0.0.1:8282/war-jsf-sample/index.jsp");

Pattern patternViewState = Pattern
.compile("id=\\\"j_id_.*:javax.faces.ViewState:\\w\\\"");
Expand Down Expand Up @@ -156,7 +152,7 @@ public void testJSF() throws Exception {
.useCookieState(cookieState)
.withResponseAssertion("Response from POST must contain 'Hello Dummy-User. We hope you enjoy Apache MyFaces'",
resp -> resp.contains("Hello Dummy-User. We hope you enjoy Apache MyFaces"))
.doPOST("http://127.0.0.1:8181/war-jsf-sample/faces/helloWorld.jsp")
.doPOST("http://127.0.0.1:8282/war-jsf-sample/faces/helloWorld.jsp")
.addParameter("mainForm:name", "Dummy-User")
.addParameter(viewStateID, viewStateValue)
.addParameter(inputID, "Press me")
Expand Down
Expand Up @@ -21,12 +21,13 @@
package org.ops4j.pax.web.itest.tomcat;

import org.apache.commons.lang3.StringUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.ops4j.pax.web.itest.base.TestConfiguration;
import org.ops4j.pax.web.itest.base.WaitCondition2;
import org.ops4j.pax.web.itest.base.assertion.BundleMatchers;
Expand Down Expand Up @@ -56,14 +57,16 @@

import static org.junit.Assert.fail;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.OptionUtils.combine;
import static org.ops4j.pax.web.itest.base.assertion.Assert.assertThat;

/**
* @author Marc Schlegel
*/
@RunWith(PaxExam.class)
// testResourceUnavailable uninstalls a bundle, so it destroys the container for
// other tests. Therefore we need a new container per test method
@ExamReactorStrategy(PerMethod.class)
public class WarJsfResourcehandlerIntegrationTest extends ITestBase {

@Configuration
Expand Down Expand Up @@ -146,7 +149,6 @@ public void testServiceOverride() throws Exception {
* </pre>
*/
@Test
@Ignore("[PAXWEB-929] should fix this")
public void testJsfResourceHandler() throws Exception {
final String pageUrl = "http://127.0.0.1:8282/osgi-resourcehandler-myfaces/index.xhtml";
final String imageUrl = "http://127.0.0.1:8282/osgi-resourcehandler-myfaces/javax.faces.resource/images/iceland.jpg.xhtml?type=osgi&ln=default&lv=2_0";
Expand Down
Expand Up @@ -148,7 +148,7 @@ public void testAdditionalWar() throws Exception {

HttpTestClientFactory.createDefaultTestClient()
.withResponseAssertion("Response must contain '<h1>Hello World</h1>'",
resp -> resp.contains("<h1>Hello World!</h1>"))
resp -> resp.contains("<h1>Hello World</h1>"))
.doGETandExecuteTest("http://127.0.0.1:8282/war/wc");
HttpTestClientFactory.createDefaultTestClient()
.withResponseAssertion("Response must contain '<h2>Hello World!</h2>'",
Expand Down
6 changes: 5 additions & 1 deletion pax-web-tomcat/pom.xml
Expand Up @@ -82,7 +82,11 @@
org.osgi.service.http; version="[1.0.0,2.0.0)",
org.slf4j; version="[1.5,2)",
javax.el; version="[2.1.0,3.1.0)";resolution:=optional,
org.apache.el.*; version="2.2",
org.apache.el; version="2.2"; resolution:=optional,
org.apache.el.lang; version="2.2"; resolution:=optional,
org.apache.el.parser; version="2.2"; resolution:=optional,
org.apache.el.stream; version="2.2"; resolution:=optional,
org.apache.el.util; version="2.2"; resolution:=optional
org.apache.catalina,
org.apache.catalina.authenticator,
org.apache.catalina.comet,
Expand Down
Expand Up @@ -26,7 +26,6 @@
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.DispatcherType;
Expand Down Expand Up @@ -73,8 +72,8 @@
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.apache.tomcat.util.descriptor.web.TaglibDescriptorImpl;
import org.ops4j.lang.NullArgumentException;
import org.ops4j.pax.swissbox.core.BundleClassLoader;
import org.ops4j.pax.swissbox.core.BundleUtils;
import org.ops4j.pax.swissbox.core.ContextClassLoaderUtils;
import org.ops4j.pax.web.service.WebContainerConstants;
import org.ops4j.pax.web.service.WebContainerContext;
import org.ops4j.pax.web.service.spi.LifeCycle;
Expand All @@ -86,6 +85,7 @@
import org.ops4j.pax.web.service.spi.model.SecurityConstraintMappingModel;
import org.ops4j.pax.web.service.spi.model.ServletModel;
import org.ops4j.pax.web.service.spi.model.WelcomeFileModel;
import org.ops4j.pax.web.service.spi.util.ResourceDelegatingBundleClassLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
Expand Down Expand Up @@ -271,23 +271,7 @@ private OsgiExistingStandardWrapper(Servlet existing, ServletModel model) {
@Override
public synchronized void load() throws ServletException {
try {
instance = ContextClassLoaderUtils.doWithClassLoader(
model.getContextModel().getClassLoader(),
new Callable<Servlet>() {

@Override
public Servlet call() {
try {
return loadServlet();
} catch (final ServletException e) {
LOG.warn(
"Caucht exception while loading Servlet with classloader {}",
e);
return null;
}
}

});
instance = loadServlet();
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
Expand Down Expand Up @@ -876,18 +860,7 @@ public void start() throws Exception {
if (!context.getState().isAvailable()) {
LOG.info("server is available, in state {}",
context.getState());

ContextClassLoaderUtils.doWithClassLoader(
context.getParentClassLoader(),
new Callable<Void>() {

@Override
public Void call() throws LifecycleException {
context.start();
return null;
}

});
context.start();
}
}

Expand Down Expand Up @@ -952,7 +925,13 @@ private Context createContext(final ContextModel contextModel) {
server.getBasedir());

context.setDisplayName(httpContext.getContextId());
context.setParentClassLoader(contextModel.getClassLoader());
// Similar to the Jetty fix for PAXWEB-725
// Without this the el implementation is not found
ClassLoader classLoader = contextModel.getClassLoader();
List<Bundle> bundles = ((ResourceDelegatingBundleClassLoader) classLoader).getBundles();
ClassLoader parentClassLoader = getClass().getClassLoader();
ResourceDelegatingBundleClassLoader containerSpecificClassLoader = new ResourceDelegatingBundleClassLoader(bundles, parentClassLoader);
context.setParentClassLoader(containerSpecificClassLoader);
// TODO: is the context already configured?
// TODO: how about security, classloader?
// TODO: compare with JettyServerWrapper.addContext
Expand Down