Java Code Examples for com.alibaba.dubbo.rpc.RpcResult#setException()
The following examples show how to use
com.alibaba.dubbo.rpc.RpcResult#setException() .
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: TransactionServiceFilter.java From ByteJTA with GNU Lesser General Public License v3.0 | 6 votes |
private Result convertResultForProvider(RpcResult result, String propagatedBy, boolean attachRequired) { TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance(); TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant(); Object value = result.getValue(); InvocationResult wrapped = new InvocationResult(); wrapped.setValue(value); if (attachRequired) { wrapped.setVariable(Propagation.class.getName(), propagatedBy); wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); } result.setException(null); result.setValue(wrapped); return result; }
Example 2
Source File: CompatibleFilterFilterTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testResulthasException() { invocation = EasyMock.createMock(Invocation.class); EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes(); EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes(); EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes(); EasyMock.replay(invocation); invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setException(new RuntimeException()); result.setValue("High"); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); Result filterResult = compatibleFilter.invoke(invoker, invocation); assertEquals(filterResult, result); }
Example 3
Source File: CompatibleFilterFilterTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Test public void testResulthasException() { invocation = EasyMock.createMock(Invocation.class); EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes(); EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes(); EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes(); EasyMock.replay(invocation); invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setException(new RuntimeException()); result.setValue("High"); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); Result filterResult = compatibleFilter.invoke(invoker, invocation); assertEquals(filterResult, result); }
Example 4
Source File: CompensablePrimaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
public Result providerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); String instanceId = StringUtils.trimToEmpty(invocation.getAttachment(RemoteCoordinator.class.getName())); this.registerRemoteParticipantIfNecessary(instanceId); RpcResult result = new RpcResult(); CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult(); wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); result.setException(null); result.setValue(wrapped); return result; }
Example 5
Source File: CompatibleFilterFilterTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void testResulthasException() { invocation = EasyMock.createMock(Invocation.class); EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes(); EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes(); EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes(); EasyMock.replay(invocation); invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setException(new RuntimeException()); result.setValue("High"); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); Result filterResult = compatibleFilter.invoke(invoker, invocation); assertEquals(filterResult, result); }
Example 6
Source File: CompensablePrimaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); RpcResult result = (RpcResult) invoker.invoke(invocation); Object value = result.getValue(); if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) { CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value; result.setValue(null); result.setException(null); if (wrapped.isFailure()) { result.setException(wrapped.getError()); } else { result.setValue(wrapped.getValue()); } // String propagatedBy = (String) wrapped.getVariable(RemoteCoordinator.class.getName()); // String identifier = compensableCoordinator.getIdentifier(); } return result; }
Example 7
Source File: CompensableSecondaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
public Result consumerInvokeForTCC(Invoker<?> invoker, Invocation invocation) throws RpcException, RemotingException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); RpcResult result = (RpcResult) invoker.invoke(invocation); Object value = result.getValue(); if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) { CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value; result.setValue(null); result.setException(null); if (wrapped.isFailure()) { result.setException(wrapped.getError()); } else { result.setValue(wrapped.getValue()); } } return result; }
Example 8
Source File: CompensableSecondaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
public Result providerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); String instanceId = StringUtils.trimToEmpty(invocation.getAttachment(RemoteCoordinator.class.getName())); this.registerRemoteParticipantIfNecessary(instanceId); RpcResult result = new RpcResult(); CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult(); wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); result.setException(null); result.setValue(wrapped); return result; }
Example 9
Source File: MyInvoker.java From dubbox with Apache License 2.0 | 5 votes |
public Result invoke(Invocation invocation) throws RpcException { RpcResult result = new RpcResult(); if (hasException == false) { result.setValue("alibaba"); return result; } else { result.setException(new RuntimeException("mocked exception")); return result; } }
Example 10
Source File: FutureFilterTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test(expected = RuntimeException.class) public void testSyncCallbackHasException() throws RpcException, Throwable { @SuppressWarnings("unchecked") Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setException(new RuntimeException()); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&"+Constants.ON_THROW_METHOD_KEY+"=echo"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); eventFilter.invoke(invoker, invocation).recreate(); }
Example 11
Source File: MyInvoker.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public Result invoke(Invocation invocation) throws RpcException { RpcResult result = new RpcResult(); if (hasException == false) { result.setValue("alibaba"); return result; } else { result.setException(new RuntimeException("mocked exception")); return result; } }
Example 12
Source File: FutureFilterTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test(expected = RuntimeException.class) public void testSyncCallbackHasException() throws RpcException, Throwable { @SuppressWarnings("unchecked") Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setException(new RuntimeException()); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&"+Constants.ON_THROW_METHOD_KEY+"=echo"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); eventFilter.invoke(invoker, invocation).recreate(); }
Example 13
Source File: MyInvoker.java From dubbox with Apache License 2.0 | 5 votes |
public Result invoke(Invocation invocation) throws RpcException { RpcResult result = new RpcResult(); if (hasException == false) { result.setValue("alibaba"); return result; } else { result.setException(new RuntimeException("mocked exception")); return result; } }
Example 14
Source File: FutureFilterTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test(expected = RuntimeException.class) public void testSyncCallbackHasException() throws RpcException, Throwable { @SuppressWarnings("unchecked") Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class); EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes(); EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes(); RpcResult result = new RpcResult(); result.setException(new RuntimeException()); EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes(); URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&"+Constants.ON_THROW_METHOD_KEY+"=echo"); EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes(); EasyMock.replay(invoker); eventFilter.invoke(invoker, invocation).recreate(); }
Example 15
Source File: MyInvoker.java From dubbox with Apache License 2.0 | 5 votes |
public Result invoke(Invocation invocation) throws RpcException { RpcResult result = new RpcResult(); if (hasException == false) { result.setValue("alibaba"); return result; } else { result.setException(new RuntimeException("mocked exception")); return result; } }
Example 16
Source File: CompensablePrimaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
public Result consumerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); RpcResult result = (RpcResult) invoker.invoke(invocation); Object value = result.getValue(); if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) { CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value; result.setValue(null); result.setException(null); if (wrapped.isFailure()) { result.setException(wrapped.getError()); } else { result.setValue(wrapped.getValue()); } String instanceId = StringUtils.trimToEmpty(String.valueOf(wrapped.getVariable(RemoteCoordinator.class.getName()))); this.registerRemoteParticipantIfNecessary(instanceId); 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); boolean resultInitRequired = (participantFlag || xaResourceFlag || coordinatorFlag) && result.getValue() == null; if (resultInitRequired) { if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_IDENTIFIER)) { result.setValue(instanceId); } else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_APPLICATION)) { result.setValue(CommonUtils.getApplication(instanceId)); } else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTEADDR)) { result.setValue(CommonUtils.getRemoteAddr(instanceId)); } else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTENODE)) { result.setValue(CommonUtils.getRemoteNode(instanceId)); } } // end-if (resultInitRequired) } // end-if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) return result; }
Example 17
Source File: ThriftCodecTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testEncodeExceptionResponse() throws Exception { URL url = URL.valueOf( ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName() ); Channel channel = new MockedChannel( url ); Request request = createRequest(); RpcResult rpcResult = new RpcResult(); String exceptionMessage = "failed"; rpcResult.setException( new RuntimeException( exceptionMessage ) ); Response response = new Response(); response.setResult( rpcResult ); response.setId( request.getId() ); ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024); ThriftCodec.RequestData rd = ThriftCodec.RequestData.create( ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" ); ThriftCodec.cachedRequest.put( request.getId(), rd ); codec.encode( channel, bos, response ); byte[] buf = new byte[bos.writerIndex() - 4]; System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 ); ByteArrayInputStream bis = new ByteArrayInputStream( buf); if ( bis.markSupported() ) { bis.mark( 0 ); } TIOStreamTransport transport = new TIOStreamTransport( bis ); TBinaryProtocol protocol = new TBinaryProtocol( transport ); Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() ); Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() ); int headerLength = protocol.readI16(); Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() ); Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() ); Assert.assertEquals( request.getId(), protocol.readI64() ); if ( bis.markSupported() ) { bis.reset(); bis.skip( headerLength ); } TMessage message = protocol.readMessageBegin(); Assert.assertEquals( "echoString", message.name ); Assert.assertEquals( TMessageType.EXCEPTION, message.type ); Assert.assertEquals( ThriftCodec.getSeqId(), message.seqid ); TApplicationException exception = TApplicationException.read( protocol ); protocol.readMessageEnd(); Assert.assertEquals( exceptionMessage, exception.getMessage() ); }
Example 18
Source File: CompensableSecondaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
public Result consumerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); RpcResult result = (RpcResult) invoker.invoke(invocation); Object value = result.getValue(); if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) { CompensableServiceFilter.InvocationResult wrapped = (CompensableServiceFilter.InvocationResult) value; result.setValue(null); result.setException(null); if (wrapped.isFailure()) { result.setException(wrapped.getError()); } else { result.setValue(wrapped.getValue()); } String instanceId = StringUtils.trimToEmpty(String.valueOf(wrapped.getVariable(RemoteCoordinator.class.getName()))); this.registerRemoteParticipantIfNecessary(instanceId); 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); boolean resultInitRequired = (participantFlag || xaResourceFlag || coordinatorFlag) && result.getValue() == null; if (resultInitRequired) { if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_IDENTIFIER)) { result.setValue(instanceId); } else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_APPLICATION)) { result.setValue(CommonUtils.getApplication(instanceId)); } else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTEADDR)) { result.setValue(CommonUtils.getRemoteAddr(instanceId)); } else if (StringUtils.equals(invocation.getMethodName(), KEY_XA_GET_REMOTENODE)) { result.setValue(CommonUtils.getRemoteNode(instanceId)); } } // end-if (resultInitRequired) } // end-if (CompensableServiceFilter.InvocationResult.class.isInstance(value)) return result; }
Example 19
Source File: ThriftCodecTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testEncodeExceptionResponse() throws Exception { URL url = URL.valueOf( ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName() ); Channel channel = new MockedChannel( url ); Request request = createRequest(); RpcResult rpcResult = new RpcResult(); String exceptionMessage = "failed"; rpcResult.setException( new RuntimeException( exceptionMessage ) ); Response response = new Response(); response.setResult( rpcResult ); response.setId( request.getId() ); ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024); ThriftCodec.RequestData rd = ThriftCodec.RequestData.create( ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" ); ThriftCodec.cachedRequest.put( request.getId(), rd ); codec.encode( channel, bos, response ); byte[] buf = new byte[bos.writerIndex() - 4]; System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 ); ByteArrayInputStream bis = new ByteArrayInputStream( buf); if ( bis.markSupported() ) { bis.mark( 0 ); } TIOStreamTransport transport = new TIOStreamTransport( bis ); TBinaryProtocol protocol = new TBinaryProtocol( transport ); Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() ); Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() ); int headerLength = protocol.readI16(); Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() ); Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() ); Assert.assertEquals( request.getId(), protocol.readI64() ); if ( bis.markSupported() ) { bis.reset(); bis.skip( headerLength ); } TMessage message = protocol.readMessageBegin(); Assert.assertEquals( "echoString", message.name ); Assert.assertEquals( TMessageType.EXCEPTION, message.type ); Assert.assertEquals( ThriftCodec.getSeqId(), message.seqid ); TApplicationException exception = TApplicationException.read( protocol ); protocol.readMessageEnd(); Assert.assertEquals( exceptionMessage, exception.getMessage() ); }
Example 20
Source File: TransactionServiceFilter.java From ByteJTA with GNU Lesser General Public License v3.0 | 4 votes |
public Result providerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException { TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance(); TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant(); String instanceId = StringUtils.trimToEmpty(invocation.getAttachment(RemoteCoordinator.class.getName())); this.registerRemoteParticipantIfNecessary(instanceId); RpcResult result = new RpcResult(); InvocationResult wrapped = new InvocationResult(); wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); result.setException(null); result.setValue(wrapped); return result; }