CdmServerInstanceInfo, RemotingLoginDialog, ShowRemotingLoginWindowHandler : function...
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 22 Jan 2015 09:36:01 +0000 (09:36 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 22 Jan 2015 09:36:01 +0000 (09:36 +0000)
moved classes to appropriate locations.
merged from trunk.

1  2 
.gitattributes
eu.etaxonomy.taxeditor.application/plugin.xml
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/server/CDMServerException.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInstanceInfo.java
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/cdmlib-remote-webapp.war
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/log4j.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowRemotingLoginWindowHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CDMServer.java

diff --cc .gitattributes
index a0720766d6718e1e3be6b0e0ea0597f810bbded7,e67243effe6d5ab1d68da5d44d853b6bc6cc675e..75cb8662541b77363bcd93cfe981c2392b731b05
@@@ -333,41 -333,15 +333,43 @@@ eu.etaxonomy.taxeditor.cdmlib/lib/yjp-c
  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/application/RemotingMonitoredGenericApplicationContext.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/RemotingMonitoredListableBeanFactory.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CachedCommonServiceImpl.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmClientCacheException.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmEntityCacheKey.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelCacher.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmModelFieldPropertyFromClass.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmRemoteCacheManager.java -text
  eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java -text
 -eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/lazyloading/CdmLazyLoader.java -text
 -eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmPersistentRemoteSource.java -text
 -eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSource.java -text
 -eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceBase.java -text
 -eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSourceException.java -text
 -eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/ICdmRemoteSource.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmTransientEntityCacher.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/ICachedCommonService.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/CdmEagerLoadingException.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/CdmRemotingException.java -text
++eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/server/CDMServerException.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmPersistentRemoteSource.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmRemoteSource.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmRemoteSourceBase.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmRemoteSourceException.java -text
++eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInstanceInfo.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/ICdmRemoteSource.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceInterceptorException.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceRequestExecutor.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/TermServiceRequestExecutor.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmClientSessionException.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySession.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySession.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ISessionEventListener.java -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.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
 +eu.etaxonomy.taxeditor.cdmlib/src/main/resources/cdmlib-ehcache.xml -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/.svnignore -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/cdmlib-remote-webapp.war -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/jetty-runner-9.2.3.v20140905.jar -text
 +eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/start-9.2.3.v20140905.jar -text
  eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/config.properties -text
  eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/httpInvokerServiceClients.xml -text
  eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/localApplicationContext.xml -text
@@@ -1275,6 -1249,6 +1278,7 @@@ eu.etaxonomy.taxeditor.store/src/main/j
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenDistributionEditorWizardHandler.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowLoginWindowHandler.java -text
++eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowRemotingLoginWindowHandler.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/identificationkey/AbstractIdentificaitonKeyWizard.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java -text
@@@ -1435,6 -1409,6 +1439,7 @@@ eu.etaxonomy.taxeditor.store/src/main/j
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/TermComboElement.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/DefaultLanguageDialog.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/LoginDialog.java -text
++eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/UriDialog.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmEnumSelectionDialog.java -text
  eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java -text
@@@ -1841,41 -1816,10 +1846,40 @@@ eu.etaxonomy.taxeditor.test/META-INF/MA
  eu.etaxonomy.taxeditor.test/build.properties -text
  eu.etaxonomy.taxeditor.test/ide/eclipse/EDITor[!!-~]Tests.launch -text
  eu.etaxonomy.taxeditor.test/pom.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/cdmlib-ehcache.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/datasources.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/eu/etaxonomy/cdm/api/cache/CdmClientCachingTest.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/eu/etaxonomy/cdm/cdm.datasources.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/eu/etaxonomy/cdm/polytomouskey/PolytomousKeyTest.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/eu/etaxonomy/cdm/testRemotingApplicationContext.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/eu/etaxonomy/taxeditor/lazyloading/AbstractLazyInitializerTest.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/eu/etaxonomy/taxeditor/lazyloading/CdmEntityCacherTest.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/eu/etaxonomy/taxeditor/remoting/session/CdmEntitySessionManagerTest.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.h2.db -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/h2/cdmTest.trace.db -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/log4j.properties -text
  eu.etaxonomy.taxeditor.test/src/main/resources/log4j.xml -text
 +eu.etaxonomy.taxeditor.test/src/main/resources/unitils.properties -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmClientCachingTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/polytomouskey/PolytomousKeyTest.java -text
  eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/application/menu/general/NewMenuTest.java -text
- eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/exception/CDMServerException.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/BaseRemotingTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CDMServer.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmPersistentRemoteSourceTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmRemoteSourceTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmServerTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmServerTestManager.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/HttpInvokerServicesTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/AbstractLazyInitializerTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/CdmEntityCacherTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/CdmServiceCacherTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemoteLazyLoadingTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/RemotePersistentCollectionTest.java -text
  eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/navigation/navigator/contextmenu/ClassificationTest.java -text
  eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/newWizard/NewTaxonWizardTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManagerTest.java -text
 +eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/MockSessionOwner.java -text
  eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/AbstractEditorTest.java -text
  eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/ContextMenuHelper.java -text
  eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/test/SwtBotUtils.java -text
index b74e209ce9d93b65fa3e04ed7461db32d7388015,b74e209ce9d93b65fa3e04ed7461db32d7388015..97897e12022fe17a56d4be80ccaeb223b3de2536
                 name="eu.etaxonomy.taxeditor.application.filemenu.io"\r
                 visible="true">\r
           </separator>\r
++         <command\r
++               commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"\r
++               id="eu.etaxonomy.taxeditor.application.menu.login"\r
++               label="Connect"\r
++               style="push">\r
++         </command>\r
           <command\r
                 commandId="org.eclipse.ui.file.exit"\r
                 id="eu.etaxonomy.taxeditor.application.menu.exit"\r
              id="eu.etaxonomy.taxeditor.install"\r
              name="%command.label.18">\r
        </command>\r
++      <command\r
++            defaultHandler="eu.etaxonomy.taxeditor.handler.ShowRemotingLoginWindowHandler"\r
++            id="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow"\r
++            name="Connect">\r
++      </command>\r
     </extension>\r
     \r
     \r
index d767f9af578403eed3ace6ea27ed64a52b087ab1,a8798c87687986d36af7c1ef194ee084cc2248df..54402fbc3d78ea613d9972163062dc00ac9884b3
@@@ -182,15 -185,8 +182,16 @@@ Export-Package: com.google.api
   eu.etaxonomy.cdm.validation.annotation,
   eu.etaxonomy.cdm.validation.constraint,
   eu.etaxonomy.remote.dto.rdf,
++ eu.etaxonomy.taxeditor.remoting.server,
 + eu.etaxonomy.taxeditor.remoting.source,
 + eu.etaxonomy.taxeditor.session,
 + eu.etaxonomy.taxeditor.session.mock,
 + javassist.util.proxy,
   javax.persistence,
   junit.framework;uses:="org.junit.runner.manipulation,org.junit.runner,org.junit.runner.notification",
 + net.sf.ehcache,
 + net.sf.ehcache.config,
 + net.sf.ehcache.store,
   net.sf.json;uses:="net.sf.json.processors,net.sf.json.util,org.apache.commons.lang.exception",
   org.apache.commons.collections;uses:="org.apache.commons.collections.keyvalue,new org.apache.commons.collections",
   org.apache.commons.io;uses:="org.apache.commons.io.filefilter",
index ed2b691ae0da85250a13df3e16ebdfeac91e3efa,0000000000000000000000000000000000000000..33cd998ea449f91a1e97eacc3fb2b3d4afd823e1
mode 100644,000000..100644
--- /dev/null
@@@ -1,31 -1,0 +1,31 @@@
- package eu.etaxonomy.taxeditor.exception;
 +// $Id$
 +/**
 +* Copyright (C) 2014 EDIT
 +* European Distributed Institute of Taxonomy
 +* http://www.e-taxonomy.eu
 +*
 +* The contents of this file are subject to the Mozilla Public License Version 1.1
 +* See LICENSE.TXT at the top of this package for the full license terms.
 +*/
++package eu.etaxonomy.taxeditor.remoting.server;
 +
 +/**
 + * @author cmathew
 + * @date 23 Sep 2014
 + *
 + */
 +public class CDMServerException extends Exception {
 +
 +    public CDMServerException(String message) {
 +        super(message);
 +    }
 +
 +    public CDMServerException(Exception e) {
 +        super(e);
 +    }
 +
 +    public CDMServerException(String message,Exception e) {
 +        super(message,e);
 +    }
 +
 +}
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..2ddac735565c956bbdc088fedfa04f1661d57504
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,124 @@@
++// $Id$
++/**
++ * Copyright (C) 2015 EDIT
++ * European Distributed Institute of Taxonomy
++ * http://www.e-taxonomy.eu
++ *
++ * The contents of this file are subject to the Mozilla Public License Version 1.1
++ * See LICENSE.TXT at the top of this package for the full license terms.
++ */
++package eu.etaxonomy.taxeditor.remoting.source;
++
++import java.io.IOException;
++import java.net.Socket;
++import java.util.ArrayList;
++import java.util.List;
++
++import org.apache.log4j.Logger;
++
++import eu.etaxonomy.cdm.config.CdmSourceException;
++import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
++
++/**
++ * @author cmathew
++ * @date 20 Jan 2015
++ *
++ */
++public class CdmServerInstanceInfo {
++    public static final Logger logger = Logger.getLogger(CdmServerInstanceInfo.class);
++
++    private final static String SERVER_LOCALHOST = "localhost";
++    private final static String NAME_LOCALHOST = "localhost";
++    private final static String NAME_LOCALHOST_MGD = "localhost mgd.";
++
++    private final static String CONTEXT_PATH_PREFIX = "cdmserver/";
++
++    private final String name;
++    private final String server;
++    private final int port;
++    private final List<String> instances;
++
++
++    public CdmServerInstanceInfo(String name, String server, int port) {
++        this.name = name;
++        this.server = server;
++        this.port = port;
++        instances = new ArrayList<String>();
++    }
++
++
++    public void refreshInstances() {
++        //FIXME:Remoting This list needs to be populated with a real fetch from the cdm server
++        if(name.equals(NAME_LOCALHOST)) {
++            instances.clear();
++            instances.add("local-cyprus");
++            instances.add("local-cichorieae");
++        }
++        if(name.equals(NAME_LOCALHOST_MGD)) {
++            instances.clear();
++            instances.add("local-test");
++        }
++    }
++
++    public CdmRemoteSource getCdmRemoteSource(String instance) {
++        return CdmRemoteSource.NewInstance(name,
++                server,
++                port,
++                CONTEXT_PATH_PREFIX + instance,
++                null);
++    }
++
++    public boolean pingServer(){
++        try {
++            Socket s = new Socket(server, port);
++            logger.info("[CDM-Server] Available @ " + server + ":" + port );
++            return true;
++        } catch (IOException ioe) {
++
++        }
++        return false;
++    }
++
++    public boolean pingInstance(String instance) throws CDMServerException  {
++
++        CdmRemoteSource crs = getCdmRemoteSource(instance);
++        try {
++            if(crs.checkConnection()) {
++                logger.info("[CDM-Server] Running @ " + server + ":" + port + " for instance " + instance);
++                return true;
++            }
++        } catch (CdmSourceException e) {
++            throw new CDMServerException(e);
++        }
++
++        return false;
++    }
++
++    public static List<CdmServerInstanceInfo> getCdmServers() {
++        List<CdmServerInstanceInfo> cdmServerInfoList = new ArrayList<CdmServerInstanceInfo>();
++        cdmServerInfoList.add(new CdmServerInstanceInfo(NAME_LOCALHOST, SERVER_LOCALHOST, 8080));
++        cdmServerInfoList.add(new CdmServerInstanceInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST,8080));
++        return cdmServerInfoList;
++    }
++
++    public String getName() {
++        return name;
++    }
++
++    public String getServer() {
++        return server;
++    }
++
++
++    public int getPort() {
++        return port;
++    }
++
++
++    public List<String> getInstances() {
++        if(instances.isEmpty()) {
++            refreshInstances();
++        }
++        return instances;
++    }
++}
index 3ddb42caf84af18e02d6adee86491b41e5537d24,0000000000000000000000000000000000000000..2267e439acf18433cdda08c91a9331006cc6f8a1
mode 100644,000000..100644
Binary files differ
index 749216de47b8caca1701898da8f85efa72dd90c6,0000000000000000000000000000000000000000..17257aa0c52814ba450299a6c284815c18a428fe
mode 100644,000000..100644
--- /dev/null
@@@ -1,26 -1,0 +1,27 @@@
 +#\r
 +#\r
 +# If you are having problems with logging you may debug Log4J initialization,\r
 +# start the application with a system property log4j.configDebug set to "true".\r
 +# E.g.:\r
 +#\r
 +#     java -Dlog4j.configDebug=true\r
 +#\r
 +\r
 +log4j.rootLogger=WARN, stdout\r
 +\r
 +\r
 +log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
 +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
 +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n\r
 +\r
 +##\r
 +## NOTICE !!!!\r
 +## no need to configure a FileAppender here\r
 +## use eu.etaxonomy.cdm.remote.config.LoggingConfigurer instead\r
 +##\r
 +\r
 +###\r
 +# cdm\r
 +###\r
 +log4j.logger.eu.etaxonomy.cdm = INFO\r
