Comprehensive Servlet 3.1 support in spring-web and spring-test

Issue: SPR-14467
This commit is contained in:
Juergen Hoeller
2016-07-15 22:11:14 +02:00
parent 177f4ec3a7
commit f0c397e4e2
14 changed files with 107 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.IOException;
import java.io.InputStream;
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import org.springframework.util.Assert;
@@ -36,6 +37,8 @@ public class DelegatingServletInputStream extends ServletInputStream {
private final InputStream sourceStream;
private boolean finished = false;
/**
* Create a DelegatingServletInputStream for the given source stream.
@@ -56,7 +59,11 @@ public class DelegatingServletInputStream extends ServletInputStream {
@Override
public int read() throws IOException {
return this.sourceStream.read();
int data = this.sourceStream.read();
if (data == -1) {
this.finished = true;
}
return data;
}
@Override
@@ -65,4 +72,19 @@ public class DelegatingServletInputStream extends ServletInputStream {
this.sourceStream.close();
}
@Override
public boolean isFinished() {
return this.finished;
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setReadListener(ReadListener readListener) {
throw new UnsupportedOperationException();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@@ -19,6 +19,7 @@ package org.springframework.mock.web;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import org.springframework.util.Assert;
@@ -71,4 +72,14 @@ public class DelegatingServletOutputStream extends ServletOutputStream {
this.targetStream.close();
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setWriteListener(WriteListener writeListener) {
throw new UnsupportedOperationException();
}
}

View File

@@ -51,6 +51,7 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpUpgradeHandler;
import javax.servlet.http.Part;
import org.springframework.http.MediaType;
@@ -68,7 +69,7 @@ import org.springframework.util.StringUtils;
* is {@link Locale#ENGLISH}. This value can be changed via {@link #addPreferredLocale}
* or {@link #setPreferredLocales}.
*
* <p>As of Spring Framework 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
* <p>As of Spring Framework 5.0, this set of mocks is designed on a Servlet 3.1 baseline.
*
* @author Juergen Hoeller
* @author Rod Johnson
@@ -1216,4 +1217,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
return result;
}
@Override
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException {
throw new UnsupportedOperationException();
}
}

View File

@@ -45,9 +45,7 @@ import org.springframework.web.util.WebUtils;
/**
* Mock implementation of the {@link javax.servlet.http.HttpServletResponse} interface.
*
* <p>As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
* Beyond that, {@code MockHttpServletResponse} is also compatible with Servlet
* 3.1's {@code setContentLengthLong()} method.
* <p>As of Spring Framework 5.0, this set of mocks is designed on a Servlet 3.1 baseline.
*
* @author Juergen Hoeller
* @author Rod Johnson

View File

@@ -676,4 +676,9 @@ public class MockServletContext implements ServletContext {
throw new UnsupportedOperationException();
}
@Override
public String getVirtualServerName() {
throw new UnsupportedOperationException();
}
}