com.alibaba.dubbo.rpc.RpcException Java Examples

The following examples show how to use com.alibaba.dubbo.rpc.RpcException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FailfastClusterInvokerTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(FailfastClusterInvokerTest.class).anyTimes();
    
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker1);
    
    resetInvoker1ToNoException();
    
    FailfastClusterInvoker<FailfastClusterInvokerTest> invoker = new FailfastClusterInvoker<FailfastClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
Example #2
Source File: DubboHttpServer.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected void doStart(URL url) {
    // TODO jetty will by default enable keepAlive so the xml config has no effect now
    httpServer = httpBinder.bind(url, new RestHandler());

    ServletContext servletContext = ServletManager.getInstance().getServletContext(url.getPort());
    if (servletContext == null) {
        servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
    }
    if (servletContext == null) {
        throw new RpcException("No servlet context found. If you are using server='servlet', " +
                "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
    }

    servletContext.setAttribute(ResteasyDeployment.class.getName(), deployment);

    try {
        dispatcher.init(new SimpleServletConfig(servletContext));
    } catch (ServletException e) {
        throw new RpcException(e);
    }
}
 
Example #3
Source File: JsonRpcProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null) {
        Class<?> cls = e.getClass();
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example #4
Source File: TransactionServiceFilter.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initializePhysicalInstanceIfNecessary(RemoteAddr remoteAddr) throws RpcException {
	if (remoteAddr != null) {
		RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance();
		RemoteCoordinator physicalInst = participantRegistry.getPhysicalInstance(remoteAddr);
		if (physicalInst == null) {
			String serverHost = remoteAddr.getServerHost();
			int serverPort = remoteAddr.getServerPort();
			final String target = String.format("%s:%s", serverHost, serverPort).intern();
			synchronized (target) {
				RemoteCoordinator participant = participantRegistry.getPhysicalInstance(remoteAddr);
				if (participant == null) {
					this.processInitPhysicalInstanceIfNecessary(remoteAddr);
				}
			} // end-synchronized (target)
		} // end-if (physicalInst == null)
	}
}
 
Example #5
Source File: AbstractProxyProtocol.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> Exporter<T> export(final Invoker<T> invoker) throws RpcException {
       final String uri = serviceKey(invoker.getUrl());
       Exporter<T> exporter = (Exporter<T>) exporterMap.get(uri);
       if (exporter != null) {
       	return exporter;
       }
       final Runnable runnable = doExport(proxyFactory.getProxy(invoker), invoker.getInterface(), invoker.getUrl());
       exporter = new AbstractExporter<T>(invoker) {
           public void unexport() {
               super.unexport();
               exporterMap.remove(uri);
               if (runnable != null) {
                   try {
                       runnable.run();
                   } catch (Throwable t) {
                       logger.warn(t.getMessage(), t);
                   }
               }
           }
       };
       exporterMap.put(uri, exporter);
       return exporter;
   }
 
Example #6
Source File: ExceptionFilterTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
Example #7
Source File: TransactionServiceFilter.java    From ByteJTA with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request,
		TransactionResponseImpl response) {
	TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();
	RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant();

	Map<String, String> attachments = invocation.getAttachments();
	attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier());

	transactionInterceptor.beforeSendRequest(request);
	if (request.getTransactionContext() != null) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		HessianOutput output = new HessianOutput(baos);
		try {
			output.writeObject(request.getTransactionContext());
		} catch (IOException ex) {
			logger.error("Error occurred in remote call!", ex);
			throw new RpcException("Error occurred in remote call!", ex);
		}
		String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray());
		attachments.put(TransactionContext.class.getName(), transactionContextContent);
	}

}
 
Example #8
Source File: MockInvoker.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private Throwable getThrowable(String throwstr){
  	Throwable throwable =(Throwable) throwables.get(throwstr);
if (throwable != null ){
	return throwable;
} else {
	Throwable t = null;
	try {
		Class<?> bizException = ReflectUtils.forName(throwstr);
          	Constructor<?> constructor;
		constructor = ReflectUtils.findConstructor(bizException, String.class);
		t = (Throwable) constructor.newInstance(new Object[] {" mocked exception for Service degradation. "});
		if (throwables.size() < 1000) {
			throwables.put(throwstr, t);	
		}
	} catch (Exception e) {
		throw new RpcException("mock throw error :" + throwstr + " argument error.", e);
	}
	return t;
}
  }
 
