Describe the feature
Implove dubbo-rpc-http for http , and support the https protocol , example
<dubbo:reference version="3.0.0" id="thirdPartyProductService" interface="com.xxxxx.ThirdPartyProductService" url=" https://testdubbo.ddky.com " timeout="60000" />
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 :
- jsonrpc4j version update to 1.5.3 by pom dependency
- update HttpProtocol code
- 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 - 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<String, String> 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<String, String> 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();
}
1条答案
按热度按时间kqqjbcuj1#
would you please submit a pr to fix it?