-
Notifications
You must be signed in to change notification settings - Fork 1k
[UNDERTOW-1870] Backport of RFE with property instead of API change #1731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
baranowb
wants to merge
1
commit into
undertow-io:2.3.x
Choose a base branch
from
baranowb:UNDERTOW-1870_2.3.x
base: 2.3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...java/io/undertow/servlet/test/listener/request/async/onTimeout/property/AsyncServlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2025 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.listener.request.async.onTimeout.property; | ||
|
||
import java.io.IOException; | ||
|
||
import io.undertow.servlet.spec.AsyncContextImpl; | ||
import jakarta.servlet.AsyncContext; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* @author baranowb | ||
*/ | ||
public class AsyncServlet extends HttpServlet { | ||
|
||
public static final String TEST_TIMEOUT="timeout"; | ||
public static final String TIMEOUT_START_TSTAMP = "tstamp"; | ||
@Override | ||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { | ||
long timeout = Long.parseLong((String)req.getParameter(TEST_TIMEOUT)); | ||
System.setProperty(AsyncContextImpl.ASYNC_CONTEXT_TIMEOUT, timeout+""); | ||
req.setAttribute(TIMEOUT_START_TSTAMP, System.currentTimeMillis()); | ||
AsyncContext ctx = req.startAsync(); | ||
ctx.addListener(new SimpleAsyncListener()); | ||
Thread t = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
Thread.sleep(timeout+3000L); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
System.setProperty(AsyncContextImpl.ASYNC_CONTEXT_TIMEOUT, "30000"); | ||
} | ||
}); | ||
t.start(); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...w/servlet/test/listener/request/async/onTimeout/property/DefaultAsyncTimeoutTestCase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2025 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.listener.request.async.onTimeout.property; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.HttpGet; | ||
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; | ||
import io.undertow.servlet.api.ListenerInfo; | ||
import io.undertow.servlet.api.ServletContainer; | ||
import io.undertow.servlet.api.ServletInfo; | ||
import io.undertow.servlet.test.listener.request.async.onTimeout.SimpleRequestListener; | ||
import io.undertow.servlet.test.util.TestClassIntrospector; | ||
import io.undertow.testutils.DefaultServer; | ||
import io.undertow.testutils.TestHttpClient; | ||
import io.undertow.util.StatusCodes; | ||
import jakarta.servlet.ServletException; | ||
|
||
@RunWith(DefaultServer.class) | ||
public class DefaultAsyncTimeoutTestCase { | ||
@BeforeClass | ||
public static void setup() throws ServletException { | ||
|
||
final PathHandler root = new PathHandler(); | ||
final ServletContainer container = ServletContainer.Factory.newInstance(); | ||
|
||
ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class) | ||
.setAsyncSupported(true) | ||
.addMapping("/async"); | ||
|
||
DeploymentInfo builder = new DeploymentInfo() | ||
.setClassLoader(DefaultAsyncTimeoutTestCase.class.getClassLoader()) | ||
.setContextPath("/servletContext") | ||
.setClassIntrospecter(TestClassIntrospector.INSTANCE) | ||
.setDeploymentName("servletContext.war") | ||
.addServlets(a) | ||
.addListener(new ListenerInfo(SimpleRequestListener.class)); | ||
|
||
DeploymentManager manager = container.addDeployment(builder); | ||
manager.deploy(); | ||
root.addPrefixPath(builder.getContextPath(), manager.start()); | ||
|
||
DefaultServer.setRootHandler(root); | ||
} | ||
|
||
@Test | ||
public void testDefaultTimeout() throws IOException { | ||
TestHttpClient client = new TestHttpClient(); | ||
try { | ||
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/async?"+AsyncServlet.TEST_TIMEOUT+"=30000"); | ||
HttpResponse response = client.execute(get); | ||
Assert.assertEquals(StatusCodes.OK, response.getStatusLine().getStatusCode()); | ||
Assert.assertFalse(SimpleRequestListener.hasNestedInvocationOccured()); | ||
} finally { | ||
client.getConnectionManager().shutdown(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testNewDefaultTimeout() throws IOException { | ||
TestHttpClient client = new TestHttpClient(); | ||
try { | ||
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/async?"+AsyncServlet.TEST_TIMEOUT+"=20000"); | ||
HttpResponse response = client.execute(get); | ||
Assert.assertEquals(StatusCodes.OK, response.getStatusLine().getStatusCode()); | ||
Assert.assertFalse(SimpleRequestListener.hasNestedInvocationOccured()); | ||
} finally { | ||
client.getConnectionManager().shutdown(); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
.../undertow/servlet/test/listener/request/async/onTimeout/property/SimpleAsyncListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2025 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.listener.request.async.onTimeout.property; | ||
|
||
import io.undertow.util.StatusCodes; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.servlet.AsyncEvent; | ||
import jakarta.servlet.AsyncListener; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
public class SimpleAsyncListener implements AsyncListener { | ||
|
||
public static final String HEADER="TIMER_HEADER"; | ||
@Override | ||
public void onComplete(AsyncEvent event) throws IOException { | ||
} | ||
|
||
@Override | ||
public void onTimeout(AsyncEvent event) throws IOException { | ||
HttpServletResponse response = (HttpServletResponse) event.getSuppliedResponse(); | ||
final long startTstamp = (long) event.getSuppliedRequest().getAttribute(AsyncServlet.TIMEOUT_START_TSTAMP); | ||
long timeout = Long.parseLong((String) event.getSuppliedRequest().getParameter(AsyncServlet.TEST_TIMEOUT)); | ||
long elapsed = System.currentTimeMillis() - startTstamp; | ||
response.setHeader(HEADER, (System.currentTimeMillis() - startTstamp) + ""); | ||
if (Math.abs(timeout - elapsed) < 2000) { | ||
response.setStatus(StatusCodes.OK); | ||
} else { | ||
response.setStatus(StatusCodes.CONFLICT); | ||
} | ||
event.getAsyncContext().complete(); | ||
} | ||
|
||
@Override | ||
public void onError(AsyncEvent event) throws IOException { | ||
} | ||
|
||
@Override | ||
public void onStartAsync(AsyncEvent event) throws IOException { | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be prefixed DEFAULT_ ?