apache / apache/dubbo

Implove dubbo-rpc-http

Open
#10,159 1 comment 0 reactions 0 assignees View on GitHub
type/proposal
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

## Describe the feature

Implove dubbo-rpc-http for http , and support the https protocol , example

for mixed cloud deploy , hisroty system of the base dubbo rpc transferto public cloud, we are will take fllow architect
public cloud consumer->https://xxxxxxx-> nginx-> private dubbo http service provider
But have lot of bug , example for jackson serialize issue
follow is we fixed :
1. jsonrpc4j version update to 1.5.3 by pom dependency
2. update HttpProtocol code
3. add resources/META-INF/services/org.apache.dubbo.rpc.Protocol file and add conteht to file http=org.apache.dubbo.rpc.protocol.http.HttpsProtocol
https=org.apache.dubbo.rpc.protocol.http.HttpsProtocolco
4. changes
@SuppressWarnings("unchecked")
@Override
protected T doRefer(final Class serviceType, URL url) throws RpcException {
final String generic = url.getParameter(GENERIC_KEY);
final boolean isGeneric = ProtocolUtils.isGeneric(generic) || serviceType.equals(GenericService.class);
JsonProxyFactoryBean jsonProxyFactoryBean = new JsonProxyFactoryBean();
JsonRpcProxyFactoryBean jsonRpcProxyFactoryBean = new JsonRpcProxyFactoryBean(jsonProxyFactoryBean);
jsonRpcProxyFactoryBean.setRemoteInvocationFactory((methodInvocation) -> {
RemoteInvocation invocation = new JsonRemoteInvocation(methodInvocation);
if (isGeneric) {
invocation.addAttribute(GENERIC_KEY, generic);
}
return invocation;
});
String key = url.setProtocol("http").toIdentityString();
if (isGeneric) {
key = key + "/" + GENERIC_KEY;
}

jsonRpcProxyFactoryBean.setServiceUrl(key);
jsonRpcProxyFactoryBean.setServiceInterface(serviceType);

ObjectMapper mapper = new ObjectMapper();
//for fixed https://github.com/FasterXML/jackson/issues/106
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonProxyFactoryBean.setObjectMapper(mapper);

try {
boolean acceptGzipResponses = false;
boolean gzipRequests = false;

Map extraHttpHeaders = new HashMap<>();
// to get gizp properties heads properties
acceptGzipResponses = url.getParameter(DdkyConstants.RESPONSE_GIZP, false);
gzipRequests = url.getParameter(DdkyConstants.REQUEST_GIZP, false);

for (Entry e:url.getParameters().entrySet()) {
if (e.getKey().startsWith(DdkyConstants.HTTP_HEADER)) {
String k = e.getKey().substring(DdkyConstants.HTTP_HEADER.length());
extraHttpHeaders.put(k, e.getValue());
}
}

JsonRpcHttpClient jsonRpcHttpClient =
new JsonRpcHttpClient(mapper, new java.net.URL(jsonProxyFactoryBean.getServiceUrl()),
extraHttpHeaders,gzipRequests,acceptGzipResponses);
//jsonRpcHttpClient.setRequestListener(jsonProxyFactoryBean.get);
//jsonRpcHttpClient.setSslContext();
//jsonRpcHttpClient.setHostNameVerifier(hostNameVerifier);
String contentType = url.getParameter(DdkyConstants.HTTP_CONTENT_TYPE, "application/json-rpc");
if (contentType != null) {
jsonRpcHttpClient.setContentType(contentType);
}

// if (exceptionResolver!=null) {
// jsonRpcHttpClient.setExceptionResolver(exceptionResolver);
// }



jsonRpcHttpClient.setConnectionTimeoutMillis(url.getPositiveParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT));
jsonRpcHttpClient.setReadTimeoutMillis(url.getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT));
jsonProxyFactoryBean.setJsonRpcHttpClient(jsonRpcHttpClient);
} catch (Exception e) {
throw new RuntimeException(e);

}


jsonProxyFactoryBean.afterPropertiesSet();
return (T) jsonProxyFactoryBean.getObject();
}

Contributor guide

Open the contributing guide

Research direction

Start with the HttpProtocol code, the pom dependency, and resources/META-INF/services/org.apache.dubbo.rpc.Protocol mentioned in the issue; inspect the doRefer entry point and current HTTP/HTTPS handling. Reproduce the HTTPS mixed-cloud example and verify that the protocol is registered and requests, Jackson deserialization, gzip options, headers, and timeouts behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, distributed-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.