Skip to content

Commit

Permalink
[WFLY-11065] Usage of static fields from java.lang classes as EL expr…
Browse files Browse the repository at this point in the history
…essions in JSPs doesn't work for servlet 4.0

 - fix of condition for version check in JspInitializationListener
 - extension of JspELTestCase for Servlet 4.0 and default servlet version with no web.xml
  • Loading branch information
jstourac committed Sep 25, 2018
1 parent d00a855 commit f0b2190
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 16 deletions.
Expand Up @@ -46,46 +46,90 @@
@RunAsClient
public class JspELTestCase {

private static final String Servlet_No_Spec_War = "jsp-el-test-no-web-xml";
private static final String Servlet_Spec_4_0_War = "jsp-el-test-4_0_servlet_spec";
private static final String Servlet_Spec_3_1_War = "jsp-el-test-3_1_servlet_spec";
private static final String Servlet_Spec_3_0_War = "jsp-el-test-3_0_servlet_spec";

@Deployment(name = Servlet_Spec_3_1_War)
@Deployment(name = Servlet_No_Spec_War)
public static WebArchive deploy() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(DummyConstants.class, DummyEnum.class)
.addAsWebInfResource(JspELTestCase.class.getResource("web-app_3_1.xml"), "web.xml")
.addAsWebResource(JspELTestCase.class.getResource("jsp-with-el.jsp"), "index.jsp");
}

@Deployment(name = Servlet_Spec_4_0_War)
public static WebArchive deploy40War() {
return deploy().addAsWebInfResource(JspELTestCase.class.getResource("web-app_4_0.xml"), "web.xml");
}

@Deployment(name = Servlet_Spec_3_1_War)
public static WebArchive deploy31War() {
return deploy().addAsWebInfResource(JspELTestCase.class.getResource("web-app_3_1.xml"), "web.xml");
}

@Deployment(name = Servlet_Spec_3_0_War)
public static WebArchive deploy30War() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(DummyConstants.class, DummyEnum.class)
.addAsWebInfResource(JspELTestCase.class.getResource("web-app_3_0.xml"), "web.xml")
.addAsWebResource(JspELTestCase.class.getResource("jsp-with-el.jsp"), "index.jsp");
return deploy().addAsWebInfResource(JspELTestCase.class.getResource("web-app_3_0.xml"), "web.xml");
}

final String POSSIBLE_ISSUES_LINKS =
"Might be caused by: https://issues.jboss.org/browse/WFLY-6939 or https://issues.jboss.org/browse/WFLY-11065";

/**
* Test that for web application using 3.1 version of servlet spec, EL expressions that use implicitly imported classes from <code>java.lang</code>
* package are evaluated correctly
* Test that for web application using default version of servlet spec, EL expressions that use implicitly imported
* classes from <code>java.lang</code> package are evaluated correctly
*
* @param url
* @throws Exception
*/
@OperateOnDeployment(Servlet_Spec_3_1_War)
@OperateOnDeployment(Servlet_No_Spec_War)
@Test
public void testJavaLangImplicitClassELEvaluation(@ArquillianResource URL url) throws Exception {
commonTestPart(url, POSSIBLE_ISSUES_LINKS);
}

/**
* Test that for web application using 4.0 version of servlet spec, EL expressions that use implicitly imported
* classes from <code>java.lang</code> package are evaluated correctly
*
* @param url
* @throws Exception
*/
@OperateOnDeployment(Servlet_Spec_4_0_War)
@Test
public void testJavaLangImplicitClassELEvaluation40(@ArquillianResource URL url) throws Exception {
commonTestPart(url, POSSIBLE_ISSUES_LINKS);
}

/**
* Test that for web application using 3.1 version of servlet spec, EL expressions that use implicitly imported
* classes from <code>java.lang</code> package are evaluated correctly
*
* @param url
* @throws Exception
*/
@OperateOnDeployment(Servlet_Spec_3_1_War)
@Test
public void testJavaLangImplicitClassELEvaluation31(@ArquillianResource URL url) throws Exception {
commonTestPart(url, POSSIBLE_ISSUES_LINKS);
}

private void commonTestPart(final URL url, final String possibleCausingIssues) throws Exception {
final String responseBody = HttpRequest.get(url + "index.jsp", 10, TimeUnit.SECONDS);
Assert.assertTrue("Unexpected EL evaluation for ${Boolean.TRUE}", responseBody.contains("Boolean.TRUE: --- " + Boolean.TRUE + " ---"));
Assert.assertTrue("Unexpected EL evaluation for ${Integer.MAX_VALUE}", responseBody.contains("Integer.MAX_VALUE: --- " + Integer.MAX_VALUE + " ---"));
Assert.assertTrue("Unexpected EL evaluation for ${DummyConstants.FOO}", responseBody.contains("DummyConstants.FOO: --- " + DummyConstants.FOO + " ---"));
Assert.assertTrue("Unexpected EL evaluation for ${DummyEnum.VALUE}", responseBody.contains("DummyEnum.VALUE: --- " + DummyEnum.VALUE + " ---"));
Assert.assertTrue("Unexpected EL evaluation for ${Boolean.TRUE}; " + possibleCausingIssues,
responseBody.contains("Boolean.TRUE: --- " + Boolean.TRUE + " ---"));
Assert.assertTrue("Unexpected EL evaluation for ${Integer.MAX_VALUE}; " + possibleCausingIssues,
responseBody.contains("Integer.MAX_VALUE: --- " + Integer.MAX_VALUE + " ---"));
Assert.assertTrue("Unexpected EL evaluation for ${DummyConstants.FOO}; " + possibleCausingIssues,
responseBody.contains("DummyConstants.FOO: --- " + DummyConstants.FOO + " ---"));
Assert.assertTrue("Unexpected EL evaluation for ${DummyEnum.VALUE}; " + possibleCausingIssues,
responseBody.contains("DummyEnum.VALUE: --- " + DummyEnum.VALUE + " ---"));
}

/**
* Test that for web application using servlet spec version lesser than 3.1, EL expressions can't consider classes belonging to <code>java.lang</code>
* package as implicitly imported and usable in the EL expressions
* Test that for web application using servlet spec version lesser than 3.1, EL expressions can't consider classes
* belonging to <code>java.lang</code> package as implicitly imported and usable in the EL expressions
*
* @param url
* @throws Exception
Expand Down
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
</web-app>
Expand Up @@ -47,7 +47,8 @@ public void contextInitialized(final ServletContextEvent sce) {
// if the servlet version is 3.1 or higher, setup a ELResolver which allows usage of static fields java.lang.*
final ServletContext servletContext = sce.getServletContext();
final JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(servletContext);
if (servletContext.getEffectiveMajorVersion() >= 3 && servletContext.getEffectiveMinorVersion() >= 1) {
if (servletContext.getEffectiveMajorVersion() > 3
|| (servletContext.getEffectiveMajorVersion() == 3 && servletContext.getEffectiveMinorVersion() >= 1)) {
jspApplicationContext.addELResolver(new ImportedClassELResolver());
}
// setup a wrapped JspApplicationContext if there are any EL expression factory wrappers for this servlet context
Expand Down

0 comments on commit f0b2190

Please sign in to comment.