Example #9
Source File: RmiProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
protected int getErrorCode(Throwable e) {
    if (e instanceof RemoteAccessException) {
        e = e.getCause();
    }
    if (e != null && e.getCause() != null) {
        Class<?> cls = e.getCause().getClass();
        if (SocketTimeoutException.class.equals(cls)) {
            return RpcException.TIMEOUT_EXCEPTION;
        } else if (IOException.class.isAssignableFrom(cls)) {
            return RpcException.NETWORK_EXCEPTION;
        } else if (ClassNotFoundException.class.isAssignableFrom(cls)) {
            return RpcException.SERIALIZATION_EXCEPTION;
        }
    }
    return super.getErrorCode(e);
}
 
Example #10
Source File: DubboParser.java    From brave with Apache License 2.0 6 votes vote down vote up
/**
 * This library is no-longer being released, so it should not have any maintenance on error codes.
 * The error codes here were defined in 2012.
 */
@Nullable static String errorCode(Throwable error) {
  if (error instanceof RpcException) {
    int code = ((RpcException) error).getCode();
    switch (code) {
      case RpcException.UNKNOWN_EXCEPTION:
        return "UNKNOWN_EXCEPTION";
      case RpcException.NETWORK_EXCEPTION:
        return "NETWORK_EXCEPTION";
      case RpcException.TIMEOUT_EXCEPTION:
        return "TIMEOUT_EXCEPTION";
      case RpcException.BIZ_EXCEPTION:
        return "BIZ_EXCEPTION";
      case RpcException.FORBIDDEN_EXCEPTION:
        return "FORBIDDEN_EXCEPTION";
      case RpcException.SERIALIZATION_EXCEPTION:
        return "SERIALIZATION_EXCEPTION";
      default:
        return String.valueOf(code);
    }
  }
  return null;
}
 
Example #11
Source File: ValidationFilter.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (validation != null && ! invocation.getMethodName().startsWith("$") 
            && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) {
        try {
            Validator validator = validation.getValidator(invoker.getUrl());
            if (validator != null) {
                validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
            }
        } catch (RpcException e) {
            throw e;
        } catch (Throwable t) {
            throw new RpcException(t.getMessage(), t);
        }
    }
    return invoker.invoke(invocation);
}
 
Example #12
Source File: AbstractClusterInvoker.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Result invoke(final Invocation invocation) throws RpcException {

        checkWheatherDestoried();

        LoadBalance loadbalance;
        
        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && invokers.size() > 0) {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        } else {
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }
 
Example #13
Source File: FailoverClusterInvokerTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker1);
    
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
Example #14
Source File: ThriftProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private ExchangeServer getServer(URL url) {
    //默认开启server关闭时发送readonly事件
    url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString());
    String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER);

    if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str))
        throw new RpcException("Unsupported server type: " + str + ", url: " + url);

    ExchangeServer server;
    try {
        server = Exchangers.bind(url, handler);
    } catch (RemotingException e) {
        throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e);
    }
    str = url.getParameter(Constants.CLIENT_KEY);
    if (str != null && str.length() > 0) {
        Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions();
        if (!supportedTypes.contains(str)) {
            throw new RpcException("Unsupported client type: " + str);
        }
    }
    return server;
}
 
