|
19 | 19 | package org.eclipse.jetty.jstl;
|
20 | 20 |
|
21 | 21 | import static org.hamcrest.Matchers.containsString;
|
| 22 | +import static org.hamcrest.Matchers.is; |
22 | 23 | import static org.hamcrest.Matchers.not;
|
23 | 24 | import static org.junit.Assert.assertThat;
|
24 | 25 |
|
25 | 26 | import java.io.File;
|
26 | 27 | import java.io.IOException;
|
| 28 | +import java.io.InputStream; |
| 29 | +import java.net.HttpURLConnection; |
27 | 30 | import java.net.URI;
|
| 31 | +import java.nio.charset.StandardCharsets; |
28 | 32 |
|
29 | 33 | import javax.servlet.jsp.JspException;
|
30 | 34 |
|
|
34 | 38 | import org.eclipse.jetty.toolchain.test.FS;
|
35 | 39 | import org.eclipse.jetty.toolchain.test.JAR;
|
36 | 40 | import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
37 |
| -import org.eclipse.jetty.toolchain.test.SimpleRequest; |
| 41 | +import org.eclipse.jetty.util.IO; |
38 | 42 | import org.eclipse.jetty.webapp.Configuration;
|
39 | 43 | import org.eclipse.jetty.webapp.WebAppContext;
|
40 | 44 | import org.junit.AfterClass;
|
@@ -100,32 +104,43 @@ public static void stopServer() throws Exception
|
100 | 104 | @Test
|
101 | 105 | public void testUrlsBasic() throws IOException
|
102 | 106 | {
|
103 |
| - SimpleRequest req = new SimpleRequest(baseUri); |
104 |
| - String resp = req.getString("/urls.jsp"); |
105 |
| - assertThat("Response should be JSP processed", resp, not(containsString("<c:url"))); |
106 |
| - assertThat("Response", resp, containsString("[c:url value] = /ref.jsp;jsessionid=")); |
107 |
| - assertThat("Response", resp, containsString("[c:url param] = ref.jsp;key=value;jsessionid=")); |
| 107 | + HttpURLConnection http = (HttpURLConnection) baseUri.resolve("/urls.jsp").toURL().openConnection(); |
| 108 | + assertThat("http response", http.getResponseCode(), is(200)); |
| 109 | + try(InputStream input = http.getInputStream()) |
| 110 | + { |
| 111 | + String resp = IO.toString(input, StandardCharsets.UTF_8); |
| 112 | + assertThat("Response should be JSP processed", resp, not(containsString("<c:url"))); |
| 113 | + assertThat("Response", resp, containsString("[c:url value] = /ref.jsp;jsessionid=")); |
| 114 | + assertThat("Response", resp, containsString("[c:url param] = ref.jsp;key=value;jsessionid=")); |
| 115 | + } |
108 | 116 | }
|
109 | 117 |
|
110 | 118 | @Test
|
111 | 119 | public void testCatchBasic() throws IOException
|
112 | 120 | {
|
113 |
| - SimpleRequest req = new SimpleRequest(baseUri); |
114 |
| - String resp = req.getString("/catch-basic.jsp"); |
115 |
| - assertThat("Response should be JSP processed", resp, not(containsString("<c:catch"))); |
116 |
| - assertThat("Response", resp, containsString("[c:catch] exception : " + JspException.class.getName())); |
117 |
| - assertThat("Response", resp, containsString("[c:catch] exception.message : In <parseNumber>")); |
| 121 | + HttpURLConnection http = (HttpURLConnection) baseUri.resolve("/catch-basic.jsp").toURL().openConnection(); |
| 122 | + assertThat("http response", http.getResponseCode(), is(200)); |
| 123 | + try(InputStream input = http.getInputStream()) |
| 124 | + { |
| 125 | + String resp = IO.toString(input, StandardCharsets.UTF_8); |
| 126 | + assertThat("Response should be JSP processed", resp, not(containsString("<c:catch"))); |
| 127 | + assertThat("Response", resp, containsString("[c:catch] exception : " + JspException.class.getName())); |
| 128 | + assertThat("Response", resp, containsString("[c:catch] exception.message : In <parseNumber>")); |
| 129 | + } |
118 | 130 | }
|
119 | 131 |
|
120 | 132 | @Test
|
121 | 133 | @Ignore
|
122 | 134 | public void testCatchTaglib() throws IOException
|
123 | 135 | {
|
124 |
| - SimpleRequest req = new SimpleRequest(baseUri); |
125 |
| - String resp = req.getString("/catch-taglib.jsp"); |
126 |
| - System.out.println("resp = " + resp); |
127 |
| - assertThat("Response should be JSP processed", resp, not(containsString("<c:catch>"))); |
128 |
| - assertThat("Response should be JSP processed", resp, not(containsString("<jtest:errorhandler>"))); |
129 |
| - assertThat("Response", resp, not(containsString("[jtest:errorhandler] exception is null"))); |
| 136 | + HttpURLConnection http = (HttpURLConnection) baseUri.resolve("/catch-taglib.jsp").toURL().openConnection(); |
| 137 | + assertThat("http response", http.getResponseCode(), is(200)); |
| 138 | + try(InputStream input = http.getInputStream()) |
| 139 | + { |
| 140 | + String resp = IO.toString(input, StandardCharsets.UTF_8); |
| 141 | + assertThat("Response should be JSP processed", resp, not(containsString("<c:catch>"))); |
| 142 | + assertThat("Response should be JSP processed", resp, not(containsString("<jtest:errorhandler>"))); |
| 143 | + assertThat("Response", resp, not(containsString("[jtest:errorhandler] exception is null"))); |
| 144 | + } |
130 | 145 | }
|
131 | 146 | }
|
0 commit comments