Author: markt
Date: Tue Jul 5 19:18:28 2016
New Revision: 1751533
URL: http://svn.apache.org/viewvc?rev=1751533&view=rev
Log:
Align 9.0.x and 8.5.x.
Modified:
tomcat/tc8.5.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java
tomcat/tc8.5.x/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
Modified:
tomcat/tc8.5.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java?rev=1751533&r1=1751532&r2=1751533&view=diff
==============================================================================
---
tomcat/tc8.5.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java
(original)
+++
tomcat/tc8.5.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java
Tue Jul 5 19:18:28 2016
@@ -246,4 +246,86 @@ public class TestApplicationContext exte
}
}
}
+
+
+ /*
+ * The expectation is that you can set a context attribute on
+ * ServletContextB from ServletContextA and then access that attribute via
+ * a cross-context dispatch to ServletContextB.
+ */
+ @Test
+ public void testCrossContextSetAttribute() throws Exception {
+ // Setup Tomcat instance
+ Tomcat tomcat = getTomcatInstance();
+
+ // No file system docBase required
+ Context ctx2 = tomcat.addContext("/second", null);
+ GetAttributeServlet getAttributeServlet = new GetAttributeServlet();
+ Tomcat.addServlet(ctx2, "getAttributeServlet", getAttributeServlet);
+ ctx2.addServletMapping("/test", "getAttributeServlet");
+
+ // No file system docBase required
+ Context ctx1 = tomcat.addContext("/first", null);
+ ctx1.setCrossContext(true);
+ SetAttributeServlet setAttributeServlet = new
SetAttributeServlet("/test", "/second");
+ Tomcat.addServlet(ctx1, "setAttributeServlet", setAttributeServlet);
+ ctx1.addServletMapping("/test", "setAttributeServlet");
+
+ tomcat.start();
+
+ ByteChunk bc = new ByteChunk();
+ int rc = getUrl("http://localhost:" + getPort() + "/first/test", bc,
null);
+
+ Assert.assertEquals(200, rc);
+ Assert.assertEquals("01-PASS", bc.toString());
+ }
+
+
+ private static class SetAttributeServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+ private static final String ATTRIBUTE_NAME = "setAttributeTest";
+ private static final String ATTRIBUTE_VALUE = "abcde";
+
+ private final String targetContextPath;
+ private final String targetPath;
+
+ public SetAttributeServlet(String targetPath, String
targetContextPath) {
+ this.targetPath = targetPath;
+ this.targetContextPath = targetContextPath;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ ServletContext sc;
+ if (targetContextPath == null) {
+ sc = req.getServletContext();
+ } else {
+ sc = req.getServletContext().getContext(targetContextPath);
+ }
+ sc.setAttribute(ATTRIBUTE_NAME, ATTRIBUTE_VALUE);
+ sc.getRequestDispatcher(targetPath).forward(req, resp);
+ }
+ }
+
+
+ private static class GetAttributeServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ resp.setContentType("text/plain");
+ PrintWriter pw = resp.getWriter();
+ String value = (String) req.getServletContext().getAttribute(
+ SetAttributeServlet.ATTRIBUTE_NAME);
+ if (SetAttributeServlet.ATTRIBUTE_VALUE.equals(value)) {
+ pw.print("01-PASS");
+ } else {
+ pw.print("01-FAIL");
+ }
+ }
+ }
}
Modified:
tomcat/tc8.5.x/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java?rev=1751533&r1=1751532&r2=1751533&view=diff
==============================================================================
---
tomcat/tc8.5.x/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
(original)
+++
tomcat/tc8.5.x/trunk/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
Tue Jul 5 19:18:28 2016
@@ -50,14 +50,10 @@ import org.apache.catalina.startup.Teste
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.catalina.valves.TesterAccessLogValve;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.buf.ByteChunk;
public class TestNonBlockingAPI extends TomcatBaseTest {
- private static final Log log = LogFactory.getLog(TestNonBlockingAPI.class);
-
private static final int CHUNK_SIZE = 1024 * 1024;
private static final int WRITE_SIZE = CHUNK_SIZE * 10;
private static final byte[] DATA = new byte[WRITE_SIZE];
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]