Java Code Examples for com.alipay.sofa.rpc.core.request.SofaRequest#getRequestProps()

The following examples show how to use com.alipay.sofa.rpc.core.request.SofaRequest#getRequestProps() . 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 vote down vote up
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: SofaRpcSerialization.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
protected void putRequestMetadataToHeader(Object requestObject, Map<String, String> header) {
    if (requestObject instanceof RequestBase) {
        RequestBase requestBase = (RequestBase) requestObject;
        header.put(RemotingConstants.HEAD_METHOD_NAME, requestBase.getMethodName());
        header.put(RemotingConstants.HEAD_TARGET_SERVICE, requestBase.getTargetServiceUniqueName());

        if (requestBase instanceof SofaRequest) {
            SofaRequest sofaRequest = (SofaRequest) requestBase;
            header.put(RemotingConstants.HEAD_TARGET_APP, sofaRequest.getTargetAppName());
            Map<String, Object> requestProps = sofaRequest.getRequestProps();
            if (requestProps != null) {
                // <String, Object> 转扁平化 <String, String>
                CodecUtils.flatCopyTo("", requestProps, header);
            }
        }
    }
}