@Override public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException{ Assert.notNull(invocation, "RemoteInvocation must not be null"); Assert.notNull(targetObject, "Target object must not be null"); return invocation.invoke(targetObject); }
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { RemoteInvocation invocation; /* package was renamed to 'org.apache.dubbo' in v2.7.0, so only provider versions after v2.7.0 can recognize org.apache.xxx.HttpRemoteInvocation'. */ if (Version.isRelease270OrHigher(url.getParameter(Constants.RELEASE_KEY))) { invocation = new HttpRemoteInvocation(methodInvocation); } else { /* The customized 'com.alibaba.dubbo.rpc.protocol.http.HttpRemoteInvocation' was firstly introduced in v2.6.3. The main purpose is to support transformation of attachments in HttpProtocol, see https://github.com/apache/incubator-dubbo/pull/1827. To guarantee interoperability with lower versions, we need to check if the provider is v2.6.3 or higher before sending customized HttpRemoteInvocation. */ if (Version.isRelease263OrHigher(url.getParameter(Constants.DUBBO_VERSION_KEY))) { invocation = new com.alibaba.dubbo.rpc.protocol.http.HttpRemoteInvocation(methodInvocation); } else { invocation = new RemoteInvocation(methodInvocation); } } if (isGeneric) { invocation.addAttribute(Constants.GENERIC_KEY, generic); } return invocation; } });
RemoteInvocation inv = new RemoteInvocation(mi); assertEquals("setName", inv.getMethodName()); assertEquals("bla", inv.getArguments()[0]); assertEquals(String.class, inv.getParameterTypes()[0]); inv = new RemoteInvocation(); inv.setArguments(new Object[] { "bla" }); assertEquals("bla", inv.getArguments()[0]); inv.setMethodName("setName"); assertEquals("setName", inv.getMethodName()); inv.setParameterTypes(new Class<?>[] {String.class}); assertEquals(String.class, inv.getParameterTypes()[0]); inv = new RemoteInvocation("setName", new Class<?>[] {String.class}, new Object[] {"bla"}); assertEquals("bla", inv.getArguments()[0]); assertEquals("setName", inv.getMethodName()); assertEquals(String.class, inv.getParameterTypes()[0]);
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { RemoteInvocation invocation = new RemoteInvocation(methodInvocation); invocation.addAttribute("myKey", "myValue"); try { invocation.addAttribute("myKey", "myValue"); fail("Should have thrown IllegalStateException"); } catch (IllegalStateException ex) { // expected: already defined } assertNotNull(invocation.getAttributes()); assertEquals(1, invocation.getAttributes().size()); assertEquals("myValue", invocation.getAttributes().get("myKey")); assertEquals("myValue", invocation.getAttribute("myKey")); return invocation; } });
@Override public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { assertNotNull(invocation.getAttributes()); assertEquals(1, invocation.getAttributes().size()); assertEquals("myValue", invocation.getAttributes().get("myKey")); assertEquals("myValue", invocation.getAttribute("myKey")); return super.invoke(invocation, targetObject); } });
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { return new RemoteInvocation(methodInvocation); }
protected Object doTransform(Object src, String encoding) throws TransformerException { if (src instanceof RemoteInvocation) { return src; } try { byte[] data = (byte[])src; ByteArrayInputStream bais = new ByteArrayInputStream(data); ObjectInputStream ois = new ObjectInputStream(bais); Object o = ois.readObject(); RemoteInvocation ri = (RemoteInvocation)o; if (logger.isDebugEnabled()) { logger.debug("request to execute " + ri.getMethodName()); for (int i = 0; i < ri.getArguments().length; i++) { Object a = ri.getArguments()[i]; logger.debug("with argument (" + a.toString() + ")"); } } return ri; } catch (Exception e) { throw new TransformerException(this, e); } }
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { RemoteInvocation invocation = new HttpRemoteInvocation(methodInvocation); if (isGeneric) { invocation.addAttribute(Constants.GENERIC_KEY, generic); } return invocation; } });
String host = (String) invocation.getAttribute(SecureRemoteInvocationFactory.HOST_KEY); if (host != null) { builder.host(host); Serializable sessionId = invocation.getAttribute(SecureRemoteInvocationFactory.SESSION_ID_KEY); if (sessionId != null) { builder.sessionId(sessionId);
protected boolean isEndSessionMethod(RemoteInvocation invocation) { Method method; try { method = getProxy().getClass().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); } catch (Exception e) { onException(invocation, e); return false; } return metadataStrategy.getMethodMetadata(method).isEndSession(); }
@Override public Object convertSendAndReceive(Object payload) throws AmqpException { Object[] arguments = ((RemoteInvocation) payload).getArguments(); if (arguments.length == 1 && arguments[0].equals("timeout")) { return null; } MessageConverter messageConverter = serviceExporter.getMessageConverter(); Address replyTo = new Address("fakeExchangeName", "fakeRoutingKey"); MessageProperties messageProperties = new MessageProperties(); messageProperties.setReplyToAddress(replyTo); Message message = messageConverter.toMessage(payload, messageProperties); serviceExporter.onMessage(message); Message resultMessage = sentSavingTemplate.getLastMessage(); return messageConverter.fromMessage(resultMessage); } };
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { return new RemoteInvocation(methodInvocation); }
if (logger.isDebugEnabled()) logger.debug("request to execute " + ri.getMethodName()); for (int i = 0; i < ri.getArguments().length; i++) Object currentArgument = ri.getArguments()[i];
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { RemoteInvocation invocation = new HttpRemoteInvocation(methodInvocation); if (isGeneric) { invocation.addAttribute(Constants.GENERIC_KEY, generic); } return invocation; } });
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { RemoteInvocation invocation = new TestRemoteInvocation(methodInvocation); assertNull(invocation.getAttributes()); assertNull(invocation.getAttribute("myKey")); return invocation; } });
@Override public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { try { CallContext ctx = (CallContext) invocation.getAttribute("callContext"); if (ctx != null) { CallContextUtil.setContext(ctx); } return super.invoke(invocation, targetObject); } finally { CallContextUtil.clear(); } }
@Override public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException{ Assert.notNull(invocation, "RemoteInvocation must not be null"); Assert.notNull(targetObject, "Target object must not be null"); return invocation.invoke(targetObject); }
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { RemoteInvocation invocation; /* package was renamed to 'org.apache.dubbo' in v2.7.0, so only provider versions after v2.7.0 can recognize org.apache.xxx.HttpRemoteInvocation'. */ if (Version.isRelease270OrHigher(url.getParameter(Constants.RELEASE_KEY))) { invocation = new HttpRemoteInvocation(methodInvocation); } else { /* The customized 'com.alibaba.dubbo.rpc.protocol.http.HttpRemoteInvocation' was firstly introduced in v2.6.3. The main purpose is to support transformation of attachments in HttpProtocol, see https://github.com/apache/incubator-dubbo/pull/1827. To guarantee interoperability with lower versions, we need to check if the provider is v2.6.3 or higher before sending customized HttpRemoteInvocation. */ if (Version.isRelease263OrHigher(url.getParameter(Constants.DUBBO_VERSION_KEY))) { invocation = new com.alibaba.dubbo.rpc.protocol.http.HttpRemoteInvocation(methodInvocation); } else { invocation = new RemoteInvocation(methodInvocation); } } if (isGeneric) { invocation.addAttribute(Constants.GENERIC_KEY, generic); } return invocation; } });
@Override public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) { return new RemoteInvocation(methodInvocation); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { RemoteInvocation remoteInvocation = getRemoteInvocationFactory().createRemoteInvocation(invocation); Object rawResult; if (getRoutingKey() == null) { // Use the template's default routing key rawResult = this.amqpTemplate.convertSendAndReceive(remoteInvocation); } else { rawResult = this.amqpTemplate.convertSendAndReceive(this.routingKey, remoteInvocation); } if (rawResult == null) { throw new RemoteProxyFailureException("No reply received from '" + remoteInvocation.getMethodName() + "' with arguments '" + Arrays.asList(remoteInvocation.getArguments()) + // NOSONAR (null) "' - perhaps a timeout in the template?", null); } else if (!(rawResult instanceof RemoteInvocationResult)) { throw new RemoteProxyFailureException("Expected a result of type " + RemoteInvocationResult.class.getCanonicalName() + " but found " + rawResult.getClass().getCanonicalName(), null); // NOSONAR (null) } RemoteInvocationResult result = (RemoteInvocationResult) rawResult; return result.recreate(); }