org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean Java Examples

The following examples show how to use org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainTest.java    From geofence with GNU General Public License v2.0 6 votes vote down vote up
public void instantiateAndRunSpringRemoting() {
    HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
    httpInvokerProxyFactoryBean.setServiceInterface(org.geoserver.geofence.services.RuleReaderService.class);
    httpInvokerProxyFactoryBean.setServiceUrl("http://localhost:9191/geofence/remoting/RuleReader");
    httpInvokerProxyFactoryBean.afterPropertiesSet();
    RuleReaderService rrs = (RuleReaderService) httpInvokerProxyFactoryBean.getObject();

    RuleFilter filter1 = new RuleFilter(SpecialFilterType.DEFAULT, true)
            .setUser("pippo")
            .setInstance("gs1")
            .setService("WMS");
    AccessInfo accessInfo = rrs.getAccessInfo(filter1);
    LOGGER.info(accessInfo);

    RuleFilter filter2 = new RuleFilter(SpecialFilterType.DEFAULT, true)
            .setUser("pippo")
            .setInstance("gs1")
            .setService("WCS");
    AccessInfo accessInfo2 = rrs.getAccessInfo(filter2);
    LOGGER.info(accessInfo2);
}
 
Example #2
Source File: SpitterConfig.java    From Project with Apache License 2.0 5 votes vote down vote up
@Bean
public HttpInvokerProxyFactoryBean spitterService() {
	HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
	proxy.setServiceUrl("http://localhost:8110/springiA4_15_httpinvoker/spitter.service");
	proxy.setServiceInterface(SpitterService.class);
	return proxy;
}
 
Example #3
Source File: HttpInvokerClientConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public UserService userService() {
    final HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
    factoryBean.setServiceInterface(UserService.class);
    factoryBean.setServiceUrl("http://localhost:8080/invoker/httpInvoker/userService");
    factoryBean.afterPropertiesSet();
    return (UserService) factoryBean.getObject();
}
 
Example #4
Source File: HttpInvokerClientConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean
public UserService userService() {
    final HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
    factoryBean.setServiceInterface(UserService.class);
    factoryBean.setServiceUrl("http://localhost:8080/invoker/httpInvoker/userService");
    factoryBean.afterPropertiesSet();
    return (UserService) factoryBean.getObject();
}
 
Example #5
Source File: RemoteClientBuilder.java    From seed with Apache License 2.0 4 votes vote down vote up
/**
 * 创建远程服务的客户端实例
 * @param serviceInterface 远程服务接口的Class
 * @param serviceUrl       远程服务接口的地址,若传入'${host.ifs}'则会从系统变量中取值
 */
public <T> T build(Class<T> serviceInterface, String serviceUrl) {
    Object value;
    synchronized(this.clientMap){
        //获取含包名的类名字符串
        //serviceInterface.getName()得到的结果就是:com.jadyer.service.IFSService
        //serviceInterface.getSimpleName()得到的结果就是:IFSService
        String key = serviceInterface.getName();
        //从缓存中获取@RemoteClient的实例
        value = this.clientMap.get(key);
        if(null == value){
            //计算URL(主要处理入参为'${}'形式的url,把它替换成环境变量里面配置的值)
            serviceUrl = serviceUrl.trim();
            if(serviceUrl.startsWith("${") && serviceUrl.endsWith("}")){
                serviceUrl = serviceUrl.substring(2, serviceUrl.length()-1);
                serviceUrl = this.environment.getProperty(serviceUrl);
            }
            //补全URL(得到的结果比如:http://1.1.1.1/remoting/IFSService)
            //这里的'remoting'和'IFSService'都是@RemoteService注解的属性值
            //'remoting'和'IFSService'的拼接方式是由服务端的RemoteServiceScannerRegistrar.java决定的
            String name = serviceInterface.getSimpleName();
            if(!serviceUrl.endsWith(name)){
                if(serviceUrl.endsWith("/")){
                    serviceUrl = serviceUrl + name;
                }else{
                    serviceUrl = serviceUrl + "/" + name;
                }
            }
            //访问RMI服务时,需要声明一个指向服务的RmiProxyFactoryBean
            //访问Burlap服务时,需要声明一个指向服务的BurlapProxyFactoryBean
            //访问Hessian服务时,需要声明一个指向服务的HessianProxyFactoryBean
            //同样,访问httpinvoker服务时,也需要声明一个指向服务的HttpInvokerProxyFactoryBean,它用来代理所公开的服务
            HttpInvokerProxyFactoryBean factory = new HttpInvokerProxyFactoryBean();
            factory.setServiceUrl(serviceUrl);
            factory.setServiceInterface(serviceInterface);
            //默认情况下,HttpInvokerPropxy会使用Simple模式(JavaSE标准API)
            //可以通过设置setHttpInvokerRequestExecutor()属性来使用HttpComponents
            factory.setHttpInvokerRequestExecutor(this.getHttpInvokerRequestExecutor());
            factory.afterPropertiesSet();
            value = factory.getObject();
            //缓存@RemoteClient的实例
            this.clientMap.put(key, value);
        }else{
            System.out.println("Build remote client class:" + serviceInterface.getName() + " from cache");
        }
    }
    //noinspection unchecked
    return (T) value;
}