Remove ReactiveResult.java
This commit is contained in:
@@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 the original author or authors.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package we.util;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hongqiaowei
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ReactiveResult<D> extends Result<D> {
|
|
||||||
|
|
||||||
public Map<Object, Object> context;
|
|
||||||
|
|
||||||
public ReactiveResult() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReactiveResult(int code, String msg, D data, Throwable t, Map<Object, Object> context) {
|
|
||||||
super(code, msg, data, t);
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> succ() {
|
|
||||||
return new ReactiveResult<D>(SUCC, null, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> succ(D data) {
|
|
||||||
ReactiveResult<D> r = succ();
|
|
||||||
r.data = data;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> fail() {
|
|
||||||
return new ReactiveResult<D>(FAIL, null, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> fail(String msg) {
|
|
||||||
ReactiveResult<D> r = fail();
|
|
||||||
r.msg = msg;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> fail(Throwable t) {
|
|
||||||
ReactiveResult<D> r = fail();
|
|
||||||
r.t = t;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> with(int code) {
|
|
||||||
return new ReactiveResult<D>(code, null, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> with(int code, String msg) {
|
|
||||||
ReactiveResult<D> r = with(code);
|
|
||||||
r.msg = msg;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> with(int code, D data) {
|
|
||||||
ReactiveResult<D> r = with(code);
|
|
||||||
r.data = data;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <D> ReactiveResult<D> with(int code, Throwable t) {
|
|
||||||
ReactiveResult<D> r = with(code);
|
|
||||||
r.t = t;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void toStringBuilder(StringBuilder b) {
|
|
||||||
super.toStringBuilder(b);
|
|
||||||
if (context != null) {
|
|
||||||
b.append(',').append("ctx=").append(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
package we.util;
|
package we.util;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongqiaowei
|
* @author hongqiaowei
|
||||||
@@ -28,26 +29,29 @@ public class Result<D> {
|
|||||||
public static final int SUCC = 1;
|
public static final int SUCC = 1;
|
||||||
public static final int FAIL = 0;
|
public static final int FAIL = 0;
|
||||||
|
|
||||||
public int code = -1;
|
public int code = -1;
|
||||||
|
|
||||||
public String msg;
|
public String msg;
|
||||||
|
|
||||||
public D data;
|
public D data;
|
||||||
|
|
||||||
public Throwable t;
|
public Throwable t;
|
||||||
|
|
||||||
|
public Map<Object, Object> context = Collections.emptyMap();
|
||||||
|
|
||||||
public Result() {
|
public Result() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result(int code, String msg, D data, Throwable t) {
|
public Result(int code, String msg, D data, Throwable t, Map<Object, Object> context) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.t = t;
|
this.t = t;
|
||||||
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D> Result<D> succ() {
|
public static <D> Result<D> succ() {
|
||||||
return new Result<D>(SUCC, null, null, null);
|
return new Result<D>(SUCC, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D> Result<D> succ(D data) {
|
public static <D> Result<D> succ(D data) {
|
||||||
@@ -56,8 +60,14 @@ public class Result<D> {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <D> Result<D> succ(D data, Map<Object, Object> context) {
|
||||||
|
Result<D> r = succ(data);
|
||||||
|
r.context = context;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static <D> Result<D> fail() {
|
public static <D> Result<D> fail() {
|
||||||
return new Result<D>(FAIL, null, null, null);
|
return new Result<D>(FAIL, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D> Result<D> fail(String msg) {
|
public static <D> Result<D> fail(String msg) {
|
||||||
@@ -66,14 +76,32 @@ public class Result<D> {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <D> Result<D> fail(String msg, Map<Object, Object> context) {
|
||||||
|
Result<D> r = fail(msg);
|
||||||
|
r.context = context;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static <D> Result<D> fail(Throwable t) {
|
public static <D> Result<D> fail(Throwable t) {
|
||||||
Result<D> r = fail();
|
Result<D> r = fail();
|
||||||
r.t = t;
|
r.t = t;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <D> Result<D> fail(Throwable t, Map<Object, Object> context) {
|
||||||
|
Result<D> r = fail(t);
|
||||||
|
r.context = context;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static <D> Result<D> with(int code) {
|
public static <D> Result<D> with(int code) {
|
||||||
return new Result<D>(code, null, null, null);
|
return new Result<D>(code, null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <D> Result<D> with(int code, Map<Object, Object> context) {
|
||||||
|
Result<D> r = with(code);
|
||||||
|
r.context = context;
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D> Result<D> with(int code, String msg) {
|
public static <D> Result<D> with(int code, String msg) {
|
||||||
@@ -82,35 +110,38 @@ public class Result<D> {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <D> Result<D> with(int code, String msg, Map<Object, Object> context) {
|
||||||
|
Result<D> r = with(code, msg);
|
||||||
|
r.context = context;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static <D> Result<D> with(int code, Throwable t) {
|
public static <D> Result<D> with(int code, Throwable t) {
|
||||||
Result<D> r = with(code);
|
Result<D> r = with(code);
|
||||||
r.t = t;
|
r.t = t;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <D> Result<D> with(int code, Throwable t, Map<Object, Object> context) {
|
||||||
|
Result<D> r = with(code, t);
|
||||||
|
r.context = context;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public static <D> Result<D> with(int code, D data) {
|
public static <D> Result<D> with(int code, D data) {
|
||||||
Result<D> r = with(code);
|
Result<D> r = with(code);
|
||||||
r.data = data;
|
r.data = data;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static <D> Result<D> with(int code, D data, Map<Object, Object> context) {
|
||||||
public String toString() {
|
Result<D> r = with(code, data);
|
||||||
StringBuilder b = new StringBuilder();
|
r.context = context;
|
||||||
toStringBuilder(b);
|
return r;
|
||||||
return b.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toStringBuilder(StringBuilder b) {
|
@Override
|
||||||
b.append("code=").append(code);
|
public String toString() {
|
||||||
if (StringUtils.isNotBlank(msg)) {
|
return JacksonUtils.writeValueAsString(this);
|
||||||
b.append(',').append("msg=") .append(msg);
|
|
||||||
}
|
|
||||||
if (data != null) {
|
|
||||||
b.append(',').append("data=").append(data);
|
|
||||||
}
|
|
||||||
if (t != null) {
|
|
||||||
b.append(',').append("err=") .append(t.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import we.config.AggregateRedisConfig;
|
|||||||
import we.config.SystemConfig;
|
import we.config.SystemConfig;
|
||||||
import we.plugin.auth.ApiConfig;
|
import we.plugin.auth.ApiConfig;
|
||||||
import we.util.JacksonUtils;
|
import we.util.JacksonUtils;
|
||||||
import we.util.ReactiveResult;
|
|
||||||
import we.util.Result;
|
import we.util.Result;
|
||||||
import we.util.UrlTransformUtils;
|
import we.util.UrlTransformUtils;
|
||||||
|
|
||||||
@@ -115,7 +114,7 @@ public class ApiPairingDocSetService {
|
|||||||
rt.listenToChannel(channel)
|
rt.listenToChannel(channel)
|
||||||
.doOnError(
|
.doOnError(
|
||||||
t -> {
|
t -> {
|
||||||
result.code = ReactiveResult.FAIL;
|
result.code = Result.FAIL;
|
||||||
result.msg = "lsn error, channel: " + channel;
|
result.msg = "lsn error, channel: " + channel;
|
||||||
result.t = t;
|
result.t = t;
|
||||||
log.error("lsn channel {} error", channel, t);
|
log.error("lsn channel {} error", channel, t);
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import reactor.core.publisher.Mono;
|
|||||||
import we.config.AggregateRedisConfig;
|
import we.config.AggregateRedisConfig;
|
||||||
import we.config.SystemConfig;
|
import we.config.SystemConfig;
|
||||||
import we.util.JacksonUtils;
|
import we.util.JacksonUtils;
|
||||||
import we.util.ReactiveResult;
|
|
||||||
import we.util.Result;
|
import we.util.Result;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
@@ -111,7 +110,7 @@ public class ApiPairingInfoService {
|
|||||||
rt.listenToChannel(channel)
|
rt.listenToChannel(channel)
|
||||||
.doOnError(
|
.doOnError(
|
||||||
t -> {
|
t -> {
|
||||||
result.code = ReactiveResult.FAIL;
|
result.code = Result.FAIL;
|
||||||
result.msg = "lsn error, channel: " + channel;
|
result.msg = "lsn error, channel: " + channel;
|
||||||
result.t = t;
|
result.t = t;
|
||||||
log.error("lsn channel {} error", channel, t);
|
log.error("lsn channel {} error", channel, t);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import we.proxy.CallbackReplayReq;
|
|||||||
import we.proxy.CallbackService;
|
import we.proxy.CallbackService;
|
||||||
import we.util.Consts;
|
import we.util.Consts;
|
||||||
import we.util.JacksonUtils;
|
import we.util.JacksonUtils;
|
||||||
import we.util.ReactiveResult;
|
import we.util.Result;
|
||||||
import we.util.ThreadContext;
|
import we.util.ThreadContext;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -61,7 +61,7 @@ public class CallbackController {
|
|||||||
callbackService.replay(req)
|
callbackService.replay(req)
|
||||||
.onErrorResume(
|
.onErrorResume(
|
||||||
t -> {
|
t -> {
|
||||||
return Mono.just(ReactiveResult.fail(t));
|
return Mono.just(Result.fail(t));
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.map(
|
.map(
|
||||||
@@ -69,13 +69,12 @@ public class CallbackController {
|
|||||||
StringBuilder b = ThreadContext.getStringBuilder();
|
StringBuilder b = ThreadContext.getStringBuilder();
|
||||||
b.append(req.id).append(' ').append(req.service).append(' ').append(req.path).append(' ');
|
b.append(req.id).append(' ').append(req.service).append(' ').append(req.path).append(' ');
|
||||||
ServerHttpResponse resp = exchange.getResponse();
|
ServerHttpResponse resp = exchange.getResponse();
|
||||||
if (r.code == ReactiveResult.SUCC) {
|
if (r.code == Result.SUCC) {
|
||||||
log.info(b.append("replay success").toString(), LogService.BIZ_ID, req.id);
|
log.info(b.append("replay success").toString(), LogService.BIZ_ID, req.id);
|
||||||
resp.setStatusCode(HttpStatus.OK);
|
resp.setStatusCode(HttpStatus.OK);
|
||||||
return Consts.S.EMPTY;
|
return Consts.S.EMPTY;
|
||||||
} else {
|
} else {
|
||||||
b.append("replay error:\n");
|
b.append("replay error:\n").append(r);
|
||||||
r.toStringBuilder(b);
|
|
||||||
log.error(b.toString(), LogService.BIZ_ID, req.id);
|
log.error(b.toString(), LogService.BIZ_ID, req.id);
|
||||||
resp.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
|
resp.setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
if (r.msg != null) {
|
if (r.msg != null) {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import reactor.core.publisher.Mono;
|
|||||||
import we.config.AggregateRedisConfig;
|
import we.config.AggregateRedisConfig;
|
||||||
import we.fizz.input.PathMapping;
|
import we.fizz.input.PathMapping;
|
||||||
import we.util.JacksonUtils;
|
import we.util.JacksonUtils;
|
||||||
import we.util.ReactiveResult;
|
|
||||||
import we.util.Result;
|
import we.util.Result;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
@@ -119,7 +118,7 @@ public class GlobalResourceService {
|
|||||||
rt.listenToChannel(channel)
|
rt.listenToChannel(channel)
|
||||||
.doOnError(
|
.doOnError(
|
||||||
t -> {
|
t -> {
|
||||||
result.code = ReactiveResult.FAIL;
|
result.code = Result.FAIL;
|
||||||
result.msg = "lsn error, channel: " + channel;
|
result.msg = "lsn error, channel: " + channel;
|
||||||
result.t = t;
|
result.t = t;
|
||||||
log.error("lsn channel {} error", channel, t);
|
log.error("lsn channel {} error", channel, t);
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ public class ApiConfigService implements ApplicationListener<ContextRefreshedEve
|
|||||||
rt.listenToChannel(channel)
|
rt.listenToChannel(channel)
|
||||||
.doOnError(
|
.doOnError(
|
||||||
t -> {
|
t -> {
|
||||||
result.code = ReactiveResult.FAIL;
|
result.code = Result.FAIL;
|
||||||
result.msg = "lsn error, channel: " + channel;
|
result.msg = "lsn error, channel: " + channel;
|
||||||
result.t = t;
|
result.t = t;
|
||||||
log.error("lsn channel {} error", channel, t);
|
log.error("lsn channel {} error", channel, t);
|
||||||
|
|||||||
@@ -204,14 +204,14 @@ public class CallbackService {
|
|||||||
.doOnError(throwable -> clean(remoteResp)).doOnCancel(() -> clean(remoteResp));
|
.doOnError(throwable -> clean(remoteResp)).doOnCancel(() -> clean(remoteResp));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<ReactiveResult> replay(CallbackReplayReq req) {
|
public Mono<Result> replay(CallbackReplayReq req) {
|
||||||
|
|
||||||
HashSet<String> gatewayGroups = new HashSet<>();
|
HashSet<String> gatewayGroups = new HashSet<>();
|
||||||
gatewayGroups.add(req.gatewayGroup);
|
gatewayGroups.add(req.gatewayGroup);
|
||||||
Result<ApiConfig> result = apiConfigService.get(gatewayGroups, req.app, req.service, req.method, req.path);
|
Result<ApiConfig> result = apiConfigService.get(gatewayGroups, req.app, req.service, req.method, req.path);
|
||||||
ApiConfig ac = result.data;
|
ApiConfig ac = result.data;
|
||||||
if (ac == null) {
|
if (ac == null) {
|
||||||
return Mono.just(ReactiveResult.fail("no api config for " + req.path));
|
return Mono.just(Result.fail("no api config for " + req.path));
|
||||||
}
|
}
|
||||||
CallbackConfig cc = ac.callbackConfig;
|
CallbackConfig cc = ac.callbackConfig;
|
||||||
|
|
||||||
@@ -259,21 +259,21 @@ public class CallbackService {
|
|||||||
.collectList()
|
.collectList()
|
||||||
.map(
|
.map(
|
||||||
sendResults -> {
|
sendResults -> {
|
||||||
int c = ReactiveResult.SUCC;
|
int c = Result.SUCC;
|
||||||
Throwable t = null;
|
Throwable t = null;
|
||||||
for (int i = 0; i < sendResults.size(); i++) {
|
for (int i = 0; i < sendResults.size(); i++) {
|
||||||
Object r = sendResults.get(i);
|
Object r = sendResults.get(i);
|
||||||
if (r instanceof FizzFailClientResponse) {
|
if (r instanceof FizzFailClientResponse) {
|
||||||
c = ReactiveResult.FAIL;
|
c = Result.FAIL;
|
||||||
t = ((FizzFailClientResponse) r).throwable;
|
t = ((FizzFailClientResponse) r).throwable;
|
||||||
} else if (r instanceof FailAggregateResult) {
|
} else if (r instanceof FailAggregateResult) {
|
||||||
c = ReactiveResult.FAIL;
|
c = Result.FAIL;
|
||||||
t = ((FailAggregateResult) r).throwable;
|
t = ((FailAggregateResult) r).throwable;
|
||||||
} else if (r instanceof ClientResponse) {
|
} else if (r instanceof ClientResponse) {
|
||||||
clean((ClientResponse) r);
|
clean((ClientResponse) r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ReactiveResult.with(c, t);
|
return Result.with(c, t);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
|
|||||||
Reference in New Issue
Block a user