public static AsyncResponseConsumer makeAsyncResponseConsumer(ResourceMethodInvoker method, AsyncStreamProvider<?> asyncStreamProvider) { if(method.isSse()) { return new AsyncGeneralStreamingSseResponseConsumer(method, asyncStreamProvider); } Stream stream = method.getMethod().getAnnotation(Stream.class); if (stream != null) { if (Stream.MODE.RAW.equals(stream.value())) { return new AsyncRawStreamingResponseConsumer(method, asyncStreamProvider); } else { return new AsyncGeneralStreamingSseResponseConsumer(method, asyncStreamProvider); } } return new AsyncStreamCollectorResponseConsumer(method, asyncStreamProvider); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { Method method = ((PostMatchContainerRequestContext) requestContext).getResourceMethod().getMethod(); Stream stream = method.getAnnotation(Stream.class); Stream.MODE mode = stream != null ? stream.value() : null; Class<?> clazz = method.getReturnType(); if ((mode == Stream.MODE.GENERAL && ResteasyProviderFactory.getInstance().getAsyncStreamProvider(clazz) != null) || requestContext instanceof PostMatchContainerRequestContext && ((PostMatchContainerRequestContext) requestContext).getResourceMethod().isSse()) { SseEventOutputImpl sink = new SseEventOutputImpl(new SseEventProvider()); ResteasyContext.getContextDataMap().put(SseEventSink.class, sink); ResteasyContext.getContextData(PostResourceMethodInvokers.class).addInvokers(new PostResourceMethodInvoker() { @Override public void invoke() { sink.flushResponseToClient(); } }); } }
public static AsyncResponseConsumer makeAsyncResponseConsumer(ResourceMethodInvoker method, AsyncStreamProvider<?> asyncStreamProvider) { if(method.isSse()) { return new AsyncStreamSseResponseConsumer(method, asyncStreamProvider); } for (Annotation annotation : method.getMethodAnnotations()) { if(annotation.annotationType() == Stream.class) { return new AsyncStreamingResponseConsumer(method, asyncStreamProvider); } } return new AsyncStreamCollectorResponseConsumer(method, asyncStreamProvider); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { if (requestContext instanceof PostMatchContainerRequestContext && ((PostMatchContainerRequestContext) requestContext).getResourceMethod().isSse()) { SseEventOutputImpl sink = new SseEventOutputImpl(new SseEventProvider()); ResteasyProviderFactory.getContextDataMap().put(SseEventSink.class, sink); ResteasyProviderFactory.getContextData(PostResourceMethodInvokers.class).addInvokers(new PostResourceMethodInvoker() { @Override public void invoke() { sink.flushResponseToClient(); } }); } }
public static AsyncResponseConsumer makeAsyncResponseConsumer(ResourceMethodInvoker method, AsyncStreamProvider<?> asyncStreamProvider) { if(method.isSse()) { return new AsyncGeneralStreamingSseResponseConsumer(method, asyncStreamProvider); } Stream stream = method.getMethod().getAnnotation(Stream.class); if (stream != null) { if (Stream.MODE.RAW.equals(stream.value())) { return new AsyncRawStreamingResponseConsumer(method, asyncStreamProvider); } else { return new AsyncGeneralStreamingSseResponseConsumer(method, asyncStreamProvider); } } return new AsyncStreamCollectorResponseConsumer(method, asyncStreamProvider); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { Method method = ((PostMatchContainerRequestContext) requestContext).getResourceMethod().getMethod(); Stream stream = method.getAnnotation(Stream.class); Stream.MODE mode = stream != null ? stream.value() : null; Class<?> clazz = method.getReturnType(); if ((mode == Stream.MODE.GENERAL && ResteasyProviderFactory.getInstance().getAsyncStreamProvider(clazz) != null) || requestContext instanceof PostMatchContainerRequestContext && ((PostMatchContainerRequestContext) requestContext).getResourceMethod().isSse()) { SseEventOutputImpl sink = new SseEventOutputImpl(new SseEventProvider()); ResteasyContext.getContextDataMap().put(SseEventSink.class, sink); ResteasyContext.getContextData(PostResourceMethodInvokers.class).addInvokers(new PostResourceMethodInvoker() { @Override public void invoke() { sink.flushResponseToClient(); } }); } }