From d9b73461ff8a59fae21f73543b7bbeb2b7734586 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 26 May 2011 13:34:21 +0000 Subject: [PATCH] Upgrade javax.servlet dependency to 3.0 for .web In support of SPR-7672 which will support code-based configuration alternatives to web.xml using new features in the Servlet 3.0 API. This upgrade does *not* force Spring users to upgrade to Servlet 3.0 capable containers. Compatibility with and support for javax.servlet >= 2.4 remains. Issue: SPR-7672 git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4365 50f2f4bb-b051-0410-bef5-90022cba6387 --- org.springframework.web/.classpath | 2 +- org.springframework.web/ivy.xml | 2 +- org.springframework.web/pom.xml | 2 +- .../mock/web/MockHttpServletRequest.java | 64 ++++++++- .../mock/web/MockHttpServletResponse.java | 12 +- .../mock/web/MockServletContext.java | 130 +++++++++++++++++- .../request/ServletWebRequestTests.java | 2 +- org.springframework.web/template.mf | 1 + org.springframework.web/web.iml | 4 +- 9 files changed, 204 insertions(+), 15 deletions(-) diff --git a/org.springframework.web/.classpath b/org.springframework.web/.classpath index f4fbe0249c9..5e6d64d01fb 100644 --- a/org.springframework.web/.classpath +++ b/org.springframework.web/.classpath @@ -15,7 +15,7 @@ - + diff --git a/org.springframework.web/ivy.xml b/org.springframework.web/ivy.xml index 44140487a09..532dc81c1e9 100644 --- a/org.springframework.web/ivy.xml +++ b/org.springframework.web/ivy.xml @@ -43,7 +43,7 @@ - + javax.servlet servlet-api - 2.5 + 3.0 provided diff --git a/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletRequest.java b/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletRequest.java index 26f7171b58f..c8ea4249a72 100644 --- a/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletRequest.java +++ b/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.mock.web; import java.io.BufferedReader; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; @@ -34,19 +35,28 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; + +import javax.servlet.AsyncContext; +import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; +import javax.servlet.ServletException; import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import javax.servlet.http.Part; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; /** * Mock implementation of the {@link javax.servlet.http.HttpServletRequest} - * interface. Supports the Servlet 2.5 API level. + * interface. Supports the Servlet 2.5 API level; throws + * {@link UnsupportedOperationException} for all methods introduced in Servlet 3.0. * *

Used for testing the web framework; also useful for testing * application controllers. @@ -55,6 +65,7 @@ import org.springframework.util.LinkedCaseInsensitiveMap; * @author Rod Johnson * @author Rick Evans * @author Mark Fisher + * @author Chris Beams * @since 1.0.2 */ public class MockHttpServletRequest implements HttpServletRequest { @@ -847,4 +858,53 @@ public class MockHttpServletRequest implements HttpServletRequest { return isRequestedSessionIdFromURL(); } + + //--------------------------------------------------------------------- + // Methods introduced in Servlet 3.0 + //--------------------------------------------------------------------- + + public AsyncContext getAsyncContext() { + throw new UnsupportedOperationException(); + } + + public DispatcherType getDispatcherType() { + throw new UnsupportedOperationException(); + } + + public boolean isAsyncSupported() { + throw new UnsupportedOperationException(); + } + + public AsyncContext startAsync() { + throw new UnsupportedOperationException(); + } + + public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1) { + throw new UnsupportedOperationException(); + } + + public boolean isAsyncStarted() { + throw new UnsupportedOperationException(); + } + + public boolean authenticate(HttpServletResponse arg0) throws IOException, ServletException { + throw new UnsupportedOperationException(); + } + + public Part getPart(String arg0) throws IOException, IllegalStateException, ServletException { + throw new UnsupportedOperationException(); + } + + public Collection getParts() throws IOException, IllegalStateException, ServletException { + throw new UnsupportedOperationException(); + } + + public void login(String arg0, String arg1) throws ServletException { + throw new UnsupportedOperationException(); + } + + public void logout() throws ServletException { + throw new UnsupportedOperationException(); + } + } diff --git a/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletResponse.java b/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletResponse.java index 46eb174615d..973ef580590 100644 --- a/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/org.springframework.web/src/test/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ import org.springframework.web.util.WebUtils; /** * Mock implementation of the {@link javax.servlet.http.HttpServletResponse} - * interface. Supports the Servlet 2.5 API level. + * interface. Supports the Servlet 3.0 API level * *

Used for testing the web framework; also useful for testing * application controllers. @@ -292,9 +292,9 @@ public class MockHttpServletResponse implements HttpServletResponse { * @param name the name of the header * @return the associated header value, or null if none */ - public Object getHeader(String name) { + public String getHeader(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); - return (header != null ? header.getValue() : null); + return (header != null ? header.getValue().toString() : null); } /** @@ -302,9 +302,9 @@ public class MockHttpServletResponse implements HttpServletResponse { * @param name the name of the header * @return the associated header values, or an empty List if none */ - public List getHeaders(String name) { + public List getHeaders(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); - return (header != null ? header.getValues() : Collections.emptyList()); + return (header != null ? header.getStringValues() : Collections.emptyList()); } /** diff --git a/org.springframework.web/src/test/java/org/springframework/mock/web/MockServletContext.java b/org.springframework.web/src/test/java/org/springframework/mock/web/MockServletContext.java index abcff79c41d..828b430e6c4 100644 --- a/org.springframework.web/src/test/java/org/springframework/mock/web/MockServletContext.java +++ b/org.springframework.web/src/test/java/org/springframework/mock/web/MockServletContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.Enumeration; +import java.util.EventListener; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -30,9 +31,17 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; import javax.activation.FileTypeMap; +import javax.servlet.Filter; +import javax.servlet.FilterRegistration; +import javax.servlet.FilterRegistration.Dynamic; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; +import javax.servlet.SessionCookieConfig; +import javax.servlet.SessionTrackingMode; +import javax.servlet.descriptor.JspConfigDescriptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -67,8 +76,12 @@ import org.springframework.web.util.WebUtils; * and XmlWebApplicationContext with an underlying MockServletContext (as long as * the MockServletContext has been configured with a FileSystemResourceLoader). * + * Supports the Servlet 3.0 API level, but throws {@link UnsupportedOperationException} + * for all methods introduced in Servlet 3.0. + * * @author Rod Johnson * @author Juergen Hoeller + * @author Chris Beams * @since 1.0.2 * @see #MockServletContext(org.springframework.core.io.ResourceLoader) * @see org.springframework.web.context.support.XmlWebApplicationContext @@ -361,4 +374,119 @@ public class MockServletContext implements ServletContext { } } + + //--------------------------------------------------------------------- + // Methods introduced in Servlet 3.0 + //--------------------------------------------------------------------- + + public Dynamic addFilter(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public Dynamic addFilter(String arg0, Filter arg1) { + throw new UnsupportedOperationException(); + } + + public Dynamic addFilter(String arg0, Class arg1) { + throw new UnsupportedOperationException(); + } + + public void addListener(Class arg0) { + throw new UnsupportedOperationException(); + } + + public void addListener(String arg0) { + throw new UnsupportedOperationException(); + } + + public void addListener(T arg0) { + throw new UnsupportedOperationException(); + } + + public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0, + Servlet arg1) { + throw new UnsupportedOperationException(); + } + + public javax.servlet.ServletRegistration.Dynamic addServlet(String arg0, + Class arg1) { + throw new UnsupportedOperationException(); + } + + public T createFilter(Class arg0) + throws ServletException { + throw new UnsupportedOperationException(); + } + + public T createListener(Class arg0) + throws ServletException { + throw new UnsupportedOperationException(); + } + + public T createServlet(Class arg0) + throws ServletException { + throw new UnsupportedOperationException(); + } + + public void declareRoles(String... arg0) { + throw new UnsupportedOperationException(); + } + + public ClassLoader getClassLoader() { + throw new UnsupportedOperationException(); + } + + public Set getDefaultSessionTrackingModes() { + throw new UnsupportedOperationException(); + } + + public int getEffectiveMajorVersion() { + throw new UnsupportedOperationException(); + } + + public int getEffectiveMinorVersion() { + throw new UnsupportedOperationException(); + } + + public Set getEffectiveSessionTrackingModes() { + throw new UnsupportedOperationException(); + } + + public FilterRegistration getFilterRegistration(String arg0) { + throw new UnsupportedOperationException(); + } + + public Map getFilterRegistrations() { + throw new UnsupportedOperationException(); + } + + public JspConfigDescriptor getJspConfigDescriptor() { + throw new UnsupportedOperationException(); + } + + public ServletRegistration getServletRegistration(String arg0) { + throw new UnsupportedOperationException(); + } + + public Map getServletRegistrations() { + throw new UnsupportedOperationException(); + } + + public SessionCookieConfig getSessionCookieConfig() { + throw new UnsupportedOperationException(); + } + + public boolean setInitParameter(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public void setSessionTrackingModes(Set arg0) + throws IllegalStateException, IllegalArgumentException { + throw new UnsupportedOperationException(); + } + } diff --git a/org.springframework.web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java b/org.springframework.web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java index 63377a8bcf2..13622a0a440 100644 --- a/org.springframework.web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java +++ b/org.springframework.web/src/test/java/org/springframework/web/context/request/ServletWebRequestTests.java @@ -136,7 +136,7 @@ public class ServletWebRequestTests { request.checkNotModified(currentTime); assertEquals(200, servletResponse.getStatus()); - assertEquals(currentTime, servletResponse.getHeader("Last-Modified")); + assertEquals(""+currentTime, servletResponse.getHeader("Last-Modified")); } @Test diff --git a/org.springframework.web/template.mf b/org.springframework.web/template.mf index ad4ba30b7cc..0deb48fc349 100644 --- a/org.springframework.web/template.mf +++ b/org.springframework.web/template.mf @@ -15,6 +15,7 @@ Import-Template: javax.portlet.*;version="[2.0.0, 3.0.0)";resolution:=optional, javax.servlet;version="[2.4.0, 4.0.0)", javax.servlet.http;version="[2.4.0, 4.0.0)", + javax.servlet.annotation;version="[3.0.0, 4.0.0)";resolution:=optional, javax.servlet.jsp.*;version="[2.0.0, 3.0.0)";resolution:=optional, javax.xml.*;version="0";resolution:=optional, org.aopalliance.*;version="[1.0.0, 2.0.0)", diff --git a/org.springframework.web/web.iml b/org.springframework.web/web.iml index 7f310042ad5..c17cad14f55 100644 --- a/org.springframework.web/web.iml +++ b/org.springframework.web/web.iml @@ -47,11 +47,11 @@ - + - +