Search in sources :

Example 1 with DEFAULT_HESSIAN2_REQUEST

use of org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HESSIAN2_REQUEST in project dubbo by alibaba.

the class HessianProtocol method doRefer.

@Override
@SuppressWarnings("unchecked")
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
    String generic = url.getParameter(GENERIC_KEY);
    boolean isGeneric = ProtocolUtils.isGeneric(generic) || serviceType.equals(GenericService.class);
    if (isGeneric) {
        RpcContext.getContext().setAttachment(GENERIC_KEY, generic);
        url = url.setPath(url.getPath() + "/" + GENERIC_KEY);
    }
    HessianProxyFactory hessianProxyFactory = new HessianProxyFactory();
    boolean isHessian2Request = url.getParameter(HESSIAN2_REQUEST_KEY, DEFAULT_HESSIAN2_REQUEST);
    hessianProxyFactory.setHessian2Request(isHessian2Request);
    boolean isOverloadEnabled = url.getParameter(HESSIAN_OVERLOAD_METHOD_KEY, DEFAULT_HESSIAN_OVERLOAD_METHOD);
    hessianProxyFactory.setOverloadEnabled(isOverloadEnabled);
    String client = url.getParameter(CLIENT_KEY, DEFAULT_HTTP_CLIENT);
    if ("httpclient".equals(client)) {
        HessianConnectionFactory factory = new HttpClientConnectionFactory();
        factory.setHessianProxyFactory(hessianProxyFactory);
        hessianProxyFactory.setConnectionFactory(factory);
    } else if (client != null && client.length() > 0 && !DEFAULT_HTTP_CLIENT.equals(client)) {
        throw new IllegalStateException("Unsupported http protocol client=\"" + client + "\"!");
    } else {
        HessianConnectionFactory factory = new DubboHessianURLConnectionFactory();
        factory.setHessianProxyFactory(hessianProxyFactory);
        hessianProxyFactory.setConnectionFactory(factory);
    }
    int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
    hessianProxyFactory.setConnectTimeout(timeout);
    hessianProxyFactory.setReadTimeout(timeout);
    hessianProxyFactory.setSerializerFactory(Hessian2FactoryInitializer.getInstance().getSerializerFactory());
    return (T) hessianProxyFactory.create(serviceType, url.setProtocol("http").toJavaURL(), Thread.currentThread().getContextClassLoader());
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) DEFAULT_HESSIAN2_REQUEST(org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HESSIAN2_REQUEST) DEFAULT_HTTP_CLIENT(org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HTTP_CLIENT) DEFAULT_TIMEOUT(org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT) HessianProxyFactory(com.caucho.hessian.client.HessianProxyFactory) HessianConnectionFactory(com.caucho.hessian.client.HessianConnectionFactory)

Aggregations

HessianConnectionFactory (com.caucho.hessian.client.HessianConnectionFactory)1 HessianProxyFactory (com.caucho.hessian.client.HessianProxyFactory)1 DEFAULT_TIMEOUT (org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT)1 DEFAULT_HESSIAN2_REQUEST (org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HESSIAN2_REQUEST)1 DEFAULT_HTTP_CLIENT (org.apache.dubbo.rpc.protocol.hessian.Constants.DEFAULT_HTTP_CLIENT)1 GenericService (org.apache.dubbo.rpc.service.GenericService)1