Java Code Examples for com.alipay.sofa.rpc.core.request.SofaRequest#getTargetServiceUniqueName()
The following examples show how to use
com.alipay.sofa.rpc.core.request.SofaRequest#getTargetServiceUniqueName() .
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: AbstractHttp2ClientTransport.java From sofa-rpc with Apache License 2.0 | 6 votes |
protected FullHttpRequest convertToHttpRequest(SofaRequest request) { HttpScheme scheme = SslContextBuilder.SSL ? HttpScheme.HTTPS : HttpScheme.HTTP; AsciiString hostName = new AsciiString(providerInfo.getHost() + ':' + providerInfo.getPort()); String url = "/" + request.getTargetServiceUniqueName() + "/" + request.getMethodName(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("send request to url :{}", url); } // Create a simple POST request with a body. FullHttpRequest httpRequest = new DefaultFullHttpRequest(HTTP_1_1, POST, url, wrappedBuffer(request.getData().array())); HttpHeaders headers = httpRequest.headers(); addToHeader(headers, HttpHeaderNames.HOST, hostName); addToHeader(headers, HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), scheme.name()); addToHeader(headers, HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP); addToHeader(headers, HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.DEFLATE); addToHeader(headers, RemotingConstants.HEAD_SERIALIZE_TYPE, SerializerFactory.getAliasByCode(request.getSerializeType())); addToHeader(headers, RemotingConstants.HEAD_TARGET_APP, request.getTargetAppName()); Map<String, Object> requestProps = request.getRequestProps(); if (requestProps != null) { // <String, Object> 转扁平化 <String, String> flatCopyTo("", requestProps, headers); } return httpRequest; }
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: LookoutSubscriber.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * create RpcClientLookoutModel * @param request * @param response * @return */ private RpcClientLookoutModel createClientMetricsModel(SofaRequest request, SofaResponse response) { RpcClientLookoutModel clientMetricsModel = new RpcClientLookoutModel(); RpcInternalContext context = RpcInternalContext.getContext(); String app = getStringAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_APP_NAME)); String service = request.getTargetServiceUniqueName(); String method = request.getMethodName(); String protocol = getStringAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_PROTOCOL_NAME)); String invokeType = request.getInvokeType(); String targetApp = request.getTargetAppName(); Long requestSize = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE)); Long responseSize = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE)); Long elapsedTime = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_CLIENT_ELAPSE)); Boolean success = response != null && !response.isError() && response.getErrorMsg() == null && (!(response.getAppResponse() instanceof Throwable)); clientMetricsModel.setApp(app); clientMetricsModel.setService(service); clientMetricsModel.setMethod(method); clientMetricsModel.setProtocol(protocol); clientMetricsModel.setInvokeType(invokeType); clientMetricsModel.setTargetApp(targetApp); clientMetricsModel.setRequestSize(requestSize); clientMetricsModel.setResponseSize(responseSize); clientMetricsModel.setElapsedTime(elapsedTime); clientMetricsModel.setSuccess(success); return clientMetricsModel; }
Example 4
Source File: LookoutSubscriber.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * create RpcServerLookoutModel * @param request * @param response * @return */ private RpcServerLookoutModel createServerMetricsModel(SofaRequest request, SofaResponse response) { RpcServerLookoutModel rpcServerMetricsModel = new RpcServerLookoutModel(); RpcInternalContext context = RpcInternalContext.getContext(); String app = request.getTargetAppName(); String service = request.getTargetServiceUniqueName(); String method = request.getMethodName(); String protocol = getStringAvoidNull(request.getRequestProp(RemotingConstants.HEAD_PROTOCOL)); String invokeType = request.getInvokeType(); String callerApp = getStringAvoidNull(request.getRequestProp(RemotingConstants.HEAD_APP_NAME)); Long elapsedTime = getLongAvoidNull(context.getAttachment(RpcConstants.INTERNAL_KEY_IMPL_ELAPSE)); boolean success = response != null && !response.isError() && response.getErrorMsg() == null && (!(response.getAppResponse() instanceof Throwable)); rpcServerMetricsModel.setApp(app); rpcServerMetricsModel.setService(service); rpcServerMetricsModel.setMethod(method); rpcServerMetricsModel.setProtocol(protocol); rpcServerMetricsModel.setInvokeType(invokeType); rpcServerMetricsModel.setCallerApp(callerApp); rpcServerMetricsModel.setElapsedTime(elapsedTime); rpcServerMetricsModel.setSuccess(success); return rpcServerMetricsModel; }
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: TestSyncFilter.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public SofaResponse invoke(FilterInvoker invoker, SofaRequest request) throws SofaRpcException { interfaceName = request.getInterfaceName(); targetServiceUniqueName = request.getTargetServiceUniqueName(); methodName = request.getMethodName(); invokeType = request.getInvokeType(); targetAppName = request.getTargetAppName(); args = request.getMethodArgs(); return invoker.invoke(request); }