mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed bug so XML messages are located and sent properly on the server
Imported appache commons to read inputstream to a bytearray #story[829]
This commit is contained in:
@@ -20,6 +20,11 @@
|
|||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>1.3.2</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.googlecode.json-simple</groupId>
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
<artifactId>json-simple</artifactId>
|
<artifactId>json-simple</artifactId>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class App extends Application
|
|||||||
primaryStage.setTitle("RaceVision");
|
primaryStage.setTitle("RaceVision");
|
||||||
primaryStage.setScene(new Scene(root));
|
primaryStage.setScene(new Scene(root));
|
||||||
|
|
||||||
primaryStage.show();
|
// primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package seng302.server;
|
|||||||
import seng302.server.messages.*;
|
import seng302.server.messages.*;
|
||||||
import seng302.server.simulator.Boat;
|
import seng302.server.simulator.Boat;
|
||||||
import seng302.server.simulator.Simulator;
|
import seng302.server.simulator.Simulator;
|
||||||
|
import sun.misc.IOUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -56,11 +59,11 @@ public class ServerThread implements Runnable, Observer {
|
|||||||
String fileContents = null;
|
String fileContents = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileContents = new String(Files.readAllBytes(Paths.get(this.getClass().getResource(fileName).getPath().substring(1))));
|
InputStream thisStream = this.getClass().getResourceAsStream(fileName);
|
||||||
|
fileContents = new String(org.apache.commons.io.IOUtils.toByteArray(thisStream));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
} catch (NullPointerException e){
|
||||||
catch (NullPointerException e){
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,20 +209,23 @@ public class ServerThread implements Runnable, Observer {
|
|||||||
*/
|
*/
|
||||||
private void sendXml(){
|
private void sendXml(){
|
||||||
try{
|
try{
|
||||||
Message raceData = getXmlMessage("server_config/race.xml", XMLMessageSubType.RACE);
|
Message raceData = getXmlMessage("/server_config/race.xml", XMLMessageSubType.RACE);
|
||||||
Message boatData = getXmlMessage("server_config/boats.xml", XMLMessageSubType.BOAT);
|
Message boatData = getXmlMessage("/server_config/boats.xml", XMLMessageSubType.BOAT);
|
||||||
Message regatta = getXmlMessage("server_config/regatta.xml", XMLMessageSubType.REGATTA);
|
Message regatta = getXmlMessage("/server_config/regatta.xml", XMLMessageSubType.REGATTA);
|
||||||
|
|
||||||
if (raceData != null){
|
if (raceData != null){
|
||||||
server.send(raceData);
|
server.send(raceData);
|
||||||
|
serverLog("Sending race data", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boatData != null){
|
if (boatData != null){
|
||||||
server.send(boatData);
|
server.send(boatData);
|
||||||
|
serverLog("Sending boat data", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regatta != null){
|
if (regatta != null){
|
||||||
server.send(regatta);
|
server.send(regatta);
|
||||||
|
serverLog("Sending regatta data", 0);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
serverLog("Couldn't send an XML Message: " + e.getMessage(), 0);
|
serverLog("Couldn't send an XML Message: " + e.getMessage(), 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user