Remove pre-3.2 deprecated classes and methods

Issue: SPR-12578
This commit is contained in:
Juergen Hoeller
2014-12-30 20:05:15 +01:00
parent fad76336f6
commit 9ac02b319d
34 changed files with 77 additions and 1649 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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,9 +23,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.activation.FileTypeMap;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -55,29 +53,31 @@ import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
/**
* Implementation of {@link ViewResolver} that resolves a view based on the request file name or {@code Accept} header.
* Implementation of {@link ViewResolver} that resolves a view based on the request file name
* or {@code Accept} header.
*
* <p>The {@code ContentNegotiatingViewResolver} does not resolve views itself, but delegates to other {@link
* ViewResolver}s. By default, these other view resolvers are picked up automatically from the application context,
* though they can also be set explicitly by using the {@link #setViewResolvers(List) viewResolvers} property.
* <strong>Note</strong> that in order for this view resolver to work properly, the {@link #setOrder(int) order}
* property needs to be set to a higher precedence than the others (the default is {@link Ordered#HIGHEST_PRECEDENCE}.)
* <p>The {@code ContentNegotiatingViewResolver} does not resolve views itself, but delegates to
* other {@link ViewResolver}s. By default, these other view resolvers are picked up automatically
* from the application context, though they can also be set explicitly by using the
* {@link #setViewResolvers viewResolvers} property. <strong>Note</strong> that in order for this
* view resolver to work properly, the {@link #setOrder order} property needs to be set to a higher
* precedence than the others (the default is {@link Ordered#HIGHEST_PRECEDENCE}).
*
* <p>This view resolver uses the requested {@linkplain MediaType media type} to select a suitable {@link View} for a
* request. The requested media type is determined through the configured {@link ContentNegotiationManager}.
* Once the requested media type has been determined, this resolver queries each delegate view resolver for a
* {@link View} and determines if the requested media type is {@linkplain MediaType#includes(MediaType) compatible}
* with the view's {@linkplain View#getContentType() content type}). The most compatible view is returned.
* <p>This view resolver uses the requested {@linkplain MediaType media type} to select a suitable
* {@link View} for a request. The requested media type is determined through the configured
* {@link ContentNegotiationManager}. Once the requested media type has been determined, this resolver
* queries each delegate view resolver for a {@link View} and determines if the requested media type
* is {@linkplain MediaType#includes(MediaType) compatible} with the view's
* {@linkplain View#getContentType() content type}). The most compatible view is returned.
*
* <p>Additionally, this view resolver exposes the {@link #setDefaultViews(List) defaultViews} property, allowing you to
* override the views provided by the view resolvers. Note that these default views are offered as candidates, and
* still need have the content type requested (via file extension, parameter, or {@code Accept} header, described above).
* You can also set the {@linkplain #setDefaultContentType(MediaType) default content type} directly, which will be
* returned when the other mechanisms ({@code Accept} header, file extension or parameter) do not result in a match.
* <p>Additionally, this view resolver exposes the {@link #setDefaultViews(List) defaultViews} property,
* allowing you to override the views provided by the view resolvers. Note that these default views are
* offered as candidates, and still need have the content type requested (via file extension, parameter,
* or {@code Accept} header, described above).
*
* <p>For example, if the request path is {@code /view.html}, this view resolver will look for a view that has the
* {@code text/html} content type (based on the {@code html} file extension). A request for {@code /view} with a {@code
* text/html} request {@code Accept} header has the same result.
* <p>For example, if the request path is {@code /view.html}, this view resolver will look for a view
* that has the {@code text/html} content type (based on the {@code html} file extension). A request
* for {@code /view} with a {@code text/html} request {@code Accept} header has the same result.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
@@ -123,90 +123,6 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
this.contentNegotiationManager = contentNegotiationManager;
}
/**
* Indicate whether the extension of the request path should be used to determine the requested media type,
* in favor of looking at the {@code Accept} header. The default value is {@code true}.
* <p>For instance, when this flag is {@code true} (the default), a request for {@code /hotels.pdf}
* will result in an {@code AbstractPdfView} being resolved, while the {@code Accept} header can be the
* browser-defined {@code text/html,application/xhtml+xml}.
* @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
*/
@Deprecated
public void setFavorPathExtension(boolean favorPathExtension) {
this.cnManagerFactoryBean.setFavorPathExtension(favorPathExtension);
}
/**
* Indicate whether to use the Java Activation Framework to map from file extensions to media types.
* <p>Default is {@code true}, i.e. the Java Activation Framework is used (if available).
* @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
*/
@Deprecated
public void setUseJaf(boolean useJaf) {
this.cnManagerFactoryBean.setUseJaf(useJaf);
}
/**
* Indicate whether a request parameter should be used to determine the requested media type,
* in favor of looking at the {@code Accept} header. The default value is {@code false}.
* <p>For instance, when this flag is {@code true}, a request for {@code /hotels?format=pdf} will result
* in an {@code AbstractPdfView} being resolved, while the {@code Accept} header can be the browser-defined
* {@code text/html,application/xhtml+xml}.
* @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
*/
@Deprecated
public void setFavorParameter(boolean favorParameter) {
this.cnManagerFactoryBean.setFavorParameter(favorParameter);
}
/**
* Set the parameter name that can be used to determine the requested media type if the {@link
* #setFavorParameter} property is {@code true}. The default parameter name is {@code format}.
* @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
*/
@Deprecated
public void setParameterName(String parameterName) {
this.cnManagerFactoryBean.setParameterName(parameterName);
}
/**
* Indicate whether the HTTP {@code Accept} header should be ignored. Default is {@code false}.
* <p>If set to {@code true}, this view resolver will only refer to the file extension and/or
* parameter, as indicated by the {@link #setFavorPathExtension favorPathExtension} and
* {@link #setFavorParameter favorParameter} properties.
* @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
*/
@Deprecated
public void setIgnoreAcceptHeader(boolean ignoreAcceptHeader) {
this.cnManagerFactoryBean.setIgnoreAcceptHeader(ignoreAcceptHeader);
}
/**
* Set the mapping from file extensions to media types.
* <p>When this mapping is not set or when an extension is not present, this view resolver
* will fall back to using a {@link FileTypeMap} when the Java Action Framework is available.
* @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
*/
@Deprecated
public void setMediaTypes(Map<String, String> mediaTypes) {
if (mediaTypes != null) {
Properties props = new Properties();
props.putAll(mediaTypes);
this.cnManagerFactoryBean.setMediaTypes(props);
}
}
/**
* Set the default content type.
* <p>This content type will be used when file extension, parameter, nor {@code Accept}
* header define a content-type, either through being disabled or empty.
* @deprecated use {@link #setContentNegotiationManager(ContentNegotiationManager)}
*/
@Deprecated
public void setDefaultContentType(MediaType defaultContentType) {
this.cnManagerFactoryBean.setDefaultContentType(defaultContentType);
}
/**
* Indicate whether a {@link HttpServletResponse#SC_NOT_ACCEPTABLE 406 Not Acceptable}
* status code should be returned if no suitable view can be found.

View File

@@ -133,25 +133,6 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
return this.modelKeys;
}
/**
* Set the attributes in the model that should be rendered by this view.
* When set, all other model attributes will be ignored.
* @deprecated use {@link #setModelKeys(Set)} instead
*/
@Deprecated
public void setRenderedAttributes(Set<String> renderedAttributes) {
this.modelKeys = renderedAttributes;
}
/**
* Return the attributes in the model that should be rendered by this view.
* @deprecated use {@link #getModelKeys()} instead
*/
@Deprecated
public final Set<String> getRenderedAttributes() {
return this.modelKeys;
}
/**
* Set whether to serialize models containing a single attribute as a map or whether to
* extract the single value from the model and serialize it directly.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -28,14 +27,6 @@ import org.junit.Test;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.ChildBeanDefinition;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.ManagedSet;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.test.MockServletContext;
import org.springframework.tests.sample.beans.TestBean;
@@ -141,213 +132,6 @@ public class ServletContextSupportTests {
assertSame(tb, sc.getAttribute("attr2"));
}
@Test
@Deprecated
public void testServletContextPropertyPlaceholderConfigurer() {
MockServletContext sc = new MockServletContext();
sc.addInitParameter("key4", "mykey4");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "${age}");
pvs.add("name", "${key4}name${var}${var}${");
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
wac.registerSingleton("tb1", TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
wac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);
pvs = new MutablePropertyValues();
pvs.add("properties", "age=98\nvar=${m}var\nref=tb2\nm=my");
wac.registerSingleton("configurer", ServletContextPropertyPlaceholderConfigurer.class, pvs);
wac.refresh();
TestBean tb1 = (TestBean) wac.getBean("tb1");
TestBean tb2 = (TestBean) wac.getBean("tb2");
assertEquals(98, tb1.getAge());
assertEquals("mykey4namemyvarmyvar${", tb1.getName());
assertEquals(tb2, tb1.getSpouse());
}
@Test
@Deprecated
public void testServletContextPropertyPlaceholderConfigurerWithLocalOverriding() {
MockServletContext sc = new MockServletContext();
sc.addInitParameter("key4", "mykey4");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "${age}");
pvs.add("name", "${key4}name${var}${var}${");
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
wac.registerSingleton("tb1", TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
wac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);
pvs = new MutablePropertyValues();
pvs.add("properties", "age=98\nvar=${m}var\nref=tb2\nm=my\nkey4=yourkey4");
wac.registerSingleton("configurer", ServletContextPropertyPlaceholderConfigurer.class, pvs);
wac.refresh();
TestBean tb1 = (TestBean) wac.getBean("tb1");
TestBean tb2 = (TestBean) wac.getBean("tb2");
assertEquals(98, tb1.getAge());
assertEquals("yourkey4namemyvarmyvar${", tb1.getName());
assertEquals(tb2, tb1.getSpouse());
}
@Test
@Deprecated
public void testServletContextPropertyPlaceholderConfigurerWithContextOverride() {
MockServletContext sc = new MockServletContext();
sc.addInitParameter("key4", "mykey4");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "${age}");
pvs.add("name", "${key4}name${var}${var}${");
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
wac.registerSingleton("tb1", TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
wac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);
pvs = new MutablePropertyValues();
pvs.add("properties", "age=98\nvar=${m}var\nref=tb2\nm=my\nkey4=yourkey4");
pvs.add("contextOverride", Boolean.TRUE);
wac.registerSingleton("configurer", ServletContextPropertyPlaceholderConfigurer.class, pvs);
wac.refresh();
TestBean tb1 = (TestBean) wac.getBean("tb1");
TestBean tb2 = (TestBean) wac.getBean("tb2");
assertEquals(98, tb1.getAge());
assertEquals("mykey4namemyvarmyvar${", tb1.getName());
assertEquals(tb2, tb1.getSpouse());
}
@Test
@Deprecated
public void testServletContextPropertyPlaceholderConfigurerWithContextOverrideAndAttributes() {
MockServletContext sc = new MockServletContext();
sc.addInitParameter("key4", "mykey4");
sc.setAttribute("key4", "attrkey4");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "${age}");
pvs.add("name", "${key4}name${var}${var}${");
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
wac.registerSingleton("tb1", TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
wac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);
pvs = new MutablePropertyValues();
pvs.add("properties", "age=98\nvar=${m}var\nref=tb2\nm=my\nkey4=yourkey4");
pvs.add("contextOverride", Boolean.TRUE);
pvs.add("searchContextAttributes", Boolean.TRUE);
wac.registerSingleton("configurer", ServletContextPropertyPlaceholderConfigurer.class, pvs);
wac.refresh();
TestBean tb1 = (TestBean) wac.getBean("tb1");
TestBean tb2 = (TestBean) wac.getBean("tb2");
assertEquals(98, tb1.getAge());
assertEquals("attrkey4namemyvarmyvar${", tb1.getName());
assertEquals(tb2, tb1.getSpouse());
}
@Test
@Deprecated
public void testServletContextPropertyPlaceholderConfigurerWithAttributes() {
MockServletContext sc = new MockServletContext();
sc.addInitParameter("key4", "mykey4");
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "${age}");
pvs.add("name", "name${var}${var}${");
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
wac.registerSingleton("tb1", TestBean.class, pvs);
ConstructorArgumentValues cas = new ConstructorArgumentValues();
cas.addIndexedArgumentValue(1, "${age}");
cas.addGenericArgumentValue("${var}name${age}");
pvs = new MutablePropertyValues();
List<Object> friends = new ManagedList<Object>();
friends.add("na${age}me");
friends.add(new RuntimeBeanReference("${ref}"));
pvs.add("friends", friends);
Set<Object> someSet = new ManagedSet<Object>();
someSet.add("na${age}me");
someSet.add(new RuntimeBeanReference("${ref}"));
pvs.add("someSet", someSet);
Map<String, Object> someMap = new ManagedMap<String, Object>();
someMap.put("key1", new RuntimeBeanReference("${ref}"));
someMap.put("key2", "${age}name");
MutablePropertyValues innerPvs = new MutablePropertyValues();
innerPvs.add("touchy", "${os.name}");
RootBeanDefinition innerBd = new RootBeanDefinition(TestBean.class);
innerBd.setPropertyValues(innerPvs);
someMap.put("key3", innerBd);
MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs);
someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child"));
pvs.add("someMap", someMap);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, cas, pvs);
wac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);
pvs = new MutablePropertyValues();
pvs.add("properties", "var=${m}var\nref=tb2\nm=my");
pvs.add("searchContextAttributes", Boolean.TRUE);
wac.registerSingleton("configurer", ServletContextPropertyPlaceholderConfigurer.class, pvs);
sc.setAttribute("age", new Integer(98));
wac.refresh();
TestBean tb1 = (TestBean) wac.getBean("tb1");
TestBean tb2 = (TestBean) wac.getBean("tb2");
assertEquals(98, tb1.getAge());
assertEquals(98, tb2.getAge());
assertEquals("namemyvarmyvar${", tb1.getName());
assertEquals("myvarname98", tb2.getName());
assertEquals(tb2, tb1.getSpouse());
assertEquals(2, tb2.getFriends().size());
assertEquals("na98me", tb2.getFriends().iterator().next());
assertEquals(tb2, tb2.getFriends().toArray()[1]);
assertEquals(2, tb2.getSomeSet().size());
assertTrue(tb2.getSomeSet().contains("na98me"));
assertTrue(tb2.getSomeSet().contains(tb2));
assertEquals(4, tb2.getSomeMap().size());
assertEquals(tb2, tb2.getSomeMap().get("key1"));
assertEquals("98name", tb2.getSomeMap().get("key2"));
TestBean inner1 = (TestBean) tb2.getSomeMap().get("key3");
TestBean inner2 = (TestBean) tb2.getSomeMap().get("mykey4");
assertEquals(0, inner1.getAge());
assertEquals(null, inner1.getName());
assertEquals(System.getProperty("os.name"), inner1.getTouchy());
assertEquals(98, inner2.getAge());
assertEquals("namemyvarmyvar${", inner2.getName());
assertEquals(System.getProperty("os.name"), inner2.getTouchy());
}
@Test
public void testServletContextResourceLoader() {
MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context");
@@ -377,8 +161,8 @@ public class ServletContextSupportTests {
ServletContextResourcePatternResolver rpr = new ServletContextResourcePatternResolver(sc);
Resource[] found = rpr.getResources("/WEB-INF/*.xml");
Set<String> foundPaths = new HashSet<String>();
for (int i = 0; i < found.length; i++) {
foundPaths.add(((ServletContextResource) found[i]).getPath());
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertEquals(2, foundPaths.size());
assertTrue(foundPaths.contains("/WEB-INF/context1.xml"));
@@ -410,8 +194,8 @@ public class ServletContextSupportTests {
ServletContextResourcePatternResolver rpr = new ServletContextResourcePatternResolver(sc);
Resource[] found = rpr.getResources("/WEB-INF/*/*.xml");
Set<String> foundPaths = new HashSet<String>();
for (int i = 0; i < found.length; i++) {
foundPaths.add(((ServletContextResource) found[i]).getPath());
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertEquals(2, foundPaths.size());
assertTrue(foundPaths.contains("/WEB-INF/mydir1/context1.xml"));
@@ -450,8 +234,8 @@ public class ServletContextSupportTests {
ServletContextResourcePatternResolver rpr = new ServletContextResourcePatternResolver(sc);
Resource[] found = rpr.getResources("/WEB-INF/**/*.xml");
Set<String> foundPaths = new HashSet<String>();
for (int i = 0; i < found.length; i++) {
foundPaths.add(((ServletContextResource) found[i]).getPath());
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertEquals(3, foundPaths.size());
assertTrue(foundPaths.contains("/WEB-INF/mydir1/context1.xml"));
@@ -479,8 +263,8 @@ public class ServletContextSupportTests {
ServletContextResourcePatternResolver rpr = new ServletContextResourcePatternResolver(sc);
Resource[] found = rpr.getResources("/WEB-INF/*.xml");
Set<String> foundPaths = new HashSet<String>();
for (int i = 0; i < found.length; i++) {
foundPaths.add(((ServletContextResource) found[i]).getPath());
for (Resource resource : found) {
foundPaths.add(((ServletContextResource) resource).getPath());
}
assertEquals(2, foundPaths.size());
assertTrue(foundPaths.contains("/WEB-INF/context1.xml"));