use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class AccessKeyAuthenticatorTest method testAuthenticateRequestNoSignature.
@Test
void testAuthenticateRequestNoSignature() {
URL url = URL.valueOf("dubbo://10.10.10.10:2181").addParameter(Constants.ACCESS_KEY_ID_KEY, "ak").addParameter(CommonConstants.APPLICATION_KEY, "test").addParameter(Constants.SECRET_ACCESS_KEY_KEY, "sk");
Invocation invocation = new RpcInvocation();
AccessKeyAuthenticator helper = new AccessKeyAuthenticator();
assertThrows(RpcAuthenticationException.class, () -> helper.authenticate(invocation, url));
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class AccessKeyAuthenticatorTest method testGetSignatureNoParameter.
@Test
void testGetSignatureNoParameter() {
URL url = mock(URL.class);
Invocation invocation = mock(Invocation.class);
String secretKey = "123456";
AccessKeyAuthenticator helper = new AccessKeyAuthenticator();
String signature = helper.getSignature(url, invocation, secretKey, String.valueOf(System.currentTimeMillis()));
assertNotNull(signature);
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class ConsumerSignFilterTest method testAuthDisabled.
@Test
void testAuthDisabled() {
URL url = mock(URL.class);
Invoker invoker = mock(Invoker.class);
Invocation invocation = mock(Invocation.class);
when(invoker.getUrl()).thenReturn(url);
ConsumerSignFilter consumerSignFilter = new ConsumerSignFilter();
consumerSignFilter.invoke(invoker, invocation);
verify(invocation, never()).setAttachment(eq(Constants.REQUEST_SIGNATURE_KEY), anyString());
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class DubboCodecSupport method getResponseSerialization.
public static Serialization getResponseSerialization(URL url, AppResponse appResponse) {
Object invocationObj = appResponse.getAttribute(INVOCATION_KEY);
if (invocationObj != null) {
Invocation invocation = (Invocation) invocationObj;
Object serializationTypeObj = invocation.get(SERIALIZATION_ID_KEY);
if (serializationTypeObj != null) {
return CodecSupport.getSerializationById((byte) serializationTypeObj);
}
}
return ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(url.getParameter(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION));
}
use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.
the class RpcUtilsTest method testIsAsync.
@Test
public void testIsAsync() {
Object[] args = new Object[] { "hello", "dubbo", 520 };
Class<?> demoServiceClass = DemoService.class;
String serviceName = demoServiceClass.getName();
Invoker invoker = mock(Invoker.class);
URL url = URL.valueOf("test://127.0.0.1:1/org.apache.dubbo.rpc.support.DemoService?interface=org.apache.dubbo.rpc.support.DemoService");
RpcInvocation inv = new RpcInvocation("test", serviceName, "", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "method", new String[] {}, args }, null, invoker, null);
Assertions.assertFalse(RpcUtils.isAsync(url, inv));
inv.setInvokeMode(InvokeMode.ASYNC);
Assertions.assertTrue(RpcUtils.isAsync(url, inv));
URL url1 = URL.valueOf("dubbo://localhost/?test.async=true");
Invocation inv1 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv1.setAttachment("test." + ASYNC_KEY, Boolean.FALSE.toString());
Assertions.assertFalse(RpcUtils.isAsync(url1, inv1));
URL url2 = URL.valueOf("dubbo://localhost/?test.async=true");
Invocation inv2 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv2.setAttachment(ASYNC_KEY, Boolean.FALSE.toString());
Assertions.assertFalse(RpcUtils.isAsync(url2, inv2));
URL url3 = URL.valueOf("dubbo://localhost/?test");
Invocation inv3 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv3.setAttachment(ASYNC_KEY, Boolean.TRUE.toString());
Assertions.assertTrue(RpcUtils.isAsync(url3, inv3));
URL url4 = URL.valueOf("dubbo://localhost/?test.async=true");
Invocation inv4 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
Assertions.assertTrue(RpcUtils.isAsync(url4, inv4));
URL url5 = URL.valueOf("dubbo://localhost/?test");
Invocation inv5 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
Assertions.assertFalse(RpcUtils.isAsync(url5, inv5));
URL url6 = URL.valueOf("dubbo://localhost/?test");
Invocation inv6 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv6.setAttachment("test." + ASYNC_KEY, Boolean.TRUE.toString());
Assertions.assertTrue(RpcUtils.isAsync(url6, inv6));
URL url7 = URL.valueOf("dubbo://localhost/?test.async=true&async=false");
Invocation inv7 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
Assertions.assertTrue(RpcUtils.isAsync(url7, inv7));
URL url8 = URL.valueOf("dubbo://localhost/?test.async=false&async=true");
Invocation inv8 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
Assertions.assertFalse(RpcUtils.isAsync(url8, inv8));
URL url9 = URL.valueOf("dubbo://localhost/?test.async=true");
Invocation inv9 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv9.setAttachment("testB." + ASYNC_KEY, Boolean.FALSE.toString());
Assertions.assertTrue(RpcUtils.isAsync(url9, inv9));
URL url10 = URL.valueOf("dubbo://localhost/?test.async=true");
Invocation inv10 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
((RpcInvocation) inv10).setInvokeMode(InvokeMode.ASYNC);
Assertions.assertTrue(RpcUtils.isAsync(url10, inv9));
}
Aggregations