use of javax.servlet.http.HttpServletResponse in project jetty.project by eclipse.
the class JDK9ALPNTest method testClientNotSupportingALPNServerSpeaksDefaultProtocol.
@Test
public void testClientNotSupportingALPNServerSpeaksDefaultProtocol() throws Exception {
startServer(new AbstractHandler.ErrorDispatchHandler() {
@Override
protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
}
});
SslContextFactory sslContextFactory = new SslContextFactory(true);
sslContextFactory.start();
SSLContext sslContext = sslContextFactory.getSslContext();
try (SSLSocket client = (SSLSocket) sslContext.getSocketFactory().createSocket("localhost", connector.getLocalPort())) {
client.setUseClientMode(true);
client.setSoTimeout(5000);
client.startHandshake();
OutputStream output = client.getOutputStream();
output.write(("" + "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: close\r\n" + "\r\n" + "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 200 "));
while (true) {
if (reader.readLine() == null)
break;
}
}
}
use of javax.servlet.http.HttpServletResponse in project jetty.project by eclipse.
the class TryFilesFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
for (int i = 0; i < files.length - 1; ++i) {
String file = files[i];
String resolved = resolve(httpRequest, file);
URL url = request.getServletContext().getResource(resolved);
if (url == null)
continue;
if (Files.isReadable(toPath(url))) {
chain.doFilter(httpRequest, httpResponse);
return;
}
}
// The last one is the fallback
fallback(httpRequest, httpResponse, chain, files[files.length - 1]);
}
use of javax.servlet.http.HttpServletResponse in project jetty.project by eclipse.
the class HttpClientTest method testPOSTWithParameters.
@Test
public void testPOSTWithParameters() throws Exception {
final String paramName = "a";
final String paramValue = "€";
start(new AbstractHandler() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
String value = request.getParameter(paramName);
if (paramValue.equals(value)) {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
response.getOutputStream().print(value);
}
}
});
ContentResponse response = client.POST(scheme + "://localhost:" + connector.getLocalPort()).param(paramName, paramValue).timeout(5, TimeUnit.SECONDS).send();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8"));
}
use of javax.servlet.http.HttpServletResponse in project jetty.project by eclipse.
the class HttpClientTest method testEarlyEOF.
@Test
public void testEarlyEOF() throws Exception {
start(new AbstractHandler() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
// Promise some content, then flush the headers, then fail to send the content.
response.setContentLength(16);
response.flushBuffer();
throw new NullPointerException("Explicitly thrown by test");
}
});
try (StacklessLogging stackless = new StacklessLogging(org.eclipse.jetty.server.HttpChannel.class)) {
client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).timeout(60, TimeUnit.SECONDS).send();
Assert.fail();
} catch (ExecutionException x) {
// Expected.
}
}
use of javax.servlet.http.HttpServletResponse in project jetty.project by eclipse.
the class HttpClientTest method testPOSTWithParametersWithContent.
@Test
public void testPOSTWithParametersWithContent() throws Exception {
final byte[] content = { 0, 1, 2, 3 };
final String paramName = "a";
final String paramValue = "€";
start(new AbstractHandler() {
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
String value = request.getParameter(paramName);
if (paramValue.equals(value)) {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream");
IO.copy(request.getInputStream(), response.getOutputStream());
}
}
});
for (int i = 0; i < 256; ++i) {
ContentResponse response = client.POST(scheme + "://localhost:" + connector.getLocalPort() + "/?b=1").param(paramName, paramValue).content(new BytesContentProvider(content)).timeout(5, TimeUnit.SECONDS).send();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertArrayEquals(content, response.getContent());
}
}
Aggregations