CdmApplicationRemoteConfiguration : removed spring bean name hack, since we now have...
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 4 Apr 2014 09:27:04 +0000 (09:27 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 4 Apr 2014 09:27:04 +0000 (09:27 +0000)
CdmApplicationRemoteController : new Controller class to handle remoting
AbstractLazyInitializer / AbstractPersistentCollection : added missing methods to check if proxy object is initialized
CdmRemoteSourceTest : Added new test class to test the CDM Remote Source
httpInvokerServiceClients.xml : added primer service

.gitattributes
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteConfiguration.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/httpInvokerServiceClients.xml
eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmRemoteSourceTest.java [new file with mode: 0644]

index 90414ee75dc1cf47cb600431c812bb0c062ad9cd..6efc31dd4781a6f8cfd64f00cf3bebf58ec392fc 100644 (file)
@@ -319,6 +319,7 @@ eu.etaxonomy.taxeditor.cdmlib/lib/xstream-1.4.4.jar -text
 eu.etaxonomy.taxeditor.cdmlib/lib/yjp-controller-api-redist-9.0.8.jar -text
 eu.etaxonomy.taxeditor.cdmlib/pom.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteConfiguration.java -text
+eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/lazyloading/CdmLazyLoader.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java -text
@@ -328,6 +329,7 @@ eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/localApplicati
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_persistence_security.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_services_security.xml -text
+eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmRemoteSourceTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteLazyLoadingTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemotePersistentCollectionTest.java -text
index 8eccee824f628d72509228d00dcb7e2e6fd61416..690972c10e43cd93515da517235275b1f14c89a2 100644 (file)
@@ -36,7 +36,7 @@ import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
  */\r
 // FIXME:Remoting This bean naming is a hack to make remoting work, in conjunction with the\r
 // exclude filter in the application package set in the remotingApplicationContext \r
-@Component("cdmApplicationDefaultConfiguration")\r
+//@Component("cdmApplicationDefaultConfiguration")\r
 public class CdmApplicationRemoteConfiguration extends CdmApplicationDefaultConfiguration {\r
        \r
        @SuppressWarnings("unused")\r
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java
new file mode 100644 (file)
index 0000000..20f7ed7
--- /dev/null
@@ -0,0 +1,138 @@
+package eu.etaxonomy.cdm.api.application;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
+import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor;
+import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor;
+import eu.etaxonomy.cdm.remote.ICdmRemoteSource;
+
+public class CdmApplicationRemoteController  extends CdmApplicationController {
+       
+    private static final Logger logger = Logger.getLogger(CdmApplicationRemoteController.class);
+
+    public static final String DEFAULT_APPLICATION_CONTEXT_RESOURCE = "/eu/etaxonomy/cdm/remoteApplicationContext.xml";
+    private final Resource applicationContextResource;
+    private final IProgressMonitor progressMonitor;
+    
+    public static CdmApplicationRemoteController NewInstance(Resource applicationContextResource, 
+                       ICdmRemoteSource remoteSource,                          
+                       boolean omitTermLoading, 
+                       IProgressMonitor progressMonitor, 
+                       List<ApplicationListener> listeners) {
+       return new CdmApplicationRemoteController(applicationContextResource, 
+                       remoteSource, 
+                       omitTermLoading, 
+                       progressMonitor, 
+                               listeners);
+       
+    }
+    
+       private CdmApplicationRemoteController(Resource applicationContextResource, 
+                               ICdmRemoteSource remoteSource,                          
+                               boolean omitTermLoading, 
+                               IProgressMonitor progressMonitor, 
+                               List<ApplicationListener> listeners){
+               logger.info("Start CdmApplicationRemoteController with remote source: " + remoteSource.getName());
+        this.applicationContextResource = applicationContextResource != null ? applicationContextResource : getClasspathResource();
+        this.progressMonitor = progressMonitor != null ? progressMonitor : new NullProgressMonitor();
+
+        setNewRemoteSource(remoteSource, omitTermLoading, listeners);
+               
+       }
+       
+    /**
+     * @return
+     */
+    protected static ClassPathResource getClasspathResource() {
+        return new ClassPathResource(DEFAULT_APPLICATION_CONTEXT_RESOURCE);
+    }
+    /**
+     * Sets the application context to a new spring ApplicationContext by using the according data source and initializes the Controller.
+     * @param dataSource
+     */
+    protected boolean setNewRemoteSource(ICdmRemoteSource remoteSource, 
+               boolean omitTermLoading, 
+               List<ApplicationListener> listeners){
+
+        logger.info("Connecting to '" + remoteSource.getName() + "'");
+
+        MonitoredGenericApplicationContext applicationContext =  new MonitoredGenericApplicationContext();
+        int refreshTasks = 45;
+        int nTasks = 5 + refreshTasks;
+
+        progressMonitor.beginTask("Connecting to '" + remoteSource.getName() + "'", nTasks);
+
+        progressMonitor.subTask("Registering remote source.");
+        PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
+        Properties properties = new Properties();
+        properties.setProperty("remoteServer", remoteSource.getServer());
+        properties.setProperty("remotePort", String.valueOf(remoteSource.getPort()));
+        properties.setProperty("remoteContext", remoteSource.getContextPath());
+        pspc.setProperties(properties);
+        applicationContext.addBeanFactoryPostProcessor(pspc);
+        progressMonitor.worked(1);
+        
+//        BeanDefinition remoteSourceBean = remoteSource.getRemoteSourceBean();
+//        remoteSourceBean.setAttribute("isLazy", false);
+//        applicationContext.registerBeanDefinition("dataSource", remoteSourceBean);
+
+
+        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext);
+        progressMonitor.subTask("Registering resources.");
+        xmlReader.loadBeanDefinitions(applicationContextResource);
+        progressMonitor.worked(1);
+
+        //omitTerms
+        if (omitTermLoading == true){
+            String initializerName = "persistentTermInitializer";
+            BeanDefinition beanDef = applicationContext.getBeanDefinition(initializerName);
+            MutablePropertyValues values = beanDef.getPropertyValues();
+            values.addPropertyValue("omit", omitTermLoading);
+        }
+
+        if (listeners != null){
+            for(ApplicationListener listener : listeners){
+                applicationContext.addApplicationListener(listener);
+            }
+        }
+
+
+        applicationContext.refresh(new SubProgressMonitor(progressMonitor, refreshTasks));
+        applicationContext.start();
+
+        progressMonitor.subTask("Cleaning up.");
+        setApplicationContext(applicationContext);
+        progressMonitor.worked(1);
+
+        progressMonitor.done();
+        return true;
+    }
+    
+    @Override
+    protected void init(){
+        logger.debug("Init " +  this.getClass().getName() + " ... ");
+        if (logger.isDebugEnabled()){for (String beanName : applicationContext.getBeanDefinitionNames()){ logger.debug(beanName);}}
+        //TODO delete next row (was just for testing)
+        if (logger.isInfoEnabled()){
+            logger.info("Registered Beans: ");
+            String[] beanNames = applicationContext.getBeanDefinitionNames();
+            for (String beanName : beanNames){
+                logger.info(beanName);
+            }
+        }
+        configuration = (ICdmApplicationConfiguration)applicationContext.getBean("cdmApplicationRemoteConfiguration");
+
+    }
+
+}
index c67e5e2ad8db2a2842e917146e5c9d729086c952..6b76cb92ec7328a5b03b2ce267fe4b22b851bdfe 100644 (file)
@@ -1336,6 +1336,10 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers
                return ((AbstractPersistentCollection)map).initialized;
        }
        
