Skip to content

Commit

Permalink
Regression test for UNDETOW-1455
Browse files Browse the repository at this point in the history
Asynchronous servlet, onComplete() is not called when error
occurs
  • Loading branch information
Martin Choma authored and stuartwdouglas committed Dec 11, 2018
1 parent cff7c3e commit c3b84a9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
Expand Up @@ -18,6 +18,18 @@

package io.undertow.servlet.test.listener.request.async.onError;

import java.io.IOException;

import javax.servlet.ServletException;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.jboss.logging.Logger;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.undertow.server.handlers.PathHandler;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
Expand All @@ -29,16 +41,6 @@
import io.undertow.testutils.HttpClientUtils;
import io.undertow.testutils.TestHttpClient;
import io.undertow.util.StatusCodes;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.jboss.logging.Logger;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.servlet.ServletException;
import java.io.IOException;

/**
* @author Jozef Hartinger
Expand Down Expand Up @@ -72,12 +74,16 @@ public static void setup() throws ServletException {
.setAsyncSupported(true)
.addMapping("/async3");

ServletInfo a4 = new ServletInfo("asyncServlet4", AsyncServlet4.class)
.setAsyncSupported(true)
.addMapping("/async4");

DeploymentInfo builder = new DeploymentInfo()
.setClassLoader(AsyncListenerOnErrorTest.class.getClassLoader())
.setContextPath("/servletContext")
.setClassIntrospecter(TestClassIntrospector.INSTANCE)
.setDeploymentName("servletContext.war")
.addServlets(f, a1, a2, a3);
.addServlets(f, a1, a2, a3, a4);

builder.setExceptionHandler(LoggingExceptionHandler.builder()
.add(IllegalStateException.class, "io.undertow", Logger.Level.DEBUG)
Expand Down Expand Up @@ -135,4 +141,25 @@ public void testMultiAsyncDispatchError() throws IOException {
client.getConnectionManager().shutdown();
}
}

/**
* Regression test for UNDERTOW-1455
*
* Compared to testAsyncListenerOnErrorInvoked* tests, exception is thrown in
* entering servlet not in asynchronous dispatch part.
*/
@Test
public void testAsyncListenerOnErrorExceptionInFirstServlet() throws IOException {
TestHttpClient client = new TestHttpClient();
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/async4");
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
final String response = HttpClientUtils.readResponse(result);
Assert.assertEquals(SimpleAsyncListener.MESSAGE, response);
Assert.assertArrayEquals(new String[]{"ERROR", "COMPLETE"}, AsyncEventListener.results(2));
} finally {
client.getConnectionManager().shutdown();
}
}
}
@@ -0,0 +1,25 @@
package io.undertow.servlet.test.listener.request.async.onError;

import java.io.IOException;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Exception occurs during its processing. No in delegated dispatch part.
*
*/
public class AsyncServlet4 extends HttpServlet {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
AsyncContext ctx = req.startAsync();
ctx.addListener(new AsyncEventListener());
ctx.addListener(new SimpleAsyncListener(ctx));
throw new NullPointerException();
}

}

0 comments on commit c3b84a9

Please sign in to comment.