++log4j.logger.eu.etaxonomy.taxeditor.remoting.source = INFO\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..025c493e4cc938cbbb254398680e314ac18de1d7
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,48 @@@
++// $Id$
++/**
++* Copyright (C) 2007 EDIT
++* European Distributed Institute of Taxonomy
++* http://www.e-taxonomy.eu
++*
++* The contents of this file are subject to the Mozilla Public License Version 1.1
++* See LICENSE.TXT at the top of this package for the full license terms.
++*/
++
++package eu.etaxonomy.taxeditor.handler;
++
++import org.eclipse.core.commands.AbstractHandler;
++import org.eclipse.core.commands.ExecutionEvent;
++import org.eclipse.core.commands.ExecutionException;
++import org.eclipse.core.commands.IHandler;
++import org.eclipse.swt.SWT;
++import org.eclipse.ui.handlers.HandlerUtil;
++
++import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
++
++/**
++ * <p>ShowLoginWindowHandler class.</p>
++ *
++ * @author n.hoffmann
++ * @created Aug 7, 2009
++ * @version 1.0
++ */
++public class ShowRemotingLoginWindowHandler extends AbstractHandler implements IHandler{
++
++      /* (non-Javadoc)
++       * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
++       */
++      /** {@inheritDoc} */
++      @Override
++    public Object execute(ExecutionEvent event) throws ExecutionException {
++
++              RemotingLoginDialog loginDialog = new RemotingLoginDialog(HandlerUtil.getActiveShell(event),SWT.DIALOG_TRIM
++                      | SWT.APPLICATION_MODAL);
++              loginDialog.open();
++
++              return null;
++
++      }
++
++
++
++}
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b9d4e631b48c541d59a8e13bf5fb51e4dcf2a559
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,341 @@@
++// $Id$
++/**
++ * Copyright (C) 2015 EDIT
++ * European Distributed Institute of Taxonomy
++ * http://www.e-taxonomy.eu
++ *
++ * The contents of this file are subject to the Mozilla Public License Version 1.1
++ * See LICENSE.TXT at the top of this package for the full license terms.
++ */
++package eu.etaxonomy.taxeditor.ui.dialog;
++
++import java.util.HashMap;
++import java.util.List;
++import java.util.Map;
++
++import org.eclipse.swt.SWT;
++import org.eclipse.swt.events.MouseAdapter;
++import org.eclipse.swt.events.MouseEvent;
++import org.eclipse.swt.events.SelectionAdapter;
++import org.eclipse.swt.events.SelectionEvent;
++import org.eclipse.swt.layout.FillLayout;
++import org.eclipse.swt.layout.GridData;
++import org.eclipse.swt.layout.GridLayout;
++import org.eclipse.swt.widgets.Button;
++import org.eclipse.swt.widgets.Combo;
++import org.eclipse.swt.widgets.Composite;
++import org.eclipse.swt.widgets.Dialog;
++import org.eclipse.swt.widgets.Display;
++import org.eclipse.swt.widgets.Label;
++import org.eclipse.swt.widgets.Shell;
++import org.eclipse.swt.widgets.Text;
++import org.eclipse.wb.swt.SWTResourceManager;
++
++import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
++import eu.etaxonomy.taxeditor.model.MessagingUtils;
++import eu.etaxonomy.taxeditor.remoting.source.CdmServerInstanceInfo;
++import eu.etaxonomy.taxeditor.store.CdmStore;
++
++/**
++ * @author cmathew
++ * @date 20 Jan 2015
++ *
++ */
++public class RemotingLoginDialog extends Dialog {
++
++    protected Object result;
++    protected Shell shlLogin;
++    private Text txtUsername;
++    private Text txtPassword;
++    private Text txtPort;
++    private Text txtCdmServerStatus;
++    private Text txtCdmInstanceStatus;
++    private Combo comboCdmServer;
++    private Combo comboCdmInstance;
++    private Button btnLogin;
++
++    private final Map<String, CdmServerInstanceInfo> csiiMap = new HashMap<String, CdmServerInstanceInfo>();
++
++    private final String STATUS_AVAILABLE = "Available";
++    private final String STATUS_NOT_AVAILABLE = "Not Available";
++    private final String STATUS_RETRIEVING = "Retrieving ...";
++    private final String STATUS_CHECKING_AVAILABILITY = "Checking ...";
++    private final String STATUS_NO_INSTANCES = "No Instances Found";
++
++    private CdmServerInstanceInfo selectedCsii;
++    private String selectedCdmInstance;
++
++
++    /**
++     * Create the dialog.
++     * @param parent
++     * @param style
++     */
++    public RemotingLoginDialog(Shell parent, int style) {
++        super(parent, style);
++        setText("Login");
++    }
++
++    /**
++     * Open the dialog.
++     * @return the result
++     */
++    public Object open() {
++        createContents();
++        populateCdmServerCombo();
++        shlLogin.open();
++        shlLogin.layout();
++
++        Display display = getParent().getDisplay();
++
++        while (!shlLogin.isDisposed()) {
++            if (!display.readAndDispatch()) {
++                display.sleep();
++            }
++        }
++
++        return result;
++    }
++
++    /**
++     * Create contents of the dialog.
++     */
++    private void createContents() {
++        shlLogin = new Shell(getParent(), getStyle());
++        shlLogin.setSize(490, 292);
++        shlLogin.setText("Login");
++        shlLogin.setLayout(new FillLayout(SWT.HORIZONTAL));
++
++        Composite composite = new Composite(shlLogin, SWT.NONE);
++        FillLayout fl_composite = new FillLayout(SWT.VERTICAL);
++        fl_composite.spacing = 5;
++        composite.setLayout(fl_composite);
++
++        Composite remotingComposite = new Composite(composite, SWT.NONE);
++        FillLayout fl_remotingComposite = new FillLayout(SWT.VERTICAL);
++        fl_remotingComposite.spacing = 5;
++        remotingComposite.setLayout(fl_remotingComposite);
++
++        Composite cdmServerComposite = new Composite(remotingComposite, SWT.NONE);
++        cdmServerComposite.setLayout(new GridLayout(5, false));
++
++        Label lblCdmServer = new Label(cdmServerComposite, SWT.NONE);
++        lblCdmServer.setText("CDM Server : ");
++        lblCdmServer.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
++        lblCdmServer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
++
++        comboCdmServer = new Combo(cdmServerComposite, SWT.READ_ONLY);
++        comboCdmServer.addSelectionListener(new SelectionAdapter() {
++            @Override
++            public void widgetSelected(SelectionEvent e) {
++                updateSelectedCdmServer();
++                updatePort();
++                populateCdmInstanceCombo(false);
++            }
++        });
++        GridData gd_comboCdmServer = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
++        gd_comboCdmServer.widthHint = 150;
++        comboCdmServer.setLayoutData(gd_comboCdmServer);
++        comboCdmServer.select(0);
++
++        Label lblPortSeparator = new Label(cdmServerComposite, SWT.NONE);
++        lblPortSeparator.setText(" :  ");
++
++        txtPort = new Text(cdmServerComposite, SWT.BORDER);
++        GridData gd_txtPort = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
++        gd_txtPort.widthHint = 50;
++        txtPort.setLayoutData(gd_txtPort);
++
++        txtCdmServerStatus = new Text(cdmServerComposite, SWT.BORDER);
++        txtCdmServerStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
++        txtCdmServerStatus.setEditable(false);
++        GridData gd_txtCdmServerStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
++        gd_txtCdmServerStatus.widthHint = 50;
++        txtCdmServerStatus.setLayoutData(gd_txtCdmServerStatus);
++
++        Label lblCdmInstance = new Label(cdmServerComposite, SWT.NONE);
++        GridData gd_lblCdmInstance = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
++        gd_lblCdmInstance.heightHint = 30;
++        lblCdmInstance.setLayoutData(gd_lblCdmInstance);
++        lblCdmInstance.setText("CDM Instance : ");
++        lblCdmInstance.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
++
++        comboCdmInstance = new Combo(cdmServerComposite, SWT.READ_ONLY);
++        comboCdmInstance.addSelectionListener(new SelectionAdapter() {
++            @Override
++            public void widgetSelected(SelectionEvent e) {
++                checkSelectedCdmServerInstance();
++            }
++        });
++        GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1);
++        gd_comboCdmInstance.widthHint = 150;
++        comboCdmInstance.setLayoutData(gd_comboCdmInstance);
++        comboCdmInstance.select(0);
++
++        txtCdmInstanceStatus = new Text(cdmServerComposite, SWT.BORDER);
++        txtCdmInstanceStatus.setBackground(SWTResourceManager.getColor(SWT.COLOR_INFO_BACKGROUND));
++        txtCdmInstanceStatus.setEditable(false);
++        GridData gd_txtCdmInstanceStatus = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
++        gd_txtCdmInstanceStatus.widthHint = 50;
++        txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
++        new Label(cdmServerComposite, SWT.NONE);
++
++        Button btnRefresh = new Button(cdmServerComposite, SWT.FLAT);
++        GridData gd_btnRefresh = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
++        gd_btnRefresh.widthHint = 110;
++        gd_btnRefresh.heightHint = 30;
++        btnRefresh.setLayoutData(gd_btnRefresh);
++        btnRefresh.setText("Refresh");
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++
++        Label lblUsername = new Label(cdmServerComposite, SWT.NONE);
++        lblUsername.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
++        lblUsername.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
++        lblUsername.setText("Username : ");
++
++        txtUsername = new Text(cdmServerComposite, SWT.BORDER);
++        txtUsername.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
++        new Label(cdmServerComposite, SWT.NONE);
++
++        Label lblPassword = new Label(cdmServerComposite, SWT.NONE);
++        lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
++        lblPassword.setText("Password : ");
++        lblPassword.setFont(SWTResourceManager.getFont("Ubuntu", 9, SWT.NORMAL));
++
++        txtPassword = new Text(cdmServerComposite, SWT.BORDER | SWT.PASSWORD);
++        txtPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++
++        btnLogin = new Button(cdmServerComposite, SWT.FLAT);
++        btnLogin.addMouseListener(new MouseAdapter() {
++            @Override
++            public void mouseUp(MouseEvent e) {
++                login();
++            }
++        });
++        GridData gd_btnLogin = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
++        gd_btnLogin.heightHint = 30;
++        btnLogin.setLayoutData(gd_btnLogin);
++        btnLogin.setText("Login");
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++        new Label(cdmServerComposite, SWT.NONE);
++
++    }
++
++    private void populateCdmServerCombo() {
++        for(CdmServerInstanceInfo csii : CdmServerInstanceInfo.getCdmServers()) {
++            csiiMap.put(csii.getName(), csii);
++            comboCdmServer.add(csii.getName());
++        }
++        comboCdmServer.select(0);
++        updateSelectedCdmServer();
++        updatePort();
++        checkSelectedCdmServer();
++    }
++
++
++    private void updateSelectedCdmServer() {
++        int selIndex = comboCdmServer.getSelectionIndex();
++        if(selIndex != -1) {
++            selectedCsii = csiiMap.get(comboCdmServer.getItem(selIndex));
++        }
++    }
++
++    private void updatePort() {
++        txtPort.setText("");
++        if(selectedCsii != null) {
++            txtPort.setText(String.valueOf(selectedCsii.getPort()));
++        }
++    }
++
++
++    private void checkSelectedCdmServer() {
++        int selIndex = comboCdmServer.getSelectionIndex();
++        if(selectedCsii != null) {
++            if(selectedCsii.pingServer()) {
++                txtCdmServerStatus.setText(STATUS_AVAILABLE);
++                populateCdmInstanceCombo(true);
++            } else {
++                txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
++            }
++        }
++    }
++
++    private void populateCdmInstanceCombo(final boolean forceRefresh) {
++        comboCdmInstance.removeAll();
++        comboCdmInstance.setEnabled(false);
++        txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
++
++        if(selectedCsii != null) {
++            if(forceRefresh) {
++                selectedCsii.refreshInstances();
++            }
++            List<String> instances = selectedCsii.getInstances();
++            if(!instances.isEmpty()) {
++                for(String cdmInstance : instances) {
++                    comboCdmInstance.add(cdmInstance);
++                }
++                comboCdmInstance.select(0);
++                checkSelectedCdmServerInstance();
++            } else {
++                txtCdmInstanceStatus.setText(STATUS_NO_INSTANCES);
++            }
++        }
++        comboCdmInstance.setEnabled(true);
++    }
++
++    private void checkSelectedCdmServerInstance() {
++        if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE)) {
++            int selInstanceIndex = comboCdmInstance.getSelectionIndex();
++            String instance = comboCdmInstance.getItem(selInstanceIndex);
++
++            try {
++                if(selectedCsii.pingInstance(instance)) {
++                    txtCdmInstanceStatus.setText(STATUS_AVAILABLE);
++                    btnLogin.setEnabled(true);
++                } else {
++                    txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
++                    btnLogin.setEnabled(false);
++                }
++            } catch (Exception e) {
++                txtCdmInstanceStatus.setText(STATUS_NOT_AVAILABLE);
++                MessagingUtils.warn(this.getClass(), e);
++            }
++        }
++
++    }
++
++    private void login() {
++        if(CdmStore.isConnecting()){
++            MessagingUtils.warningDialog("Already connecting", this, "You are currently connecting to a different CDM Instance already.");
++            return;
++        }
++
++        int selInstanceIndex = comboCdmInstance.getSelectionIndex();
++        String instance = comboCdmInstance.getItem(selInstanceIndex);
++
++        try {
++            checkSelectedCdmServerInstance();
++            CdmDataSourceRepository.changeDataSource(selectedCsii.getCdmRemoteSource(instance));
++
++        } catch (Exception e) {
++            // Do not expect anything to go wrong at this point, so we throw a runtime exception
++            // if any problems
++            throw new RuntimeException(e);
++        }
++
++        //boolean result = CdmStore.getLoginManager().authenticate(txtUsername.getText(), txtPassword.getText());
++    }
++
++
++}
index 69d2a9f931d642b018c802561fd5fd67283572ac,0000000000000000000000000000000000000000..f15dfd94a4444aa1d4ed182935a320f657b18b1a
mode 100644,000000..100644
--- /dev/null
@@@ -1,350 -1,0 +1,348 @@@
 +// $Id$
 +/**
 + * Copyright (C) 2014 EDIT
 + * European Distributed Institute of Taxonomy
 + * http://www.e-taxonomy.eu
 + *
 + * The contents of this file are subject to the Mozilla Public License Version 1.1
 + * See LICENSE.TXT at the top of this package for the full license terms.
 + */
 +package eu.etaxonomy.taxeditor.httpinvoker;
 +
 +import java.io.BufferedReader;
 +import java.io.IOException;
 +import java.io.InputStreamReader;
 +import java.net.Socket;
 +