+       public static boolean isInitialized(Set set) {
+               return ((AbstractPersistentCollection)set).initialized;
+       }
+       
        //FIXME:Remoting These methods may no longer be required since we are 
        //               initialising collections as default behaviour
        private int remoteSize() {
index 3aa9fccdf02197672f01439024302db06cbbc836..d0b8274468a64abfc4c765a0b76f5446b0295298 100644 (file)
@@ -24,6 +24,7 @@
 package org.hibernate.proxy;
 
 import java.io.Serializable;
+import java.util.Set;
 
 import javax.naming.NamingException;
 
@@ -32,6 +33,7 @@ import org.hibernate.LazyInitializationException;
 import org.hibernate.Session;
 import org.hibernate.SessionException;
 import org.hibernate.TransientObjectException;
+import org.hibernate.collection.internal.AbstractPersistentCollection;
 import org.hibernate.engine.spi.EntityKey;
 import org.hibernate.engine.spi.SessionFactoryImplementor;
 import org.hibernate.engine.spi.SessionImplementor;
@@ -461,5 +463,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
                }
        }
        
-       
+       public static boolean isInitialized(AbstractLazyInitializer obj) {
+               return obj.initialized;
+       }
 }
index 250a837572e9f6bfe3c3e0d5ccfe00d473360253..29bacfa4330ef795d38752fc3c3bb1fada2da9c4 100644 (file)
@@ -15,7 +15,7 @@
    <bean id="agentService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/agent.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/agent.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IAgentService</value>\r
