=== modified file 'dhis-live/pom.xml'
--- dhis-live/pom.xml 2014-11-21 13:04:46 +0000
+++ dhis-live/pom.xml 2014-11-26 15:44:28 +0000
@@ -1,172 +1,188 @@
-
- 4.0.0
- org.hisp.dhis
- dhis-live
- jar
- 1.0-SNAPSHOT
- DHIS Live
-
- http://maven.apache.org
-
-
- dhis2-live
- install
-
+ 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">
+
+ 4.0.0
+ org.hisp.dhis
+ dhis-live
+ jar
+ 1.0-SNAPSHOT
+ DHIS Live
+
+ http://maven.apache.org
+
+
+ 9.2.5.v20141112
+
+
+
+
+ central
+ http://central.maven.org/maven2
+
+
+
+
+ dhis2-live
+ install
+
-
-
- maven-assembly-plugin
- 2.2
-
-
- jar-with-dependencies
-
-
-
- org.hisp.dhis.TrayApp
-
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
+
+
+ maven-assembly-plugin
+ 2.2
+
+
+ jar-with-dependencies
+
+
+
+ org.hisp.dhis.TrayApp
+
+
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
+
-
-
- maven-compiler-plugin
- 2.0.2
-
- true
- 1.7
- 1.7
-
-
+
+
+ maven-compiler-plugin
+ 2.0.2
+
+ true
+ 1.7
+ 1.7
+
+
-
-
- org.bluestemsoftware.open.maven.plugin
- launch4j-plugin
- 1.5.0.0
-
-
- default
- package
-
- launch4j
-
-
- true
- gui
- ${project.build.directory}/dhis2-live.exe
- dhis2-live.jar
- dhis2
- normal
- http://java.com/download
- http://dhis2.org
- false
- false
-
- ${basedir}/util/launch4j/favicon.ico
-
- dhis-live.mutex
-
-
-
- 1.6.0_14
-
-
- ${basedir}/util/launch4j/dhis2-splash.bmp
- false
- 10
- false
-
-
-
-
- embedded
- package
-
- launch4j
-
-
- true
- gui
- ${project.build.directory}/dhis2-live-embedded.exe
- dhis2-live.jar
- dhis2
- normal
- http://java.com/download
- http://dhis2.org
- false
- false
-
- ${basedir}/util/launch4j/favicon.ico
-
- dhis-live.mutex
-
-
-
- jre6
- 1.6.0_14
-
-
- ${basedir}/util/launch4j/dhis2-splash.bmp
- false
- 10
- false
-
-
-
-
-
-
-
+
+
+ org.bluestemsoftware.open.maven.plugin
+ launch4j-plugin
+ 1.5.0.0
+
+
+ default
+ package
+
+ launch4j
+
+
+ true
+ gui
+ ${project.build.directory}/dhis2-live.exe
+ dhis2-live.jar
+ dhis2
+ normal
+ http://java.com/download
+ http://dhis2.org
+ false
+ false
+
+ ${basedir}/util/launch4j/favicon.ico
+
+ dhis-live.mutex
+
+
+
+ 1.6.0_14
+
+
+ ${basedir}/util/launch4j/dhis2-splash.bmp
+ false
+ 10
+ false
+
+
+
+
+ embedded
+ package
+
+ launch4j
+
+
+ true
+ gui
+ ${project.build.directory}/dhis2-live-embedded.exe
+ dhis2-live.jar
+ dhis2
+ normal
+ http://java.com/download
+ http://dhis2.org
+ false
+ false
+
+ ${basedir}/util/launch4j/favicon.ico
+
+ dhis-live.mutex
+
+
+
+ jre6
+ 1.6.0_14
+
+
+ ${basedir}/util/launch4j/dhis2-splash.bmp
+ false
+ 10
+ false
+
+
+
+
+
+
+
-
-
- org.mortbay.jetty
- jetty
- 6.1.25
- jar
-
-
- org.mortbay.jetty
- jetty-util
- 6.1.26
- jar
-
-
- org.mortbay.jetty
- servlet-api
- 3.0.20100224
- jar
-
-
- commons-logging
- commons-logging
- 1.1
- compile
-
-
- avalon-framework
- avalon-framework
-
-
- logkit
- logkit
-
-
-
-
+
+
+ org.eclipse.jetty
+ jetty-server
+ ${jettyVersion}
+ jar
+
+
+ org.eclipse.jetty
+ jetty-webapp
+ ${jettyVersion}
+
+
+ org.eclipse.jetty
+ jetty-util
+ ${jettyVersion}
+ jar
+
+
+ org.mortbay.jetty
+ servlet-api
+ 3.0.20100224
+ jar
+
+
+ commons-logging
+ commons-logging
+ 1.1
+ compile
+
+
+ avalon-framework
+ avalon-framework
+
+
+ logkit
+ logkit
+
+
+
+
=== modified file 'dhis-live/src/main/java/org/hisp/dhis/TrayApp.java'
--- dhis-live/src/main/java/org/hisp/dhis/TrayApp.java 2010-12-06 10:21:18 +0000
+++ dhis-live/src/main/java/org/hisp/dhis/TrayApp.java 2014-11-26 15:44:28 +0000
@@ -24,7 +24,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package org.hisp.dhis;
import java.awt.AWTException;
@@ -45,15 +44,15 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.mortbay.component.LifeCycle;
+import org.eclipse.jetty.util.component.LifeCycle;
/**
* @author Bob Jolliffe
*/
public class TrayApp
- implements LifeCycle.Listener
-{
- private static final Log log = LogFactory.getLog( TrayApp.class );
+ implements LifeCycle.Listener {
+
+ private static final Log log = LogFactory.getLog(TrayApp.class);
private static final String CONFIG_DIR = "/conf";
private static final String STOPPED_ICON = "/icons/stopped.png";
@@ -62,8 +61,8 @@
private static final String RUNNING_ICON = "/icons/running.png";
private static final String CMD_OPEN = "Open DHIS 2 Live";
private static final String CMD_EXIT = "Exit";
-
- private WebAppServer appServer;
+
+ private final WebAppServer appServer;
private TrayIcon trayIcon;
@@ -72,199 +71,177 @@
// -------------------------------------------------------------------------
// Main method
// -------------------------------------------------------------------------
-
- public static void main( String[] args )
- throws Exception
- {
- log.info( "Environment variable DHIS2_HOME: " + System.getenv( "DHIS2_HOME" ) );
- if ( !SystemTray.isSupported() )
- {
+ public static void main(String[] args)
+ throws Exception {
+ log.info("Environment variable DHIS2_HOME: " + System.getenv("DHIS2_HOME"));
+ if (!SystemTray.isSupported()) {
String message = "SystemTray not supported on this platform";
- JOptionPane.showMessageDialog( (JFrame) null, message );
- System.exit( 0 );
+ JOptionPane.showMessageDialog((JFrame) null, message);
+ System.exit(0);
}
- new TrayApp();
+ TrayApp trayApp = new TrayApp();
+ trayApp.start();
}
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
-
public TrayApp()
- throws Exception
- {
- log.info( "Initialising DHIS 2 Live..." );
-
+ throws Exception {
+ log.info("Initialising DHIS 2 Live...");
+
installDir = getInstallDir();
- if ( installDir == null )
- {
- log.info( "jar not installed, setting installdir to DHIS2_HOME: " + System.getenv( "DHIS2_HOME" ) );
- installDir = System.getenv( "DHIS2_HOME" );
+ if (installDir == null) {
+ log.info("jar not installed, setting installdir to DHIS2_HOME: " + System.getenv("DHIS2_HOME"));
+ installDir = System.getenv("DHIS2_HOME");
}
- System.setProperty( "dhis2.home", installDir + CONFIG_DIR );
- System.setProperty( "jetty.home", installDir );
+ System.setProperty("dhis2.home", installDir + CONFIG_DIR);
+ System.setProperty("jetty.home", installDir);
SystemTray tray = SystemTray.getSystemTray();
- Image image = createImage( STOPPED_ICON, "tray icon" );
+ Image image = createImage(STOPPED_ICON, "tray icon");
PopupMenu popup = new PopupMenu();
- MenuItem openItem = new MenuItem( CMD_OPEN );
- MenuItem exitItem = new MenuItem( CMD_EXIT );
- popup.add( openItem );
- popup.add( exitItem );
-
- trayIcon = new TrayIcon( image, "DHIS 2 Live", popup );
- trayIcon.setImageAutoSize( true );
-
- ActionListener listener = new ActionListener()
- {
- public void actionPerformed( ActionEvent e )
- {
+ MenuItem openItem = new MenuItem(CMD_OPEN);
+ MenuItem exitItem = new MenuItem(CMD_EXIT);
+ popup.add(openItem);
+ popup.add(exitItem);
+
+ trayIcon = new TrayIcon(image, "DHIS 2 Live", popup);
+ trayIcon.setImageAutoSize(true);
+
+ ActionListener listener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
- if ( cmd.equals( CMD_OPEN ) )
- {
- launchBrowser();
- }
- else if ( cmd.equals( CMD_EXIT ) )
- {
- shutdown();
- }
- };
+ switch (cmd) {
+ case CMD_OPEN:
+ launchBrowser();
+ break;
+ case CMD_EXIT:
+ shutdown();
+ break;
+ }
+ }
+ ;
};
- openItem.addActionListener( listener );
- exitItem.addActionListener( listener );
-
- try
- {
- tray.add( trayIcon );
- }
- catch ( AWTException ex )
- {
- log.warn( "Oops: " + ex.toString() );
- }
-
- appServer = new WebAppServer();
- appServer.init( installDir, this );
-
+ openItem.addActionListener(listener);
+ exitItem.addActionListener(listener);
+
+ try {
+ tray.add(trayIcon);
+ } catch (AWTException ex) {
+ log.warn("Oops: " + ex.toString());
+ }
+
+ appServer = new WebAppServer(installDir, this);
+
+ }
+
+ public void start() {
appServer.start();
-
}
// -------------------------------------------------------------------------
// Listener implementation
// -------------------------------------------------------------------------
-
- public void lifeCycleFailure( LifeCycle arg0, Throwable arg1 )
- {
- log.warn( "Lifecycle: server failed" );
- trayIcon.setImage( createImage( FAILED_ICON, "Running icon" ) );
+ @Override
+ public void lifeCycleFailure(LifeCycle arg0, Throwable arg1) {
+ log.warn("Lifecycle: server failed");
+ trayIcon.setImage(createImage(FAILED_ICON, "Running icon"));
String message = "Web server failed to start - see logs for details";
- JOptionPane.showMessageDialog( (JFrame) null, message );
+ JOptionPane.showMessageDialog((JFrame) null, message);
shutdown();
}
- public void lifeCycleStarted( LifeCycle arg0 )
- {
- log.info( "Lifecycle: server started" );
- trayIcon.displayMessage( "Started", "DHIS 2 is running. Your browser will\n be pointed to " + getUrl() + ".",
- TrayIcon.MessageType.INFO );
- trayIcon.setToolTip( "DHIS 2 Server running" );
- trayIcon.setImage( createImage( RUNNING_ICON, "Running icon" ) );
-
+ @Override
+ public void lifeCycleStarted(LifeCycle arg0) {
+ log.info("Lifecycle: server started");
+ trayIcon.displayMessage("Started", "DHIS 2 is running. Your browser will\n be pointed to " + getUrl() + ".",
+ TrayIcon.MessageType.INFO);
+ trayIcon.setToolTip("DHIS 2 Server running");
+ trayIcon.setImage(createImage(RUNNING_ICON, "Running icon"));
+
launchBrowser();
}
- public void lifeCycleStarting( LifeCycle arg0 )
- {
- log.info( "Lifecycle: server starting" );
- trayIcon.displayMessage( "Starting", "DHIS 2 is starting.\nPlease be patient.", TrayIcon.MessageType.INFO );
- trayIcon.setImage( createImage( STARTING_ICON, "Starting icon" ) );
- }
-
- public void lifeCycleStopped( LifeCycle arg0 )
- {
- log.info( "Lifecycle: server stopped" );
- trayIcon.displayMessage( "Stopped", "DHIS 2 has stopped.", TrayIcon.MessageType.INFO );
- trayIcon.setImage( createImage( STOPPED_ICON, "Running icon" ) );
- }
-
- public void lifeCycleStopping( LifeCycle arg0 )
- {
- log.info( "Lifecycle: server stopping" );
+ @Override
+ public void lifeCycleStarting(LifeCycle arg0) {
+ log.info("Lifecycle: server starting");
+ trayIcon.displayMessage("Starting", "DHIS 2 is starting.\nPlease be patient.", TrayIcon.MessageType.INFO);
+ trayIcon.setImage(createImage(STARTING_ICON, "Starting icon"));
+ }
+
+ @Override
+ public void lifeCycleStopped(LifeCycle arg0) {
+ log.info("Lifecycle: server stopped");
+ trayIcon.displayMessage("Stopped", "DHIS 2 has stopped.", TrayIcon.MessageType.INFO);
+ trayIcon.setImage(createImage(STOPPED_ICON, "Running icon"));
+ }
+
+ @Override
+ public void lifeCycleStopping(LifeCycle arg0) {
+ log.info("Lifecycle: server stopping");
}
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
-
/**
* Returns the URL where the application can be accessed.
- *
+ *
* @return the URL where the application can be accessed.
*/
- private String getUrl()
- {
- return "http://localhost:" + appServer.getConnectorPort();
+ private String getUrl() {
+ return appServer.getURI().toString();
}
-
+
/**
* Launches the application in the default browser.
*/
- private void launchBrowser()
- {
- try
- {
- Desktop.getDesktop().browse( URI.create( getUrl() ) );
- }
- catch ( Exception ex )
- {
- log.warn( "Couldn't open default desktop browser: " + ex );
+ private void launchBrowser() {
+ try {
+ Desktop.getDesktop().browse(URI.create(getUrl()));
+ } catch (Exception ex) {
+ log.warn("Couldn't open default desktop browser: " + ex);
}
}
-
+
/**
* Shuts down the web application server.
*/
- private void shutdown()
- {
- log.info( "Graceful shutdown..." );
- try
- {
+ private void shutdown() {
+ log.info("Graceful shutdown...");
+ try {
appServer.shutdown();
- }
- catch ( Exception ex )
- {
- log.warn( "Oops: " + ex.toString() );
- }
- log.info( "Exiting..." );
- System.exit( 0 );
+ } catch (Exception ex) {
+ log.warn("Oops: " + ex.toString());
+ }
+ log.info("Exiting...");
+ System.exit(0);
}
/**
* Creates an image based on the given path and description.
- *
+ *
* @param path the image path.
* @param description the image description.
* @return an Image.
*/
- private static Image createImage( String path, String description )
- {
- URL imageURL = TrayApp.class.getResource( path );
+ private static Image createImage(String path, String description) {
+ URL imageURL = TrayApp.class.getResource(path);
- if ( imageURL == null )
- {
- log.warn( "Resource not found: " + path );
+ if (imageURL == null) {
+ log.warn("Resource not found: " + path);
return null;
- }
- else
- {
- return (new ImageIcon( imageURL, description )).getImage();
+ } else {
+ return (new ImageIcon(imageURL, description)).getImage();
}
}
@@ -273,25 +250,24 @@
* directory the DHIS 2 Live package is installed in. It does this by
* finding the file URL of a resource within the executable jar and
* extracting the installation path from that.
- *
- * @return a String
value representing the installation directory
+ *
+ * @return a String
value representing the installation
+ * directory
*/
- private static String getInstallDir()
- {
+ private static String getInstallDir() {
// find a resource
- String resourceString = TrayApp.class.getResource( "/icons/" ).toString();
+ String resourceString = TrayApp.class.getResource("/icons/").toString();
// we expect to see something of the form:
// "jar:file:/dhis_xxx.jar!/icons"
- if ( !resourceString.startsWith( "jar:file:" ) )
- {
+ if (!resourceString.startsWith("jar:file:")) {
// we're in trouble - its not in a jar file
return null;
}
// find the last "/" just before the "!"
- int endIndex = resourceString.lastIndexOf( "/", resourceString.lastIndexOf( "!" ) );
- String result = resourceString.substring( 9, endIndex );
+ int endIndex = resourceString.lastIndexOf("/", resourceString.lastIndexOf("!"));
+ String result = resourceString.substring(9, endIndex);
// replace encoded spaces
- result = result.replaceAll( "%20", " " );
+ result = result.replaceAll("%20", " ");
return result;
}
}
=== modified file 'dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java'
--- dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java 2010-12-06 10:21:18 +0000
+++ dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java 2014-11-26 15:44:28 +0000
@@ -24,116 +24,85 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
/**
*
* @author Bob Jolliffe
* @version $$Id$$
*/
-
package org.hisp.dhis;
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.Reader;
+import java.io.File;
+import java.net.URI;
+import java.util.Scanner;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.mortbay.component.LifeCycle;
-import org.mortbay.jetty.Connector;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.nio.SelectChannelConnector;
-import org.mortbay.jetty.webapp.WebAppContext;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.util.component.LifeCycle;
+import org.eclipse.jetty.webapp.WebAppContext;
/**
* @author Bob Jolliffe
*/
-public class WebAppServer extends Thread
-{
+public class WebAppServer extends Thread {
+
public static final String DHIS_DIR = "/webapps/dhis";
public static final String JETTY_PORT_CONF = "/conf/jetty.port";
public static final int DEFAULT_JETTY_PORT = 8080;
- private static final Log log = LogFactory.getLog( WebAppServer.class );
+ public static int MAX_FORM_CONTENT_SIZE = 5000000;
+
+ private static final Log log = LogFactory.getLog(WebAppServer.class);
protected Server server;
- protected Connector connector;
-
- public WebAppServer()
- {
- server = new Server();
- connector = new SelectChannelConnector();
- }
-
- public void init( String installDir, LifeCycle.Listener serverListener )
- throws Exception
- {
- try
- {
- int portFromConfig = this.getPortFromConfig( installDir + JETTY_PORT_CONF );
- connector.setPort( portFromConfig );
- log.info( "Loading DHIS 2 on port: " + portFromConfig );
- }
- catch ( Exception ex )
- {
- log.info( "Couldn't load port number from " + installDir + JETTY_PORT_CONF );
- connector.setPort( DEFAULT_JETTY_PORT );
- log.info( "Loading DHIS 2 on port: " + DEFAULT_JETTY_PORT );
- }
-
- server.setConnectors( new Connector[] { connector } );
- server.addLifeCycleListener( serverListener );
-
- loadDHISContext(installDir+DHIS_DIR);
- }
-
- public void loadDHISContext(String webappPath)
- {
+ public WebAppServer(String installDir, LifeCycle.Listener serverListener)
+ throws Exception {
+
+ int port;
+ try {
+ Scanner scanner = new Scanner(new File(installDir + JETTY_PORT_CONF));
+ port = scanner.nextInt();
+ log.info("Loading DHIS 2 on port: " + port);
+ } catch (Exception ex) {
+ log.info("Couldn't load port number from " + installDir + JETTY_PORT_CONF);
+ port = DEFAULT_JETTY_PORT;
+ log.info("Loading DHIS 2 on port: " + DEFAULT_JETTY_PORT);
+ }
+
+ server = new Server(port);
+ server.addLifeCycleListener(serverListener);
+ loadDHISContext(installDir + DHIS_DIR);
+ }
+
+ private void loadDHISContext(String webappPath) {
WebAppContext dhisWebApp = new WebAppContext();
- dhisWebApp.setMaxFormContentSize( 5000000 );
- dhisWebApp.setWar( webappPath );
- log.info( "Setting DHIS 2 web app context to: " + webappPath );
+ dhisWebApp.setMaxFormContentSize(MAX_FORM_CONTENT_SIZE);
+ dhisWebApp.setWar(webappPath);
+ log.info("Setting DHIS 2 web app context to: " + webappPath);
- server.setHandler( dhisWebApp );
+ server.setHandler(dhisWebApp);
}
- public void run()
- {
- try
- {
+ @Override
+ public void run() {
+ try {
log.debug("Server thread starting");
server.start();
log.debug("Server thread exiting");
- } catch ( Exception ex )
- {
- log.error( "Server wouldn't start : " + ex);
+ } catch (Exception ex) {
+ log.error("Server wouldn't start : " + ex);
}
}
public void shutdown()
- throws Exception
- {
+ throws Exception {
server.stop();
}
- public int getConnectorPort()
- {
- return connector.getPort();
- }
-
- private int getPortFromConfig( String conf )
- throws FileNotFoundException, IOException
- {
- Reader r = new BufferedReader( new FileReader( conf ) );
- char[] cbuf = new char[10];
- r.read( cbuf );
- String numstr = String.copyValueOf( cbuf );
- Integer port = Integer.valueOf( numstr.trim() );
- return port.intValue();
+ public URI getURI() {
+ return server.getURI();
}
}