Java Code Examples for com.alipay.sofa.rpc.core.request.SofaRequest#getMethodArgSigs()
The following examples show how to use
com.alipay.sofa.rpc.core.request.SofaRequest#getMethodArgSigs() .
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: SofaRpcUtils.java From Sentinel with Apache License 2.0 | 6 votes |
public static String getMethodResourceName(SofaRequest request) { StringBuilder buf = new StringBuilder(64); buf.append(request.getInterfaceName()) .append("#") .append(request.getMethodName()) .append("("); boolean isFirst = true; for (String methodArgSig : request.getMethodArgSigs()) { if (!isFirst) { buf.append(","); } else { isFirst = false; } buf.append(methodArgSig); } buf.append(")"); return buf.toString(); }
Example 2
Source File: RestClientTransport.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override protected Method getMethod(SofaRequest request) throws SofaRpcException { String serviceUniqueName = request.getTargetServiceUniqueName(); String methodName = request.getMethodName(); String[] methodSigns = request.getMethodArgSigs(); Method method = ReflectCache.getOverloadMethodCache(serviceUniqueName, methodName, methodSigns); if (method == null) { try { String interfaceName = request.getInterfaceName(); method = ClassUtils.forName(interfaceName) .getMethod(methodName, ClassTypeUtils.getClasses(methodSigns)); ReflectCache.putOverloadMethodCache(serviceUniqueName, method); } catch (NoSuchMethodException e) { throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR, "Method not found", e); } } return method; }
Example 3
Source File: SofaRpcProviderInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
/** * Format operation name. e.g. org.apache.skywalking.apm.plugin.test.Test.test(String) * * @return operation name. */ private String generateViewPoint(SofaRequest sofaRequest) { StringBuilder operationName = new StringBuilder(); operationName.append(sofaRequest.getInterfaceName()); operationName.append("." + sofaRequest.getMethodName() + "("); for (String arg : sofaRequest.getMethodArgSigs()) { operationName.append(arg + ","); } if (sofaRequest.getMethodArgs().length > 0) { operationName.delete(operationName.length() - 1, operationName.length()); } operationName.append(")"); return operationName.toString(); }
Example 4
Source File: SofaRpcConsumerInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
/** * Format operation name. e.g. org.apache.skywalking.apm.plugin.test.Test.test(String) * * @return operation name. */ private String generateOperationName(ProviderInfo providerInfo, SofaRequest sofaRequest) { StringBuilder operationName = new StringBuilder(); operationName.append(sofaRequest.getInterfaceName()); operationName.append("." + sofaRequest.getMethodName() + "("); for (String arg : sofaRequest.getMethodArgSigs()) { operationName.append(arg + ","); } if (sofaRequest.getMethodArgs().length > 0) { operationName.delete(operationName.length() - 1, operationName.length()); } operationName.append(")"); return operationName.toString(); }
Example 5
Source File: SofaRequestHessianSerializer.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void decodeObjectByTemplate(AbstractByteBuf data, Map<String, String> context, SofaRequest template) throws SofaRpcException { try { UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(data.array()); Hessian2Input input = new Hessian2Input(inputStream); input.setSerializerFactory(serializerFactory); Object object = input.readObject(); SofaRequest tmp = (SofaRequest) object; String targetServiceName = tmp.getTargetServiceUniqueName(); if (targetServiceName == null) { throw buildDeserializeError("Target service name of request is null!"); } // copy values to template template.setMethodName(tmp.getMethodName()); template.setMethodArgSigs(tmp.getMethodArgSigs()); template.setTargetServiceUniqueName(tmp.getTargetServiceUniqueName()); template.setTargetAppName(tmp.getTargetAppName()); template.addRequestProps(tmp.getRequestProps()); String interfaceName = ConfigUniqueNameGenerator.getInterfaceName(targetServiceName); template.setInterfaceName(interfaceName); // decode args String[] sig = template.getMethodArgSigs(); Class<?>[] classSig = ClassTypeUtils.getClasses(sig); final Object[] args = new Object[sig.length]; for (int i = 0; i < template.getMethodArgSigs().length; ++i) { args[i] = input.readObject(classSig[i]); } template.setMethodArgs(args); input.close(); } catch (IOException e) { throw buildDeserializeError(e.getMessage(), e); } }
Example 6
Source File: SofaRequestHessianSerializer.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public SofaRequest decodeObject(AbstractByteBuf data, Map<String, String> context) throws SofaRpcException { try { UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(data.array()); Hessian2Input input = new Hessian2Input(inputStream); input.setSerializerFactory(serializerFactory); Object object = input.readObject(); SofaRequest sofaRequest = (SofaRequest) object; String targetServiceName = sofaRequest.getTargetServiceUniqueName(); if (targetServiceName == null) { throw buildDeserializeError("Target service name of request is null!"); } String interfaceName = ConfigUniqueNameGenerator.getInterfaceName(targetServiceName); sofaRequest.setInterfaceName(interfaceName); String[] sig = sofaRequest.getMethodArgSigs(); Class<?>[] classSig = ClassTypeUtils.getClasses(sig); final Object[] args = new Object[sig.length]; for (int i = 0; i < sofaRequest.getMethodArgSigs().length; ++i) { args[i] = input.readObject(classSig[i]); } sofaRequest.setMethodArgs(args); input.close(); return sofaRequest; } catch (IOException e) { throw buildDeserializeError(e.getMessage(), e); } }
Example 7
Source File: ComplexTestMix.java From sofa-hessian with Apache License 2.0 | 4 votes |
@Test public void testSofaRequest() throws IOException { SofaRequest request = dg.generateSofaRequest(); // serialization uses GenericHessian ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); output.setSerializerFactory(new GenericSerializerFactory()); output.writeObject(request); final Object[] args = request.getMethodArgs(); if (args != null) { for (int i = 0; i < args.length; i++) { output.writeObject(args[i]); } } output.close(); byteArray.close(); // deserialization uses Hessian byte[] body = byteArray.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); SofaRequest deRequest = (SofaRequest) hin.readObject(); String[] sig = deRequest.getMethodArgSigs(); Class<?>[] classSig = new Class[sig.length]; final Object[] deArgs = new Object[sig.length]; for (int i = 0; i < deRequest.getMethodArgSigs().length; ++i) { deArgs[i] = hin.readObject(classSig[i]); } deRequest.setMethodArgs(deArgs); bin.close(); hin.close(); assertEquals(request.getTargetServiceUniqueName(), deRequest.getTargetServiceUniqueName()); assertEquals(request.getMethodName(), deRequest.getMethodName()); assertEquals(request.getTargetAppName(), deRequest.getTargetAppName()); assertEquals(request.getRequestProps(), deRequest.getRequestProps()); // 1st argument is a Person, and 2nd argument is an int cmpGPersonEqualPerson((GenericObject) request.getMethodArgs()[0], (Person) deRequest.getMethodArgs()[0]); assertEquals(request.getMethodArgs()[1], deRequest.getMethodArgs()[1]); }