Search in sources :

Example 1 with JsonProxyFactoryBean

use of com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean in project dubbo by alibaba.

the class HttpProtocol method doRefer.

@SuppressWarnings("unchecked")
@Override
protected <T> T doRefer(final Class<T> 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);
    jsonProxyFactoryBean.afterPropertiesSet();
    return (T) jsonProxyFactoryBean.getObject();
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) GenericService(org.apache.dubbo.rpc.service.GenericService) JsonProxyFactoryBean(com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean)

Aggregations

JsonProxyFactoryBean (com.googlecode.jsonrpc4j.spring.JsonProxyFactoryBean)1 GenericService (org.apache.dubbo.rpc.service.GenericService)1 RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)1