--- projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostInit.java 2004/08/01 10:41:05 1.40 +++ projects/cms/source/server/uk/org/iscream/cms/server/filtermanager/HostInit.java 2005/09/25 09:57:42 1.41 @@ -36,7 +36,7 @@ import java.util.*; * and a reference to a Filter to which it should pass data. * * @author $Author: tdb $ - * @version $Id: HostInit.java,v 1.40 2004/08/01 10:41:05 tdb Exp $ + * @version $Id: HostInit.java,v 1.41 2005/09/25 09:57:42 tdb Exp $ */ class HostInit extends Thread { @@ -45,7 +45,7 @@ class HostInit extends Thread { /** * The current CVS revision of this class */ - public final String REVISION = "$Revision: 1.40 $"; + public final String REVISION = "$Revision: 1.41 $"; //---STATIC METHODS--- @@ -87,23 +87,23 @@ class HostInit extends Thread { while(!cmd.equals("END")) { if(cmd.equals("STARTCONFIG")) { // respond to STARTCONFIG - _socketOut.println("OK"); + send("OK"); // try for LASTMODIFIED getInBound("LASTMODIFIED"); - _socketOut.println(cp.getLastModified(configName)); + send("" + cp.getLastModified(configName)); // try for FILELIST getInBound("FILELIST"); - _socketOut.println(cp.getFileList(configName)); + send(cp.getFileList(configName)); // try for FQDN getInBound("FQDN"); - _socketOut.println(_socket.getInetAddress().getHostName().toLowerCase()); + send(_socket.getInetAddress().getHostName().toLowerCase()); // try for IP getInBound("IP"); - _socketOut.println(_socket.getInetAddress().getHostAddress()); + send(_socket.getInetAddress().getHostAddress()); // get properties String reqProperty = getInBound(); @@ -111,15 +111,15 @@ class HostInit extends Thread { // get the property try { String returnedProperty = cp.getProperty(configName, "Host."+reqProperty); - _socketOut.println(returnedProperty); + send(returnedProperty); } catch (PropertyNotFoundException e) { - _socketOut.println("ERROR"); + send("ERROR"); } // get the next request reqProperty = _socketIn.readLine(); } _logger.write(toString(), Logger.SYSMSG, "configured host"); - _socketOut.println("OK"); + send("OK"); // get filter reference getInBound("FILTER"); @@ -143,29 +143,29 @@ class HostInit extends Thread { _logger.write(toString(), Logger.DEBUG, " found filter- " + filter); try { // tell the host about it... - _socketOut.println(filterInfoRef.getHostName() + ";" + send(filterInfoRef.getHostName() + ";" + filterInfoRef.getUDPPort()); } catch(org.omg.CORBA.COMM_FAILURE e) { // failed to talk to filter, lets signal an error - _socketOut.println("ERROR"); + send("ERROR"); throw new IOException("error communicating with filter - " + e); } } else { // ...or throw a wobbly (and tell the host!) - _socketOut.println("ERROR"); + send("ERROR"); throw new IOException("unable to find filter for host"); } } else if(cmd.equals("CHECKCONFIG")) { // respond to CHECKCONFIG - _socketOut.println("OK"); + send("OK"); // try for {filelist} String filelist = getInBound(); - _socketOut.println("OK"); + send("OK"); // try for {lastModified} String lastModified = getInBound(); @@ -174,7 +174,7 @@ class HostInit extends Thread { lastmod = Long.parseLong(lastModified); } catch(NumberFormatException e) { - _socketOut.println("ERROR"); + send("ERROR"); throw new IOException("Last Modified invalid: " + e); } @@ -182,21 +182,21 @@ class HostInit extends Thread { boolean newConfig = _configManager.isModified(filelist, lastmod); if(newConfig) { // new config ! - _socketOut.println("EXPIRED"); + send("EXPIRED"); } else { // nothing has changed - _socketOut.println("OK"); + send("OK"); } } else { - _socketOut.println("ERROR"); + send("ERROR"); } // get the next command cmd = getInBound(); } // respond to END - _socketOut.println("OK"); + send("OK"); } catch (Exception e) { _logger.write(toString(), Logger.ERROR, "ERROR - " + e); @@ -236,7 +236,7 @@ class HostInit extends Thread { String inBound = getInBound(); // check if it's what we're expecting if(!inBound.equals(expected)) { - _socketOut.println("ERROR"); + send("ERROR"); throw new IOException("protocol error - expected:"+expected+" got:" + inBound); } // it should be ok then @@ -253,6 +253,14 @@ class HostInit extends Thread { // it's a valid message it seems return inBound; } + + /* Use this instead of println. println under windows terminates the lines + * in \c\n which is not the expected result for the ihost client. + */ + private void send(String data) { + _socketOut.print(data + "\n"); + _socketOut.flush(); + } //---ACCESSOR/MUTATOR METHODS---