-
Notifications
You must be signed in to change notification settings - Fork 888
/
AsynchronousResponseInjector.java
executable file
·51 lines (43 loc) · 1.58 KB
/
AsynchronousResponseInjector.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.jboss.resteasy.core;
import org.jboss.resteasy.resteasy_jaxrs.i18n.Messages;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyAsynchronousResponse;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public class AsynchronousResponseInjector implements ValueInjector
{
long timeout = -1;
TimeUnit unit = null;
public AsynchronousResponseInjector()
{
}
@Override
public CompletionStage<Object> inject(boolean unwrapAsync)
{
throw new IllegalStateException(Messages.MESSAGES.cannotInjectAsynchronousResponse());
}
@Override
public CompletionStage<Object> inject(HttpRequest request, HttpResponse response, boolean unwrapAsync)
{
ResteasyAsynchronousResponse asynchronousResponse = null;
if (timeout == -1)
{
asynchronousResponse = request.getAsyncContext().suspend();
}
else
{
asynchronousResponse = request.getAsyncContext().suspend(timeout, unit);
}
ResourceMethodInvoker invoker = (ResourceMethodInvoker)request.getAttribute(ResourceMethodInvoker.class.getName());
invoker.initializeAsync(asynchronousResponse);
return CompletableFuture.completedFuture(asynchronousResponse);
}
}