Skip to content
Permalink
Browse files

UNDERTOW-1382 HttpServerExchange cannot have both async IO resumed an…

…d dispatch() called in the same cycle
  • Loading branch information...
stuartwdouglas committed Jul 24, 2018
1 parent 7f60713 commit 4d808be94ed6b54be848ecd608fbfa14cbbd6701
@@ -359,7 +359,7 @@ public static void executeRootHandler(final HttpHandler handler, final HttpServe
exchange.setInCall(true);
handler.handleRequest(exchange);
exchange.setInCall(false);
boolean resumed = exchange.runResumeReadWrite();
boolean resumed = exchange.isResumed();
if (exchange.isDispatched()) {
if (resumed) {
UndertowLogger.REQUEST_LOGGER.resumedAndDispatched();
@@ -383,6 +383,8 @@ public static void executeRootHandler(final HttpHandler handler, final HttpServe
}
} else if (!resumed) {
exchange.endExchange();
} else {
exchange.runResumeReadWrite();
}
} catch (Throwable t) {
exchange.putAttachment(DefaultResponseListener.EXCEPTION, t);
@@ -1863,6 +1863,17 @@ boolean runResumeReadWrite() {
return ret;
}

boolean isResumed() {
boolean ret = false;
if(anyAreSet(state, FLAG_SHOULD_RESUME_WRITES)) {
ret = true;
}
if(anyAreSet(state, FLAG_SHOULD_RESUME_READS)) {
ret = true;
}
return ret;
}

private static class ExchangeCompleteNextListener implements ExchangeCompletionListener.NextListener {
private final ExchangeCompletionListener[] list;
private final HttpServerExchange exchange;
@@ -0,0 +1,61 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.undertow.servlet.test.streams;

import java.io.IOException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.undertow.testutils.DefaultServer;
import io.undertow.testutils.TestHttpClient;

@RunWith(DefaultServer.class)
public class ServletInputStreamSSLTestCase extends ServletInputStreamTestCase {

@BeforeClass
public static void ssl() throws Exception {
DefaultServer.startSSLServer();
}

@AfterClass
public static void stopssl() throws IOException {
DefaultServer.stopSSLServer();
}


@Override
protected TestHttpClient createClient() {
TestHttpClient client = super.createClient();
client.setSSLContext(DefaultServer.createClientSslContext());
return client;
}


@Test
@Ignore
public void testAsyncServletInputStream3() {

}

@Override
protected String getBaseUrl() {
return DefaultServer.getDefaultServerSSLAddress();
}
}
@@ -158,7 +158,7 @@ private void runTestViaJavaImpl(final String message, String url)
throws IOException {
HttpURLConnection urlcon = null;
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + url;
String uri = getBaseUrl() + "/servletContext/" + url;
urlcon = (HttpURLConnection) new URL(uri).openConnection();
urlcon.setInstanceFollowRedirects(true);
urlcon.setRequestProperty("Connection", "close");
@@ -190,6 +190,10 @@ private void runTestViaJavaImpl(final String message, String url)
}
}

protected String getBaseUrl() {
return DefaultServer.getDefaultServerURL();
}

@Test
public void testAsyncServletInputStream3() {
String message = "to_user_id=7999&msg_body=msg3";
@@ -206,9 +210,9 @@ public void testAsyncServletInputStream3() {


public void runTest(final String message, String url, boolean preamble, boolean offIOThread) throws IOException {
TestHttpClient client = new TestHttpClient();
TestHttpClient client = createClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + url;
String uri = getBaseUrl() + "/servletContext/" + url;
HttpPost post = new HttpPost(uri);
if (preamble && !message.isEmpty()) {
post.addHeader("preamble", Integer.toString(message.length() / 2));
@@ -227,4 +231,8 @@ public void runTest(final String message, String url, boolean preamble, boolean
}
}

protected TestHttpClient createClient() {
return new TestHttpClient();
}

}
@@ -0,0 +1,52 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.undertow.servlet.test.streams;

import java.io.IOException;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import io.undertow.testutils.DefaultServer;
import io.undertow.testutils.TestHttpClient;

@RunWith(DefaultServer.class)
public class ServletOutputStreamSSLTestCase extends ServletOutputStreamTestCase {

@BeforeClass
public static void ssl() throws Exception {
DefaultServer.startSSLServer();
}

@AfterClass
public static void stopssl() throws IOException {
DefaultServer.stopSSLServer();
}


@Override
protected TestHttpClient createClient() {
TestHttpClient client = super.createClient();
client.setSSLContext(DefaultServer.createClientSslContext());
return client;
}

@Override
protected String getBaseUrl() {
return DefaultServer.getDefaultServerSSLAddress();
}
}
@@ -76,9 +76,9 @@ public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servl

@Test
public void testFlushAndCloseWithContentLength() throws Exception {
TestHttpClient client = new TestHttpClient();
TestHttpClient client = createClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + CONTENT_LENGTH_SERVLET;
String uri = getBaseUrl() + "/servletContext/" + CONTENT_LENGTH_SERVLET;

HttpGet get = new HttpGet(uri);
HttpResponse result = client.execute(get);
@@ -96,13 +96,16 @@ public void testFlushAndCloseWithContentLength() throws Exception {
}
}

protected TestHttpClient createClient() {
return new TestHttpClient();
}


@Test
public void testResetBuffer() throws Exception {
TestHttpClient client = new TestHttpClient();
TestHttpClient client = createClient();
try {
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + RESET;
String uri = getBaseUrl() + "/servletContext/" + RESET;

HttpGet get = new HttpGet(uri);
HttpResponse result = client.execute(get);
@@ -226,10 +229,10 @@ public void testAsyncServletOutputStreamWithPreable() {
}

public void runTest(final String message, String url, final boolean flush, final boolean close, int reps, boolean initialFlush, boolean writePreable, boolean offIoThread) throws IOException {
TestHttpClient client = new TestHttpClient();
TestHttpClient client = createClient();
try {
ServletOutputStreamTestCase.message = message;
String uri = DefaultServer.getDefaultServerURL() + "/servletContext/" + url + "?reps=" + reps + "&";
String uri = getBaseUrl() + "/servletContext/" + url + "?reps=" + reps + "&";
if (flush) {
uri = uri + "flush=true&";
}
@@ -266,4 +269,8 @@ public void runTest(final String message, String url, final boolean flush, final
}
}

protected String getBaseUrl() {
return DefaultServer.getDefaultServerURL();
}

}

0 comments on commit 4d808be

Please sign in to comment.
You can’t perform that action at this time.