Example #15
Source File: ZookeeperRegistry.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
public List<URL> lookup(URL url) {
    if (url == null) {
        throw new IllegalArgumentException("lookup url == null");
    }
    try {
        List<String> providers = new ArrayList<String>();
        for (String path : toCategoriesPath(url)) {
            List<String> children = zkClient.getChildren(path);
            if (children != null) {
                providers.addAll(children);
            }
        }
        return toUrlsWithoutEmpty(url, providers);
    } catch (Throwable e) {
        throw new RpcException("Failed to lookup " + url + " from zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);
    }
}
 
Example #16
Source File: FailoverClusterInvokerTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test()
public void testInvoke_retryTimes() {
    given(invoker1.invoke(invocation)).willThrow(new RpcException(RpcException.TIMEOUT_EXCEPTION));
    given(invoker1.isAvailable()).willReturn(false);
    given(invoker1.getUrl()).willReturn(url);
    given(invoker1.getInterface()).willReturn(FailoverClusterInvokerTest.class);

    given(invoker2.invoke(invocation)).willThrow(new RpcException());
    given(invoker2.isAvailable()).willReturn(false);
    given(invoker2.getUrl()).willReturn(url);
    given(invoker2.getInterface()).willReturn(FailoverClusterInvokerTest.class);

    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    try {
        Result ret = invoker.invoke(invocation);
        assertSame(result, ret);
        fail();
    } catch (RpcException expected) {
        assertTrue((expected.isTimeout() || expected.getCode() == 0));
        assertTrue(expected.getMessage().indexOf((retries + 1) + " times") > 0);
    }
}
 
Example #17
Source File: FailoverClusterInvokerTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeWithRuntimeException() {
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
    
    EasyMock.reset(invoker2);
    EasyMock.expect(invoker2.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker2);
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertEquals(0,expected.getCode());
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
Example #18
Source File: MockClusterInvokerTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testMockInvokerFromOverride_Invoke_force_throw(){
	URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
			.addParameter("getBoolean2.mock","force:throw ")
			.addParameter("invoke_return_error", "true" );
	Invoker<IHelloService> cluster = getClusterInvoker(url);        
	//方法配置了mock
       RpcInvocation invocation = new RpcInvocation();
	invocation.setMethodName("getBoolean2");
	try {
		cluster.invoke(invocation);
		Assert.fail();
	} catch (RpcException e) {
		Assert.assertFalse("not custem exception", e.isBiz());
	}
}
 
Example #19
Source File: HessianProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new HessianHandler());
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    HessianSkeleton skeleton = new HessianSkeleton(impl, type);
    skeletonMap.put(path, skeleton);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example #20
Source File: CompensableSecondaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Result providerInvoke(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException {
	String interfaceClazz = RpcContext.getContext().getUrl().getServiceInterface();

	boolean participantFlag = TransactionParticipant.class.getName().equals(interfaceClazz);
	boolean xaResourceFlag = XAResource.class.getName().equals(interfaceClazz);
	boolean coordinatorFlag = RemoteCoordinator.class.getName().equals(interfaceClazz);

	if (participantFlag == false && xaResourceFlag == false && coordinatorFlag == false) {
		return this.providerInvokeForSVC(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_RESOURCE_START)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_IDENTIFIER)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_APPLICATION)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTEADDR)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTENODE)) {
		return this.providerInvokeForKey(invoker, invocation);
	} else {
		return this.providerInvokeForTCC(invoker, invocation);
	}
}
 
Example #21
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
       url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY);
       Registry registry = registryFactory.getRegistry(url);
       if (RegistryService.class.equals(type)) {
       	return proxyFactory.getInvoker((T) registry, type, url);
       }

       // group="a,b" or group="*"
       Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
       String group = qs.get(Constants.GROUP_KEY);
       if (group != null && group.length() > 0 ) {
           if ( ( Constants.COMMA_SPLIT_PATTERN.split( group ) ).length > 1
                   || "*".equals( group ) ) {
               return doRefer( getMergeableCluster(), registry, type, url );
           }
       }
       return doRefer(cluster, registry, type, url);
   }
 
Example #22
Source File: AbstractProxyProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> Exporter<T> export(final Invoker<T> invoker) throws RpcException {
       final String uri = serviceKey(invoker.getUrl());
       Exporter<T> exporter = (Exporter<T>) exporterMap.get(uri);
       if (exporter != null) {
       	return exporter;
       }
       final Runnable runnable = doExport(proxyFactory.getProxy(invoker), invoker.getInterface(), invoker.getUrl());
       exporter = new AbstractExporter<T>(invoker) {
           public void unexport() {
               super.unexport();
               exporterMap.remove(uri);
               if (runnable != null) {
                   try {
                       runnable.run();
                   } catch (Throwable t) {
                       logger.warn(t.getMessage(), t);
                   }
               }
           }
       };
       exporterMap.put(uri, exporter);
       return exporter;
   }
 
Example #23
Source File: ExceptionFilterTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
Example #24
Source File: ITTracingFilter_Consumer.java    From brave with Apache License 2.0 6 votes vote down vote up
/** Shows if you aren't using RpcTracing, the old "dubbo.error_code" works */
@Test public void setsError_onUnimplemented_legacy() {
  ((TracingFilter) ExtensionLoader.getExtensionLoader(Filter.class)
      .getExtension("tracing")).isInit = false;

  ((TracingFilter) ExtensionLoader.getExtensionLoader(Filter.class)
      .getExtension("tracing"))
      .setTracing(tracing);

  assertThatThrownBy(() -> wrongClient.get().sayHello("jorge"))
      .isInstanceOf(RpcException.class);

  MutableSpan span =
      testSpanHandler.takeRemoteSpanWithErrorMessage(CLIENT, ".*Not found exported service.*");
  assertThat(span.tags())
      .containsEntry("dubbo.error_code", "1");
}
 
Example #25
Source File: FutureFilter.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
    public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
        final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);

        fireInvokeCallback(invoker, invocation);
        // need to configure if there's return value before the invocation in order to help invoker to judge if it's
        // necessary to return future. 需要在调用之前配置是否有返回值,以便帮助调用程序判断是否需要返回future。
