-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Support jetty-eeX-env.xml, as per jetty-eeX-web.xml #11752
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
124fd25
Support jetty-eeX-env.xml, as per jetty-eeX-web.xml
janbartel cc7887b
Fix checkstyle
janbartel 88f3cd6
Update jetty-ee10/jetty-ee10-plus/src/main/java/org/eclipse/jetty/ee1…
janbartel 919a0ce
Update jetty-ee9/jetty-ee9-plus/src/main/java/org/eclipse/jetty/ee9/p…
janbartel 2dc9d90
Update jetty-ee11/jetty-ee11-plus/src/main/java/org/eclipse/jetty/ee1…
janbartel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...etty-ee10-plus/src/test/java/org/eclipse/jetty/ee10/plus/webapp/EnvConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.ee10.plus.webapp; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.eclipse.jetty.ee10.webapp.WebAppContext; | ||
import org.eclipse.jetty.plus.jndi.NamingEntryUtil; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class EnvConfigurationTest | ||
{ | ||
Server _server; | ||
|
||
@BeforeEach | ||
public void setUp() | ||
{ | ||
_server = new Server(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() throws Exception | ||
{ | ||
if (_server != null) | ||
_server.stop(); | ||
} | ||
|
||
@Test | ||
public void testWithOnlyJettyWebXml() throws Exception | ||
{ | ||
Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-env-xml"); | ||
assertTrue(Files.exists(testWebappDir)); | ||
|
||
WebAppContext context = new WebAppContext(); | ||
context.setContextPath("/"); | ||
_server.setHandler(context); | ||
context.setWar(testWebappDir.toFile().getAbsolutePath()); | ||
_server.start(); | ||
assertNotNull(NamingEntryUtil.lookupNamingEntry(context, "apricot")); | ||
} | ||
|
||
@Test | ||
public void testWithJettyEEWebXml() throws Exception | ||
{ | ||
Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-ee10-env-xml"); | ||
assertTrue(Files.exists(testWebappDir)); | ||
|
||
WebAppContext context = new WebAppContext(); | ||
context.setContextPath("/"); | ||
_server.setHandler(context); | ||
context.setWar(testWebappDir.toFile().getAbsolutePath()); | ||
_server.start(); | ||
assertNotNull(NamingEntryUtil.lookupNamingEntry(context, "peach")); | ||
assertNull(NamingEntryUtil.lookupNamingEntry(context, "cabbage")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ty-ee10-plus/src/test/resources/webapp-with-jetty-ee10-env-xml/WEB-INF/jetty-ee10-env.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
|
||
<Configure id='wac' class="org.eclipse.jetty.ee10.webapp.WebAppContext"> | ||
|
||
<!-- Add an EnvEntry only valid for this webapp --> | ||
<New id="gargle" class="org.eclipse.jetty.plus.jndi.EnvEntry"> | ||
<Arg><Ref refid='wac'/></Arg> | ||
<Arg>peach</Arg> | ||
<Arg type="java.lang.Double">100</Arg> | ||
<Arg type="boolean">true</Arg> | ||
</New> | ||
|
||
</Configure> | ||
|
15 changes: 15 additions & 0 deletions
15
...y-ee10-plus/src/test/resources/webapp-with-jetty-ee10-env-xml/WEB-INF/jetty-ee101-env.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
|
||
<Configure id='wac' class="org.eclipse.jetty.ee10.webapp.WebAppContext"> | ||
|
||
<!-- Add an EnvEntry only valid for this webapp --> | ||
<New id="gargle" class="org.eclipse.jetty.plus.jndi.EnvEntry"> | ||
<Arg><Ref refid='wac'/></Arg> | ||
<Arg>cabbage</Arg> | ||
<Arg type="java.lang.Double">100</Arg> | ||
<Arg type="boolean">true</Arg> | ||
</New> | ||
|
||
</Configure> | ||
|
15 changes: 15 additions & 0 deletions
15
...0/jetty-ee10-plus/src/test/resources/webapp-with-jetty-ee10-env-xml/WEB-INF/jetty-env.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
|
||
<Configure id='wac' class="org.eclipse.jetty.ee10.webapp.WebAppContext"> | ||
|
||
<!-- Add an EnvEntry only valid for this webapp --> | ||
<New id="gargle" class="org.eclipse.jetty.plus.jndi.EnvEntry"> | ||
<Arg><Ref refid='wac'/></Arg> | ||
<Arg>apricot</Arg> | ||
<Arg type="java.lang.Double">100</Arg> | ||
<Arg type="boolean">true</Arg> | ||
</New> | ||
|
||
</Configure> | ||
|
15 changes: 15 additions & 0 deletions
15
...y-ee10/jetty-ee10-plus/src/test/resources/webapp-with-jetty-env-xml/WEB-INF/jetty-env.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
|
||
<Configure id='wac' class="org.eclipse.jetty.ee10.webapp.WebAppContext"> | ||
|
||
<!-- Add an EnvEntry only valid for this webapp --> | ||
<New id="gargle" class="org.eclipse.jetty.plus.jndi.EnvEntry"> | ||
<Arg><Ref refid='wac'/></Arg> | ||
<Arg>apricot</Arg> | ||
<Arg type="java.lang.Double">100</Arg> | ||
<Arg type="boolean">true</Arg> | ||
</New> | ||
|
||
</Configure> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ public class EnvConfiguration extends AbstractConfiguration | |
private static final Logger LOG = LoggerFactory.getLogger(EnvConfiguration.class); | ||
|
||
private static final String JETTY_ENV_BINDINGS = "org.eclipse.jetty.jndi.EnvConfiguration"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this name isn't ee11 specific, shouldn't this be in jetty-core? |
||
private static final String JETTY_EE11_ENV_XML_FILENAME = "jetty-ee11-env.xml"; | ||
private static final String JETTY_ENV_XML_FILENAME = "jetty-env.xml"; | ||
|
||
public EnvConfiguration() | ||
{ | ||
|
@@ -69,25 +71,11 @@ public void configure(WebAppContext context) throws Exception | |
if (LOG.isDebugEnabled()) | ||
LOG.debug("Created java:comp/env for webapp {}", context.getContextPath()); | ||
|
||
//check to see if an explicit file has been set, if not, | ||
//look in WEB-INF/jetty-env.xml | ||
|
||
//check to see if an explicit file has been set, | ||
Resource jettyEnvXmlResource = (Resource)context.getAttribute(JETTY_ENV_XML); | ||
if (jettyEnvXmlResource == null) | ||
{ | ||
//look for a file called WEB-INF/jetty-env.xml | ||
//and process it if it exists | ||
Resource webInf = context.getWebInf(); | ||
if (webInf != null && webInf.isDirectory()) | ||
{ | ||
// TODO: should never return from WEB-INF/lib/foo.jar!/WEB-INF/jetty-env.xml | ||
// TODO: should also never return from a META-INF/versions/#/WEB-INF/jetty-env.xml location | ||
Resource jettyEnv = webInf.resolve("jetty-env.xml"); | ||
if (Resources.exists(jettyEnv)) | ||
{ | ||
jettyEnvXmlResource = jettyEnv; | ||
} | ||
} | ||
jettyEnvXmlResource = resolveJettyEnvXml(context.getWebInf()); | ||
} | ||
|
||
if (jettyEnvXmlResource != null) | ||
|
@@ -241,6 +229,40 @@ protected void createEnvContext(WebAppContext wac) | |
} | ||
} | ||
|
||
/** | ||
* Obtain a WEB-INF/jetty-ee11-env.xml, falling back to | ||
* looking for WEB-INF/jetty-env.xml. | ||
* | ||
* @param webInf the WEB-INF of the context to search | ||
* @return the file if it exists or null otherwise | ||
*/ | ||
private Resource resolveJettyEnvXml(Resource webInf) | ||
{ | ||
try | ||
{ | ||
if (webInf == null || !webInf.isDirectory()) | ||
return null; | ||
|
||
//try to find jetty-ee10-env.xml | ||
Resource xmlResource = webInf.resolve(JETTY_EE11_ENV_XML_FILENAME); | ||
if (!Resources.missing(xmlResource)) | ||
return xmlResource; | ||
|
||
//failing that, look for jetty-env.xml | ||
xmlResource = webInf.resolve(JETTY_ENV_XML_FILENAME); | ||
if (!Resources.missing(xmlResource)) | ||
return xmlResource; | ||
|
||
return null; | ||
} | ||
catch (Exception e) | ||
{ | ||
if (LOG.isDebugEnabled()) | ||
LOG.debug("Error resolving", e); | ||
return null; | ||
} | ||
} | ||
|
||
private static class Dumper extends NamingDump | ||
{ | ||
Dumper(ClassLoader loader, String name) | ||
|
76 changes: 76 additions & 0 deletions
76
...etty-ee11-plus/src/test/java/org/eclipse/jetty/ee11/plus/webapp/EnvConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.ee11.plus.webapp; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import org.eclipse.jetty.ee11.webapp.WebAppContext; | ||
import org.eclipse.jetty.plus.jndi.NamingEntryUtil; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class EnvConfigurationTest | ||
{ | ||
Server _server; | ||
|
||
@BeforeEach | ||
public void setUp() | ||
{ | ||
_server = new Server(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() throws Exception | ||
{ | ||
if (_server != null) | ||
_server.stop(); | ||
} | ||
|
||
@Test | ||
public void testWithOnlyJettyWebXml() throws Exception | ||
{ | ||
Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-env-xml"); | ||
assertTrue(Files.exists(testWebappDir)); | ||
|
||
WebAppContext context = new WebAppContext(); | ||
context.setContextPath("/"); | ||
_server.setHandler(context); | ||
context.setWar(testWebappDir.toFile().getAbsolutePath()); | ||
_server.start(); | ||
assertNotNull(NamingEntryUtil.lookupNamingEntry(context, "apricot")); | ||
} | ||
|
||
@Test | ||
public void testWithJettyEEWebXml() throws Exception | ||
{ | ||
Path testWebappDir = MavenTestingUtils.getTargetPath("test-classes/webapp-with-jetty-ee11-env-xml"); | ||
assertTrue(Files.exists(testWebappDir)); | ||
|
||
WebAppContext context = new WebAppContext(); | ||
context.setContextPath("/"); | ||
_server.setHandler(context); | ||
context.setWar(testWebappDir.toFile().getAbsolutePath()); | ||
_server.start(); | ||
assertNotNull(NamingEntryUtil.lookupNamingEntry(context, "peach")); | ||
assertNull(NamingEntryUtil.lookupNamingEntry(context, "cabbage")); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ty-ee11-plus/src/test/resources/webapp-with-jetty-ee11-env-xml/WEB-INF/jetty-ee11-env.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"> | ||
|
||
<Configure id='wac' class="org.eclipse.jetty.ee11.webapp.WebAppContext"> | ||
|
||
<!-- Add an EnvEntry only valid for this webapp --> | ||
<New id="gargle" class="org.eclipse.jetty.plus.jndi.EnvEntry"> | ||
<Arg><Ref refid='wac'/></Arg> | ||
<Arg>peach</Arg> | ||
<Arg type="java.lang.Double">100</Arg> | ||
<Arg type="boolean">true</Arg> | ||
</New> | ||
|
||
</Configure> | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this binding key isn't ee10 specific, should this be in core?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe but there's no good place to put it (yet?).