@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { final RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); /* RMI needs extra parameter since it uses customized remote invocation object The customized RemoteInvocation was firstly introduced in v2.6.3; The package was renamed to 'org.apache.*' since v2.7.0 Considering the above two conditions, we need to check before sending customized RemoteInvocation: 1. if the provider version is v2.7.0 or higher, send 'org.apache.dubbo.rpc.protocol.rmi.RmiRemoteInvocation'. 2. if the provider version is v2.6.3 or higher, send 'com.alibaba.dubbo.rpc.protocol.rmi.RmiRemoteInvocation'. 3. if the provider version is lower than v2.6.3, does not use customized RemoteInvocation. */ if (isRelease270OrHigher(url.getParameter(Constants.RELEASE_KEY))) { rmiProxyFactoryBean.setRemoteInvocationFactory(RmiRemoteInvocation::new); } else if (isRelease263OrHigher(url.getParameter(Constants.DUBBO_VERSION_KEY))) { rmiProxyFactoryBean.setRemoteInvocationFactory(com.alibaba.dubbo.rpc.protocol.rmi.RmiRemoteInvocation::new); } rmiProxyFactoryBean.setServiceUrl(url.toIdentityString()); rmiProxyFactoryBean.setServiceInterface(serviceType); rmiProxyFactoryBean.setCacheStub(true); rmiProxyFactoryBean.setLookupStubOnStartup(true); rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true); rmiProxyFactoryBean.afterPropertiesSet(); return (T) rmiProxyFactoryBean.getObject(); }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(getBeanClassLoader()); }
@Override protected <T> T createService(ConnectionDescriptor connectionDescriptor, Class<T> serviceInterface, String serviceId, boolean stateful) { final RmiProxyFactoryBean proxyFactoryBean = new RmiProxyFactoryBean(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); proxyFactoryBean.setBeanClassLoader(classLoader); proxyFactoryBean.setServiceInterface(serviceInterface); proxyFactoryBean.setLookupStubOnStartup(true); proxyFactoryBean.setServiceUrl(connectionDescriptor.getLocation().toString()); proxyFactoryBean.afterPropertiesSet(); @SuppressWarnings("unchecked") final T service = clientInterceptorUtil.addHttpInterceptors((T) proxyFactoryBean.getObject(), connectionDescriptor); return service; } }
@Bean RmiProxyFactoryBean userService(@Value("${rmi.server.host:0.0.0.0}") final String rmiServerHost) { final RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); rmiProxyFactoryBean.setServiceUrl(format("rmi://%s:1199/UserService", rmiServerHost)); rmiProxyFactoryBean.setServiceInterface(UserService.class); rmiProxyFactoryBean.setLookupStubOnStartup(false); // fail safe on startup return rmiProxyFactoryBean; }
logger.debug("postInvoke:" + bean.getServiceUrl()); bean.afterPropertiesSet(); T service = (T) bean.getObject(); return method.invoke(service, args); }catch(RemoteConnectFailureException e){
@Override public Class<?> getObjectType() { return getServiceInterface(); }
@Override public Class<?> getObjectType() { return getServiceInterface(); }
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { final RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); /* RMI needs extra parameter since it uses customized remote invocation object The customized RemoteInvocation was firstly introduced in v2.6.3; The package was renamed to 'org.apache.*' since v2.7.0 Considering the above two conditions, we need to check before sending customized RemoteInvocation: 1. if the provider version is v2.7.0 or higher, send 'org.apache.dubbo.rpc.protocol.rmi.RmiRemoteInvocation'. 2. if the provider version is v2.6.3 or higher, send 'com.alibaba.dubbo.rpc.protocol.rmi.RmiRemoteInvocation'. 3. if the provider version is lower than v2.6.3, does not use customized RemoteInvocation. */ if (isRelease270OrHigher(url.getParameter(Constants.RELEASE_KEY))) { rmiProxyFactoryBean.setRemoteInvocationFactory(RmiRemoteInvocation::new); } else if (isRelease263OrHigher(url.getParameter(Constants.DUBBO_VERSION_KEY))) { rmiProxyFactoryBean.setRemoteInvocationFactory(com.alibaba.dubbo.rpc.protocol.rmi.RmiRemoteInvocation::new); } rmiProxyFactoryBean.setServiceUrl(url.toIdentityString()); rmiProxyFactoryBean.setServiceInterface(serviceType); rmiProxyFactoryBean.setCacheStub(true); rmiProxyFactoryBean.setLookupStubOnStartup(true); rmiProxyFactoryBean.setRefreshStubOnConnectFailure(true); rmiProxyFactoryBean.afterPropertiesSet(); return (T) rmiProxyFactoryBean.getObject(); }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(getBeanClassLoader()); }
@Override public Class<?> getObjectType() { return getServiceInterface(); }
factory.setServiceInterface(IBusinessBean.class); factory.setServiceUrl(serviceUrl); factory.afterPropertiesSet(); IBusinessBean proxy = (IBusinessBean) factory.getObject();
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); Class<?> ifc = getServiceInterface(); Assert.notNull(ifc, "Property 'serviceInterface' is required"); this.serviceProxy = new ProxyFactory(ifc, this).getProxy(getBeanClassLoader()); }
@SuppressWarnings("unchecked") @Override public Class getServiceInterface() { try { return Class.forName(clazz.getName()); } catch (ClassNotFoundException e) { //logger.error("远程调用错误ClassNotFoundException", e); } return super.getServiceInterface(); }
@Bean public DataManipulationService dataManipulationService() { RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); rmiProxyFactoryBean.setServiceUrl("rmi://127.0.0.1:1199/DataManipulationService"); rmiProxyFactoryBean.setServiceInterface(DataManipulationService.class); rmiProxyFactoryBean.afterPropertiesSet(); return (DataManipulationService) rmiProxyFactoryBean.getObject(); }
@Bean public GlobalConfigurationManagementService globalConfigurationManagementService() { RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); rmiProxyFactoryBean.setServiceUrl("rmi://127.0.0.1:1199/GlobalConfigurationManagementService"); rmiProxyFactoryBean.setServiceInterface(GlobalConfigurationManagementService.class); rmiProxyFactoryBean.afterPropertiesSet(); return (GlobalConfigurationManagementService) rmiProxyFactoryBean.getObject(); }
private RequestReplyExchanger createProxy(String url) { RmiProxyFactoryBean proxyFactory = new RmiProxyFactoryBean(); proxyFactory.setServiceInterface(RequestReplyExchanger.class); proxyFactory.setServiceUrl(url); proxyFactory.setLookupStubOnStartup(false); proxyFactory.setRefreshStubOnConnectFailure(true); if (this.configurer != null) { this.configurer.configure(proxyFactory); } proxyFactory.afterPropertiesSet(); return (RequestReplyExchanger) proxyFactory.getObject(); }
@Bean public RemoteJco jcoPool(){ RmiProxyFactoryBean jcoPool = new RmiProxyFactoryBean(); jcoPool.setServiceUrl("rmi://localhost/CH"); jcoPool.setServiceInterface(RemoteJco.class); jcoPool.setRefreshStubOnConnectFailure(true); jcoPool.afterPropertiesSet(); return (RemoteJco) jcoPool.getObject(); }
public class RMIConnectionService { public DeviceService connect(String serverUrl) { RmiProxyFactoryBean factory = new RmiProxyFactoryBean(); factory.setServiceInterface(DeviceService.class); factory.setServiceUrl("rmi://" + serverUrl + ":1099/SERVICE_URL"); factory.afterPropertiesSet(); //... return (DeviceService) factory.getObject(); } }
@Bean public BarService createBarServiceLink() { RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean(); rmiProxyFactoryBean.setServiceUrl("rmi://localhost:5000/BarService"); rmiProxyFactoryBean.setServiceInterface(BarService.class); rmiProxyFactoryBean.afterPropertiesSet(); return (BarService) rmiProxyFactoryBean.getObject(); }
String serverHost = "www.example.com"; RmiProxyFactoryBean factory = new RmiProxyFactoryBean(); factory.setServiceUrl("rmi://" + serverHost + ":80/MyService"); factory.setServiceInterface(MyService.class); try { factory.afterPropertiesSet(); } catch (Exception e) { throw new RuntimeException( "Problem initializing myService factory", e); } MyService myService = (MyService) factory.getObject();