Java Code Examples for com.alibaba.dubbo.rpc.Result#getValue()
The following examples show how to use
com.alibaba.dubbo.rpc.Result#getValue() .
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: DubboCodec.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Override protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException { Result result = (Result) data; Throwable th = result.getException(); if (th == null) { Object ret = result.getValue(); if (ret == null) { out.writeByte(RESPONSE_NULL_VALUE); } else { out.writeByte(RESPONSE_VALUE); out.writeObject(ret); } } else { out.writeByte(RESPONSE_WITH_EXCEPTION); out.writeObject(th); } }
Example 2
Source File: DubboCodec.java From dubbox with Apache License 2.0 | 6 votes |
@Override protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException { Result result = (Result) data; Throwable th = result.getException(); if (th == null) { Object ret = result.getValue(); if (ret == null) { out.writeByte(RESPONSE_NULL_VALUE); } else { out.writeByte(RESPONSE_VALUE); out.writeObject(ret); } } else { out.writeByte(RESPONSE_WITH_EXCEPTION); out.writeObject(th); } }
Example 3
Source File: MockClusterInvokerTest.java From dubbox with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListPojo(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getUsers.mock","force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); Result ret = cluster.invoke(invocation); List<User> rl = (List<User>)ret.getValue(); System.out.println(rl); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi1", ((User)rl.get(0)).getName()); }
Example 4
Source File: DubboCodec.java From dubbox with Apache License 2.0 | 6 votes |
@Override protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException { Result result = (Result) data; Throwable th = result.getException(); if (th == null) { Object ret = result.getValue(); if (ret == null) { out.writeByte(RESPONSE_NULL_VALUE); } else { out.writeByte(RESPONSE_VALUE); out.writeObject(ret); } } else { out.writeByte(RESPONSE_WITH_EXCEPTION); out.writeObject(th); } }
Example 5
Source File: MockClusterInvokerTest.java From dubbox with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListPojo(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getUsers.mock","force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); Result ret = cluster.invoke(invocation); List<User> rl = (List<User>)ret.getValue(); System.out.println(rl); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi1", ((User)rl.get(0)).getName()); }
Example 6
Source File: DubboCodec.java From dubbo3 with Apache License 2.0 | 6 votes |
@Override protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException { Result result = (Result) data; Throwable th = result.getException(); if (th == null) { Object ret = result.getValue(); if (ret == null) { out.writeByte(RESPONSE_NULL_VALUE); } else { out.writeByte(RESPONSE_VALUE); out.writeObject(ret); } } else { out.writeByte(RESPONSE_WITH_EXCEPTION); out.writeObject(th); } }
Example 7
Source File: MockClusterInvokerTest.java From dubbo3 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListPojo(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getUsers.mock","force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); Result ret = cluster.invoke(invocation); List<User> rl = (List<User>)ret.getValue(); System.out.println(rl); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi1", ((User)rl.get(0)).getName()); }
Example 8
Source File: MockClusterInvokerTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListPojo(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getUsers.mock","force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); Result ret = cluster.invoke(invocation); List<User> rl = (List<User>)ret.getValue(); System.out.println(rl); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi1", ((User)rl.get(0)).getName()); }
Example 9
Source File: DubboCodec.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override protected void encodeResponseData(Channel channel, ObjectOutput out, Object data, String version) throws IOException { Result result = (Result) data; // currently, the version value in Response records the version of Request boolean attach = Version.isSupportResponseAttatchment(version); Throwable th = result.getException(); if (th == null) { Object ret = result.getValue(); if (ret == null) { out.writeByte(attach ? RESPONSE_NULL_VALUE_WITH_ATTACHMENTS : RESPONSE_NULL_VALUE); } else { out.writeByte(attach ? RESPONSE_VALUE_WITH_ATTACHMENTS : RESPONSE_VALUE); out.writeObject(ret); } } else { out.writeByte(attach ? RESPONSE_WITH_EXCEPTION_WITH_ATTACHMENTS : RESPONSE_WITH_EXCEPTION); out.writeObject(th); } if (attach) { // returns current version of Response to consumer side. result.getAttachments().put(Constants.DUBBO_VERSION_KEY, Version.getProtocolVersion()); out.writeObject(result.getAttachments()); } }
Example 10
Source File: CacheFilter.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) { Cache cache = cacheFactory.getCache(invoker.getUrl(), invocation); if (cache != null) { String key = StringUtils.toArgumentString(invocation.getArguments()); Object value = cache.get(key); if (value != null) { return new RpcResult(value); } Result result = invoker.invoke(invocation); if (!result.hasException() && result.getValue() != null) { cache.put(key, result.getValue()); } return result; } } return invoker.invoke(invocation); }
Example 11
Source File: MockClusterInvokerTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListPojo() { URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()) .addParameter("getUsers.mock", "force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); //Configured with mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getUsers"); Result ret = cluster.invoke(invocation); List<User> rl = (List<User>) ret.getValue(); System.out.println(rl); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi1", ((User) rl.get(0)).getName()); }
Example 12
Source File: MockClusterInvokerTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getListString.mock","force:return [\"hi\",\"hi2\"]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); List<String> rl = (List<String>)ret.getValue(); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi", rl.get(0)); }
Example 13
Source File: ITTracingFilter_Consumer.java From brave with Apache License 2.0 | 5 votes |
@Test public void customParser() { Tag<DubboResponse> javaValue = new Tag<DubboResponse>("dubbo.result_value") { @Override protected String parseValue(DubboResponse input, TraceContext context) { Result result = input.result(); if (result == null) return null; Object value = result.getValue(); if (value instanceof JavaBeanDescriptor) { return String.valueOf(((JavaBeanDescriptor) value).getProperty("value")); } return null; } }; RpcTracing rpcTracing = RpcTracing.newBuilder(tracing) .clientResponseParser((res, context, span) -> { RpcResponseParser.DEFAULT.parse(res, context, span); if (res instanceof DubboResponse) { javaValue.tag((DubboResponse) res, span); } }).build(); init().setRpcTracing(rpcTracing); String javaResult = client.get().sayHello("jorge"); assertThat(testSpanHandler.takeRemoteSpan(CLIENT).tags()) .containsEntry("dubbo.result_value", javaResult); }
Example 14
Source File: MockClusterInvokerTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString() { URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()) .addParameter("getListString.mock", "force:return [\"hi\",\"hi2\"]") .addParameter("invoke_return_error", "true"); Invoker<IHelloService> cluster = getClusterInvoker(url); //Configured with mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); List<String> rl = (List<String>) ret.getValue(); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi", rl.get(0)); }
Example 15
Source File: MockClusterInvokerTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getListString.mock","force:return [\"hi\",\"hi2\"]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); List<String> rl = (List<String>)ret.getValue(); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi", rl.get(0)); }
Example 16
Source File: ITTracingFilter_Provider.java From brave with Apache License 2.0 | 5 votes |
@Test public void customParser() { Tag<DubboResponse> javaValue = new Tag<DubboResponse>("dubbo.result_value") { @Override protected String parseValue(DubboResponse input, TraceContext context) { Result result = input.result(); if (result == null) return null; Object value = result.getValue(); if (value instanceof JavaBeanDescriptor) { return String.valueOf(((JavaBeanDescriptor) value).getProperty("value")); } return null; } }; RpcTracing rpcTracing = RpcTracing.newBuilder(tracing) .serverResponseParser((res, context, span) -> { RpcResponseParser.DEFAULT.parse(res, context, span); if (res instanceof DubboResponse) { javaValue.tag((DubboResponse) res, span); } }) .build(); init().setRpcTracing(rpcTracing); String javaResult = client.get().sayHello("jorge"); assertThat(testSpanHandler.takeRemoteSpan(SERVER).tags()) .containsEntry("dubbo.result_value", javaResult); }
Example 17
Source File: MockClusterInvokerTest.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getListString.mock","force:return [\"hi\",\"hi2\"]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); List<String> rl = (List<String>)ret.getValue(); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi", rl.get(0)); }
Example 18
Source File: MockClusterInvokerTest.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getListString.mock","force:return [\"hi\",\"hi2\"]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); List<String> rl = (List<String>)ret.getValue(); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi", rl.get(0)); }
Example 19
Source File: TraceFilter.java From dubbo-samples with Apache License 2.0 | 5 votes |
@Override public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException { Result result = invoker.invoke(invocation); Object o = result.getValue(); if (o instanceof User) { User u = (User) o; u.setName("filtered: " + u.getName()); } return result; }
Example 20
Source File: MockClusterInvokerTest.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testMockInvokerFromOverride_Invoke_check_ListString(){ URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName()) .addParameter("getListString.mock","force:return [\"hi\",\"hi2\"]") .addParameter("invoke_return_error", "true" ); Invoker<IHelloService> cluster = getClusterInvoker(url); //方法配置了mock RpcInvocation invocation = new RpcInvocation(); invocation.setMethodName("getListString"); Result ret = cluster.invoke(invocation); List<String> rl = (List<String>)ret.getValue(); Assert.assertEquals(2, rl.size()); Assert.assertEquals("hi", rl.get(0)); }