#4073 Add new project for lanuching embedded jetty server using cdmlib webapp
authorCherian Mathew <c.mathew@bgbm.org>
Wed, 11 Nov 2015 15:13:56 +0000 (16:13 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Mon, 16 Nov 2015 14:11:59 +0000 (15:11 +0100)
#4073 Add jetty server dependencies

#4073 Add stop start possibility for server

#4073 Add functionality to control managed server in login dialog

#4073 Add start / stop methods for managed server

#4073 Simplify manged server ui

#4073 Fix incorrect stop behaviour, Add mysql jdbc connector jar

#4073 Add webapp to editor project and fix file location issue

#4073 Add error callback for CDM Server start

41 files changed:
.gitignore
eu.etaxonomy.taxeditor.application/.classpath
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmTransientEntityCacher.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/server/CDMServerUtils.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java
eu.etaxonomy.taxeditor.test/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/BaseRemotingTest.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CDMServer.java [deleted file]
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmRemoteSourceTest.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmServerTest.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/TestConfig.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/ThreadedTest.java
eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/cdm.datasources.xml
eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/mgd.datasources.xml [new file with mode: 0644]
eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/test.mgd.datasources.xml [new file with mode: 0644]
eu.etaxonomy.taxeditor.test/src/test/resources/log4j.xml
eu.etaxonomy.taxeditor.test/src/test/resources/server.properties
eu.etaxonomy.taxeditor.webapp/.classpath [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/.gitignore [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/.project [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/META-INF/MANIFEST.MF [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/build.properties [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/lib/cdmlib-remote-webapp.war [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/lib/javax.servlet-api-3.1.0.jar [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/lib/jetty-all-9.2.9.v20150224.jar [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/lib/log4j-1.2.17.jar [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/lib/mysql-connector-java-5.1.24.jar [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/pom.xml [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMEmbeddedServerException.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMServer.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/ICDMServerError.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/TaxeditorWebappPlugin.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.webapp/src/main/resources/etc/jetty/.svnignore [moved from eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/.svnignore with 100% similarity]
eu.etaxonomy.taxeditor.webapp/src/main/resources/etc/jetty/jetty-runner-9.2.3.v20140905.jar [moved from eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/jetty-runner-9.2.3.v20140905.jar with 100% similarity]
eu.etaxonomy.taxeditor.webapp/src/main/resources/etc/jetty/start-9.2.3.v20140905.jar [moved from eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/start-9.2.3.v20140905.jar with 100% similarity]
pom.xml

index ee184e8334b2e5f3709f6c32585fac6c41d1c255..8912e41be5614f92eda1024092f7c6075302649b 100644 (file)
@@ -37,6 +37,8 @@ eu.etaxonomy.taxeditor.store/.settings
 eu.etaxonomy.taxeditor.store/hibernate.log
 eu.etaxonomy.taxeditor.store/target
 eu.etaxonomy.taxeditor.test/screenshots/*.jpeg
+eu.etaxonomy.taxeditor.test/src/test/resources/.cdm-server-ehcache
+eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/remote-webapp
 eu.etaxonomy.taxeditor.test/target
 eu.etaxonomy.taxeditor/.settings
 eu.etaxonomy.taxeditor/target
index 6bca977bed3b6d2bc7f202c8a811de4878f0c42b..65bcb3b5711edccc8b36d8c2aff21836b7df49fb 100644 (file)
@@ -4,5 +4,6 @@
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry including="**/*.java" kind="src" path="src/main/java"/>
        <classpathentry kind="src" path="src/test/java"/>
+       <classpathentry kind="src" path="src/main/resources/"/>
        <classpathentry kind="output" path="target/classes"/>
 </classpath>
index 8bee46bf9946ebd9e7472e970d04d4646aeb4827..05ac0435a1800f5173a69cf5e4897c5d9969dff0 100644 (file)
@@ -246,7 +246,7 @@ public class CdmApplicationState {
                     URL fileURL = bundle.getEntry(jar);
                     File file = null;
                     try {
-                        String urlString = FileLocator.resolve(fileURL).toExternalForm().replace(" ", "%20");;
+                        String urlString = FileLocator.resolve(fileURL).toExternalForm().replace(" ", "%20");
                         file = new File(new URI(urlString));
                         JarFile jarFile = new JarFile(file);
                         Manifest manifest = jarFile.getManifest();
index 7047b190d5d681558aca023a467b3621cdb5d00a..1f1d3d357e88260de7e6369dc4e527910c98819c 100644 (file)
@@ -73,6 +73,7 @@ public class CdmTransientEntityCacher implements ICdmCacher {
 
         cache = new Cache(getEntityCacheConfiguration(cacheId));
 
+        CacheManager.create().removeCache(cache.getName());
         CacheManager.create().addCache(cache);
 
         this.cdmEntitySessionManager = cdmEntitySessionManager;
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/server/CDMServerUtils.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/server/CDMServerUtils.java
new file mode 100644 (file)
index 0000000..976d2a5
--- /dev/null
@@ -0,0 +1,79 @@
+// $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.server;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationUtils;
+import eu.etaxonomy.cdm.config.CdmPersistentXMLSource.CdmSourceProperties;
+import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
+
+/**
+ * @author cmathew
+ * @date 11 Nov 2015
+ *
+ */
+public class CDMServerUtils {
+
+
+    public static String convertEditorToServerConfig() {
+        StringBuilder configStringBuilder = new StringBuilder();
+        configStringBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + System.lineSeparator());
+        configStringBuilder.append("<!-- DO NOT EDIT THIS FILE MANUALLY. -->");
+        configStringBuilder.append("<!-- It is created by the Taxonomic Editor for launching a managed CDM Server. -->");
+        configStringBuilder.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"" + System.lineSeparator());
+        configStringBuilder.append("  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + System.lineSeparator());
+        configStringBuilder.append("  xmlns:tx=\"http://www.springframework.org/schema/tx\"" + System.lineSeparator());
+        configStringBuilder.append("  xmlns:context=\"http://www.springframework.org/schema/context\"" + System.lineSeparator());
+        configStringBuilder.append("  xsi:schemaLocation=\"http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" + System.lineSeparator());
+        configStringBuilder.append("  http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-2.5.xsd" + System.lineSeparator());
+        configStringBuilder.append("  http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" + System.lineSeparator());
+        configStringBuilder.append("\">" + System.lineSeparator());
+        configStringBuilder.append(" <bean id=\"dataSourceProperties\" class=\"eu.etaxonomy.cdm.remote.config.DataSourceProperties\">" + System.lineSeparator());
+        configStringBuilder.append("   <property name=\"propsMap\">" + System.lineSeparator());
+        configStringBuilder.append("       <map/>" + System.lineSeparator());
+        configStringBuilder.append("   </property>" + System.lineSeparator());
+        configStringBuilder.append(" </bean>" + System.lineSeparator());
+
+        for(CdmPersistentDataSource dataSource : CdmPersistentDataSource.getAllDataSources()) {
+            String beanId = dataSource.getName();
+            String user = dataSource.getUsername();
+            String password = dataSource.getPassword();
+            String driverClass = dataSource.getCdmSourceProperty(CdmSourceProperties.DRIVER_CLASS);
+            String jdbcUrl = StringEscapeUtils.escapeXml(dataSource.getCdmSourceProperty(CdmSourceProperties.URL));
+            configStringBuilder.append(" <bean id=\""  + beanId + "\" lazy-init=\"true\" class=\"com.mchange.v2.c3p0.ComboPooledDataSource\">" + System.lineSeparator());
+            configStringBuilder.append("   <property name=\"driverClass\" value=\"" + driverClass + "\"/>" + System.lineSeparator());
+            configStringBuilder.append("   <property name=\"user\" value=\"" + user + "\"/>" + System.lineSeparator());
+            configStringBuilder.append("   <property name=\"password\" value=\"" + password + "\"/>" + System.lineSeparator());
+            configStringBuilder.append("   <property name=\"jdbcUrl\" value=\"" + jdbcUrl + "\"/>" + System.lineSeparator());
+            configStringBuilder.append(" </bean>" + System.lineSeparator());
+
+        }
+        configStringBuilder.append("</beans>" + System.lineSeparator());
+
+        return configStringBuilder.toString();
+    }
+
+    public static File writeManagedServerConfig(String config, String fileName) throws IOException {
+        File managedConfigFile = new File(CdmApplicationUtils.getWritableResourceDir(), fileName);
+        if(managedConfigFile.exists()) {
+            managedConfigFile.delete();
+        }
+        if(managedConfigFile.createNewFile()) {
+            FileUtils.writeStringToFile(managedConfigFile, config);
+        }
+        return managedConfigFile;
+    }
+
+}
index f30a93dcdfb17d7949b400aae3de95c86093d459..ec938383acfe9ef3c301894298b8683f0eebe3ae 100644 (file)
@@ -73,9 +73,13 @@ public class CdmServerInfo {
     private final static int PORT_LOCALHOST_DEV = 8080;
     private final static String BASEPATH_LOCALHOST_DEV = "";
 
+    public final static int NULL_PORT = -1;
+    public final static String NULL_PORT_STRING = "N/A";
+
+
     private final String name;
     private final String server;
-    private final int port;
+    private int port;
     private final List<CdmInstanceInfo> instances;
 
     private static List<CdmServerInfo> cdmServerInfoList;
@@ -94,7 +98,11 @@ public class CdmServerInfo {
 
 
     public CdmInstanceInfo addInstance(String name, String basePath) {
-        CdmInstanceInfo cii = new CdmInstanceInfo(name, basePath);
+        String _basePath = basePath;
+        if(isLocalhostMgd()) {
+            _basePath = "";
+        }
+        CdmInstanceInfo cii = new CdmInstanceInfo(name, _basePath);
         instances.add(cii);
         return cii;
 
@@ -212,12 +220,10 @@ public class CdmServerInfo {
     }
 
     public void addInstancesFromDataSourcesConfig() {
-
         for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()){
-            logger.warn("Adding local instance " + dataSource.getName());
+            logger.info("Adding local instance " + dataSource.getName());
             addInstance(dataSource.getName(), dataSource.getName());
         }
-
     }
 
     public String toString(String instanceName, int port) {
@@ -249,6 +255,9 @@ public class CdmServerInfo {
     }
 
     public boolean pingServer() {
+        if(isLocalhostMgd()) {
+            return true;
+        }
         try {
             Socket s = new Socket(server, port);
             logger.info("[CDM-Server] Available @ " + server + ":" + port );
@@ -365,7 +374,7 @@ public class CdmServerInfo {
             cdmServerInfoList.add(new CdmServerInfo(NAME_DEMO_2, SERVER_DEMO_2, 80));
             cdmServerInfoList.add(new CdmServerInfo(NAME_TEST, SERVER_TEST, 80));
             cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST, SERVER_LOCALHOST, 8080));
-            cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST,8080));
+            cdmServerInfoList.add(new CdmServerInfo(NAME_LOCALHOST_MGD, SERVER_LOCALHOST,NULL_PORT));
         }
         return cdmServerInfoList;
     }
@@ -383,6 +392,9 @@ public class CdmServerInfo {
         return port;
     }
 
+    public void setPort(int port) {
+        this.port = port;
+    }
 
     public List<CdmInstanceInfo> getInstances() throws CDMServerException {
         if(instances.isEmpty()) {
@@ -417,7 +429,7 @@ public class CdmServerInfo {
         /**
          * The full path of the instance including the the prefix (if any).
          * E.g. for an EDIT instance this would be something like "cdmserver/remoting"
-         * For a managed local server this would simply be "remoting"
+         * For a managed local server this would simply be ""
          */
         private final String basePath;
 
index 061e6683440f343a85a718dc9990c61b32b90191..4629862f6ead3c43dcc326c8f306a69815f11423 100644 (file)
@@ -68,7 +68,8 @@ Require-Bundle: org.eclipse.osgi,
  org.eclipse.core.databinding.observable,
  org.eclipse.core.databinding.property,
  org.eclipse.jface.databinding
-Import-Package: org.eclipse.core.commands,
+Import-Package: eu.etaxonomy.taxeditor.webapp,
+ org.eclipse.core.commands,
  org.eclipse.core.commands.operations,
  org.eclipse.core.expressions,
  org.eclipse.core.runtime,
index c4d231be2f82347b1c118371dbcc9c90a7e66b20..bd594ad195403921c50c83a659ac4609e111d4f6 100644 (file)
@@ -50,6 +50,7 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 import eu.etaxonomy.taxeditor.ui.dialog.RemotingLoginDialog;
 import eu.etaxonomy.taxeditor.util.ProgressMonitorClientManager;
 import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
+import eu.etaxonomy.taxeditor.webapp.CDMServer;
 
 /**
  * This implementation of ICdmDataRepository depends on hibernate sessions to
@@ -90,6 +91,8 @@ public class CdmStore {
 
     private static CdmStoreConnector job;
 
+    private static CDMServer managedServer;
+
     private Language language;
 
     private ICdmSource cdmSource;
@@ -594,4 +597,13 @@ public class CdmStore {
         return cdmSource;
     }
 
+
+    public static void setManagedServer(CDMServer server) {
+        managedServer = server;
+    }
+
+    public static CDMServer getManagedServer() {
+        return managedServer;
+    }
+
 }
index 4d088a4f3b912fef618696a214697691922df449..b8cca7c84b4af373ecf93ec9a0487200c5d1f176 100644 (file)
@@ -9,6 +9,8 @@
  */
 package eu.etaxonomy.taxeditor.ui.dialog;
 
+import java.io.File;
+import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
@@ -43,6 +45,7 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.events.ExpansionEvent;
 import org.eclipse.ui.forms.events.IExpansionListener;
 import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.progress.IProgressConstants;
 import org.eclipse.wb.swt.SWTResourceManager;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
@@ -53,18 +56,24 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
+import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils;
 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
 import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
 import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo.CdmInstanceInfo;
 import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException;
+import eu.etaxonomy.taxeditor.webapp.CDMServer;
+import eu.etaxonomy.taxeditor.webapp.ICDMServerError;
+
 
 /**
  * @author cmathew
  * @date 20 Jan 2015
  *
  */
-public class RemotingLoginDialog extends Dialog {
+public class RemotingLoginDialog extends Dialog implements ICDMServerError {
 
     protected Object result;
     protected Shell shlConnect;
@@ -78,6 +87,8 @@ public class RemotingLoginDialog extends Dialog {
 
     private final static String STATUS_AVAILABLE = "Available";
     private final static String STATUS_NOT_AVAILABLE = "Not Available";
+    private final static String STATUS_STARTED = "Started";
+    private final static String STATUS_NOT_STARTED = "Not Started";
     private final static String STATUS_RETRIEVING = "Retrieving ...";
     private final static String STATUS_CHECKING_AVAILABILITY = "Checking ...";
     private final static String STATUS_NO_INSTANCES = "No Instances Found";
@@ -98,11 +109,14 @@ public class RemotingLoginDialog extends Dialog {
     private final static String LAST_SERVER_KEY = "lastServerKey";
     private final static String LAST_INSTANCE_KEY = "lastInstanceKey";
 
+    private final static String REFRESH_LABEL = "Refresh";
 
     private Composite remotingComposite;
     private CdmServerInfo selectedCsii;
     private CdmInstanceInfo selectedCdmInstance;
     private Button btnCdmServerRefresh;
+    private Button btnCdmInstanceRefresh;
+    private Button btnStopServer;
     private Composite loginComposite;
     private Label lblLogin;
     private Text txtLogin;
@@ -133,7 +147,7 @@ public class RemotingLoginDialog extends Dialog {
     private boolean autoConnect = false;
     private boolean loadLoginPrefs = true;
     private boolean isDevRemoteSource = false;
-
+    private Job serverJob;
     /**
      * Create the dialog.
      * @param parent
@@ -166,10 +180,7 @@ public class RemotingLoginDialog extends Dialog {
      * @return the result
      */
     public Object open() {
-        //        ICdmRemoteSource devRemoteSource = CdmServerInfo.getDevServerRemoteSource();
-        //        if(devRemoteSource != null) {
-        //            connect(devRemoteSource);
-        //        } else {
+
         createContents();
         if(serverName == null && instanceName == null) {
             readPrefLastServerInstance();
@@ -189,7 +200,7 @@ public class RemotingLoginDialog extends Dialog {
                 display.sleep();
             }
         }
-        //}
+
         return result;
     }
 
@@ -258,8 +269,7 @@ public class RemotingLoginDialog extends Dialog {
         comboCdmInstance.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                updateSelectedCdmInstance();
-                checkSelectedCdmInstance();
+                refreshCdmInstance();
             }
         });
         GridData gd_comboCdmInstance = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
@@ -274,7 +284,7 @@ public class RemotingLoginDialog extends Dialog {
         gd_txtCdmInstanceStatus.widthHint = 100;
         txtCdmInstanceStatus.setLayoutData(gd_txtCdmInstanceStatus);
 
-        Button btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
+        btnCdmInstanceRefresh = new Button(cdmServerComposite, SWT.FLAT);
         btnCdmInstanceRefresh.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -328,7 +338,11 @@ public class RemotingLoginDialog extends Dialog {
         btnConnect.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseUp(MouseEvent e) {
-                connect();
+                if(selectedCsii.isLocalhostMgd() && !isSelectedCdmInstanceRunningInManagedServer()) {
+                    startManagedServer();
+                } else {
+                    connect();
+                }
             }
         });
         btnConnect.setText("Connect");
@@ -404,8 +418,15 @@ public class RemotingLoginDialog extends Dialog {
         txtServerVersion = new Text(compAdvanced, SWT.BORDER);
         txtServerVersion.setEditable(false);
         txtServerVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
-        new Label(compAdvanced, SWT.NONE);
-        new Label(compAdvanced, SWT.NONE);
+        btnStopServer = new Button(compAdvanced, SWT.FLAT);
+        btnStopServer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+        btnStopServer.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseUp(MouseEvent e) {
+                stopManagedServer();
+            }
+        });
+        btnStopServer.setText("Stop Managed Server");
 
         lblEditorVersion = new Label(compAdvanced, SWT.CENTER);
         lblEditorVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
@@ -504,16 +525,23 @@ public class RemotingLoginDialog extends Dialog {
     private void updatePort() {
         txtPort.setText("");
         if(selectedCsii != null) {
-            txtPort.setText(String.valueOf(selectedCsii.getPort()));
+            int port = selectedCsii.getPort();
+            if(port == CdmServerInfo.NULL_PORT) {
+                txtPort.setText(CdmServerInfo.NULL_PORT_STRING);
+            } else {
+                txtPort.setText(String.valueOf(port));
+            }
         }
     }
 
     private int getPort() {
-        int port = 0;
+        int port = CdmServerInfo.NULL_PORT;
         try {
             port = Integer.valueOf(txtPort.getText());
         } catch (NumberFormatException nfe) {
-            setMessage("Port should be an integer");
+            if(!CdmServerInfo.NULL_PORT_STRING.equals(txtPort.getText())) {
+                setMessage("Port should be an integer");
+            }
         }
         return port;
     }
@@ -531,9 +559,8 @@ public class RemotingLoginDialog extends Dialog {
             if(selectedCsii.pingServer()) {
                 txtCdmServerStatus.setText(STATUS_AVAILABLE);
                 populateCdmInstanceCombo(true);
-                txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion());
-                txtServerVersion.setToolTipText(generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified()));
-
+                String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
+                txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp);
             } else {
                 txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
                 comboCdmInstance.removeAll();
@@ -549,7 +576,7 @@ public class RemotingLoginDialog extends Dialog {
         txtCdmInstanceStatus.setText(STATUS_RETRIEVING);
         txtCdmInstanceStatus.setToolTipText("");
 
-        Job job = new Job("Retrieve Server Instances") {
+        serverJob = new Job("Retrieve Server Instances") {
             @Override
             protected IStatus run(IProgressMonitor monitor) {
                 try {
@@ -575,8 +602,7 @@ public class RemotingLoginDialog extends Dialog {
                                     } else {
                                         comboCdmInstance.select(instanceIndex);
                                     }
-                                    updateSelectedCdmInstance();
-                                    checkSelectedCdmInstance();
+                                    refreshCdmInstance();
                                     comboCdmInstance.setEnabled(true);
                                     if(autoConnect) {
                                         connect();
@@ -607,9 +633,10 @@ public class RemotingLoginDialog extends Dialog {
 
         if(txtCdmServerStatus.getText().equals(STATUS_AVAILABLE) && !isDevRemoteSource) {
             // Start the Job
-            job.schedule();
+            serverJob.schedule();
         }
 
+
     }
 
     private void refreshCdmInstance() {
@@ -617,18 +644,160 @@ public class RemotingLoginDialog extends Dialog {
         clearOnInstanceChange();
         updateSelectedCdmInstance();
         checkSelectedCdmInstance();
+        updateManagedServerControls();
     }
 
     private void updateSelectedCdmInstance() {
         int selIndex = comboCdmInstance.getSelectionIndex();
         if(selIndex != -1) {
             selectedCdmInstance = selectedCsii.getInstanceFromName(comboCdmInstance.getItem(selIndex));
+
             if(loadLoginPrefs && !isDevRemoteSource) {
                 readPrefCredentials();
             }
         }
     }
 
+    private void updateManagedServerControls() {
+        if(selectedCsii.isLocalhostMgd()) {
+            if(isSelectedCdmInstanceRunningInManagedServer()) {
+                txtCdmInstanceStatus.setText(STATUS_STARTED);
+            } else {
+                txtCdmInstanceStatus.setText(STATUS_NOT_STARTED);
+            }
+            btnConnect.setEnabled(true);
+            selectedCsii.setPort(getManagedServerPort());
+            updatePort();
+        }
+
+
+        if(isManagedServerRunning()) {
+            btnStopServer.setEnabled(true);
+        } else {
+            btnStopServer.setEnabled(false);
+        }
+    }
+
+    private boolean isManagedServerRunning() {
+        return CdmStore.getManagedServer() != null && CdmStore.getManagedServer().isAlive();
+    }
+
+    private boolean isSelectedCdmInstanceRunningInManagedServer() {
+        return CdmStore.getManagedServer() != null &&
+                CdmStore.getManagedServer().isAlive() &&
+                selectedCsii.isLocalhostMgd() &&
+                CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName());
+    }
+
+    private boolean isActiveCdmInstanceRunningInManagedServer() {
+        return CdmStore.getManagedServer() != null &&
+                CdmStore.getManagedServer().isAlive() &&
+                CdmStore.isActive() &&
+                CdmServerInfo.NAME_LOCALHOST_MGD.equals(CdmStore.getActiveCdmSource().getName());
+    }
+
+
+    private void startManagedServer() {
+        if(isManagedServerRunning()) {
+            if(CdmStore.getManagedServer().getDataSourceName().equals(selectedCdmInstance.getName())) {
+                return;
+            } else {
+                Display.getDefault().syncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        stopManagedServer();
+                    }
+                });
+            }
+        }
+
+
+        Job job = new Job("Managed CDM Server Launch") {
+
+            @Override
+            public IStatus run(IProgressMonitor monitor) {
+                String mgdServerConfigFileName = "mgd.datasources.xml";
+                String config = CDMServerUtils.convertEditorToServerConfig();
+                File managedServerConfigFile;
+                int maxUnits = 50;
+                monitor.beginTask("Launching Managed CDM Server", maxUnits);
+                try {
+                    monitor.subTask("Generating datasources config file for " + selectedCdmInstance.getName());
+                    managedServerConfigFile = CDMServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
+                    monitor.worked(1);
+                    CdmStore.setManagedServer(new CDMServer(selectedCdmInstance.getName(), managedServerConfigFile));
+                    monitor.subTask("Starting Managed CDM Server. This may take a while.");
+                    CdmStore.getManagedServer().start(false, RemotingLoginDialog.this);
+                    int serverUnits = 0;
+
+                    // the following loop is a 'fake' progress monitoring where the progress
+                    // bar is advanced by one unit every second until maxUnits -2
+                    while(!CdmStore.getManagedServer().isStarted()) {
+                        if(serverUnits < maxUnits - 2) {
+                            try {
+                                Thread.sleep(1000);
+                            } catch (InterruptedException e) {
+                            }
+                            monitor.worked(1);
+                            serverUnits++;
+                        }
+                    }
+                    Display.getDefault().asyncExec(new Runnable() {
+                        @Override
+                        public void run() {
+                            hide(false);
+                            updateManagedServerControls();
+                            connect();
+                        }
+                    });
+                } catch (IOException ioe) {
+                    MessagingUtils.errorDialog("Error generating server config file",
+                            this,
+                            ioe.getMessage(),
+                            TaxeditorStorePlugin.PLUGIN_ID,
+                            ioe,
+                            true);
+                } catch (CDMEmbeddedServerException cse) {
+                    MessagingUtils.errorDialog("Error starting managed server",
+                            this,
+                            cse.getMessage(),
+                            TaxeditorStorePlugin.PLUGIN_ID,
+                            cse,
+                            true);
+                } finally {
+                    monitor.done();
+                }
+                return Status.OK_STATUS;
+            }
+        };
+
+        // configure the job
+        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+        job.setUser(true);
+        // schedule job
+        hide(true);
+        job.schedule();
+    }
+
+    private void stopManagedServer() {
+        try {
+            CdmStore.getManagedServer().stop();
+        } catch (Exception e) {
+            MessagingUtils.errorDialog("Error stopping managed server",
+                    this,
+                    "Could not stop managed server running at port " + CdmStore.getManagedServer().getPort() + ". Please stop it manually",
+                    TaxeditorStorePlugin.PLUGIN_ID,
+                    e,
+                    true);
+        }
+        CdmStore.setManagedServer(null);
+        updateManagedServerControls();
+    }
+
+    private int getManagedServerPort() {
+        return CdmStore.getManagedServer() == null ? CdmServerInfo.NULL_PORT : CdmStore.getManagedServer().getPort();
+    }
+
     private void checkSelectedCdmInstance() {
         boolean available = false;
         String status = STATUS_NOT_AVAILABLE;
@@ -676,9 +845,7 @@ public class RemotingLoginDialog extends Dialog {
                     setMessage(message);
                 }
             }
-
         }
-
     }
 
     private void connect() {
@@ -845,20 +1012,23 @@ public class RemotingLoginDialog extends Dialog {
     }
 
     private String generateLastModifiedTooltip(String cdmlibLastModified) {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z");
+        if(StringUtils.isBlank(cdmlibLastModified)) {
+            return "";
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.z");
         Date cdmlibLastModifiedDate;
         String cdmlibLastModifiedTimestamp = "";
 
         cdmlibLastModifiedDate = new Date(Long.valueOf(cdmlibLastModified));
         cdmlibLastModifiedTimestamp = sdf.format(cdmlibLastModifiedDate);
 
-        return "last modified : " + cdmlibLastModifiedTimestamp;
+        return cdmlibLastModifiedTimestamp;
     }
 
     private void setEditorInfo() {
         txtEditorCDMVersion.setText(CdmMetaData.getDbSchemaVersion());
-        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion());
-        txtEditorVersion.setToolTipText(generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified()));
+        String editorVersionTimestamp = generateLastModifiedTooltip(CdmApplicationState.getCdmlibLastModified());
+        txtEditorVersion.setText(CdmApplicationState.getCdmlibVersion() + ":" + editorVersionTimestamp);
     }
 
     private void clearOnServerChange() {
@@ -876,8 +1046,30 @@ public class RemotingLoginDialog extends Dialog {
         txtServerCDMVersion.setText("");
     }
 
-    private void updateOnServerChange(String serverVersion, String serverVersionTooltip) {
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void handleError(final Throwable t) {
+
+        Display.getDefault().syncExec(new Runnable() {
+            @Override
+            public void run() {
+                serverJob.cancel();
 
+                String title = "CDM Server launch error";
+                String  message = t.getMessage();
+
+
+                MessagingUtils.errorDialog(title,
+                        this,
+                        message,
+                        TaxeditorStorePlugin.PLUGIN_ID,
+                        t,
+                        true);
+            }
+        });
     }
 
+
 }
index 9dd1f4af85ba0e6240cf1c4cf27e3331ef3d9c00..858c25d4fab82c0e18a649ae72e74fcec5b249f4 100644 (file)
@@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.ui,
  org.apache.log4j,
  org.hamcrest,
  org.eclipse.swtbot.eclipse.core,
- org.eclipse.swtbot.eclipse.finder
+ org.eclipse.swtbot.eclipse.finder,
+ eu.etaxonomy.taxeditor.webapp;bundle-version="3.12.0"
 Eclipse-RegisterBuddy: org.apache.log4j, org.eclipse.swtbot.swt.finder
 Bundle-ClassPath: .,
  lib/byte-buddy-0.5.1.jar,
index 8a0e1859127e0d36acca4fa39462c6d44eb359ba..177638db1f8460cd725afb73bb7b8b2279196145 100644 (file)
@@ -8,24 +8,14 @@
  */
 package eu.etaxonomy.taxeditor.httpinvoker;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
 import java.lang.reflect.Field;
-import java.net.URL;
 import java.util.Map;
-import java.util.Properties;
 
 import net.sf.ehcache.CacheManager;
 
 import org.apache.log4j.Logger;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
 import org.junit.Assert;
 import org.junit.BeforeClass;
-import org.osgi.framework.Bundle;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -63,71 +53,20 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 public abstract class BaseRemotingTest extends ThreadedTest {
     private static final Logger logger = Logger.getLogger(BaseRemotingTest.class);
 
-
-    public static final Resource SERVER_PROPERTIES_FILE =
-            new ClassPathResource("server.properties");
-
     private static ICdmRemoteSource cdmRemoteSource;
     private static CdmPersistentRemoteSource remotePersistentSource;
-
-    public static boolean useManagedServer = true;
-
-
     protected static ICdmEntitySessionManager cdmEntitySessionManager;
 
-    private final static String DEFAULT_USER = "admin";
-    private final static String DEFAULT_PASSWORD = "00000";
-
-    private static String userHomeKey = "user.home";
-
-    private static String user = DEFAULT_USER;
-    private static String password = DEFAULT_PASSWORD;
-
-
-    protected static CDMServer cdmServer;
-
     @BeforeClass
     public static void initializeBaseRemotingTest() {
 
         DatabaseUnitils.disableConstraints();
 
         try {
-            String userHomeDirPath;
-            Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.test");
-
-            URL userHomeDirURL = bundle.getEntry("src/test/resources");
-            File userHomeDir = new File(FileLocator.resolve(userHomeDirURL).toURI());
-            userHomeDirPath = userHomeDir.getAbsolutePath();
-
-            URL serverPropertiesURL = bundle.getEntry("src/test/resources/server.properties");
-            File serverPropertiesFile = new File(FileLocator.resolve(serverPropertiesURL).toURI());
-            InputStream inputStream = new FileInputStream(serverPropertiesFile);
-
-            Properties prop = new Properties();
-            if (inputStream != null) {
-                prop.load(inputStream);
-                inputStream.close();
-            }
-
-            logger.info("Setting user.home to " + userHomeDirPath);
-            System.setProperty(userHomeKey, userHomeDirPath);
-
-
-            cdmServer = new CDMServer("cdmTest", serverPropertiesURL);
-
-
-            if(prop.getProperty("user") != null) {
-                user = prop.getProperty("user");
-            }
-
-            if(prop.getProperty("password") != null) {
-                password = prop.getProperty("password");
-            }
-
-            initializeController(cdmServer.getName(),
-                    cdmServer.getHost(),
-                    cdmServer.getPort(),
-                    cdmServer.getContextPath(),
+            initializeController(sourceName,
+                    host,
+                    httpPort,
+                    contextPath,
                     NomenclaturalCode.ICNAFP,
                     user,
                     password);
diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CDMServer.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CDMServer.java
deleted file mode 100644 (file)
index 2453912..0000000
+++ /dev/null
@@ -1,401 +0,0 @@
-// $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.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Properties;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanServerConnection;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-import javax.sql.DataSource;
-
-import org.apache.log4j.Logger;
-import org.eclipse.core.runtime.FileLocator;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.unitils.database.annotations.TestDataSource;
-
-import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
-import eu.etaxonomy.cdm.database.ICdmDataSource;
-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 int httpPort = 9090;
-    private int stopPort = 9191;
-    private String stopKey = "jetty-cdm-server";
-    private final String contextPath = "";
-
-    public static final Resource DEFAULT_CDM_WEBAPP_RESOURCE =
-            new ClassPathResource("/etc/jetty/cdmlib-remote-webapp.war");
-
-    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 boolean serverAlreadyRunning = false;
-
-    private File dataSourcesFile;
-    private final String dataSourceName;
-
-    public CDMServer(String dataSourceName, URL serverPropertiesURL) throws CDMServerException {
-        this.dataSourceName = dataSourceName;
-        Properties prop = new Properties();
-
-        try {
-            File serverPropertiesFile = new File(FileLocator.resolve(serverPropertiesURL).toURI());
-            InputStream inputStream = new FileInputStream(serverPropertiesFile);
-
-            prop.load(inputStream);
-            inputStream.close();
-
-        } catch (FileNotFoundException e) {
-            throw new CDMServerException(e);
-        } catch (URISyntaxException e) {
-            throw new CDMServerException(e);
-        } catch (IOException e) {
-            throw new CDMServerException(e);
-        }
-
-
-
-        if(prop.getProperty("httpPort") != null) {
-            setHttpPort(Integer.valueOf(prop.getProperty("httpPort")));
-        }
-
-        if(prop.getProperty("stopPort") != null) {
-            setStopPort(Integer.valueOf(prop.getProperty("stopPort")));
-        }
-
-        if(prop.getProperty("stopKey") != null) {
-            setStopKey(prop.getProperty("stopKey"));
-        }
-
-    }
-
-
-
-    public String getName() {
-        return name;
-    }
-
-    public String getHost() {
-        return host;
-    }
-
-    public int getPort() {
-        return httpPort;
-    }
-
-    public String getContextPath() {
-        return contextPath;
-    }
-
-    public void setHttpPort(int port) {
-        this.httpPort = port;
-    }
-
-    public void setStopPort(int stopPort) {
-        this.stopPort = stopPort;
-    }
-
-    public void setStopKey(String stopKey) {
-        this.stopKey = stopKey;
-    }
-
-
-    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() throws IOException {
-        StringBuilder sb = new StringBuilder();
-        sb.append(" --port " + httpPort);
-        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(isStarted(1)) {
-            logger.info("[CDM-Server] Server already running @ " + host + ":" + httpPort );
-            serverAlreadyRunning = true;
-            return;
-        }
-
-        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 inpReader =
-                            new BufferedReader(new InputStreamReader(p.getInputStream()));
-
-                    BufferedReader errReader =
-                            new BufferedReader(new InputStreamReader(p.getErrorStream()));
-
-                    String line = "";
-                    while ((line = inpReader.readLine())!= null) {
-                        logger.info("[CDM-Server Start] : " + line);
-                    }
-
-                    while ((line = errReader.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(isStarted(50)) {
-            logger.info("[CDM-Server] Server running @ " + host + ":" + httpPort );
-        } 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 isStarted(int checkingIntervals) throws CDMServerException  {
-        CdmRemoteSourceBase crsb = new CdmRemoteSourceBase("local-cdm-server",
-                host,
-                httpPort,
-                contextPath,
-                null);
-        int intervalsCount = 0;
-        do {
-            try {
-                if(cdmse != null) {
-                    return false;
-                }
-                boolean check = crsb.checkConnection();
-                if(check) {
-                    logger.info("[CDM-Server] Running @ " + host + ":" + httpPort );
-                    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(!cdmServer.isStarted(1)) {
-                logger.info("[CDM-Server] Server already stopped @ " + host + ":" + httpPort );
-                return;
-            }
-        }
-
-        if(serverAlreadyRunning) {
-            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);
-
-                    BufferedReader inpReader =
-                            new BufferedReader(new InputStreamReader(p.getInputStream()));
-
-                    BufferedReader errReader =
-                            new BufferedReader(new InputStreamReader(p.getErrorStream()));
-
-                    String line = "";
-                    while ((line = inpReader.readLine())!= null) {
-                        logger.info("[CDM-Server Stop] : " + line);
-                    }
-
-                    while ((line = errReader.readLine())!= null) {
-                        logger.info("[CDM-Server Stop] : " + line);
-                    }
-                    logger.info("CDM-Server Stopped : ");
-                } catch (Exception e) {
-                    logger.info("[CDM-Server] Could not stop @ " + host + ":" + httpPort + ". Please kill it manually");
-
-                }
-
-            }
-        };
-
-        t.setDaemon(true);
-        t.start();
-
-    }
-
-    public static void stopServerViaJMX(int jmxPort) throws CDMServerException  {
-        String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
-        logger.warn("Shutting down Jetty instance ... ");
-
-        try {
-            JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), null);
-            connector.connect(null);
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName objectName = new ObjectName("org.eclipse.jetty.server:type=server,id=0");
-            connection.invoke(objectName, "stop", null, null);
-            logger.warn("Shutdown command sent");
-        } catch (InstanceNotFoundException e) {
-            throw new CDMServerException(e);
-        } catch (MBeanException e) {
-            throw new CDMServerException(e);
-        } catch (ReflectionException e) {
-            throw new CDMServerException(e);
-        } catch (IOException e) {
-            throw new CDMServerException(e);
-        } catch (MalformedObjectNameException e) {
-            throw new CDMServerException(e);
-        }
-    }
-
-    public void convertEditorToServerConfig() {
-        String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + System.lineSeparator() +
-                "<beans xmlns=\"http://www.springframework.org/schema/beans\"" + System.lineSeparator() +
-                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + System.lineSeparator() +
-                "xmlns:tx=\"http://www.springframework.org/schema/tx\"" + System.lineSeparator() +
-                "xmlns:context=\"http://www.springframework.org/schema/context\"" + System.lineSeparator() +
-                "xsi:schemaLocation=\"http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" + System.lineSeparator() +
-                "http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-2.5.xsd" + System.lineSeparator() +
-                "http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" + System.lineSeparator() +
-                ">" + System.lineSeparator() +
-                "<bean id=\"dataSourceProperties\" class=\"eu.etaxonomy.cdm.remote.config.DataSourceProperties\">" + System.lineSeparator() +
-                "   <property name=\"propsMap\">" + System.lineSeparator() +
-                "       <map/>" + System.lineSeparator() +
-                "   </property>" + System.lineSeparator() +
-                "</bean>";
-
-        for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()) {
-
-        }
-    }
-}
index bf4557555c341b2f7a375cf0e69359981b3c05aa..b3225b97fc948ee38a45abb2640f9aa6b458a119 100644 (file)
@@ -26,10 +26,10 @@ public class CdmRemoteSourceTest extends BaseRemotingTest {
        public void whenConnectingToInactiveServerThenFailToConnect() {
 
                // check if non-active server throws the right exception
-               CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(cdmServer.getName(),
-                       cdmServer.getHost(),
+               CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(sourceName,
+                       host,
                        808080,
-                       cdmServer.getContextPath(),
+                       contextPath,
                        NomenclaturalCode.ICNAFP);
                try {
                        inactiveCrs.getDbSchemaVersion();
@@ -68,10 +68,10 @@ public class CdmRemoteSourceTest extends BaseRemotingTest {
        @Test
        public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
                // check if active server throws the right exception
-               CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(cdmServer.getName(),
-                       cdmServer.getHost(),
-                       cdmServer.getPort(),
-                       cdmServer.getContextPath(),
+               CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(sourceName,
+                       host,
+                       httpPort,
+                       contextPath,
                 NomenclaturalCode.ICNAFP);
                String dbSchemaVersion = "";
                try {
index 81f9dda707622556042ea0c6c958371248ace956..e78d31d488c913eb63801f2bf12cb5da63c6fc54 100644 (file)
@@ -9,39 +9,58 @@
 */
 package eu.etaxonomy.taxeditor.httpinvoker;
 
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
 import java.net.URL;
 
 import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.FileLocator;
 import org.eclipse.core.runtime.Platform;
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
-import org.unitils.UnitilsJUnit4;
 
-import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
+import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils;
+import eu.etaxonomy.taxeditor.webapp.CDMEmbeddedServerException;
+import eu.etaxonomy.taxeditor.webapp.CDMServer;
+import eu.etaxonomy.taxeditor.webapp.ICDMServerError;
+
 
 /**
  * @author cmathew
  * @date 6 Oct 2014
  *
  */
-public class CdmServerTest extends UnitilsJUnit4 {
+public class CdmServerTest extends TestConfig {
     private static final Logger logger = Logger.getLogger(CdmServerTest.class);
 
-    @Ignore // this should be targetting integration or production
+
+
     @Test
-    public void startCdmServer() throws CDMServerException {
+    public void generateConfigFile() throws IOException {
+        String mgdServerConfigFileName = "test.mgd.datasources.xml";
+        String config = CDMServerUtils.convertEditorToServerConfig();
+        CDMServerUtils.writeManagedServerConfig(config, mgdServerConfigFileName);
+    }
+
+    @Test
+    public void manageCdmServer() throws IOException, URISyntaxException, CDMEmbeddedServerException {
         Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.test");
-        URL serverPropertiesURL = bundle.getEntry("src/test/resources/server.properties");
-        CDMServer cdmServer = new CDMServer("cdmTest", serverPropertiesURL);
-        cdmServer .start();
+        URL mgdDatasourcesConfigURL = bundle.getEntry("src/test/resources/.cdmLibrary/writableResources/mgd.datasources.xml");
+        File mgdDatasourcesConfigFile = new File(FileLocator.resolve(mgdDatasourcesConfigURL).toURI());
+        CDMServer cdmServer = new CDMServer("cdmTest", mgdDatasourcesConfigFile);
+        cdmServer.start(new ICDMServerError() {
+            @Override
+            public void handleError(Throwable t) {
+                Assert.fail("Error starting server. Reason : " + t.getMessage());
+            }
+        });
         try {
-            cdmServer.stop(true);
+            cdmServer.stop();
         } catch (Exception e) {
             e.printStackTrace();
-            Assert.fail("Server could not be stopped. Reason : " + e.getMessage());
+            Assert.fail("Error stopping server. Reason : " + e.getMessage());
         }
     }
-
 }
diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/TestConfig.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/TestConfig.java
new file mode 100644 (file)
index 0000000..4e28075
--- /dev/null
@@ -0,0 +1,96 @@
+// $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.httpinvoker;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.junit.BeforeClass;
+import org.osgi.framework.Bundle;
+import org.unitils.UnitilsJUnit4;
+
+/**
+ * @author cmathew
+ * @date 11 Nov 2015
+ *
+ */
+public class TestConfig extends UnitilsJUnit4 {
+
+    private static final Logger logger = Logger.getLogger(TestConfig.class);
+
+    private final static String DEFAULT_USER = "admin";
+    private final static String DEFAULT_PASSWORD = "00000";
+    private final static int DEFAULT_HTTP_PORT = 9090;
+    private final static String DEFAULT_CONTEXT_PATH = "";
+    private final static String DEFAULT_SOURCE_NAME = "default";
+    private final static String DEFAULT_HOST = "localhost";
+
+    private static String userHomeKey = "user.home";
+
+    protected static String user = DEFAULT_USER;
+    protected static String password = DEFAULT_PASSWORD;
+    protected static int httpPort = DEFAULT_HTTP_PORT;
+    protected static String contextPath = DEFAULT_CONTEXT_PATH;
+    protected static String sourceName = DEFAULT_SOURCE_NAME;
+    protected static String host = DEFAULT_HOST;
+
+    @BeforeClass
+    public static void initializeTestConfig() {
+        try {
+            String userHomeDirPath;
+            Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.test");
+
+            URL userHomeDirURL = bundle.getEntry("src/test/resources");
+            File userHomeDir = new File(FileLocator.resolve(userHomeDirURL).toURI());
+            userHomeDirPath = userHomeDir.getAbsolutePath();
+
+            URL serverPropertiesURL = bundle.getEntry("src/test/resources/server.properties");
+            File serverPropertiesFile = new File(FileLocator.resolve(serverPropertiesURL).toURI());
+            InputStream inputStream = new FileInputStream(serverPropertiesFile);
+
+            Properties prop = new Properties();
+
+            prop.load(inputStream);
+            inputStream.close();
+
+
+            logger.warn("Setting user.home to " + userHomeDirPath);
+            System.setProperty(userHomeKey, userHomeDirPath);
+
+
+            if(prop.getProperty("user") != null) {
+                user = prop.getProperty("user");
+            }
+
+            if(prop.getProperty("password") != null) {
+                password = prop.getProperty("password");
+            }
+
+            if(prop.getProperty("httpPort") != null) {
+                httpPort = Integer.valueOf(prop.getProperty("httpPort"));
+            }
+
+            if(prop.getProperty("contextPath") != null) {
+                contextPath = prop.getProperty("contextPath");
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            // Assert.fail("Server failed to start. Reason : " + e.getMessage());
+        }
+    }
+
+}
index bea9a62ec90d06ea67e0b95c3c0d6165e52af00a..43e99701f61628c3dc0320a0a00f6fb6acc4d84c 100644 (file)
@@ -13,14 +13,13 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.junit.After;
-import org.unitils.UnitilsJUnit4;
 
 /**
  * @author cmathew
  * @date 16 Oct 2015
  *
  */
-public abstract class ThreadedTest extends UnitilsJUnit4 {
+public abstract class ThreadedTest  extends TestConfig {
 
     private Set<TestThread> threadPool = new HashSet<TestThread>();
 
index 7cb8fa81b8b6f27f16b8bfadc11c86f4f897d94c..a7dbcd7734d9d9cbb1011a07c80f9457ea02dc0a 100644 (file)
@@ -1,13 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd      http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context-2.5.xsd">
-  <bean id="defaultRemoteSource">
-    <property name="server" value="127.0.0.1" />
-    <property name="port" value="9090" />
-    <property name="contextPath" value="" />
-  </bean>
-  <bean id="incompleteRemoteSource">
-    <property name="port" value="9090" />
-    <property name="contextPath" value="" />
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-2.5.xsd">ls 
+  <bean id="cdmTestDataSource" class="eu.etaxonomy.cdm.database.LocalH2" lazy-init="true">
+    <property name="driverClassName" value="org.h2.Driver" />
+    <property name="url" value="jdbc:h2:file:./target/classes/h2/cdmTest;AUTO_SERVER=TRUE" />
+    <property name="username" value="sa" />
+    <property name="password" value="" />
+    <property name="mode" value="embedded" />
+    <property name="nomenclaturalCode" value="ICNAFP" />
   </bean>
 </beans>
 
diff --git a/eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/mgd.datasources.xml b/eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/mgd.datasources.xml
new file mode 100644 (file)
index 0000000..3532951
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:tx="http://www.springframework.org/schema/tx"
+  xmlns:context="http://www.springframework.org/schema/context"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+  http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-2.5.xsd
+  http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+">
+ <bean id="dataSourceProperties" class="eu.etaxonomy.cdm.remote.config.DataSourceProperties">
+   <property name="propsMap">
+       <map/>
+   </property>
+ </bean>
+ <bean id="cdmTest" lazy-init="true" class="com.mchange.v2.c3p0.ComboPooledDataSource">
+   <property name="driverClass" value="org.h2.Driver"/>
+   <property name="user" value="sa"/>
+   <property name="password" value=""/>
+   <property name="jdbcUrl" value="jdbc:h2:file:./target/classes/h2/cdmTest;AUTO_SERVER=TRUE"/>
+ </bean>
+</beans>
diff --git a/eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/test.mgd.datasources.xml b/eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/test.mgd.datasources.xml
new file mode 100644 (file)
index 0000000..38be93b
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<!-- DO NOT EDIT THIS FILE MANUALLY. --><!-- It is created by the Taxonomic Editor for launching a managed CDM Server. --><beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:tx="http://www.springframework.org/schema/tx"
+  xmlns:context="http://www.springframework.org/schema/context"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+  http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-2.5.xsd
+  http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+">
+ <bean id="dataSourceProperties" class="eu.etaxonomy.cdm.remote.config.DataSourceProperties">
+   <property name="propsMap">
+       <map/>
+   </property>
+ </bean>
+ <bean id="cdmTest" lazy-init="true" class="com.mchange.v2.c3p0.ComboPooledDataSource">
+   <property name="driverClass" value="org.h2.Driver"/>
+   <property name="user" value="sa"/>
+   <property name="password" value=""/>
+   <property name="jdbcUrl" value="jdbc:h2:file:/exthd1/home/Development/EDIT/taxeditor/eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/h2/LocalH2/cdmTest;AUTO_SERVER=TRUE"/>
+ </bean>
+</beans>
index 64c4d55a94f1756a6e2780c0b831142d54182a1a..11c15a6e8ed8de99a5705d0144024aa003f152e3 100644 (file)
@@ -1,24 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
-    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> 
-        <param name="Target" value="System.out"/>
-        <layout class="org.apache.log4j.PatternLayout"> 
-            <param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
-        </layout>
-        <filter class="org.apache.log4j.filter.ExpressionFilter">
-            <param name="expression" value="msg like  '.*has a maxElementsInMemory of 0. This might lead to performance degradation or OutOfMemoryError at Terracotta client.*'" />
-            <param name="acceptOnMatch" value="false"/>
-        </filter>            
-    </appender>
-    <root>
-        <priority value ="WARN" />
-        <appender-ref ref="CONSOLE"/>
-    </root>
-    <logger name="org.hibernate.proxy.AbstractLazyInitializer">
-        <level value="info"/> 
-    </logger>
-    <logger name="org.hibernate.collection.internal.AbstractPersistentCollection">
-        <level value="info"/> 
-    </logger>
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
+  debug="false">
+  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out" />
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d %p [%c] - %m%n" />
+    </layout>
+  </appender>
+  <root>
+    <priority value="WARN" />
+    <appender-ref ref="CONSOLE" />
+  </root>
 </log4j:configuration>
\ No newline at end of file
index 5b20cc495517dadfdf0615504fa9906498643d3d..06d7199b797987924956fb4f98d49b1beabf4b28 100644 (file)
@@ -3,3 +3,4 @@ stopPort=9191
 stopKey=jetty-cdm-server
 user=admin
 password=00000
+contextPath=
diff --git a/eu.etaxonomy.taxeditor.webapp/.classpath b/eu.etaxonomy.taxeditor.webapp/.classpath
new file mode 100644 (file)
index 0000000..e932ef5
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry exported="true" kind="lib" path="lib/mysql-connector-java-5.1.24.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/javax.servlet-api-3.1.0.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/jetty-all-9.2.9.v20150224.jar"/>
+       <classpathentry exported="true" kind="lib" path="lib/log4j-1.2.17.jar"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src/main/java"/>
+       <classpathentry kind="src" path="src/main/resources"/>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/eu.etaxonomy.taxeditor.webapp/.gitignore b/eu.etaxonomy.taxeditor.webapp/.gitignore
new file mode 100644 (file)
index 0000000..09e3bc9
--- /dev/null
@@ -0,0 +1,2 @@
+/bin/
+/target/
diff --git a/eu.etaxonomy.taxeditor.webapp/.project b/eu.etaxonomy.taxeditor.webapp/.project
new file mode 100644 (file)
index 0000000..4dba6d3
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>eu.etaxonomy.taxeditor.webapp</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/eu.etaxonomy.taxeditor.webapp/.settings/org.eclipse.jdt.core.prefs b/eu.etaxonomy.taxeditor.webapp/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..d17b672
--- /dev/null
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/eu.etaxonomy.taxeditor.webapp/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.webapp/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..3d8b366
--- /dev/null
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Webapp
+Bundle-SymbolicName: eu.etaxonomy.taxeditor.webapp;singleton:=true
+Bundle-Version: 3.12.0.qualifier
+Require-Bundle: org.eclipse.core.runtime
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Bundle-ActivationPolicy: lazy
+Export-Package: eu.etaxonomy.taxeditor.webapp
+Bundle-ClassPath: .,
+ lib/log4j-1.2.17.jar,
+ lib/jetty-all-9.2.9.v20150224.jar,
+ lib/javax.servlet-api-3.1.0.jar,
+ lib/mysql-connector-java-5.1.24.jar
+Bundle-Vendor: EDIT
+Import-Package: org.eclipse.jface.resource,
+ org.eclipse.ui.plugin
+Bundle-Activator: eu.etaxonomy.taxeditor.webapp.TaxeditorWebappPlugin
diff --git a/eu.etaxonomy.taxeditor.webapp/build.properties b/eu.etaxonomy.taxeditor.webapp/build.properties
new file mode 100644 (file)
index 0000000..4ff6758
--- /dev/null
@@ -0,0 +1,9 @@
+source.. = src/main/java/,\           
+           src/main/resources/           
+bin.includes = META-INF/,\
+               .,\
+               lib/log4j-1.2.17.jar,\
+               lib/jetty-all-9.2.9.v20150224.jar,\
+               lib/javax.servlet-api-3.1.0.jar,\
+               lib/mysql-connector-java-5.1.24.jar,\
+               lib/cdmlib-remote-webapp.war
diff --git a/eu.etaxonomy.taxeditor.webapp/lib/cdmlib-remote-webapp.war b/eu.etaxonomy.taxeditor.webapp/lib/cdmlib-remote-webapp.war
new file mode 100644 (file)
index 0000000..2e93af3
Binary files /dev/null and b/eu.etaxonomy.taxeditor.webapp/lib/cdmlib-remote-webapp.war differ
diff --git a/eu.etaxonomy.taxeditor.webapp/lib/javax.servlet-api-3.1.0.jar b/eu.etaxonomy.taxeditor.webapp/lib/javax.servlet-api-3.1.0.jar
new file mode 100644 (file)
index 0000000..6b14c3d
Binary files /dev/null and b/eu.etaxonomy.taxeditor.webapp/lib/javax.servlet-api-3.1.0.jar differ
diff --git a/eu.etaxonomy.taxeditor.webapp/lib/jetty-all-9.2.9.v20150224.jar b/eu.etaxonomy.taxeditor.webapp/lib/jetty-all-9.2.9.v20150224.jar
new file mode 100644 (file)
index 0000000..2926f45
Binary files /dev/null and b/eu.etaxonomy.taxeditor.webapp/lib/jetty-all-9.2.9.v20150224.jar differ
diff --git a/eu.etaxonomy.taxeditor.webapp/lib/log4j-1.2.17.jar b/eu.etaxonomy.taxeditor.webapp/lib/log4j-1.2.17.jar
new file mode 100644 (file)
index 0000000..1d425cf
Binary files /dev/null and b/eu.etaxonomy.taxeditor.webapp/lib/log4j-1.2.17.jar differ
diff --git a/eu.etaxonomy.taxeditor.webapp/lib/mysql-connector-java-5.1.24.jar b/eu.etaxonomy.taxeditor.webapp/lib/mysql-connector-java-5.1.24.jar
new file mode 100644 (file)
index 0000000..c640a8d
Binary files /dev/null and b/eu.etaxonomy.taxeditor.webapp/lib/mysql-connector-java-5.1.24.jar differ
diff --git a/eu.etaxonomy.taxeditor.webapp/pom.xml b/eu.etaxonomy.taxeditor.webapp/pom.xml
new file mode 100644 (file)
index 0000000..83915ed
--- /dev/null
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>eu.etaxonomy</groupId>
+    <artifactId>taxeditor-parent</artifactId>
+    <version>3.12.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>eu.etaxonomy.taxeditor.webapp</artifactId>
+  <packaging>eclipse-plugin</packaging>
+  <name>CDM Library Webapp Plugin</name>
+  <description>CDM Library webapp as a plugin</description>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.7</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>2.4</version>
+        <executions>
+          <execution>
+            <id>copy-dependency-war</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>copy-dependencies</goal>
+            </goals>
+            <configuration>
+              <includeArtifactIds>
+                cdmlib-remote-webapp
+              </includeArtifactIds>
+              <outputDirectory>
+                ${basedir}/lib
+              </outputDirectory>
+              <overWriteReleases>true</overWriteReleases>
+              <overWriteSnapshots>true</overWriteSnapshots>
+              <excludeTransitive>true</excludeTransitive>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.7</version>
+        <executions>
+          <execution>
+            <id>update-snapshot-jar-names</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <target>
+                <echo>Anonymizing war</echo>
+                <move todir="./lib">
+                  <fileset dir="./lib" />
+                  <mapper type="regexp"
+                    from="(^cdmlib\-remote\-webapp).*(\.war)" to="\1\2" />
+                </move>
+              </target>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>SpringSource Enterprise Bundle Repository - External Bundle
+        Milestones
+      </id>
+      <url>http://repository.springsource.com/maven/bundles/milestone
+      </url>
+    </repository>
+    <repository>
+      <id>SpringSource Enterprise Bundle Repository - SpringSource
+        Bundle
+        Releases
+      </id>
+      <url>http://repository.springsource.com/maven/bundles/release
+      </url>
+    </repository>
+    <repository>
+      <id>SpringSource Enterprise Bundle Repository - External Bundle
+        Releases
+      </id>
+      <url>http://repository.springsource.com/maven/bundles/external
+      </url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>eu.etaxonomy</groupId>
+      <artifactId>cdmlib-remote-webapp</artifactId>
+      <version>${cdmlib.version}</version>
+      <type>war</type>
+    </dependency>
+  </dependencies>
+</project>
+
diff --git a/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMEmbeddedServerException.java b/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMEmbeddedServerException.java
new file mode 100644 (file)
index 0000000..456e073
--- /dev/null
@@ -0,0 +1,31 @@
+// $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.webapp;
+
+/**
+ * @author cmathew
+ * @date 23 Sep 2014
+ *
+ */
+public class CDMEmbeddedServerException extends Exception {
+
+    public CDMEmbeddedServerException(String message) {
+        super(message);
+    }
+
+    public CDMEmbeddedServerException(Exception e) {
+        super(e);
+    }
+
+    public CDMEmbeddedServerException(String message,Exception e) {
+        super(message,e);
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMServer.java b/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/CDMServer.java
new file mode 100644 (file)
index 0000000..98e68a5
--- /dev/null
@@ -0,0 +1,241 @@
+// $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.webapp;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.util.StringUtil;
+import org.eclipse.jetty.util.preventers.AppContextLeakPreventer;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * (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);
+
+
+    private final String dataSourceName;
+    private final String host = "127.0.0.1";
+    private int httpPort = 9090;
+    private final String contextPath = "/";
+
+    private File warFile;
+    private Server server;
+
+
+    public CDMServer(String dataSourceName, File dataSourcesFile) throws CDMEmbeddedServerException {
+        if(StringUtil.isBlank(dataSourceName)) {
+            throw new CDMEmbeddedServerException("DataSource name is not valid");
+        }
+
+        if(dataSourcesFile == null || !dataSourcesFile.exists()) {
+            throw new CDMEmbeddedServerException("DataSource config file does not exist");
+        }
+        this.dataSourceName = dataSourceName;
+        Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.webapp");
+        URL warURL = bundle.getEntry("lib/cdmlib-remote-webapp.war");
+
+        try {
+            URL resolvedWarURL = FileLocator.toFileURL(warURL);
+            // We need to use the 3-arg constructor of URI in order to properly escape file system chars
+            URI resolvedURI = new URI(resolvedWarURL.getProtocol(), resolvedWarURL.getPath(), null);
+            warFile = new File(resolvedURI);
+            System.out.println("war url : " + warFile.getAbsolutePath());
+
+            if(warFile == null || !warFile.exists()) {
+                throw new CDMEmbeddedServerException("Cdmlib War file does not exist");
+            }
+        } catch (URISyntaxException use) {
+            throw new CDMEmbeddedServerException(use);
+        } catch (IOException ioe) {
+            throw new CDMEmbeddedServerException(ioe);
+        }
+
+        System.setProperty("spring.profiles.active", "remoting");
+        System.setProperty("cdm.beanDefinitionFile", dataSourcesFile.getAbsolutePath());
+        System.setProperty("cdm.datasource", dataSourceName);
+
+        httpPort = findFreePort();
+
+        logger.warn("Starting server on port : " + httpPort);
+
+        server = new Server(httpPort);
+
+        server.addBean(new AppContextLeakPreventer());
+
+        WebAppContext webapp = new WebAppContext();
+        webapp.setContextPath(contextPath);
+        webapp.setWar(warFile.getAbsolutePath());
+
+        server.setHandler(webapp);
+    }
+
+    public String getDataSourceName() {
+        return dataSourceName;
+    }
+    public String getHost() {
+        return host;
+    }
+
+    public int getPort() {
+        return httpPort;
+    }
+
+    public String getContextPath() {
+        return contextPath;
+    }
+
+    private static int findFreePort() throws CDMEmbeddedServerException {
+        ServerSocket socket = null;
+        try {
+            socket = new ServerSocket(0);
+            socket.setReuseAddress(true);
+            int port = socket.getLocalPort();
+            try {
+                socket.close();
+            } catch (IOException e) {
+
+            }
+            return port;
+        } catch (IOException e) {
+        } finally {
+            if (socket != null) {
+                try {
+                    socket.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+        throw new CDMEmbeddedServerException("Could not find a free TCP/IP port to start embedded Jetty HTTP Server on");
+    }
+
+    public void start(ICDMServerError cdmServerError) throws CDMEmbeddedServerException {
+        start(true, cdmServerError);
+    }
+
+    public void start(boolean wait, final ICDMServerError cdmServerError) throws CDMEmbeddedServerException {
+
+        if(server == null) {
+            throw new CDMEmbeddedServerException("Server is already disposed");
+        }
+
+        if(server.isStarting()) {
+            throw new CDMEmbeddedServerException("Server is starting");
+        }
+
+        if(server.isStarted()) {
+            throw new CDMEmbeddedServerException("Server has started");
+        }
+
+        if(server.isRunning()) {
+            throw new CDMEmbeddedServerException("Server is running");
+        }
+
+        if(server.isStopping()) {
+            throw new CDMEmbeddedServerException("Server is currently stopping. Please re-try in about 10 seconds");
+        }
+
+        Thread serverThread = new Thread() {
+
+            @Override
+            public void run() {
+                try {
+                    server.start();
+                    server.join();
+                } catch (Throwable t) {
+                    cdmServerError.handleError(t);
+                }
+            }
+        };
+
+        serverThread.start();
+
+        if(wait) {
+            while(!server.isStarted()) {}
+
+        }
+    }
+
+    public boolean isAlive()  {
+        return server.isRunning() || server.isStarting() || server.isStarted();
+    }
+
+    public boolean isStarted() {
+        return server.isStarted();
+    }
+
+    public void stop() throws Exception {
+        server.stop();
+        server.destroy();
+        server = null;
+    }
+
+
+
+
+    public static void stopServerViaJMX(int jmxPort) throws CDMEmbeddedServerException  {
+        String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
+        logger.warn("Shutting down Jetty instance ... ");
+
+        try {
+            JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), null);
+            connector.connect(null);
+            MBeanServerConnection connection = connector.getMBeanServerConnection();
+            ObjectName objectName = new ObjectName("org.eclipse.jetty.server:type=server,id=0");
+            connection.invoke(objectName, "stop", null, null);
+            logger.warn("Shutdown command sent");
+        } catch (InstanceNotFoundException e) {
+            throw new CDMEmbeddedServerException(e);
+        } catch (MBeanException e) {
+            throw new CDMEmbeddedServerException(e);
+        } catch (ReflectionException e) {
+            throw new CDMEmbeddedServerException(e);
+        } catch (IOException e) {
+            throw new CDMEmbeddedServerException(e);
+        } catch (MalformedObjectNameException e) {
+            throw new CDMEmbeddedServerException(e);
+        }
+    }
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/ICDMServerError.java b/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/ICDMServerError.java
new file mode 100644 (file)
index 0000000..88cc1a4
--- /dev/null
@@ -0,0 +1,21 @@
+// $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.webapp;
+
+/**
+ * @author cmathew
+ * @date 16 Nov 2015
+ *
+ */
+public interface ICDMServerError {
+
+    public void handleError(Throwable t);
+
+}
diff --git a/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/TaxeditorWebappPlugin.java b/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/webapp/TaxeditorWebappPlugin.java
new file mode 100644 (file)
index 0000000..83c0949
--- /dev/null
@@ -0,0 +1,81 @@
+package eu.etaxonomy.taxeditor.webapp;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ *
+ * @author n.hoffmann
+ * @version $Id: $
+ */
+public class TaxeditorWebappPlugin extends AbstractUIPlugin {
+
+       // The plug-in ID
+       /** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.editor"</code> */
+       public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.editor";
+
+       // The shared instance
+       private static TaxeditorWebappPlugin plugin;
+
+       /**
+        * The constructor
+        */
+       public TaxeditorWebappPlugin() {
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+        */
+       /** {@inheritDoc} */
+       @Override
+    public void start(BundleContext context) throws Exception {
+               super.start(context);
+               plugin = this;
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+        */
+       /** {@inheritDoc} */
+       @Override
+    public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        *
+        * @return the shared instance
+        */
+       public static TaxeditorWebappPlugin getDefault() {
+               return plugin;
+       }
+
+       /**
+        * Returns an image descriptor for the image file at the given
+        * plug-in relative path
+        *
+        * @param path the path
+        * @return the image descriptor
+        */
+       public static ImageDescriptor getImageDescriptor(String path) {
+               return imageDescriptorFromPlugin(PLUGIN_ID, path);
+       }
+
+
+       /**
+        * Exposes this normally protected method.
+        *
+        * @return a {@link org.eclipse.jface.resource.ImageRegistry} object.
+        */
+       @Override
+    public ImageRegistry createImageRegistry(){
+               return super.createImageRegistry();
+       }
+}
diff --git a/pom.xml b/pom.xml
index 0dad8594b2338afe26aa0b5eab65182a8b883e53..427cf9e9199ad095e816e6274244084925811a65 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,7 @@
     <module>eu.etaxonomy.taxeditor.help</module>
     <module>eu.etaxonomy.taxeditor.molecular</module>
     <module>eu.etaxonomy.taxeditor.molecular.lib</module>
+    <module>eu.etaxonomy.taxeditor.webapp</module>
     <module>eu.etaxonomy.taxeditor.application</module>
     <module>eu.etaxonomy.taxeditor.feature.platform</module>
     <module>eu.etaxonomy.taxeditor.feature</module>