* For #10734,Implement grpc server interceptor and grpc param extractors * For #10734,add unit test for grpc server interceptor and grpc param extractors * For #10734,alter the test case * For #10734,delete the ConnectionSetupRequestParamExtractor
This commit is contained in:
parent
e7fbbc1301
commit
cae21e2dcd
@ -18,6 +18,7 @@ package com.alibaba.nacos.core.paramcheck;
|
||||
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.spi.NacosServiceLoader;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -60,6 +61,9 @@ public class RpcParamExtractorManager {
|
||||
}
|
||||
|
||||
public AbstractRpcParamExtractor getExtractor(String type) {
|
||||
if (StringUtils.isBlank(type)) {
|
||||
return DEFAULT_EXTRACTOR;
|
||||
}
|
||||
AbstractRpcParamExtractor extractor = extractorMap.get(type);
|
||||
if (extractor == null) {
|
||||
extractor = DEFAULT_EXTRACTOR;
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.remote.request.BatchInstanceRequest;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamInfo;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Param Extractor and check for grpc batch instance request{@link BatchInstanceRequest}.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class BatchInstanceRequestParamExtractor extends AbstractRpcParamExtractor {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addTargetRequest(BatchInstanceRequest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractParamAndCheck(Request request) throws Exception {
|
||||
BatchInstanceRequest req = (BatchInstanceRequest) request;
|
||||
ParamInfo paramInfo = new ParamInfo();
|
||||
paramInfo.setNamespaceId(req.getNamespace());
|
||||
paramInfo.setServiceName(req.getServiceName());
|
||||
paramInfo.setGroup(req.getGroupName());
|
||||
ParamCheckUtils.checkParamInfoFormat(paramInfo);
|
||||
List<Instance> instanceList = req.getInstances();
|
||||
if (instanceList == null) {
|
||||
return;
|
||||
}
|
||||
for (Instance instance : instanceList) {
|
||||
ParamInfo instanceParamInfo = new ParamInfo();
|
||||
instanceParamInfo.setIp(instance.getIp());
|
||||
instanceParamInfo.setPort(String.valueOf(instance.getPort()));
|
||||
instanceParamInfo.setServiceName(instance.getServiceName());
|
||||
instanceParamInfo.setCluster(instance.getClusterName());
|
||||
instanceParamInfo.setMetadata(instance.getMetadata());
|
||||
ParamCheckUtils.checkParamInfoFormat(instanceParamInfo);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamInfo;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Param extractor and checker for grpc config batch listen request{@link ConfigBatchListenRequest}.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class ConfigBatchListenRequestParamExtractor extends AbstractRpcParamExtractor {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addTargetRequest(ConfigBatchListenRequest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractParamAndCheck(Request request) throws Exception {
|
||||
ConfigBatchListenRequest req = (ConfigBatchListenRequest) request;
|
||||
List<ConfigBatchListenRequest.ConfigListenContext> configListenContextList = req.getConfigListenContexts();
|
||||
if (configListenContextList == null) {
|
||||
return;
|
||||
}
|
||||
for (ConfigBatchListenRequest.ConfigListenContext configListenContext : configListenContextList) {
|
||||
ParamInfo configListContextParamInfo = new ParamInfo();
|
||||
configListContextParamInfo.setNamespaceId(configListenContext.getTenant());
|
||||
configListContextParamInfo.setGroup(configListenContext.getGroup());
|
||||
configListContextParamInfo.setDataId(configListenContext.getDataId());
|
||||
ParamCheckUtils.checkParamInfoFormat(configListContextParamInfo);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.remote.request.AbstractConfigRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigPublishRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigQueryRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigRemoveRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.cluster.ConfigChangeClusterSyncRequest;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamInfo;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
|
||||
/**
|
||||
* The type Config request param extractor {@link AbstractConfigRequest}.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class ConfigRequestParamExtractor extends AbstractRpcParamExtractor {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addTargetRequest(ConfigRemoveRequest.class.getSimpleName());
|
||||
addTargetRequest(ConfigQueryRequest.class.getSimpleName());
|
||||
addTargetRequest(ConfigPublishRequest.class.getSimpleName());
|
||||
addTargetRequest(ConfigChangeClusterSyncRequest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractParamAndCheck(Request request) throws Exception {
|
||||
AbstractConfigRequest req = (AbstractConfigRequest) request;
|
||||
ParamInfo paramInfo = new ParamInfo();
|
||||
paramInfo.setDataId(req.getDataId());
|
||||
paramInfo.setGroup(req.getGroup());
|
||||
paramInfo.setNamespaceId(req.getTenant());
|
||||
ParamCheckUtils.checkParamInfoFormat(paramInfo);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.remote.request.InstanceRequest;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamInfo;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
|
||||
/**
|
||||
* Param extractor for {@link InstanceRequest}.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class InstanceRequestParamExtractor extends AbstractRpcParamExtractor {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addTargetRequest(InstanceRequest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractParamAndCheck(Request request) throws Exception {
|
||||
InstanceRequest req = (InstanceRequest) request;
|
||||
ParamInfo paramInfo = new ParamInfo();
|
||||
paramInfo.setNamespaceId(req.getNamespace());
|
||||
paramInfo.setServiceName(req.getServiceName());
|
||||
paramInfo.setGroup(req.getGroupName());
|
||||
Instance instance = req.getInstance();
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
paramInfo.setIp(instance.getIp());
|
||||
paramInfo.setPort(String.valueOf(instance.getPort()));
|
||||
paramInfo.setCluster(instance.getClusterName());
|
||||
paramInfo.setMetadata(instance.getMetadata());
|
||||
ParamCheckUtils.checkParamInfoFormat(paramInfo);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.ServiceListRequest;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamInfo;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
|
||||
/**
|
||||
* Param extractor for {@link ServiceListRequest}.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class ServiceListRequestParamExtractor extends AbstractRpcParamExtractor {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addTargetRequest(ServiceListRequest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractParamAndCheck(Request request) throws Exception {
|
||||
ServiceListRequest req = (ServiceListRequest) request;
|
||||
ParamInfo paramInfo = new ParamInfo();
|
||||
paramInfo.setNamespaceId(req.getNamespace());
|
||||
paramInfo.setServiceName(req.getServiceName());
|
||||
paramInfo.setGroup(req.getGroupName());
|
||||
ParamCheckUtils.checkParamInfoFormat(paramInfo);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamInfo;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
|
||||
/**
|
||||
* Param extractor for {@link ServiceQueryRequest}.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class ServiceQueryRequestParamExtractor extends AbstractRpcParamExtractor {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addTargetRequest(ServiceQueryRequest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractParamAndCheck(Request request) throws Exception {
|
||||
ServiceQueryRequest req = (ServiceQueryRequest) request;
|
||||
ParamInfo paramInfo = new ParamInfo();
|
||||
paramInfo.setNamespaceId(req.getNamespace());
|
||||
paramInfo.setServiceName(req.getServiceName());
|
||||
paramInfo.setGroup(req.getGroupName());
|
||||
paramInfo.setPort(String.valueOf(req.getUdpPort()));
|
||||
ParamCheckUtils.checkParamInfoFormat(paramInfo);
|
||||
String clusterString = req.getCluster();
|
||||
if (StringUtils.isNotBlank(clusterString)) {
|
||||
String[] clusters = clusterString.split(",");
|
||||
for (String cluster : clusters) {
|
||||
ParamCheckUtils.checkClusterFormat(cluster);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils;
|
||||
import com.alibaba.nacos.common.paramcheck.ParamInfo;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
|
||||
/**
|
||||
* Param extractor for {@link SubscribeServiceRequest}.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class SubscribeServiceRequestParamExtractor extends AbstractRpcParamExtractor {
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
addTargetRequest(SubscribeServiceRequest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractParamAndCheck(Request request) throws Exception {
|
||||
SubscribeServiceRequest req = (SubscribeServiceRequest) request;
|
||||
ParamInfo paramInfo = new ParamInfo();
|
||||
paramInfo.setNamespaceId(req.getNamespace());
|
||||
paramInfo.setServiceName(req.getServiceName());
|
||||
paramInfo.setGroup(req.getGroupName());
|
||||
ParamCheckUtils.checkParamInfoFormat(paramInfo);
|
||||
String clusterString = req.getClusters();
|
||||
if (StringUtils.isNotBlank(clusterString)) {
|
||||
String[] clusters = clusterString.split(",");
|
||||
for (String cluster : clusters) {
|
||||
ParamCheckUtils.checkClusterFormat(cluster);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -87,7 +87,7 @@ public abstract class BaseGrpcServer extends BaseRpcServer {
|
||||
@Override
|
||||
public void startServer() throws Exception {
|
||||
final MutableHandlerRegistry handlerRegistry = new MutableHandlerRegistry();
|
||||
addServices(handlerRegistry, new GrpcConnectionInterceptor());
|
||||
addServices(handlerRegistry, new GrpcConnectionInterceptor(), new GrpcServerParamCheckInterceptor());
|
||||
NettyServerBuilder builder = NettyServerBuilder.forPort(getServicePort()).executor(getRpcExecutor());
|
||||
|
||||
if (rpcServerTlsConfig.getEnableTls()) {
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.remote.grpc;
|
||||
|
||||
import com.alibaba.nacos.api.grpc.auto.Payload;
|
||||
import com.alibaba.nacos.api.remote.request.Request;
|
||||
import com.alibaba.nacos.common.remote.client.grpc.GrpcUtils;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import com.alibaba.nacos.sys.env.EnvUtil;
|
||||
import io.grpc.ForwardingServerCallListener;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.ServerCall;
|
||||
import io.grpc.ServerCallHandler;
|
||||
import io.grpc.ServerInterceptor;
|
||||
import io.grpc.Status;
|
||||
|
||||
/**
|
||||
* Grpc server interceptor for param check.
|
||||
*
|
||||
* @author zhuoguang
|
||||
*/
|
||||
public class GrpcServerParamCheckInterceptor implements ServerInterceptor {
|
||||
|
||||
@Override
|
||||
public <T, S> ServerCall.Listener<T> interceptCall(ServerCall<T, S> call, Metadata headers,
|
||||
ServerCallHandler<T, S> next) {
|
||||
return new ForwardingServerCallListener.SimpleForwardingServerCallListener<T>(next.startCall(call, headers)) {
|
||||
@Override
|
||||
public void onMessage(T message) {
|
||||
boolean ifParamCheck = EnvUtil.getProperty("nacos.paramcheck", Boolean.class, true);
|
||||
if (!ifParamCheck) {
|
||||
super.onMessage(message);
|
||||
return;
|
||||
}
|
||||
Payload payload = (Payload) message;
|
||||
String type = payload.getMetadata().getType();
|
||||
Object parseObj;
|
||||
try {
|
||||
parseObj = GrpcUtils.parse(payload);
|
||||
if (parseObj instanceof Request) {
|
||||
Request request = (Request) parseObj;
|
||||
RpcParamExtractorManager extractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor = extractorManager.getExtractor(type);
|
||||
extractor.extractParamAndCheck(request);
|
||||
}
|
||||
super.onMessage(message);
|
||||
} catch (Exception e) {
|
||||
call.close(Status.INVALID_ARGUMENT.withDescription(e.getMessage()), headers);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
#
|
||||
# Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
com.alibaba.nacos.core.paramcheck.impl.SubscribeServiceRequestParamExtractor
|
||||
com.alibaba.nacos.core.paramcheck.impl.ServiceQueryRequestParamExtractor
|
||||
com.alibaba.nacos.core.paramcheck.impl.ServiceListRequestParamExtractor
|
||||
com.alibaba.nacos.core.paramcheck.impl.InstanceRequestParamExtractor
|
||||
com.alibaba.nacos.core.paramcheck.impl.ConfigRequestParamExtractor
|
||||
com.alibaba.nacos.core.paramcheck.impl.ConfigBatchListenRequestParamExtractor
|
||||
com.alibaba.nacos.core.paramcheck.impl.BatchInstanceRequestParamExtractor
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.BatchInstanceRequest;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BatchInstanceRequestParamExtractorTest {
|
||||
|
||||
private static BatchInstanceRequest req;
|
||||
|
||||
@BeforeClass
|
||||
public static void initBatchInstanceRequest() {
|
||||
req = new BatchInstanceRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extract param and check.
|
||||
*/
|
||||
@Test
|
||||
public void testExtractParamAndCheck() throws Exception {
|
||||
RpcParamExtractorManager paramExtractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor = paramExtractorManager.getExtractor(req.getClass().getSimpleName());
|
||||
assertEquals(extractor.getClass().getSimpleName(), BatchInstanceRequestParamExtractor.class.getSimpleName());
|
||||
extractor.extractParamAndCheck(req);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ConfigBatchListenRequestParamExtractorTest {
|
||||
|
||||
private static ConfigBatchListenRequest req;
|
||||
|
||||
@BeforeClass
|
||||
public static void initConfigBatchListenRequest() {
|
||||
req = new ConfigBatchListenRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extract param and check.
|
||||
*/
|
||||
@Test
|
||||
public void testExtractParamAndCheck() throws Exception {
|
||||
RpcParamExtractorManager paramExtractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor = paramExtractorManager.getExtractor(req.getClass().getSimpleName());
|
||||
assertEquals(extractor.getClass().getSimpleName(), ConfigBatchListenRequestParamExtractor.class.getSimpleName());
|
||||
extractor.extractParamAndCheck(req);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.config.remote.request.AbstractConfigRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigPublishRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigQueryRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.ConfigRemoveRequest;
|
||||
import com.alibaba.nacos.api.config.remote.request.cluster.ConfigChangeClusterSyncRequest;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ConfigRequestParamExtractorTest {
|
||||
|
||||
private static AbstractConfigRequest req1;
|
||||
|
||||
private static AbstractConfigRequest req2;
|
||||
|
||||
private static AbstractConfigRequest req3;
|
||||
|
||||
private static AbstractConfigRequest req4;
|
||||
|
||||
@BeforeClass
|
||||
public static void initAbstractConfigRequest() {
|
||||
req1 = new ConfigPublishRequest();
|
||||
req2 = new ConfigQueryRequest();
|
||||
req3 = new ConfigRemoveRequest();
|
||||
req4 = new ConfigChangeClusterSyncRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extract param and check.
|
||||
*/
|
||||
@Test
|
||||
public void testExtractParamAndCheck() throws Exception {
|
||||
RpcParamExtractorManager paramExtractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor1 = paramExtractorManager.getExtractor(req1.getClass().getSimpleName());
|
||||
assertEquals(extractor1.getClass().getSimpleName(), ConfigRequestParamExtractor.class.getSimpleName());
|
||||
extractor1.extractParamAndCheck(req1);
|
||||
|
||||
AbstractRpcParamExtractor extractor2 = paramExtractorManager.getExtractor(req2.getClass().getSimpleName());
|
||||
assertEquals(extractor2.getClass().getSimpleName(), ConfigRequestParamExtractor.class.getSimpleName());
|
||||
extractor2.extractParamAndCheck(req2);
|
||||
|
||||
AbstractRpcParamExtractor extractor3 = paramExtractorManager.getExtractor(req3.getClass().getSimpleName());
|
||||
assertEquals(extractor3.getClass().getSimpleName(), ConfigRequestParamExtractor.class.getSimpleName());
|
||||
extractor3.extractParamAndCheck(req3);
|
||||
|
||||
AbstractRpcParamExtractor extractor4 = paramExtractorManager.getExtractor(req4.getClass().getSimpleName());
|
||||
assertEquals(extractor4.getClass().getSimpleName(), ConfigRequestParamExtractor.class.getSimpleName());
|
||||
extractor4.extractParamAndCheck(req4);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.InstanceRequest;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class InstanceRequestParamExtractorTest {
|
||||
|
||||
private static InstanceRequest req;
|
||||
|
||||
@BeforeClass
|
||||
public static void initInstanceRequest() {
|
||||
req = new InstanceRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extract param and check.
|
||||
*/
|
||||
@Test
|
||||
public void testExtractParamAndCheck() throws Exception {
|
||||
RpcParamExtractorManager paramExtractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor = paramExtractorManager.getExtractor(req.getClass().getSimpleName());
|
||||
assertEquals(extractor.getClass().getSimpleName(), InstanceRequestParamExtractor.class.getSimpleName());
|
||||
extractor.extractParamAndCheck(req);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.ServiceListRequest;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ServiceListRequestParamExtractorTest {
|
||||
|
||||
private static ServiceListRequest req;
|
||||
|
||||
@BeforeClass
|
||||
public static void initServiceListRequest() {
|
||||
req = new ServiceListRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extract param and check.
|
||||
*/
|
||||
@Test
|
||||
public void testExtractParamAndCheck() throws Exception {
|
||||
RpcParamExtractorManager paramExtractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor = paramExtractorManager.getExtractor(req.getClass().getSimpleName());
|
||||
assertEquals(extractor.getClass().getSimpleName(), ServiceListRequestParamExtractor.class.getSimpleName());
|
||||
extractor.extractParamAndCheck(req);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ServiceQueryRequestParamExtractorTest {
|
||||
|
||||
private static ServiceQueryRequest req;
|
||||
|
||||
@BeforeClass
|
||||
public static void initServiceQueryRequest() {
|
||||
req = new ServiceQueryRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extract param and check.
|
||||
*/
|
||||
@Test
|
||||
public void testExtractParamAndCheck() throws Exception {
|
||||
RpcParamExtractorManager paramExtractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor = paramExtractorManager.getExtractor(req.getClass().getSimpleName());
|
||||
assertEquals(extractor.getClass().getSimpleName(), ServiceQueryRequestParamExtractor.class.getSimpleName());
|
||||
extractor.extractParamAndCheck(req);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.nacos.core.paramcheck.impl;
|
||||
|
||||
import com.alibaba.nacos.api.naming.remote.request.SubscribeServiceRequest;
|
||||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor;
|
||||
import com.alibaba.nacos.core.paramcheck.RpcParamExtractorManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SubscribeServiceRequestParamExtractorTest {
|
||||
|
||||
private static SubscribeServiceRequest req;
|
||||
|
||||
@BeforeClass
|
||||
public static void initSubscribeServiceRequest() {
|
||||
req = new SubscribeServiceRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test extract param and check.
|
||||
*/
|
||||
@Test
|
||||
public void testExtractParamAndCheck() throws Exception {
|
||||
RpcParamExtractorManager paramExtractorManager = RpcParamExtractorManager.getInstance();
|
||||
AbstractRpcParamExtractor extractor = paramExtractorManager.getExtractor(req.getClass().getSimpleName());
|
||||
assertEquals(extractor.getClass().getSimpleName(), SubscribeServiceRequestParamExtractor.class.getSimpleName());
|
||||
extractor.extractParamAndCheck(req);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1999-2020 Alibaba Group Holding Ltd.
|
||||
* Copyright 1999-2023 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -349,9 +349,9 @@ public abstract class AbstractInstanceOperate_ITCase {
|
||||
*/
|
||||
@Test
|
||||
public void registerEphemeralInstanceWithInvalidClusterName() throws Exception {
|
||||
expectedException.expect(NacosException.class);
|
||||
expectedException.expect(Exception.class);
|
||||
expectedException.expectMessage(
|
||||
"Instance 'clusterName' should be characters with only 0-9a-zA-Z-. (current: cluster1,cluster2)");
|
||||
"Param 'cluster' is illegal, Chinese characters and ',' should not appear in the param");
|
||||
|
||||
String serviceName = NamingBase.randomDomainName();
|
||||
Instance instance = new Instance();
|
||||
|
Loading…
Reference in New Issue
Block a user