//        com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.com.alibaba.dubbo.rpc.Invoker.invoke()
        Result result = invoker.invoke(invocation);
        if (isAsync) {
            asyncCallback(invoker, invocation);
        } else {
            syncCallback(invoker, invocation, result);
        }
        return result;
    }
 
Example #26
Source File: MonitorFilter.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {
        RpcContext context = RpcContext.getContext(); // 提供方必须在invoke()之前获取context信息
        long start = System.currentTimeMillis(); // 记录起始时间戮
        getConcurrent(invoker, invocation).incrementAndGet(); // 并发计数
        try {
            Result result = invoker.invoke(invocation); // 让调用链往下执行
            collect(invoker, invocation, result, context, start, false);
            return result;
        } catch (RpcException e) {
            collect(invoker, invocation, null, context, start, true);
            throw e;
        } finally {
            getConcurrent(invoker, invocation).decrementAndGet(); // 并发计数
        }
    } else {
        return invoker.invoke(invocation);
    }
}
 
Example #27
Source File: DubboProtocol.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
/**
 * 创建新连接.
 */
private ExchangeClient initClient(URL url) {
    
    // client type setting.
    String str = url.getParameter(Constants.CLIENT_KEY, url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_CLIENT));

    String version = url.getParameter(Constants.DUBBO_VERSION_KEY);
    boolean compatible = (version != null && version.startsWith("1.0."));
    url = url.addParameter(Constants.CODEC_KEY, Version.isCompatibleVersion() && compatible ? COMPATIBLE_CODEC_NAME : DubboCodec.NAME);
    //默认开启heartbeat
    url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT));
    
    // BIO存在严重性能问题,暂时不允许使用
    if (str != null && str.length() > 0 && ! ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) {
        throw new RpcException("Unsupported client type: " + str + "," +
                " supported client type is " + StringUtils.join(ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(), " "));
    }
    
    ExchangeClient client ;
    try {
        //设置连接应该是lazy的 
        if (url.getParameter(Constants.LAZY_CONNECT_KEY, false)){
            client = new LazyConnectExchangeClient(url ,requestHandler);
        } else {
            client = Exchangers.connect(url ,requestHandler);
        }
    } catch (RemotingException e) {
        throw new RpcException("Fail to create remoting client for service(" + url
                + "): " + e.getMessage(), e);
    }
    return client;
}
 
Example #28
Source File: XAResourceDeserializerImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void processInitRemoteParticipantIfNecessary(String application) {
	RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance();
	TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance();

	RemoteCoordinator participant = participantRegistry.getParticipant(application);
	if (participant == null) {
		ApplicationConfig applicationConfig = beanRegistry.getBean(ApplicationConfig.class);
		RegistryConfig registryConfig = beanRegistry.getBean(RegistryConfig.class);
		ProtocolConfig protocolConfig = beanRegistry.getBean(ProtocolConfig.class);

		ReferenceConfig<RemoteCoordinator> referenceConfig = new ReferenceConfig<RemoteCoordinator>();
		referenceConfig.setInterface(RemoteCoordinator.class);
		referenceConfig.setTimeout(15000);
		referenceConfig.setCluster("failfast");
		referenceConfig.setLoadbalance("bytejta");
		referenceConfig.setFilter("bytejta");
		referenceConfig.setGroup(application);
		referenceConfig.setCheck(false);
		referenceConfig.setRetries(-1);
		referenceConfig.setScope(Constants.SCOPE_REMOTE);

		referenceConfig.setApplication(applicationConfig);
		if (registryConfig != null) {
			referenceConfig.setRegistry(registryConfig);
		}
		if (protocolConfig != null) {
			referenceConfig.setProtocol(protocolConfig.getName());
		} // end-if (protocolConfig != null)

		RemoteCoordinator reference = referenceConfig.get();
		if (reference == null) {
			throw new RpcException("Cannot get the application name of the remote application.");
		}

		participantRegistry.putParticipant(application, reference);
	}
}
 
Example #29
Source File: FutureFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
	final boolean isAsync = RpcUtils.isAsync(invoker.getUrl(), invocation);
    
	fireInvokeCallback(invoker, invocation);
    //需要在调用前配置好是否有返回值,已供invoker判断是否需要返回future.
    Result result = invoker.invoke(invocation);
    if (isAsync) {
        asyncCallback(invoker, invocation);
    } else {
        syncCallback(invoker, invocation, result);
    }
    return result;
}
 
Example #30
Source File: FileRouterEngineTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected Result doInvoke(Invocation invocation, List<Invoker<T>> invokers,
                          LoadBalance loadbalance) throws RpcException {
    Invoker<T> invoker = select(loadbalance, invocation, invokers, null);
    selectedInvoker = invoker;
    return null;
}