@@ -28,7 +28,7 @@
    <bean id="annotationService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/annotation.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/annotation.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IAnnotationService</value>\r
@@ -41,7 +41,7 @@
    <bean id="auditeventService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/auditevent.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/auditevent.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IAuditEventService</value>\r
@@ -54,7 +54,7 @@
    <bean id="classificationService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/classification.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/classification.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IClassificationService</value>\r
@@ -67,7 +67,7 @@
    <bean id="collectionService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/collection.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/collection.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.ICollectionService</value>\r
@@ -80,7 +80,7 @@
    <bean id="commonService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/common.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/common.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.ICommonService</value>\r
@@ -93,7 +93,7 @@
    <bean id="descriptionService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/description.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/description.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IDescriptionService</value>\r
    <bean id="editGeoService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/editgeo.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/editgeo.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.ext.geo.IEditGeoService</value>\r
    <bean id="featureNodeService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/featurenode.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/featurenode.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IFeatureNodeService</value>\r
    <bean id="featureTreeService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/featuretree.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/featuretree.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IFeatureTreeService</value>\r
    <bean id="groupService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/group.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/group.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IGroupService</value>\r
    <bean id="identificationKeyService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/identificationkey.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/identificationkey.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IIdentificationKeyService</value>\r
    <bean id="locationService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/location.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/location.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.ILocationService</value>\r
    <bean id="markerService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/marker.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/marker.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IMarkerService</value>\r
    <bean id="mediaService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/media.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/media.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IMediaService</value>\r
    <bean id="nameService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/name.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/name.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.INameService</value>\r
    <bean id="occurrenceService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/occurrence.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/occurrence.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IOccurrenceService</value>\r
    <bean id="polytomousKeyNodeService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/polytomouskeynode.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/polytomouskeynode.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService</value>\r
    <bean id="polytomousKeyService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/polytomouskey.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/polytomouskey.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IPolytomousKeyService</value>\r
    <bean id="referenceService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/reference.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/reference.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IReferenceService</value>\r
    <bean id="serviceService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/service.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/service.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IService</value>\r
    <bean id="taxonNodeService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/taxonnode.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/taxonnode.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.ITaxonNodeService</value>\r
    <bean id="taxonService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/taxon.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/taxon.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.ITaxonService</value>\r
    <bean id="termService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/term.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/term.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.ITermService</value>\r
    <bean id="userService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/user.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/user.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IUserService</value>\r
    <bean id="vocabularyService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/vocabulary.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/vocabulary.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IVocabularyService</value>\r
    <bean id="workingSetService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/workingset.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/workingset.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IWorkingSetService</value>\r
    <bean id="grantedAuthorityService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/grantedauthority.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/grantedauthority.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IGrantedAuthorityService</value>\r
    <bean id="databaseService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/database.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/database.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.IDatabaseService</value>\r
    <bean id="lsidAuthorityService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/lsidauthoruty.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/lsidauthoruty.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.lsid.LSIDAuthorityService</value>\r
    <bean id="lsidMetadataService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/lsidmetadata.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/lsidmetadata.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.lsid.LSIDMetadataService</value>\r
    <bean id="lsiDataService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/lsiddata.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/lsiddata.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>eu.etaxonomy.cdm.api.service.lsid.LSIDDataService</value>\r
        <bean id="providerManager"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
                <property name="serviceUrl">\r