- import org.unitils.spring.annotation.SpringApplicationContext;
 +import javax.sql.DataSource;
 +
 +import org.apache.log4j.Level;
 +import org.apache.log4j.Logger;
 +import org.springframework.core.io.ClassPathResource;
 +import org.springframework.core.io.Resource;
 +import org.unitils.database.annotations.TestDataSource;
- import eu.etaxonomy.taxeditor.exception.CDMServerException;
 +
-             } catch (IOException ioe) {               
++import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
 +import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceBase;
 +
 +/**
 + *
 + * (Singleton) Server instance which manages a compatible cdmlib-webapp-war.
 + * This is done by launching a jetty instance (using jetty-runner) as an
 + * executed process. The choice of the external process over a more
 + * preferable 'embedded jetty' instance is due to problems arising from the
 + * class loading of classes (e.g. from hibernate core) which are needed
 + * for both the webapp as well as the remoting client.
 + *
 + * @author cmathew
 + * @date 23 Sep 2014
 + *
 + */
 +
 +public class CDMServer {
 +
 +    public static final Logger logger = Logger.getLogger(CDMServer.class);
 +
 +    @TestDataSource
 +    protected DataSource dataSource;
 +
 +    private final String name = "default";
 +    private final String host = "127.0.0.1";
 +    private final int port = 9090;
 +    private final int stopPort = 9191;
 +    private final String stopKey = "jetty-cdm-server";
 +    private final String contextPath = "";
 +
 +    private boolean keepServerRunning = false;
 +
 +    public static final Resource DEFAULT_CDM_WEBAPP_RESOURCE =
 +            new ClassPathResource("/etc/jetty/cdmlib-remote-webapp.war");
 +
 +    public static final Resource DEFAULT_JETTY_CONFIG_RESOURCE =
 +            new ClassPathResource("/etc/jetty/jetty.xml");
 +
 +    public static final Resource DEFAULT_JETTY_TEMP_RESOURCE =
 +            new ClassPathResource("/etc/jetty/temp");
 +
 +    public static final Resource DEFAULT_JETTY_TEMP_WAR_LIB_RESOURCE =
 +            new ClassPathResource("/etc/jetty/temp/webapp/WEB-INF/lib");
 +
 +    public static final Resource DEFAULT_DATASOURCE_FILE =
 +            new ClassPathResource("datasources.xml");
 +
 +    public static final Resource DEFAULT_JETTY_RUNNER_RESOURCE =
 +            new ClassPathResource("/etc/jetty/jetty-runner-9.2.3.v20140905.jar");
 +
 +    public static final Resource DEFAULT_JETTY_RESOURCE =
 +            new ClassPathResource("/etc/jetty/start-9.2.3.v20140905.jar");
 +
 +
 +
 +    private static CDMServer cdmServer = null;
 +    private static CDMServerException cdmse = null;
 +
 +    private void CDMServer() {
 +        logger.setLevel(Level.INFO);
 +    }
 +
 +    public static CDMServer getInstance() {
 +        if(cdmServer == null) {
 +            cdmServer = new CDMServer();
 +        }
 +        return cdmServer;
 +    }
 +
 +    public String getName() {
 +        return name;
 +    }
 +
 +    public String getHost() {
 +        return host;
 +    }
 +
 +    public int getPort() {
 +        return port;
 +    }
 +
 +    public String getContextPath() {
 +        return contextPath;
 +    }
 +
 +    public boolean getKeepServerRunning() {
 +        return keepServerRunning;
 +    }
 +
 +    public void setKeepServerRunning(boolean keepServerRunning) {
 +        this.keepServerRunning = keepServerRunning;
 +    }
 +
 +    public static boolean isRunningInEclipse() {
 +        return (System.getProperty("sun.java.command") != null &&
 +                System.getProperty("sun.java.command").startsWith("org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"));
 +    }
 +
 +    private String getVMArgs() throws IOException {
 +        StringBuilder sb = new StringBuilder();
 +        sb.append(" -Dspring.profiles.active=remoting");
 +        sb.append(" -Dcdm.beanDefinitionFile=" + DEFAULT_DATASOURCE_FILE.getFile().getAbsolutePath());
 +        sb.append(" -Dcdm.datasource=cdmTest");
 +        return sb.toString();
 +    }
 +
 +    private String getStartServerArgs() {
 +        StringBuilder sb = new StringBuilder();
 +        sb.append(" --port ");
 +        sb.append(port);
 +        return sb.toString();
 +    }
 +
 +    private String getStopServerSettings() {
 +        StringBuilder sb = new StringBuilder();
 +        sb.append(" --stop-port ");
 +        sb.append(stopPort);
 +        sb.append(" --stop-key ");
 +        sb.append(stopKey);
 +        return sb.toString();
 +    }
 +
 +    private String getStopServerArgs() {
 +        StringBuilder sb = new StringBuilder();
 +        sb.append(" STOP.PORT=");
 +        sb.append(stopPort);
 +        sb.append(" STOP.KEY=");
 +        sb.append(stopKey);
 +        return sb.toString();
 +    }
 +
 +    public void start() throws CDMServerException {
 +
 +        /**
 +         * First check if the CDM server responds to a service request, which implies that
 +         * the server has started properly. If no response is received then check if the
 +         * server is listening on specific host / port, which implies that the server
 +         * has started but incorrectly, in which case we try to force stop it (if we can)
 +         * and start a new server.
 +         */
 +        if(isRunning(1)) {
 +            logger.info("[CDM-Server] Server already running @ " + host + ":" + port );
 +            return;
 +        } else if (isAvailable(1)){
 +            logger.info("[CDM-Server] Server available, but not started correctly @ " + host + ":" + port );
 +            logger.info("[CDM-Server] .... trying to force stop server @ " + host + ":" + port );
 +            try {
 +                stop(true);
 +            } catch (Exception e) {
 +                throw new CDMServerException("CDM Server could not be stopped : " + e.getMessage());
 +            }
 +        }
 +
 +        Thread t = new Thread() {
 +            @Override
 +            public void run() {
 +                StringBuffer output = new StringBuffer();
 +                try{
 +                    Process p;
 +                    String command = "java "
 +                            + getVMArgs()
 +                            + " -jar "
 +                            + DEFAULT_JETTY_RUNNER_RESOURCE.getFile().getAbsolutePath()
 +                            + getStartServerArgs()
 +                            + getStopServerSettings()
 +                            + " "
 +                            + DEFAULT_CDM_WEBAPP_RESOURCE.getFile().getAbsolutePath();
 +                    logger.info("[CDM-Server] Starting server with Command : " + command);
 +                    p = Runtime.getRuntime().exec(command);
 +
 +                    BufferedReader reader =
 +                            new BufferedReader(new InputStreamReader(p.getInputStream()));
 +
 +                    String line = "";
 +                    while ((line = reader.readLine())!= null) {
 +                        logger.info("[CDM-Server] Start : " + line);
 +                    }
 +
 +                } catch (Exception e) {
 +                    e.printStackTrace();
 +                    cdmse = new CDMServerException(e);
 +                }
 +
 +            }
 +        };
 +
 +        t.setDaemon(true);
 +        cdmse = null;
 +        t.start();
 +
 +        if(isRunning(50)) {
 +            logger.info("[CDM-Server] Started Server @ " + host + ":" + port );
 +        } else {
 +            logger.info("[CDM-Server] Server not started within given interval");
 +            // making sure to kill server if it is not started correctly
 +            try {
 +                stop(true);
 +            } catch (Exception e) {
 +                throw new CDMServerException("CDM Server could not be stopped : " + e.getMessage());
 +            }
 +            throw new CDMServerException("CDM Server not started : ");
 +        }
 +
 +    }
 +
 +    public boolean isAvailable(int checkingIntervals) throws CDMServerException {
 +        int intervalsCount = 0;
 +        do {
 +            try {
 +                Socket s = new Socket(host, port);
 +                logger.info("[CDM-Server] Available @ " + host + ":" + port );
 +                return true;
 +            } catch (IOException ioe) {
 +
 +            }
 +            try {
 +                Thread.sleep(1000);
 +            } catch (InterruptedException ie) {
 +                throw new CDMServerException("Error checking CDM Server status", ie);
 +            }
 +            intervalsCount++;
 +        } while (intervalsCount < checkingIntervals);
 +
 +        return false;
 +    }
 +
 +    public boolean isStopped(int checkingIntervals) throws CDMServerException {
 +        int intervalsCount = 0;
 +        do {
 +            try {
 +                Socket s = new Socket(host, port);
++            } catch (IOException ioe) {
 +                return true;
 +            }
 +            try {
 +                Thread.sleep(1000);
 +            } catch (InterruptedException ie) {
 +                throw new CDMServerException("Error checking CDM Server status", ie);
 +            }
 +            intervalsCount++;
 +        } while (intervalsCount < checkingIntervals);
 +
 +        return false;
 +    }
 +
 +    public boolean isRunning(int checkingIntervals) throws CDMServerException  {
 +        CdmRemoteSourceBase crsb = new CdmRemoteSourceBase("local-cdm-server",
 +                host,
 +                port,
 +                contextPath,
 +                null);
 +        int intervalsCount = 0;
 +        do {
 +            try {
 +                if(cdmse != null) {
 +                    return false;
 +                }
 +                if(crsb.checkConnection()) {
 +                    logger.info("[CDM-Server] Running @ " + host + ":" + port );
 +                    return true;
 +                }
 +            } catch (Exception e) {
 +            }
 +            try {
 +                Thread.sleep(1000);
 +            } catch (InterruptedException ie) {
 +                throw new CDMServerException("Error checking CDM Server status", ie);
 +            }
 +            intervalsCount++;
 +        } while (intervalsCount < checkingIntervals);
 +        return false;
 +    }
 +
 +    public void stop() throws Exception {
 +        stop(false);
 +    }
 +    public void stop(boolean force) throws Exception {
 +
 +        if(!force) {
 +            if(!getInstance().isAvailable(1)) {
 +                logger.info("[CDM-Server] Server already stopped @ " + host + ":" + port );
 +                return;
 +            }
 +
 +            if(getInstance().getKeepServerRunning()) {
 +                logger.info("[CDM-Server] Server @ " + host + ":" + port + " is set to keep running");
 +                return;
 +            }
 +        }
 +        Thread t = new Thread() {
 +            @Override
 +            public void run() {
 +                StringBuffer output = new StringBuffer();
 +                try{
 +                    Process p;
 +                    String command = "java -jar " + DEFAULT_JETTY_RESOURCE.getFile().getAbsolutePath()
 +                            + getStopServerArgs() + " --stop ";
 +                    logger.info("[CDM-Server] Stop Command : " + command);
 +                    p = Runtime.getRuntime().exec(command);
 +                    p.waitFor();
 +                    BufferedReader reader =
 +                            new BufferedReader(new InputStreamReader(p.getInputStream()));
 +                    String line = "";
 +                    while ((line = reader.readLine())!= null) {
 +                        logger.info("CDM-Server Stop : " + line + "\n");
 +                    }
 +                } catch (Exception e) {
 +                    e.printStackTrace();
 +                }
 +
 +            }
 +        };
 +
 +        t.setDaemon(true);
 +        t.start();
 +
 +        if(isStopped(5)) {
 +            logger.info("[CDM-Server] Stopped Server @ " + host + ":" + port );
 +        } else {
 +            logger.info("[CDM-Server] Could not stop @ " + host + ":" + port + ". Please kill it manually");
 +        }
 +    }
 +}