Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-4985-AttributeNameSet

This commit is contained in:
Lachlan Roberts 2020-06-30 11:22:41 +10:00
commit 9126b282b1
18 changed files with 131 additions and 148 deletions

View File

@ -135,7 +135,7 @@
<!-- ensure we don't have legacy comments that confuse javadoc tooling -->
<module name="Regexp">
<property name="id" value="LegacyMethodSeparators"/>
<property name="format" value="/\*\s*[=*-]*\s*\*/"/>
<property name="format" value="/\*\s*[=*-]+\s*\*/" />
<property name="illegalPattern" value="true"/>
<property name="ignoreComments" value="false"/>
<property name="message" value="Legacy Method Separators"/>

View File

@ -54,23 +54,28 @@ public class TestSecurityAnnotationConversions
{
}
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = {
"tom", "dick", "harry"
}))
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed =
{
"tom", "dick", "harry"
}))
public static class RolesServlet extends HttpServlet
{
}
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = {
"tom", "dick", "harry"
}), httpMethodConstraints = {@HttpMethodConstraint(value = "GET")})
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed =
{
"tom", "dick", "harry"
}), httpMethodConstraints = {@HttpMethodConstraint(value = "GET")})
public static class Method1Servlet extends HttpServlet
{
}
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = {
"tom", "dick", "harry"
}), httpMethodConstraints = {@HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL)})
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed =
{
"tom", "dick", "harry"
}), httpMethodConstraints = {
@HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL)
})
public static class Method2Servlet extends HttpServlet
{
}

View File

