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();
}
}
Aggregations