Search in sources :

Example 6 with AbstractNamingRequest

use of com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest in project nacos by alibaba.

the class GrpcRequestFilter method filter.

@Override
protected Response filter(Request request, RequestMeta meta, Class handlerClazz) throws NacosException {
    if (request instanceof AbstractNamingRequest && !upgradeJudgement.isUseGrpcFeatures()) {
        Response response = getDefaultResponseInstance(handlerClazz);
        response.setErrorInfo(NacosException.SERVER_ERROR, "Nacos cluster is running with 1.X mode, can't accept gRPC request temporarily. Please check the server status or close Double write to force open 2.0 mode. Detail https://nacos.io/en-us/docs/2.0.0-upgrading.html.");
        return response;
    }
    return null;
}
Also used : AbstractNamingRequest(com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest) Response(com.alibaba.nacos.api.remote.response.Response)

Example 7 with AbstractNamingRequest

use of com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest in project nacos by alibaba.

the class NamingResourceParser method parseName.

@Override
public String parseName(Object requestObj) {
    String namespaceId = null;
    String serviceName = null;
    String groupName = null;
    if (requestObj instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) requestObj;
        namespaceId = NamespaceUtil.processNamespaceParameter(req.getParameter(CommonParams.NAMESPACE_ID));
        serviceName = req.getParameter(CommonParams.SERVICE_NAME);
        groupName = req.getParameter(CommonParams.GROUP_NAME);
    } else if (requestObj instanceof AbstractNamingRequest) {
        AbstractNamingRequest request = (AbstractNamingRequest) requestObj;
        namespaceId = request.getNamespace();
        groupName = request.getGroupName();
        serviceName = request.getServiceName();
    } else if (requestObj instanceof Request) {
        Request request = (Request) requestObj;
        namespaceId = (String) ReflectUtils.getFieldValue(request, FieldsConstants.NAME_SPACE, "");
        groupName = (String) ReflectUtils.getFieldValue(request, FieldsConstants.GROUP_NAME, "");
        serviceName = (String) ReflectUtils.getFieldValue(request, FieldsConstants.SERVICE_NAME, "");
    }
    if (StringUtils.isBlank(groupName)) {
        groupName = NamingUtils.getGroupName(serviceName);
    }
    serviceName = NamingUtils.getServiceName(serviceName);
    StringBuilder sb = new StringBuilder();
    if (StringUtils.isNotBlank(namespaceId)) {
        sb.append(namespaceId);
    }
    if (StringUtils.isBlank(groupName)) {
        sb.append(Resource.SPLITTER).append('*');
    } else {
        sb.append(Resource.SPLITTER).append(groupName);
    }
    if (StringUtils.isBlank(serviceName)) {
        sb.append(Resource.SPLITTER).append(AUTH_NAMING_PREFIX).append('*');
    } else {
        sb.append(Resource.SPLITTER).append(AUTH_NAMING_PREFIX).append(serviceName);
    }
    return sb.toString();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractNamingRequest(com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractNamingRequest(com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest) Request(com.alibaba.nacos.api.remote.request.Request)

Aggregations

AbstractNamingRequest (com.alibaba.nacos.api.naming.remote.request.AbstractNamingRequest)7 Secured (com.alibaba.nacos.auth.annotation.Secured)4 Resource (com.alibaba.nacos.plugin.auth.api.Resource)4 Test (org.junit.Test)4 Request (com.alibaba.nacos.api.remote.request.Request)1 Response (com.alibaba.nacos.api.remote.response.Response)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1