-                       <value>http://${serverName}/${contextPath}/authenticationManager.service</value>\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/authenticationManager.service</value>\r
                </property>\r
                <property name="serviceInterface">\r
                        <value>org.springframework.security.authentication.AuthenticationManager</value>\r
                        <bean class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
                </property>\r
        </bean>\r
+       \r
+          <bean id="primerService"\r
+               class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
+               <property name="serviceUrl">\r
+                       <value>http://${remoteServer}:${remotePort}/${remoteContext}/remoting/primer.service</value>\r
+               </property>\r
+               <property name="serviceInterface">\r
+                       <value>eu.etaxonomy.cdm.api.service.IPrimerService</value>\r
+               </property>\r
+               <property name="httpInvokerRequestExecutor">\r
+                       <bean class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor" />\r
+               </property>\r
+       </bean>\r
 \r
 \r
 \r
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmRemoteSourceTest.java b/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmRemoteSourceTest.java
new file mode 100644 (file)
index 0000000..f63e3db
--- /dev/null
@@ -0,0 +1,89 @@
+package eu.etaxonomy.taxeditor.remoting;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.springframework.remoting.RemoteAccessException;
+import org.unitils.UnitilsJUnit4;
+
+import eu.etaxonomy.cdm.config.CdmSourceException;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.cdm.remote.CdmRemoteSource;
+
+public class CdmRemoteSourceTest extends UnitilsJUnit4 {
+       private static final Logger logger = Logger.getLogger(RemotePersistentCollectionTest.class);
+       @Rule
+       public ExpectedException exception = ExpectedException.none();
+       
+       @BeforeClass
+       public static void initialize() {
+               Logger.getRootLogger().setLevel(Level.INFO);
+               
+       }
+       
+       @Test
+       public void localCdmRemoteSourceConnectionTest() {
+               // check if non-active server throws the right exception
+               CdmRemoteSource crs = CdmRemoteSource.NewInstance("local", "127.0.0.1", 808080, "", NomenclaturalCode.ICNAFP);
+               try {
+                       crs.getDbSchemaVersion();
+                       Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException");
+               } catch(CdmSourceException cse) {
+                       Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
+               } catch(RemoteAccessException rae){
+                       
+               }
+               
+               try {
+                       crs.isDbEmpty();
+                       Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException");
+               } catch(CdmSourceException cse) {
+                       Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
+               } catch(RemoteAccessException rae){
+                       
+               }
+               
+               try {
+                       crs.checkConnection();
+                       Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException");
+               } catch(CdmSourceException cse) {
+                       Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
+               } catch(RemoteAccessException rae){
+                       
+               }
+               
+               // check if active server throws the right exception
+               crs = CdmRemoteSource.NewInstance("local", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
+               String dbSchemaVersion = "";
+               try {
+                       dbSchemaVersion = crs.getDbSchemaVersion();
+               } catch (CdmSourceException e) {
+                       Assert.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
+               }
+               logger.info("dbSchemaVersion is " + dbSchemaVersion);
+               
+
+               boolean isDbEmpty = false;
+               try {
+                       isDbEmpty = crs.isDbEmpty();
+               } catch (CdmSourceException e) {
+                       Assert.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
+               }
+               Assert.assertFalse(isDbEmpty);
+               
+               
+               boolean check = true;
+               try {
+                       isDbEmpty = crs.checkConnection();
+               } catch (CdmSourceException e) {
+                       Assert.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
+               }
+               Assert.assertTrue(check);
+               
+       }
+
+}