Merged branch 'jetty-9.4.x' into 'jetty-10.0.x'.
This commit is contained in:
commit
5346980dbb
|
@ -2,21 +2,21 @@
|
|||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
|
||||
|
||||
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
<Call name="prependServerClass">
|
||||
<Arg>-org.eclipse.jetty.util.Decorator</Arg>
|
||||
</Call>
|
||||
<Call name="prependServerClass">
|
||||
<Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
|
||||
</Call>
|
||||
<Call name="prependServerClass">
|
||||
<Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
|
||||
</Call>
|
||||
<Call name="prependServerClass">
|
||||
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
|
||||
</Call>
|
||||
<Call name="prependServerClass">
|
||||
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
|
||||
</Call>
|
||||
|
||||
<Get name="serverClasspathPattern">
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.util.Decorator</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.util.DecoratedObjectFactory</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.server.handler.ContextHandler.</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.server.handler.ContextHandler</Arg>
|
||||
</Call>
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.servlet.ServletContextHandler</Arg>
|
||||
</Call>
|
||||
</Get>
|
||||
</Configure>
|
||||
|
|
|
@ -32,7 +32,8 @@ ____
|
|||
|
||||
This configuration is essentially the multiple logger configuration with added configuration to the deployers to force a `WebAppClassLoader` change to use the server classpath over the webapps classpath for the logger specific classes.
|
||||
|
||||
The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[WebAppContext.addSystemClass(String)] for the common logging classes.
|
||||
The technique used by this configuration is to provide an link:{JDURL}org/eclipse/jetty/deploy/AppLifeCycle.Binding.html[AppLifeCycle.Binding] against the link:{JDURL}/org/eclipse/jetty/deploy/AppLifeCycle.html[`"deploying"`node] that modifies the
|
||||
link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#getSystemClasspathPattern()[WebAppContext.getSystemClasspathPattern().add(String)] for the common logging classes.
|
||||
See https://github.com/jetty-project/jetty-webapp-logging/blob/master/src/main/java/org/eclipse/jetty/webapp/logging/CentralizedWebAppLoggingBinding.java[org.eclipse.jetty.logging.CentralizedWebAppLoggingBinding] for actual implementation.
|
||||
|
||||
A convenient replacement `logging` module has been created to bootstrap your `${jetty.base}` directory for capturing all Jetty server logging from multiple logging frameworks into a single logging output file managed by Logback.
|
||||
|
|
|
@ -94,9 +94,11 @@ From a context xml file, you reference the Server instance as a Ref:
|
|||
[source, xml, subs="{sub-order}"]
|
||||
----
|
||||
<!-- Expose the jetty infinispan classes for session serialization -->
|
||||
<Call name="prependServerClass">
|
||||
<Arg>-org.eclipse.jetty.session.infinispan.</Arg>
|
||||
</Call>
|
||||
<Get name="serverClasspathPattern">
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.session.infinispan.</Arg>
|
||||
</Call>
|
||||
</Get>
|
||||
|
||||
|
||||
<!-- Get a reference to the InfinispanSessionIdManager -->
|
||||
|
@ -132,10 +134,12 @@ From a `WEB-INF/jetty-web.xml` file, you can reference the Server instance direc
|
|||
|
||||
[source, xml, subs="{sub-order}"]
|
||||
----
|
||||
<!-- Expose the jetty infinispan classes for session serialization -->
|
||||
<Call name="prependServerClass">
|
||||
<!-- Expose the jetty infinispan classes for session serialization -->
|
||||
<Get name="serverClasspathPattern">
|
||||
<Call name="add">
|
||||
<Arg>-org.eclipse.jetty.session.infinispan.</Arg>
|
||||
</Call>
|
||||
</Get>
|
||||
|
||||
<!-- Reference the server directly -->
|
||||
<Get name="server">
|
||||
|
@ -143,25 +147,25 @@ From a `WEB-INF/jetty-web.xml` file, you can reference the Server instance direc
|
|||
</Get>
|
||||
|
||||
<!-- Get a reference to the Cache via the InfinispanSessionIdManager -->
|
||||
<Ref id="idMgr">
|
||||
<Get id="cache" name="cache"/>
|
||||
</Ref>
|
||||
<Ref id="idMgr">
|
||||
<Get id="cache" name="cache"/>
|
||||
</Ref>
|
||||
|
||||
<!-- Apply the SessionIdManager and Cache to the InfinispanSessionManager -->
|
||||
<Set name="sessionHandler">
|
||||
<New class="org.eclipse.jetty.server.session.SessionHandler">
|
||||
<Arg>
|
||||
<New id="mgr" class="org.eclipse.jetty.session.infinispan.InfinispanSessionManager">
|
||||
<Set name="sessionIdManager">
|
||||
<Ref id="idMgr"/>
|
||||
</Set>
|
||||
<Set name="cache">
|
||||
<Ref id="cache">
|
||||
</Ref>
|
||||
</Set>
|
||||
<Set name="scavengeInterval">600</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
<Arg>
|
||||
<New id="mgr" class="org.eclipse.jetty.session.infinispan.InfinispanSessionManager">
|
||||
<Set name="sessionIdManager">
|
||||
<Ref id="idMgr"/>
|
||||
</Set>
|
||||
<Set name="cache">
|
||||
<Ref id="cache">
|
||||
</Ref>
|
||||
</Set>
|
||||
<Set name="scavengeInterval">600</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</New>
|
||||
</Set>
|
||||
----
|
||||
|
@ -178,7 +182,7 @@ staleIntervalSec::
|
|||
===== Using HotRod
|
||||
|
||||
If you're using the hotrod client - where serialization will be required - you will need to ensure that the hotrod marshalling software works with Jetty classloading.
|
||||
To do this, firstly ensure that you have included the lines containing the `prependServerClass` to your context xml file as shown above.
|
||||
To do this, firstly ensure that you have included the lines containing the `getServerClasspathPattern().add(...)` to your context xml file as shown above.
|
||||
|
||||
Then, create the file `${jetty.base}/resources/hotrod-client.properties`.
|
||||
Add the following line to this file:
|
||||
|
|
|
@ -79,7 +79,11 @@ Below is an example of implementing this feature using Jetty IoC XML format:
|
|||
[[classloading-setting-system-classes]]
|
||||
===== Setting System Classes
|
||||
|
||||
You can call the methods link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#setSystemClasses%28java.lang.String%5B%5D%29[org.eclipse.jetty.webapp.WebAppContext.setSystemClasses(String Array)] or link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#addSystemClass(java.lang.String)[org.eclipse.jetty.webapp.WebAppContext.addSystemClass(String)] to allow fine control over which classes are considered System classes.
|
||||
You can call the methods
|
||||
link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#setSystemClasses%28java.lang.String%5B%5D%29[WebAppContext.setSystemClasses(String[\])]
|
||||
or
|
||||
link:{JDURL}/org/eclipse/jetty/webapp/WebAppContext.html#getSystemClasspathPattern()[WebAppContext.getSystemClasspathPattern().add(String)]
|
||||
to allow fine control over which classes are considered system classes.
|
||||
|
||||
* A web application can see a System class.
|
||||
* A WEB-INF class cannot replace a System class.
|
||||
|
|
|
@ -1103,7 +1103,8 @@ public class NamingContext implements Context, Dumpable
|
|||
/* ------------------------------------------------------------ */
|
||||
public boolean isLocked()
|
||||
{
|
||||
return _lock != null || (_parent!=null && _parent.isLocked());
|
||||
//TODO lock whole hierarchy?
|
||||
return _lock != null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -479,7 +479,10 @@ public class TestJNDI
|
|||
{
|
||||
zzz = new InitialContext();
|
||||
|
||||
((Context)zzz.lookup("java:comp/ttt/ttt2")).bind("zzz2", "zzz2");
|
||||
//TODO test deep locking
|
||||
// ((Context)zzz.lookup("java:comp/ttt/ttt2")).bind("zzz2", "zzz2");
|
||||
// fail("Should not be able to write to locked context");
|
||||
((Context)zzz.lookup("java:comp")).bind("foo", "bar");
|
||||
fail("Should not be able to write to locked context");
|
||||
}
|
||||
catch (NamingException ne)
|
||||
|
|
|
@ -38,8 +38,8 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
public class StringUtil
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(StringUtil.class);
|
||||
|
||||
|
||||
|
||||
|
||||
private final static Trie<String> CHARSETS= new ArrayTrie<>(256);
|
||||
|
||||
public static final String ALL_INTERFACES="0.0.0.0";
|
||||
|
|
|
@ -198,36 +198,62 @@ public abstract class AbstractLogger implements Logger
|
|||
* the fully qualified class name
|
||||
* @return the condensed name
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected static String condensePackageString(String classname)
|
||||
{
|
||||
if(classname == null || classname.isEmpty())
|
||||
if (classname == null || classname.isEmpty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
// strip non-allowed character
|
||||
String allowed = classname.replaceAll("[^\\w.]", "");
|
||||
int len = allowed.length();
|
||||
// find end of classname (strip empty sections. eg: "org.Foo.")
|
||||
while(allowed.charAt(--len) == '.');
|
||||
String parts[] = allowed.substring(0,len+1).split("\\.");
|
||||
StringBuilder dense = new StringBuilder();
|
||||
for (int i = 0; i < (parts.length - 1); i++)
|
||||
|
||||
int rawLen = classname.length();
|
||||
StringBuilder dense = new StringBuilder(rawLen);
|
||||
boolean foundStart = false;
|
||||
boolean hasPackage = false;
|
||||
int startIdx = -1;
|
||||
int endIdx = -1;
|
||||
for (int i = 0; i < rawLen; i++)
|
||||
{
|
||||
String part = parts[i].trim();
|
||||
if(!part.isEmpty())
|
||||
char c = classname.charAt(i);
|
||||
if (!foundStart)
|
||||
{
|
||||
dense.append(part.charAt(0));
|
||||
foundStart = Character.isJavaIdentifierStart(c);
|
||||
if (foundStart)
|
||||
{
|
||||
if (startIdx >= 0)
|
||||
{
|
||||
dense.append(classname.charAt(startIdx));
|
||||
hasPackage = true;
|
||||
}
|
||||
startIdx = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundStart)
|
||||
{
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
{
|
||||
foundStart = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
endIdx = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dense.length() > 0)
|
||||
// append remaining from startIdx
|
||||
if ((startIdx >= 0) && (endIdx >= startIdx))
|
||||
{
|
||||
dense.append('.');
|
||||
if (hasPackage)
|
||||
{
|
||||
dense.append('.');
|
||||
}
|
||||
dense.append(classname, startIdx, endIdx + 1);
|
||||
}
|
||||
dense.append(parts[parts.length - 1]);
|
||||
|
||||
return dense.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void debug(String msg, long arg)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.util.log;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -101,20 +100,41 @@ public class LogTest
|
|||
public static Stream<Arguments> packageCases()
|
||||
{
|
||||
return Stream.of(
|
||||
Arguments.of(null, ""),
|
||||
Arguments.of("org.eclipse.Foo.\u0000", "oe.Foo"),
|
||||
Arguments.of(".foo", "foo"),
|
||||
Arguments.of(".bar.Foo", "b.Foo"),
|
||||
Arguments.of("org...bar..Foo", "ob.Foo")
|
||||
// null entry
|
||||
Arguments.of(null, ""),
|
||||
// empty entry
|
||||
Arguments.of("", ""),
|
||||
// all whitespace entry
|
||||
Arguments.of(" \t ", ""),
|
||||
// bad / invalid characters
|
||||
Arguments.of("org.eclipse.Foo.\u0000", "oe.Foo"),
|
||||
Arguments.of("org.eclipse.\u20ac.Euro", "oe\u20ac.Euro"),
|
||||
// bad package segments
|
||||
Arguments.of(".foo", "foo"),
|
||||
Arguments.of(".bar.Foo", "b.Foo"),
|
||||
Arguments.of("org...bar..Foo", "ob.Foo"),
|
||||
Arguments.of("org . . . bar . . Foo ", "ob.Foo"),
|
||||
Arguments.of("org . . . bar . . Foo ", "ob.Foo"),
|
||||
// long-ish classname
|
||||
Arguments.of("org.eclipse.jetty.websocket.common.extensions.compress.DeflateFrameExtension", "oejwcec.DeflateFrameExtension"),
|
||||
// internal class
|
||||
Arguments.of("org.eclipse.jetty.foo.Bar$Internal", "oejf.Bar$Internal")
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("packageCases")
|
||||
public void testCondensePackage(String input, String expected)
|
||||
public void testCondensePackageViaLogger(String input, String expected)
|
||||
{
|
||||
StdErrLog log = new StdErrLog();
|
||||
StdErrLog logger = (StdErrLog) log.newLogger(input);
|
||||
assertThat("log[" + input + "] condenses to name", logger._abbrevname, is(expected));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("packageCases")
|
||||
public void testCondensePackageDirect(String input, String expected)
|
||||
{
|
||||
assertThat("log[" + input + "] condenses to name", AbstractLogger.condensePackageString(input), is(expected));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.util.log;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Param;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
import org.openjdk.jmh.profile.GCProfiler;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
@Fork(value = 5)
|
||||
@State(Scope.Benchmark)
|
||||
|
||||
@Warmup(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
|
||||
@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
|
||||
public class LogCondensePackageStringBenchmark
|
||||
{
|
||||
@Param({"com.acme.Dump",
|
||||
"org.eclipse.jetty.websocket.common.extensions.compress.DeflateFrameExtension$Pool"
|
||||
})
|
||||
String fqClassName;
|
||||
|
||||
@Benchmark
|
||||
public void testCondensePackage(Blackhole blackhole)
|
||||
{
|
||||
blackhole.consume(AbstractLogger.condensePackageString(fqClassName));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RunnerException
|
||||
{
|
||||
Options opt = new OptionsBuilder()
|
||||
.include(LogCondensePackageStringBenchmark.class.getSimpleName())
|
||||
.addProfiler(GCProfiler.class)
|
||||
.build();
|
||||
|
||||
new Runner(opt).run();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,145 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.tests.distribution;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class DemoBaseTests extends AbstractDistributionTest
|
||||
{
|
||||
@Test
|
||||
public void testJspDump() throws Exception
|
||||
{
|
||||
String jettyVersion = System.getProperty("jettyVersion");
|
||||
DistributionTester distribution = DistributionTester.Builder.newInstance()
|
||||
.jettyVersion(jettyVersion)
|
||||
.jettyBase(Paths.get("demo-base"))
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
int httpPort = distribution.freePort();
|
||||
int httpsPort = distribution.freePort();
|
||||
assertThat("httpPort != httpsPort", httpPort, is(not(httpsPort)));
|
||||
|
||||
String[] args = {
|
||||
"jetty.http.port=" + httpPort,
|
||||
"jetty.httpConfig.port=" + httpsPort,
|
||||
"jetty.ssl.port=" + httpsPort
|
||||
};
|
||||
|
||||
try (DistributionTester.Run run1 = distribution.start(args))
|
||||
{
|
||||
assertTrue(run1.awaitConsoleLogsFor("Started @", 20, TimeUnit.SECONDS));
|
||||
|
||||
startHttpClient();
|
||||
ContentResponse response = client.GET("http://localhost:" + httpPort + "/test/jsp/dump.jsp");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertThat(response.getContentAsString(), containsString("PathInfo"));
|
||||
assertThat(response.getContentAsString(), not(containsString("<%")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncRest() throws Exception
|
||||
{
|
||||
String jettyVersion = System.getProperty("jettyVersion");
|
||||
DistributionTester distribution = DistributionTester.Builder.newInstance()
|
||||
.jettyVersion(jettyVersion)
|
||||
.jettyBase(Paths.get("demo-base"))
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
int httpPort = distribution.freePort();
|
||||
int httpsPort = distribution.freePort();
|
||||
assertThat("httpPort != httpsPort", httpPort, is(not(httpsPort)));
|
||||
|
||||
String[] args = {
|
||||
"jetty.http.port=" + httpPort,
|
||||
"jetty.httpConfig.port=" + httpsPort,
|
||||
"jetty.ssl.port=" + httpsPort
|
||||
};
|
||||
|
||||
try (DistributionTester.Run run1 = distribution.start(args))
|
||||
{
|
||||
assertTrue(run1.awaitConsoleLogsFor("Started @", 20, TimeUnit.SECONDS));
|
||||
|
||||
startHttpClient();
|
||||
ContentResponse response;
|
||||
|
||||
response = client.GET("http://localhost:" + httpPort + "/async-rest/testSerial?items=kayak");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertThat(response.getContentAsString(), containsString("Blocking: kayak"));
|
||||
|
||||
response = client.GET("http://localhost:" + httpPort + "/async-rest/testSerial?items=mouse,beer,gnome");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertThat(response.getContentAsString(), containsString("Blocking: mouse,beer,gnome"));
|
||||
|
||||
response = client.GET("http://localhost:" + httpPort + "/async-rest/testAsync?items=kayak");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertThat(response.getContentAsString(), containsString("Asynchronous: kayak"));
|
||||
|
||||
response = client.GET("http://localhost:" + httpPort + "/async-rest/testAsync?items=mouse,beer,gnome");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertThat(response.getContentAsString(), containsString("Asynchronous: mouse,beer,gnome"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpec() throws Exception
|
||||
{
|
||||
String jettyVersion = System.getProperty("jettyVersion");
|
||||
DistributionTester distribution = DistributionTester.Builder.newInstance()
|
||||
.jettyVersion(jettyVersion)
|
||||
.jettyBase(Paths.get("demo-base"))
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
int httpPort = distribution.freePort();
|
||||
int httpsPort = distribution.freePort();
|
||||
assertThat("httpPort != httpsPort", httpPort, is(not(httpsPort)));
|
||||
|
||||
String[] args = {
|
||||
"jetty.http.port=" + httpPort,
|
||||
"jetty.httpConfig.port=" + httpsPort,
|
||||
"jetty.ssl.port=" + httpsPort
|
||||
};
|
||||
|
||||
try (DistributionTester.Run run1 = distribution.start(args))
|
||||
{
|
||||
assertTrue(run1.awaitConsoleLogsFor("Started @", 20, TimeUnit.SECONDS));
|
||||
|
||||
startHttpClient();
|
||||
ContentResponse response = client.POST("http://localhost:" + httpPort + "/test-spec/asy/xx").send();
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertThat(response.getContentAsString(), containsString("<span class=\"pass\">PASS</span>"));
|
||||
assertThat(response.getContentAsString(), not(containsString("<span class=\"fail\">FAIL</span>")));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -189,29 +189,6 @@ public class DistributionTests extends AbstractDistributionTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDemoBase() throws Exception
|
||||
{
|
||||
String jettyVersion = System.getProperty("jettyVersion");
|
||||
DistributionTester distribution = DistributionTester.Builder.newInstance()
|
||||
.jettyVersion(jettyVersion)
|
||||
.jettyBase(Paths.get("demo-base"))
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
int port = distribution.freePort();
|
||||
try (DistributionTester.Run run1 = distribution.start("jetty.http.port=" + port))
|
||||
{
|
||||
assertTrue(run1.awaitConsoleLogsFor("Started @", 20, TimeUnit.SECONDS));
|
||||
|
||||
startHttpClient();
|
||||
ContentResponse response = client.GET("http://localhost:" + port + "/test/jsp/dump.jsp");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertThat(response.getContentAsString(), containsString("PathInfo"));
|
||||
assertThat(response.getContentAsString(), not(containsString("<%")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnixSocket() throws Exception
|
||||
{
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.AsyncEvent;
|
||||
import javax.servlet.AsyncListener;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.plus.jndi.EnvEntry;
|
||||
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
|
||||
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.webapp.Configuration;
|
||||
import org.eclipse.jetty.webapp.FragmentConfiguration;
|
||||
import org.eclipse.jetty.webapp.MetaInfConfiguration;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.webapp.WebInfConfiguration;
|
||||
import org.eclipse.jetty.webapp.WebXmlConfiguration;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AnnotatedAsyncListenerTest
|
||||
{
|
||||
private Server server;
|
||||
private ServerConnector connector;
|
||||
private HttpClient client;
|
||||
|
||||
private void start(HttpServlet servlet) throws Exception
|
||||
{
|
||||
QueuedThreadPool serverExecutor = new QueuedThreadPool();
|
||||
serverExecutor.setName("server");
|
||||
server = new Server(serverExecutor);
|
||||
connector = new ServerConnector(server, 1, 1);
|
||||
server.addConnector(connector);
|
||||
|
||||
Path webAppDir = MavenTestingUtils.getTargetTestingPath(AnnotatedAsyncListenerTest.class.getName() + "@" + servlet.hashCode());
|
||||
Path webInf = webAppDir.resolve("WEB-INF");
|
||||
Files.createDirectories(webInf);
|
||||
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(webInf.resolve("web.xml"), StandardCharsets.UTF_8, StandardOpenOption.CREATE))
|
||||
{
|
||||
writer.write("<web-app xmlns=\"http://xmlns.jcp.org/xml/ns/javaee\" " +
|
||||
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
|
||||
"xsi:schemaLocation=\"http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd\" " +
|
||||
"version=\"3.1\">" +
|
||||
"</web-app>");
|
||||
}
|
||||
|
||||
WebAppContext context = new WebAppContext(webAppDir.toString(), "/");
|
||||
context.setConfigurations(new Configuration[]
|
||||
{
|
||||
new AnnotationConfiguration(),
|
||||
new WebXmlConfiguration(),
|
||||
new WebInfConfiguration(),
|
||||
new MetaInfConfiguration(),
|
||||
new FragmentConfiguration(),
|
||||
new EnvConfiguration(),
|
||||
new PlusConfiguration()
|
||||
});
|
||||
context.addServlet(new ServletHolder(servlet), "/*");
|
||||
new EnvEntry(context, "value", 1307D, false);
|
||||
server.setHandler(context);
|
||||
|
||||
QueuedThreadPool clientExecutor = new QueuedThreadPool();
|
||||
clientExecutor.setName("client");
|
||||
client = new HttpClient();
|
||||
client.setExecutor(clientExecutor);
|
||||
server.addBean(client);
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dispose() throws Exception
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotatedAsyncListener() throws Exception
|
||||
{
|
||||
start(new HttpServlet()
|
||||
{
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException
|
||||
{
|
||||
AsyncContext asyncContext = request.startAsync();
|
||||
AnnotatedAsyncListener listener = asyncContext.createListener(AnnotatedAsyncListener.class);
|
||||
assertEquals(listener.value, 1307D);
|
||||
asyncContext.complete();
|
||||
}
|
||||
});
|
||||
|
||||
ContentResponse response = client.GET("http://localhost:" + connector.getLocalPort() + "/test");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
}
|
||||
|
||||
public static class AnnotatedAsyncListener implements AsyncListener
|
||||
{
|
||||
@Resource(mappedName = "value")
|
||||
private Double value;
|
||||
|
||||
@Override
|
||||
public void onComplete(AsyncEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeout(AsyncEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(AsyncEvent event)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartAsync(AsyncEvent event)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue