Search in sources :

Example 6 with HessianProxyFactory

use of com.caucho.hessian.client.HessianProxyFactory in project tomee by apache.

the class HessianServiceTest method client.

@Test
public void client() throws MalformedURLException {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    final HessianProxyFactory clientFactory = new HessianProxyFactory(loader);
    final SerializerFactory factory = new SerializerFactory(loader);
    factory.setAllowNonSerializable(true);
    clientFactory.setSerializerFactory(factory);
    final HessianWebService client = HessianWebService.class.cast(clientFactory.create(HessianWebService.class, "http://127.0.0.1:" + port + "/HessianServiceTest/hessian/" + MyHessianWebService.class.getSimpleName()));
    final Out out = client.call(new In("test"));
    assertThat(out, instanceOf(Out.class));
    assertEquals("test", out.value);
}
Also used : SerializerFactory(com.caucho.hessian.io.SerializerFactory) HessianProxyFactory(com.caucho.hessian.client.HessianProxyFactory) Test(org.junit.Test)

Example 7 with HessianProxyFactory

use of com.caucho.hessian.client.HessianProxyFactory 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

HessianProxyFactory (com.caucho.hessian.client.HessianProxyFactory)7 SerializerFactory (com.caucho.hessian.io.SerializerFactory)3 Test (org.junit.Test)3 HessianConnectionFactory (com.caucho.hessian.client.HessianConnectionFactory)1 AuthorityException (com.netsteadfast.greenstep.base.exception.AuthorityException)1 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)1 GreenStepHessianProxyFactory (com.netsteadfast.greenstep.sys.GreenStepHessianProxyFactory)1 Annotation (java.lang.annotation.Annotation)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)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 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 Before (org.junit.Before)1