Search in sources :

Example 11 with Response

use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.

the class ClusterRpcClientProxyTest method testAsyncRequest.

@Test
public void testAsyncRequest() {
    RequestCallBack requestCallBack = new RequestCallBack() {

        @Override
        public Executor getExecutor() {
            return null;
        }

        @Override
        public long getTimeout() {
            return 0;
        }

        @Override
        public void onResponse(Response response) {
        }

        @Override
        public void onException(Throwable e) {
            Assert.assertTrue(e instanceof NacosException);
        }
    };
    Member member = new Member();
    member.setIp("1.1.1.1");
    try {
        clusterRpcClientProxy.asyncRequest(member, new HealthCheckRequest(), requestCallBack);
    } catch (NacosException e) {
        Assert.assertEquals(500, e.getErrCode());
    }
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) RequestCallBack(com.alibaba.nacos.api.remote.RequestCallBack) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) Member(com.alibaba.nacos.core.cluster.Member) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 12 with Response

use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.

the class RemoteRequestAuthFilterTest method testFilter.

@Test
public void testFilter() {
    Mockito.when(authConfigs.isAuthEnabled()).thenReturn(true);
    Request healthCheckRequest = new HealthCheckRequest();
    try {
        Response healthCheckResponse = remoteRequestAuthFilter.filter(healthCheckRequest, new RequestMeta(), MockRequestHandler.class);
        Assert.assertNull(healthCheckResponse);
    } catch (NacosException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) Request(com.alibaba.nacos.api.remote.request.Request) HealthCheckRequest(com.alibaba.nacos.api.remote.request.HealthCheckRequest) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 13 with Response

use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.

the class NamingGrpcClientProxy method requestToServer.

private <T extends Response> T requestToServer(AbstractNamingRequest request, Class<T> responseClass) throws NacosException {
    try {
        request.putAllHeader(getSecurityHeaders(request.getNamespace(), request.getGroupName(), request.getServiceName()));
        Response response = requestTimeout < 0 ? rpcClient.request(request) : rpcClient.request(request, requestTimeout);
        if (ResponseCode.SUCCESS.getCode() != response.getResultCode()) {
            throw new NacosException(response.getErrorCode(), response.getMessage());
        }
        if (responseClass.isAssignableFrom(response.getClass())) {
            return (T) response;
        }
        NAMING_LOGGER.error("Server return unexpected response '{}', expected response should be '{}'", response.getClass().getName(), responseClass.getName());
    } catch (Exception e) {
        throw new NacosException(NacosException.SERVER_ERROR, "Request nacos server failed: ", e);
    }
    throw new NacosException(NacosException.SERVER_ERROR, "Server return invalid response");
}
Also used : QueryServiceResponse(com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse) Response(com.alibaba.nacos.api.remote.response.Response) SubscribeServiceResponse(com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse) ServiceListResponse(com.alibaba.nacos.api.naming.remote.response.ServiceListResponse) NacosException(com.alibaba.nacos.api.exception.NacosException) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 14 with Response

use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.

the class NamingPushRequestHandlerTest method testRequestReply.

@Test
public void testRequestReply() {
    // given
    ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
    NamingPushRequestHandler handler = new NamingPushRequestHandler(holder);
    ServiceInfo info = new ServiceInfo("name", "cluster1");
    Request req = NotifySubscriberRequest.buildNotifySubscriberRequest(info);
    // when
    Response response = handler.requestReply(req);
    // then
    Assert.assertTrue(response instanceof NotifySubscriberResponse);
    verify(holder, times(1)).processServiceInfo(info);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Response(com.alibaba.nacos.api.remote.response.Response) NotifySubscriberResponse(com.alibaba.nacos.api.naming.remote.response.NotifySubscriberResponse) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) NotifySubscriberResponse(com.alibaba.nacos.api.naming.remote.response.NotifySubscriberResponse) NotifySubscriberRequest(com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest) Request(com.alibaba.nacos.api.remote.request.Request) Test(org.junit.Test)

Example 15 with Response

use of com.alibaba.nacos.api.remote.response.Response in project nacos by alibaba.

the class RequestLogAspect method interfaceListenConfigRpc.

/**
 * GetConfig.
 */
@Around(CLIENT_INTERFACE_LISTEN_CONFIG_RPC)
public Object interfaceListenConfigRpc(ProceedingJoinPoint pjp, ConfigBatchListenRequest request, RequestMeta meta) throws Throwable {
    MetricsMonitor.getConfigMonitor().incrementAndGet();
    final String requestIp = meta.getClientIp();
    String appName = request.getHeader(RequestUtil.CLIENT_APPNAME_HEADER);
    final long st = System.currentTimeMillis();
    Response retVal = (Response) pjp.proceed();
    final long rt = System.currentTimeMillis() - st;
    // rt | status | requestIp | opType | listen size | listen or cancel | empty | empty |
    // appName
    LogUtil.CLIENT_LOG.info("{}|{}|{}|{}|{}|{}|{}|{}|{}", rt, retVal.isSuccess() ? retVal.getResultCode() : retVal.getErrorCode(), requestIp, "listen", request.getConfigListenContexts().size(), request.isListen(), "", "", appName);
    return retVal;
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) Around(org.aspectj.lang.annotation.Around)

Aggregations

Response (com.alibaba.nacos.api.remote.response.Response)31 NacosException (com.alibaba.nacos.api.exception.NacosException)23 Payload (com.alibaba.nacos.api.grpc.auto.Payload)9 ErrorResponse (com.alibaba.nacos.api.remote.response.ErrorResponse)9 Member (com.alibaba.nacos.core.cluster.Member)8 Test (org.junit.Test)7 Request (com.alibaba.nacos.api.remote.request.Request)6 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)6 RequestCallBack (com.alibaba.nacos.api.remote.RequestCallBack)5 ConnectionSetupRequest (com.alibaba.nacos.api.remote.request.ConnectionSetupRequest)4 ServerCheckResponse (com.alibaba.nacos.api.remote.response.ServerCheckResponse)4 DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)4 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)4 ConnectResetRequest (com.alibaba.nacos.api.remote.request.ConnectResetRequest)3 HealthCheckRequest (com.alibaba.nacos.api.remote.request.HealthCheckRequest)3 ServerCheckRequest (com.alibaba.nacos.api.remote.request.ServerCheckRequest)3 ConnectResetResponse (com.alibaba.nacos.api.remote.response.ConnectResetResponse)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 InstanceRequest (com.alibaba.nacos.api.naming.remote.request.InstanceRequest)2