This commit is contained in:
@@ -13,6 +13,7 @@ import java.nio.channels.*;
|
|||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
@@ -311,6 +312,62 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
finish(convert.convertTo(context.getBufferSupplier(), ret));
|
finish(convert.convertTo(context.getBufferSupplier(), ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将CompletableFuture的结果对象以JSON格式输出
|
||||||
|
*
|
||||||
|
* @param future 输出对象的句柄
|
||||||
|
*/
|
||||||
|
public void finishJson(final CompletableFuture future) {
|
||||||
|
finishJson(request.getJsonConvert(), future);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将CompletableFuture的结果对象以JSON格式输出
|
||||||
|
*
|
||||||
|
* @param convert 指定的JsonConvert
|
||||||
|
* @param future 输出对象的句柄
|
||||||
|
*/
|
||||||
|
public void finishJson(final JsonConvert convert, final CompletableFuture future) {
|
||||||
|
future.whenCompleteAsync((v, e) -> {
|
||||||
|
if (e != null) {
|
||||||
|
context.getLogger().log(Level.WARNING, "Servlet occur, forece to close channel. request = " + request, e);
|
||||||
|
finish(500, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (v instanceof CharSequence) {
|
||||||
|
finish(v.toString());
|
||||||
|
} else if (v instanceof org.redkale.service.RetResult) {
|
||||||
|
finishJson(convert, (org.redkale.service.RetResult) v);
|
||||||
|
} else {
|
||||||
|
finishJson(convert, v);
|
||||||
|
}
|
||||||
|
}, this.context.getExecutor());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将CompletableFuture的结果对象以JSON格式输出
|
||||||
|
*
|
||||||
|
* @param convert 指定的JsonConvert
|
||||||
|
* @param type 指定的类型
|
||||||
|
* @param future 输出对象的句柄
|
||||||
|
*/
|
||||||
|
public void finishJson(final JsonConvert convert, final Type type, final CompletableFuture future) {
|
||||||
|
future.whenCompleteAsync((v, e) -> {
|
||||||
|
if (e != null) {
|
||||||
|
context.getLogger().log(Level.WARNING, "Servlet occur, forece to close channel. request = " + request, e);
|
||||||
|
finish(500, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (v instanceof CharSequence) {
|
||||||
|
finish(v.toString());
|
||||||
|
} else if (v instanceof org.redkale.service.RetResult) {
|
||||||
|
finishJson(convert, (org.redkale.service.RetResult) v);
|
||||||
|
} else {
|
||||||
|
finishJson(convert, type, v);
|
||||||
|
}
|
||||||
|
}, this.context.getExecutor());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将指定字符串以响应结果输出
|
* 将指定字符串以响应结果输出
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.lang.reflect.*;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
@@ -91,6 +92,15 @@ public interface HttpResponseDesc {
|
|||||||
//将RetResult对象以JSON格式输出
|
//将RetResult对象以JSON格式输出
|
||||||
public void finishJson(final JsonConvert convert, final org.redkale.service.RetResult ret);
|
public void finishJson(final JsonConvert convert, final org.redkale.service.RetResult ret);
|
||||||
|
|
||||||
|
//将CompletableFuture的结果对象以JSON格式输出
|
||||||
|
public void finishJson(final CompletableFuture future);
|
||||||
|
|
||||||
|
//将CompletableFuture的结果对象以JSON格式输出
|
||||||
|
public void finishJson(final JsonConvert convert, final CompletableFuture future);
|
||||||
|
|
||||||
|
//将CompletableFuture的结果对象以JSON格式输出
|
||||||
|
public void finishJson(final JsonConvert convert, final Type type, final CompletableFuture future);
|
||||||
|
|
||||||
//将指定字符串以响应结果输出
|
//将指定字符串以响应结果输出
|
||||||
public void finish(String obj);
|
public void finish(String obj);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user