------------------------------------------------------------ revno: 17600 committer: Bob Jolliffe <[email protected]> branch nick: dhis2 timestamp: Wed 2014-11-26 15:44:28 +0000 message: Upgraded jetty from 6.1.25 to 9.2.5 Simplified some code in the process. modified: dhis-live/pom.xml dhis-live/src/main/java/org/hisp/dhis/TrayApp.java dhis-live/src/main/java/org/hisp/dhis/WebAppServer.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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 @@ <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"> - - <modelVersion>4.0.0</modelVersion> - <groupId>org.hisp.dhis</groupId> - <artifactId>dhis-live</artifactId> - <packaging>jar</packaging> - <version>1.0-SNAPSHOT</version> - <name>DHIS Live</name> - - <url>http://maven.apache.org</url> - - <build> - <finalName>dhis2-live</finalName> - <defaultGoal>install</defaultGoal> - <plugins> + 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"> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.hisp.dhis</groupId> + <artifactId>dhis-live</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>DHIS Live</name> + + <url>http://maven.apache.org</url> + + <properties> + <jettyVersion>9.2.5.v20141112</jettyVersion> + </properties> + + <repositories> + <repository> + <id>central</id> + <url>http://central.maven.org/maven2</url> + </repository> + </repositories> + + <build> + <finalName>dhis2-live</finalName> + <defaultGoal>install</defaultGoal> + <plugins> - <!-- Maven Assembly --> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <version>2.2</version> - <configuration> - <descriptorRefs> - <descriptorRef>jar-with-dependencies</descriptorRef> - </descriptorRefs> - <archive> - <manifest> - <mainClass>org.hisp.dhis.TrayApp</mainClass> - </manifest> - </archive> - </configuration> - <executions> - <execution> - <id>make-assembly</id> <!-- this is used for inheritance merges --> - <phase>package</phase> <!-- append to the packaging phase --> - <goals> - <goal>single</goal> <!-- goals == mojos --> - </goals> - </execution> - </executions> - </plugin> + <!-- Maven Assembly --> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.2</version> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + <archive> + <manifest> + <mainClass>org.hisp.dhis.TrayApp</mainClass> + </manifest> + </archive> + </configuration> + <executions> + <execution> + <id>make-assembly</id> <!-- this is used for inheritance merges --> + <phase>package</phase> <!-- append to the packaging phase --> + <goals> + <goal>single</goal> <!-- goals == mojos --> + </goals> + </execution> + </executions> + </plugin> - <!-- Maven Compiler --> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.0.2</version> - <configuration> - <debug>true</debug> - <source>1.7</source> - <target>1.7</target> - </configuration> - </plugin> + <!-- Maven Compiler --> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0.2</version> + <configuration> + <debug>true</debug> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> - <!-- Launch4J --> - <plugin> - <groupId>org.bluestemsoftware.open.maven.plugin</groupId> - <artifactId>launch4j-plugin</artifactId> - <version>1.5.0.0</version> - <executions> - <execution> - <id>default</id> - <phase>package</phase> - <goals> - <goal>launch4j</goal> - </goals> - <configuration> - <dontWrapJar>true</dontWrapJar> - <headerType>gui</headerType> - <outfile>${project.build.directory}/dhis2-live.exe</outfile> - <jar>dhis2-live.jar</jar> - <errTitle>dhis2</errTitle> - <priority>normal</priority> - <downloadUrl>http://java.com/download</downloadUrl> - <supportUrl>http://dhis2.org</supportUrl> - <customProcName>false</customProcName> - <stayAlive>false</stayAlive> - <manifest></manifest> - <icon>${basedir}/util/launch4j/favicon.ico</icon> - <singleInstance> - <mutexName>dhis-live.mutex</mutexName> - <windowTitle></windowTitle> - </singleInstance> - <jre> - <minVersion>1.6.0_14</minVersion> - </jre> - <splash> - <file>${basedir}/util/launch4j/dhis2-splash.bmp</file> - <waitForWindow>false</waitForWindow> - <timeout>10</timeout> - <timeoutErr>false</timeoutErr> - </splash> - </configuration> - </execution> - <execution> - <id>embedded</id> - <phase>package</phase> - <goals> - <goal>launch4j</goal> - </goals> - <configuration> - <dontWrapJar>true</dontWrapJar> - <headerType>gui</headerType> - <outfile>${project.build.directory}/dhis2-live-embedded.exe</outfile> - <jar>dhis2-live.jar</jar> - <errTitle>dhis2</errTitle> - <priority>normal</priority> - <downloadUrl>http://java.com/download</downloadUrl> - <supportUrl>http://dhis2.org</supportUrl> - <customProcName>false</customProcName> - <stayAlive>false</stayAlive> - <manifest></manifest> - <icon>${basedir}/util/launch4j/favicon.ico</icon> - <singleInstance> - <mutexName>dhis-live.mutex</mutexName> - <windowTitle></windowTitle> - </singleInstance> - <jre> - <path>jre6</path> - <minVersion>1.6.0_14</minVersion> - </jre> - <splash> - <file>${basedir}/util/launch4j/dhis2-splash.bmp</file> - <waitForWindow>false</waitForWindow> - <timeout>10</timeout> - <timeoutErr>false</timeoutErr> - </splash> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> + <!-- Launch4J --> + <plugin> + <groupId>org.bluestemsoftware.open.maven.plugin</groupId> + <artifactId>launch4j-plugin</artifactId> + <version>1.5.0.0</version> + <executions> + <execution> + <id>default</id> + <phase>package</phase> + <goals> + <goal>launch4j</goal> + </goals> + <configuration> + <dontWrapJar>true</dontWrapJar> + <headerType>gui</headerType> + <outfile>${project.build.directory}/dhis2-live.exe</outfile> + <jar>dhis2-live.jar</jar> + <errTitle>dhis2</errTitle> + <priority>normal</priority> + <downloadUrl>http://java.com/download</downloadUrl> + <supportUrl>http://dhis2.org</supportUrl> + <customProcName>false</customProcName> + <stayAlive>false</stayAlive> + <manifest></manifest> + <icon>${basedir}/util/launch4j/favicon.ico</icon> + <singleInstance> + <mutexName>dhis-live.mutex</mutexName> + <windowTitle></windowTitle> + </singleInstance> + <jre> + <minVersion>1.6.0_14</minVersion> + </jre> + <splash> + <file>${basedir}/util/launch4j/dhis2-splash.bmp</file> + <waitForWindow>false</waitForWindow> + <timeout>10</timeout> + <timeoutErr>false</timeoutErr> + </splash> + </configuration> + </execution> + <execution> + <id>embedded</id> + <phase>package</phase> + <goals> + <goal>launch4j</goal> + </goals> + <configuration> + <dontWrapJar>true</dontWrapJar> + <headerType>gui</headerType> + <outfile>${project.build.directory}/dhis2-live-embedded.exe</outfile> + <jar>dhis2-live.jar</jar> + <errTitle>dhis2</errTitle> + <priority>normal</priority> + <downloadUrl>http://java.com/download</downloadUrl> + <supportUrl>http://dhis2.org</supportUrl> + <customProcName>false</customProcName> + <stayAlive>false</stayAlive> + <manifest></manifest> + <icon>${basedir}/util/launch4j/favicon.ico</icon> + <singleInstance> + <mutexName>dhis-live.mutex</mutexName> + <windowTitle></windowTitle> + </singleInstance> + <jre> + <path>jre6</path> + <minVersion>1.6.0_14</minVersion> + </jre> + <splash> + <file>${basedir}/util/launch4j/dhis2-splash.bmp</file> + <waitForWindow>false</waitForWindow> + <timeout>10</timeout> + <timeoutErr>false</timeoutErr> + </splash> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> - <dependencies> - <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty</artifactId> - <version>6.1.25</version> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty-util</artifactId> - <version>6.1.26</version> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>servlet-api</artifactId> - <version>3.0.20100224</version> - <type>jar</type> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.1</version> - <scope>compile</scope> - <exclusions> - <exclusion> - <groupId>avalon-framework</groupId> - <artifactId>avalon-framework</artifactId> - </exclusion> - <exclusion> - <groupId>logkit</groupId> - <artifactId>logkit</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-server</artifactId> + <version>${jettyVersion}</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-webapp</artifactId> + <version>${jettyVersion}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-util</artifactId> + <version>${jettyVersion}</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>servlet-api</artifactId> + <version>3.0.20100224</version> + <type>jar</type> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1</version> + <scope>compile</scope> + <exclusions> + <exclusion> + <groupId>avalon-framework</groupId> + <artifactId>avalon-framework</artifactId> + </exclusion> + <exclusion> + <groupId>logkit</groupId> + <artifactId>logkit</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> </project> === 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 <code>String</code> value representing the installation directory + * + * @return a <code>String</code> 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:<install_dir>/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(); } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

