use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class CryptorRequestPluginTest method encryptTest.
@Test
public void encryptTest() {
this.ruleData.setHandle("{\"strategyName\":\"rsa\"," + "\"fieldNames\":\"inputToken\"," + "\"decryptKey\":\"MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAtrfolGUtLhZVSpd5L/oAXbGW9Rn54mD96Ny" + "uWsxp/KCscDoeFScN7uSc3LwKk14wrC4X0+fSDxm0kMPTvgNBywIDAQABAkBFPvt4ycNOlQ4r364A3akn2PbR2s9V2NZBW" + "ukE5jVAlOvgCn6L/+tsVDSQgeVtOPd6rwM2a24iASDsNEbnVrwBAiEA34DwAmsa1phE5aGKM1bPHJiGgM8yolIYDWBaBCu" + "PTgECIQDRSOWA8rLJWP+Vijm/QB8C41Gw1V7WXC2Kuj07Jv5nywIgTDKCIODw8m5RNtRe8GfNDlu1p158TbidOJo7tiY/og" + "ECIQCaj0tvP83qBWA8AClFpQVCDL936RxxEwJPQduWo+WeoQIhAN7HKEW0E97il2RvCsgeArdt83WjZh7OhMhW6MLPrMjs\"," + "\"encryptKey\":\"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALa36JRlLS4WVUqXeS/6AF2xlvUZ+eJg/ejcrlrMafygrHA6Hh" + "UnDe7knNy8CpNeMKwuF9Pn0g8ZtJDD074DQcsCAwEAAQ\\u003d\\u003d\"," + "\"way\":\"encrypt\"" + "}\n");
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.POST, "/test").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).body("{\"inputToken\": " + "\"shenyu\"" + "}"));
SelectorData selectorData = mock(SelectorData.class);
when(this.chain.execute(any())).thenReturn(Mono.empty());
cryptorRequestPluginDataHandler.handlerRule(ruleData);
StepVerifier.create(cryptorRequestPlugin.doExecute(this.exchange, this.chain, selectorData, this.ruleData)).expectSubscription().verifyComplete();
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class CryptorRequestPluginTest method multiJsonDecryptTest.
@Test
public void multiJsonDecryptTest() {
this.ruleData.setHandle("{\"strategyName\":\"rsa\"," + "\"fieldNames\":\"inputToken.test\"," + "\"decryptKey\":\"MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAtrfolGUtLhZVSpd5L/oAXbGW9Rn54mD96Ny" + "uWsxp/KCscDoeFScN7uSc3LwKk14wrC4X0+fSDxm0kMPTvgNBywIDAQABAkBFPvt4ycNOlQ4r364A3akn2PbR2s9V2NZBW" + "ukE5jVAlOvgCn6L/+tsVDSQgeVtOPd6rwM2a24iASDsNEbnVrwBAiEA34DwAmsa1phE5aGKM1bPHJiGgM8yolIYDWBaBCu" + "PTgECIQDRSOWA8rLJWP+Vijm/QB8C41Gw1V7WXC2Kuj07Jv5nywIgTDKCIODw8m5RNtRe8GfNDlu1p158TbidOJo7tiY/og" + "ECIQCaj0tvP83qBWA8AClFpQVCDL936RxxEwJPQduWo+WeoQIhAN7HKEW0E97il2RvCsgeArdt83WjZh7OhMhW6MLPrMjs\"," + "\"encryptKey\":\"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALa36JRlLS4WVUqXeS/6AF2xlvUZ+eJg/ejcrlrMafygrHA6Hh" + "UnDe7knNy8CpNeMKwuF9Pn0g8ZtJDD074DQcsCAwEAAQ\\u003d\\u003d\"," + "\"way\":\"decrypt\"" + "}\n");
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.POST, "/test").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).body("{\"inputToken\": " + "{\"test\":\"kYPZgOAR2pEipskl5WURW/r3CMxNQJwbs4jbTAOfZNV39L4WkaTOqAeolV+rlKCKiXKvhfHWaxQOTMm9hQBxLA==\"}" + "}"));
SelectorData selectorData = mock(SelectorData.class);
when(this.chain.execute(any())).thenReturn(Mono.empty());
cryptorRequestPluginDataHandler.handlerRule(ruleData);
StepVerifier.create(cryptorRequestPlugin.doExecute(this.exchange, this.chain, selectorData, this.ruleData)).expectSubscription().verifyComplete();
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class CryptorRequestPluginTest method multiJsonEncryptTest.
@Test
public void multiJsonEncryptTest() {
this.ruleData.setHandle("{\"strategyName\":\"rsa\"," + "\"fieldNames\":\"inputToken.test\"," + "\"decryptKey\":\"MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAtrfolGUtLhZVSpd5L/oAXbGW9Rn54mD96Ny" + "uWsxp/KCscDoeFScN7uSc3LwKk14wrC4X0+fSDxm0kMPTvgNBywIDAQABAkBFPvt4ycNOlQ4r364A3akn2PbR2s9V2NZBW" + "ukE5jVAlOvgCn6L/+tsVDSQgeVtOPd6rwM2a24iASDsNEbnVrwBAiEA34DwAmsa1phE5aGKM1bPHJiGgM8yolIYDWBaBCu" + "PTgECIQDRSOWA8rLJWP+Vijm/QB8C41Gw1V7WXC2Kuj07Jv5nywIgTDKCIODw8m5RNtRe8GfNDlu1p158TbidOJo7tiY/og" + "ECIQCaj0tvP83qBWA8AClFpQVCDL936RxxEwJPQduWo+WeoQIhAN7HKEW0E97il2RvCsgeArdt83WjZh7OhMhW6MLPrMjs\"," + "\"encryptKey\":\"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALa36JRlLS4WVUqXeS/6AF2xlvUZ+eJg/ejcrlrMafygrHA6Hh" + "UnDe7knNy8CpNeMKwuF9Pn0g8ZtJDD074DQcsCAwEAAQ\\u003d\\u003d\"," + "\"way\":\"encrypt\"" + "}\n");
this.exchange = MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.POST, "/test").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).body("{\"inputToken\": " + "{\"test\":\"shenyu\"}" + "}"));
SelectorData selectorData = mock(SelectorData.class);
when(this.chain.execute(any())).thenReturn(Mono.empty());
cryptorRequestPluginDataHandler.handlerRule(ruleData);
StepVerifier.create(cryptorRequestPlugin.doExecute(this.exchange, this.chain, selectorData, this.ruleData)).expectSubscription().verifyComplete();
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class AlibabaDubboPlugin method doDubboInvoker.
/**
* do dubbo invoker.
*
* @param exchange exchange the current server exchange {@linkplain ServerWebExchange}
* @param chain chain the current chain {@linkplain ServerWebExchange}
* @param selector selector {@linkplain SelectorData}
* @param rule rule {@linkplain RuleData}
* @param metaData the medata
* @param param the param
* @return {@code Mono<Void>} to indicate when request handling is complete
*/
@Override
protected Mono<Void> doDubboInvoker(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule, final MetaData metaData, final String param) {
RpcContext.getContext().setAttachment(Constants.DUBBO_SELECTOR_ID, selector.getId());
RpcContext.getContext().setAttachment(Constants.DUBBO_RULE_ID, rule.getId());
RpcContext.getContext().setAttachment(Constants.DUBBO_REMOTE_ADDRESS, Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress());
return Mono.create(monoSink -> {
ResponseFuture future = alibabaDubboProxyService.genericInvoker(param, metaData);
future.setCallback(new ResponseCallback() {
@Override
public void done(final Object resultObj) {
assert resultObj instanceof Result;
Result result = (Result) resultObj;
if (result.hasException()) {
this.caught(result.getException());
return;
}
monoSink.success(result.getValue());
}
@Override
public void caught(final Throwable ex) {
LOG.error("dubbo failed using async genericInvoker() metaData={} param={}", metaData, param, ex);
monoSink.error(ex);
}
});
}).flatMap(response -> {
exchange.getAttributes().put(Constants.RPC_RESULT, Objects.nonNull(response) ? response : Constants.DUBBO_RPC_RESULT_EMPTY);
exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName());
return chain.execute(exchange);
});
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class AlibabaDubboPluginTest method testAlibabaDubboPlugin.
@Test
public void testAlibabaDubboPlugin() {
final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("localhost").remoteAddress(new InetSocketAddress("127.0.0.1", 20880)).build());
ShenyuContext context = mock(ShenyuContext.class);
when(context.getRpcType()).thenReturn(RpcTypeEnum.DUBBO.getName());
exchange.getAttributes().put(Constants.CONTEXT, context);
exchange.getAttributes().put(Constants.META_DATA, metaData);
ShenyuPluginChain chain = mock(ShenyuPluginChain.class);
when(chain.execute(exchange)).thenReturn(Mono.empty());
RuleData data = mock(RuleData.class);
SelectorData selectorData = mock(SelectorData.class);
Mono<Void> voidMono = alibabaDubboPluginUnderTest.doExecute(exchange, chain, selectorData, data);
StepVerifier.create(voidMono).expectSubscription().verifyComplete();
}
Aggregations