@ -30,7 +30,6 @@ import com.hazelcast.config.SerializerConfig;
import com.hazelcast.config.XmlConfigBuilder;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.eclipse.jetty.server.session.AbstractSessionDataStoreFactory;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.server.session.SessionDataStore;
@ -61,7 +60,7 @@ public class HazelcastSessionDataStoreFactory
private boolean scavengeZombies = false;
private String addresses;
public boolean isScavengeZombies()
{
return scavengeZombies;
@ -86,12 +85,12 @@ public class HazelcastSessionDataStoreFactory
if (StringUtil.isEmpty(configurationLocation))
{
ClientConfig config = new ClientConfig();
if (addresses != null && !addresses.isEmpty())
{
config.getNetworkConfig().setAddresses(Arrays.asList(addresses.split(",")));
}
SerializerConfig sc = new SerializerConfig()
.setImplementation(new SessionDataSerializer())
.setTypeClass(SessionData.class);
@ -212,7 +211,7 @@ public class HazelcastSessionDataStoreFactory
{
this.hazelcastInstanceName = hazelcastInstanceName;
}
public String getAddresses()
{
return addresses;

View File

@ -21,7 +21,6 @@ package org.eclipse.jetty.http;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContext;
import org.eclipse.jetty.util.QuotedStringTokenizer;
@ -33,22 +32,22 @@ import org.eclipse.jetty.util.log.Logger;
public class HttpCookie
{
private static final Logger LOG = Log.getLogger(HttpCookie.class);
private static final String __COOKIE_DELIM = "\",;\\ \t";
private static final String __01Jan1970_COOKIE = DateGenerator.formatCookieDate(0).trim();
/**
*If this string is found within the comment parsed with {@link #isHttpOnlyInComment(String)} the check will return true
* If this string is found within the comment parsed with {@link #isHttpOnlyInComment(String)} the check will return true
**/
public static final String HTTP_ONLY_COMMENT = "__HTTP_ONLY__";
/**
*These strings are used by {@link #getSameSiteFromComment(String)} to check for a SameSite specifier in the comment
* These strings are used by {@link #getSameSiteFromComment(String)} to check for a SameSite specifier in the comment
**/
private static final String SAME_SITE_COMMENT = "__SAME_SITE_";
public static final String SAME_SITE_NONE_COMMENT = SAME_SITE_COMMENT + "NONE__";
public static final String SAME_SITE_LAX_COMMENT = SAME_SITE_COMMENT + "LAX__";
public static final String SAME_SITE_STRICT_COMMENT = SAME_SITE_COMMENT + "STRICT__";
/**
* Name of context attribute with default SameSite cookie value
*/
@ -82,7 +81,7 @@ public class HttpCookie
private final boolean _httpOnly;
private final long _expiration;
private final SameSite _sameSite;
public HttpCookie(String name, String value)
{
this(name, value, -1);
@ -463,7 +462,7 @@ public class HttpCookie
/**
* Get the default value for SameSite cookie attribute, if one
* has been set for the given context.
*
*
* @param context the context to check for default SameSite value
* @return the default SameSite value or null if one does not exist
* @throws IllegalStateException if the default value is not a permitted value
@ -479,10 +478,10 @@ public class HttpCookie
LOG.debug("No default value for SameSite");
return null;
}
if (o instanceof SameSite)
return (SameSite)o;
try
{
SameSite samesite = Enum.valueOf(SameSite.class, o.toString().trim().toUpperCase(Locale.ENGLISH));

View File

@ -28,7 +28,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.RequestDispatcher;

View File

@ -23,7 +23,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.jaas.spi;
import java.io.File;
import java.util.HashMap;
import javax.security.auth.Subject;
import org.eclipse.jetty.jaas.callback.DefaultCallbackHandler;

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.memcached.session;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.plus.annotation;
import java.lang.reflect.Method;
import javax.servlet.http.HttpServlet;
import org.eclipse.jetty.plus.webapp.PlusDecorator;
@ -41,12 +40,12 @@ public class LifeCycleCallbackCollectionTest
{
public static int postConstructCount = 0;
public static int preDestroyCount = 0;
public void postconstruct()
{
++postConstructCount;
}
public void predestroy()
{
++preDestroyCount;
@ -55,7 +54,6 @@ public class LifeCycleCallbackCollectionTest
/**
* An unsupported lifecycle callback type
*
*/
public class TestLifeCycleCallback extends LifeCycleCallback
{
@ -79,7 +77,6 @@ public class LifeCycleCallbackCollectionTest
/**
* A class that we can use to simulate having PostConstruct and
* PreDestroy annotations on.
*
*/
public class SomeTestClass
{
@ -177,7 +174,7 @@ public class LifeCycleCallbackCollectionTest
//expected
}
}
@Test
public void testServletPostConstructPreDestroy() throws Exception
{
@ -186,7 +183,7 @@ public class LifeCycleCallbackCollectionTest
context.setResourceBase(MavenTestingUtils.getTargetTestingDir("predestroy-test").toURI().toURL().toString());
context.setContextPath("/");
server.setHandler(context);
//add a non-async servlet
ServletHolder notAsync = new ServletHolder();
notAsync.setHeldClass(TestServlet.class);
@ -194,7 +191,7 @@ public class LifeCycleCallbackCollectionTest
notAsync.setAsyncSupported(false);
notAsync.setInitOrder(1);
context.getServletHandler().addServletWithMapping(notAsync, "/notasync/*");
//add an async servlet
ServletHolder async = new ServletHolder();
async.setHeldClass(TestServlet.class);
@ -202,7 +199,7 @@ public class LifeCycleCallbackCollectionTest
async.setAsyncSupported(true);
async.setInitOrder(1);
context.getServletHandler().addServletWithMapping(async, "/async/*");
//add a run-as servlet
ServletHolder runas = new ServletHolder();
runas.setHeldClass(TestServlet.class);
@ -210,7 +207,7 @@ public class LifeCycleCallbackCollectionTest
runas.setRunAsRole("admin");
runas.setInitOrder(1);
context.getServletHandler().addServletWithMapping(runas, "/runas/*");
//add both run-as and non async servlet
ServletHolder both = new ServletHolder();
both.setHeldClass(TestServlet.class);
@ -219,7 +216,7 @@ public class LifeCycleCallbackCollectionTest
both.setAsyncSupported(false);
both.setInitOrder(1);
context.getServletHandler().addServletWithMapping(both, "/both/*");
//Make fake lifecycle callbacks for all servlets
LifeCycleCallbackCollection collection = new LifeCycleCallbackCollection();
context.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION, collection);
@ -227,31 +224,31 @@ public class LifeCycleCallbackCollectionTest
collection.add(pcNotAsync);
PreDestroyCallback pdNotAsync = new PreDestroyCallback(TestServlet.class, "predestroy");
collection.add(pdNotAsync);
PostConstructCallback pcAsync = new PostConstructCallback(TestServlet.class, "postconstruct");
collection.add(pcAsync);
PreDestroyCallback pdAsync = new PreDestroyCallback(TestServlet.class, "predestroy");
collection.add(pdAsync);
PostConstructCallback pcRunAs = new PostConstructCallback(TestServlet.class, "postconstruct");
collection.add(pcRunAs);
PreDestroyCallback pdRunAs = new PreDestroyCallback(TestServlet.class, "predestroy");
collection.add(pdRunAs);
PostConstructCallback pcBoth = new PostConstructCallback(TestServlet.class, "postconstruct");
collection.add(pcBoth);
PreDestroyCallback pdBoth = new PreDestroyCallback(TestServlet.class, "predestroy");
collection.add(pdBoth);
//ensure we invoke the lifecyclecallbacks
context.getObjectFactory().addDecorator(new PlusDecorator(context));
server.start();
assertEquals(4, TestServlet.postConstructCount);
server.stop();
assertEquals(4, TestServlet.preDestroyCount);
}

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
@ -134,7 +133,7 @@ public class DefaultSessionCache extends AbstractSessionCache
{
if (LOG.isDebugEnabled())
LOG.debug("Shutdown sessions, invalidating = {}", isInvalidateOnShutdown());
// loop over all the sessions in memory (a few times if necessary to catch sessions that have been
// added while we're running
int loop = 100;

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.server.session;
import java.util.function.Function;
import javax.servlet.http.HttpServletRequest;
/**

View File

@ -38,7 +38,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Stream;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
@ -967,7 +966,7 @@ public class ResponseTest
assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly", set);
}
@Test
public void testAddCookieInInclude() throws Exception
{
@ -984,7 +983,7 @@ public class ResponseTest
assertNull(response.getHttpFields().get("Set-Cookie"));
}
@Test
public void testAddCookieSameSiteDefault() throws Exception
{
@ -1001,12 +1000,12 @@ public class ResponseTest
response.addCookie(cookie);
String set = response.getHttpFields().get("Set-Cookie");
assertEquals("name=value; Path=/path; Domain=domain; Secure; HttpOnly; SameSite=Strict", set);
response.getHttpFields().remove("Set-Cookie");
//test bad default samesite value
context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "FooBar");
assertThrows(IllegalStateException.class,
() -> response.addCookie(cookie));
}
@ -1081,7 +1080,7 @@ public class ResponseTest
response.setContentType("some/type");
response.setContentLength(3);
response.setHeader(HttpHeader.EXPIRES,"never");
response.setHeader(HttpHeader.EXPIRES, "never");
response.setHeader("SomeHeader", "SomeValue");
@ -1149,7 +1148,7 @@ public class ResponseTest
List<String> actual = Collections.list(response.getHttpFields().getValues("Set-Cookie"));
assertThat("HttpCookie order", actual, hasItems(expected));
}
@Test
public void testReplaceHttpCookieSameSite()
{
@ -1191,7 +1190,7 @@ public class ResponseTest
actual = Collections.list(response.getHttpFields().getValues("Set-Cookie"));
assertThat(actual, hasItems(new String[]{"Foo=replaced; Path=/path; Domain=Bah"}));
}
@Test
public void testReplaceParsedHttpCookieSiteDefault()
{
@ -1199,7 +1198,7 @@ public class ResponseTest
TestServletContextHandler context = new TestServletContextHandler();
context.setAttribute(HttpCookie.SAME_SITE_DEFAULT_ATTRIBUTE, "LAX");
_channel.getRequest().setContext(context.getServletContext());
response.addHeader(HttpHeader.SET_COOKIE.asString(), "Foo=123456");
response.replaceCookie(new HttpCookie("Foo", "value"));
String set = response.getHttpFields().get("Set-Cookie");
@ -1233,7 +1232,7 @@ public class ResponseTest
super(handler, new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300));
}
}
private static class TestServletContextHandler extends ContextHandler
{
private class Context extends ContextHandler.Context
@ -1255,7 +1254,7 @@ public class ResponseTest
@Override
public void setAttribute(String name, Object object)
{
_attributes.put(name,object);
_attributes.put(name, object);
}
@Override

View File

@ -27,7 +27,6 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServletRequest;
@ -448,7 +447,7 @@ public class ContextHandlerTest
assertThat(connector.getResponse("GET /foo/xxx HTTP/1.0\n\n"), Matchers.containsString("ctx='/foo'"));
assertThat(connector.getResponse("GET /foo/bar/xxx HTTP/1.0\n\n"), Matchers.containsString("ctx='/foo/bar'"));
}
@Test
public void testContextInitializationDestruction() throws Exception
{
@ -859,12 +858,12 @@ public class ContextHandlerTest
writer.println("ctx='" + request.getContextPath() + "'");
}
}
private static class TestServletContextListener implements ServletContextListener
{
public int initialized = 0;
public int destroyed = 0;
@Override
public void contextInitialized(ServletContextEvent sce)
{

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import javax.servlet.SessionCookieConfig;
import javax.servlet.http.HttpServletRequest;

View File

@ -29,7 +29,6 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@ -109,12 +108,12 @@ public class ServletContextHandlerTest
private static final AtomicInteger __testServlets = new AtomicInteger();
private static int __initIndex = 0;
private static int __destroyIndex = 0;
public class StopTestFilter implements Filter
{
int _initIndex;
int _destroyIndex;
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
@ -135,7 +134,7 @@ public class ServletContextHandlerTest
}
public class StopTestServlet extends GenericServlet
{
{
int _initIndex;
int _destroyIndex;
@ -251,7 +250,7 @@ public class ServletContextHandlerTest
}
public static class MyTestSessionListener implements HttpSessionAttributeListener, HttpSessionListener
{
{
@Override
public void sessionCreated(HttpSessionEvent se)
{
@ -277,13 +276,13 @@ public class ServletContextHandlerTest
{
}
}
public static class MySCAListener implements ServletContextAttributeListener
{
public static int adds = 0;
public static int removes = 0;
public static int replaces = 0;
@Override
public void attributeAdded(ServletContextAttributeEvent event)
{
@ -310,7 +309,7 @@ public class ServletContextHandlerTest
@Override
public void requestDestroyed(ServletRequestEvent sre)
{
{
++destroys;
}
@ -320,13 +319,13 @@ public class ServletContextHandlerTest
++inits;
}
}
public static class MyRAListener implements ServletRequestAttributeListener
{
public static int adds = 0;
public static int removes = 0;
public static int replaces = 0;
@Override
public void attributeAdded(ServletRequestAttributeEvent srae)
{
@ -345,7 +344,7 @@ public class ServletContextHandlerTest
++replaces;
}
}
public static class MySListener implements HttpSessionListener
{
public static int creates = 0;
@ -362,15 +361,14 @@ public class ServletContextHandlerTest
{
++destroys;
}
}
public static class MySAListener implements HttpSessionAttributeListener
{
public static int adds = 0;
public static int removes = 0;
public static int replaces = 0;
@Override
public void attributeAdded(HttpSessionBindingEvent event)
{
@ -387,20 +385,20 @@ public class ServletContextHandlerTest
public void attributeReplaced(HttpSessionBindingEvent event)
{
++replaces;
}
}
}
public static class MySIListener implements HttpSessionIdListener
{
public static int changes = 0;
@Override
public void sessionIdChanged(HttpSessionEvent event, String oldSessionId)
{
++changes;
}
}
public class InitialListener implements ServletContextListener
{
@Override
@ -446,16 +444,15 @@ public class ServletContextHandlerTest
{
fail(x);
}
sce.getServletContext().setAttribute("foo", "bar");
}
@Override
public void contextDestroyed(ServletContextEvent sce)
{
}
}
@BeforeEach
@ -496,7 +493,7 @@ public class ServletContextHandlerTest
root.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
_server.start();
_server.stop();
assertEquals(0, stopTestListener._initIndex); //listeners contextInitialized called first
assertEquals(1, stopTestFilter._initIndex); //filters init
assertEquals(2, stopTestServlet._initIndex); //servlets init
@ -505,7 +502,7 @@ public class ServletContextHandlerTest
assertEquals(1, stopTestServlet._destroyIndex); //servlets destroyed next
assertEquals(2, stopTestListener._destroyIndex); //listener contextDestroyed last
}
@Test
public void testAddSessionListener() throws Exception
{
@ -536,7 +533,7 @@ public class ServletContextHandlerTest
assertTrue((Boolean)root.getServletContext().getAttribute("MySCI.startup"));
assertTrue((Boolean)root.getServletContext().getAttribute("MyContextListener.contextInitialized"));
}
@Test
public void testContextInitializationDestruction() throws Exception
{
@ -549,7 +546,7 @@ public class ServletContextHandlerTest
{
public int initialized = 0;
public int destroyed = 0;
@Override
public void contextInitialized(ServletContextEvent sce)
{
@ -562,7 +559,7 @@ public class ServletContextHandlerTest
destroyed++;
}
}
TestServletContextListener listener = new TestServletContextListener();
root.addEventListener(listener);
server.start();
@ -571,7 +568,7 @@ public class ServletContextHandlerTest
server.stop();
assertEquals(1, listener.destroyed);
}
@Test
public void testListenersFromContextListener() throws Exception
{
@ -584,7 +581,7 @@ public class ServletContextHandlerTest
root.getServletHandler().addListener(initialListener);
ServletHolder holder0 = root.addServlet(TestServlet.class, "/test");
_server.start();
ListenerHolder[] listenerHolders = root.getServletHandler().getListeners();
assertNotNull(listenerHolders);
for (ListenerHolder l : listenerHolders)
@ -598,27 +595,29 @@ public class ServletContextHandlerTest
assertTrue(root.isProgrammaticListener(l.getListener()));
}
}
EventListener[] listeners = root.getEventListeners();
assertNotNull(listeners);
List<String> listenerClassNames = new ArrayList<>();
for (EventListener l : listeners)
{
listenerClassNames.add(l.getClass().getName());
}
assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySCAListener"));
assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MyRequestListener"));
assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MyRAListener"));
assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySListener"));
assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySAListener"));
assertTrue(listenerClassNames.contains("org.eclipse.jetty.servlet.ServletContextHandlerTest$MySIListener"));
//test ServletRequestAttributeListener
String response = _connector.getResponse("GET /test?req=all HTTP/1.0\r\n\r\n");
assertThat(response, Matchers.containsString("200 OK"));
assertEquals(1, MyRAListener.adds);
assertEquals(1, MyRAListener.replaces);
assertEquals(1, MyRAListener.removes);
//test HttpSessionAttributeListener
response = _connector.getResponse("GET /test?session=create HTTP/1.0\r\n\r\n");
String sessionid = response.substring(response.indexOf("JSESSIONID"), response.indexOf(";"));
@ -649,7 +648,7 @@ public class ServletContextHandlerTest
assertEquals(1, MySAListener.adds);
assertEquals(1, MySAListener.replaces);
assertEquals(1, MySAListener.removes);
//test HttpSessionIdListener.sessionIdChanged
request = new StringBuffer();
request.append("GET /test?session=change HTTP/1.0\n");
@ -660,7 +659,7 @@ public class ServletContextHandlerTest
assertThat(response, Matchers.containsString("200 OK"));
assertEquals(1, MySIListener.changes);
sessionid = response.substring(response.indexOf("JSESSIONID"), response.indexOf(";"));
//test HttpServletListener.sessionDestroyed
request = new StringBuffer();
request.append("GET /test?session=delete HTTP/1.0\n");
@ -670,7 +669,7 @@ public class ServletContextHandlerTest
response = _connector.getResponse(request.toString());
assertThat(response, Matchers.containsString("200 OK"));
assertEquals(1, MySListener.destroys);
//test ServletContextAttributeListener
//attribute was set when context listener registered
assertEquals(1, MySCAListener.adds);
@ -749,7 +748,7 @@ public class ServletContextHandlerTest
{
//A servlet cannot be added by another servlet
Logger logger = Log.getLogger(ContextHandler.class.getName() + "ROOT");
try (StacklessLogging stackless = new StacklessLogging(logger))
{
ServletContextHandler context = new ServletContextHandler();
@ -769,7 +768,7 @@ public class ServletContextHandlerTest
assertTrue(e.getCause() instanceof IllegalStateException);
}
else
fail(e);
fail(e);
}
}
@ -829,9 +828,8 @@ public class ServletContextHandlerTest
@Override
public void destroy()
{
{
}
});
context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
context.getServletHandler().setStartWithUnavailable(false);
@ -881,9 +879,8 @@ public class ServletContextHandlerTest
@Override
public void destroy()
{
{
}
});
context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
context.getServletHandler().setStartWithUnavailable(false);
@ -933,9 +930,8 @@ public class ServletContextHandlerTest
@Override
public void destroy()
{
{
}
});
context.addFilter(holder, "/*", EnumSet.of(DispatcherType.REQUEST));
context.getServletHandler().setStartWithUnavailable(false);
@ -956,7 +952,7 @@ public class ServletContextHandlerTest
fail(e);
}
}
}
}
@Test
public void testAddServletFromSCL() throws Exception
@ -977,9 +973,8 @@ public class ServletContextHandlerTest
@Override
public void contextDestroyed(ServletContextEvent sce)
{
{
}
});
_server.setHandler(context);
_server.start();
@ -1010,10 +1005,10 @@ public class ServletContextHandlerTest
rego.addMapping("/hello/*");
}
}
root.addBean(new MySCIStarter(root.getServletContext(), new ServletAddingSCI()), true);
_server.start();
StringBuffer request = new StringBuffer();
request.append("GET /hello HTTP/1.0\n");
request.append("Host: localhost\n");
@ -1050,7 +1045,7 @@ public class ServletContextHandlerTest
response = _connector.getResponse(request.toString());
assertThat("Response", response, containsString("Hello World"));
}
@Test
public void testServletRegistrationByClass() throws Exception
{
@ -1090,7 +1085,7 @@ public class ServletContextHandlerTest
String response = _connector.getResponse(request.toString());
assertThat("Response", response, containsString("Test"));
}
@Test
public void testPartialServletRegistrationByName() throws Exception
{
@ -1099,7 +1094,7 @@ public class ServletContextHandlerTest
ServletHolder partial = new ServletHolder();
partial.setName("test");
context.addServlet(partial, "/test");
//complete partial servlet registration by providing name of the servlet class
ServletRegistration reg = context.getServletContext().addServlet("test", TestServlet.class.getName());
assertNotNull(reg);
@ -1116,7 +1111,7 @@ public class ServletContextHandlerTest
String response = _connector.getResponse(request.toString());
assertThat("Response", response, containsString("Test"));
}
@Test
public void testPartialServletRegistrationByClass() throws Exception
{
@ -1125,7 +1120,7 @@ public class ServletContextHandlerTest
ServletHolder partial = new ServletHolder();
partial.setName("test");
context.addServlet(partial, "/test");
//complete partial servlet registration by providing the servlet class
ServletRegistration reg = context.getServletContext().addServlet("test", TestServlet.class);
assertNotNull(reg);
@ -1143,7 +1138,7 @@ public class ServletContextHandlerTest
String response = _connector.getResponse(request.toString());
assertThat("Response", response, containsString("Test"));
}
@Test
public void testNullServletRegistration() throws Exception
{
@ -1153,7 +1148,7 @@ public class ServletContextHandlerTest
full.setName("test");
full.setHeldClass(TestServlet.class);
context.addServlet(full, "/test");
//Must return null if the servlet has been fully defined previously
ServletRegistration reg = context.getServletContext().addServlet("test", TestServlet.class);
assertNull(reg);
@ -1169,7 +1164,7 @@ public class ServletContextHandlerTest
String response = _connector.getResponse(request.toString());
assertThat("Response", response, containsString("Test"));
}
@Test
public void testHandlerBeforeServletHandler() throws Exception
{
@ -1261,7 +1256,7 @@ public class ServletContextHandlerTest
SecurityHandler securityHandler = context.getSecurityHandler();
assertNotNull(context.getGzipHandler());
GzipHandler gzipHandler = context.getGzipHandler();
//check the handler linking order
HandlerWrapper h = (HandlerWrapper)context.getHandler();
assertSame(h, sessionHandler);
@ -1297,16 +1292,16 @@ public class ServletContextHandlerTest
@Override
protected boolean checkWebResourcePermissions(String pathInContext, Request request, Response response,
Object constraintInfo, UserIdentity userIdentity)
throws IOException
throws IOException
{
return false;
}
};
//check the linking order
context.setSecurityHandler(myHandler);
assertSame(myHandler, context.getSecurityHandler());
h = (HandlerWrapper)context.getHandler();
assertSame(h, sessionHandler);
@ -1316,7 +1311,7 @@ public class ServletContextHandlerTest
h = (HandlerWrapper)h.getHandler();
assertSame(h, gzipHandler);
}
@Test
public void testReplaceServletHandlerWithoutServlet() throws Exception
{
@ -1491,7 +1486,7 @@ public class ServletContextHandlerTest
writer.write("Hello World");
}
}
public static class MyFilter implements Filter
{
@ -1590,7 +1585,7 @@ public class ServletContextHandlerTest
dynamic.addMapping("/added/*");
}
}
public static class FilterAddingServlet extends HttpServlet
{
@Override
@ -1643,7 +1638,7 @@ public class ServletContextHandlerTest
resp.setStatus(HttpServletResponse.SC_OK);
PrintWriter writer = resp.getWriter();
writer.write("Test");
String action = req.getParameter("session");
if (!Objects.isNull(action))
{
@ -1675,7 +1670,7 @@ public class ServletContextHandlerTest
}
else
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
@ -1686,10 +1681,10 @@ public class ServletContextHandlerTest
req.setAttribute("some", "value");
req.setAttribute("some", "other");
req.removeAttribute("some");
return;
}
action = req.getParameter("ctx");
if (!Objects.isNull(action))
{

View File

@ -17,7 +17,7 @@
<jetty.url>http://www.eclipse.org/jetty</jetty.url>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build-support.version>1.4</build-support.version>
<checkstyle.version>8.20</checkstyle.version>
<checkstyle.version>8.29</checkstyle.version>
<slf4j.version>1.7.30</slf4j.version>
<log4j2.version>2.11.2</log4j2.version>
<disruptor.version>3.4.2</disruptor.version>

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.server.session;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -51,7 +50,7 @@ public class DuplicateCookieTest
String contextPath = "";
String servletMapping = "/server";
HttpClient client = null;
DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory();
SessionDataStoreFactory storeFactory = new TestSessionDataStoreFactory();
@ -69,7 +68,7 @@ public class DuplicateCookieTest
createUnExpiredSession(contextHandler.getSessionHandler().getSessionCache(),
contextHandler.getSessionHandler().getSessionCache().getSessionDataStore(),
"4422");
client = new HttpClient();
client.start();
@ -87,14 +86,14 @@ public class DuplicateCookieTest
client.stop();
}
}
@Test
public void testMultipleSessionCookiesOnlyOneValid() throws Exception
{
String contextPath = "";
String servletMapping = "/server";
HttpClient client = null;
DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory();
SessionDataStoreFactory storeFactory = new TestSessionDataStoreFactory();
@ -116,7 +115,7 @@ public class DuplicateCookieTest
createInvalidSession(contextHandler.getSessionHandler().getSessionCache(),
contextHandler.getSessionHandler().getSessionCache().getSessionDataStore(),
"2233");
client = new HttpClient();
client.start();
@ -134,7 +133,7 @@ public class DuplicateCookieTest
client.stop();
}
}
@Test
public void testMultipleSessionCookiesMultipleExists() throws Exception
{
@ -165,7 +164,7 @@ public class DuplicateCookieTest
createUnExpiredSession(contextHandler.getSessionHandler().getSessionCache(),
contextHandler.getSessionHandler().getSessionCache().getSessionDataStore(),
"9111");
client = new HttpClient();
client.start();
@ -192,14 +191,14 @@ public class DuplicateCookieTest
cache.add(id, s);
return s;
}
public Session createInvalidSession(SessionCache cache, SessionDataStore store, String id) throws Exception
{
Session session = createUnExpiredSession(cache, store, id);
session._state = Session.State.INVALID;
return session;
}
public static class TestServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.server.session;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -96,7 +95,7 @@ public class SessionInvalidationTest
server.stop();
}
}
public static class TestServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
@ -118,7 +117,7 @@ public class SessionInvalidationTest
//invalidate existing session
session.invalidate();
assertThrows(IllegalStateException.class, () -> session.invalidate());
assertThrows(IllegalStateException.class, () -> session.getLastAccessedTime());
assertThrows(IllegalStateException.class, () -> session.getCreationTime());
@ -131,7 +130,6 @@ public class SessionInvalidationTest
assertThrows(IllegalStateException.class, () -> session.removeValue("foo"));
assertThrows(IllegalStateException.class, () -> session.setAttribute("a", "b"));
assertDoesNotThrow(() -> session.getId());
}
}
}