Search in sources :

Example 1 with AsyncOutputWriter

use of org.jboss.resteasy.spi.AsyncOutputWriter in project resteasy by resteasy.

the class Jackson2JsonpInterceptor method asyncAroundWriteTo.

@Override
public CompletionStage<Void> asyncAroundWriteTo(AsyncWriterInterceptorContext context) {
    LogMessages.LOGGER.debugf("Interceptor : %s,  Method : aroundWriteTo", getClass().getName());
    String function = uri.getQueryParameters().getFirst(callbackQueryParameter);
    if (enabled && function != null && !function.trim().isEmpty() && !jsonpCompatibleMediaTypes.getPossible(context.getMediaType()).isEmpty()) {
        AsyncOutputWriter writer = new AsyncOutputWriter(context.getAsyncOutputStream());
        CompletionStage<Void> ret = CompletableFuture.completedFuture(null);
        if (wrapInTryCatch) {
            ret = ret.thenCompose(v -> writer.asyncWrite("try{"));
        }
        ret = ret.thenCompose(v -> writer.asyncWrite(function + "(")).thenCompose(v -> writer.asyncFlush()).thenCompose(v -> context.asyncProceed()).thenCompose(v -> writer.asyncFlush()).thenCompose(v -> writer.asyncWrite(")"));
        if (wrapInTryCatch) {
            ret = ret.thenCompose(v -> writer.asyncWrite("}catch(e){}"));
        }
        return ret.thenCompose(v -> writer.asyncFlush());
    } else {
        return context.asyncProceed();
    }
}
Also used : Context(jakarta.ws.rs.core.Context) CompletableFuture(java.util.concurrent.CompletableFuture) WebApplicationException(jakarta.ws.rs.WebApplicationException) ResteasyConfiguration(org.jboss.resteasy.spi.ResteasyConfiguration) BufferedOutputStream(java.io.BufferedOutputStream) ResteasyContext(org.jboss.resteasy.core.ResteasyContext) LogMessages(org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages) CommitHeaderOutputStream(org.jboss.resteasy.util.CommitHeaderOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) OutputStream(java.io.OutputStream) WriterInterceptorContext(jakarta.ws.rs.ext.WriterInterceptorContext) AsyncOutputWriter(org.jboss.resteasy.spi.AsyncOutputWriter) RuntimeType(jakarta.ws.rs.RuntimeType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) UriInfo(jakarta.ws.rs.core.UriInfo) Provider(jakarta.ws.rs.ext.Provider) MediaTypeMap(org.jboss.resteasy.core.MediaTypeMap) CompletionStage(java.util.concurrent.CompletionStage) MediaType(jakarta.ws.rs.core.MediaType) ContextResolver(jakarta.ws.rs.ext.ContextResolver) ConstrainedTo(jakarta.ws.rs.ConstrainedTo) Providers(jakarta.ws.rs.ext.Providers) AsyncWriterInterceptor(org.jboss.resteasy.spi.AsyncWriterInterceptor) AsyncWriterInterceptorContext(org.jboss.resteasy.spi.AsyncWriterInterceptorContext) AsyncOutputWriter(org.jboss.resteasy.spi.AsyncOutputWriter)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ConstrainedTo (jakarta.ws.rs.ConstrainedTo)1 RuntimeType (jakarta.ws.rs.RuntimeType)1 WebApplicationException (jakarta.ws.rs.WebApplicationException)1 Context (jakarta.ws.rs.core.Context)1 MediaType (jakarta.ws.rs.core.MediaType)1 UriInfo (jakarta.ws.rs.core.UriInfo)1 ContextResolver (jakarta.ws.rs.ext.ContextResolver)1 Provider (jakarta.ws.rs.ext.Provider)1 Providers (jakarta.ws.rs.ext.Providers)1 WriterInterceptorContext (jakarta.ws.rs.ext.WriterInterceptorContext)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 MediaTypeMap (org.jboss.resteasy.core.MediaTypeMap)1 ResteasyContext (org.jboss.resteasy.core.ResteasyContext)1 LogMessages (org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages)1