Skip to content

Commit

Permalink
pr final fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EricChen-Lei committed Sep 11, 2023
1 parent 199b1d7 commit 9367abf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,11 @@ public void initialize(long startTime, long endTime) throws InternalFederateExce
//set the connected server URL
try{
URL xmlRpcServerUrl = new URL("http://127.0.0.1:8090/RPC2");
carlaXmlRpcClient = new CarlaXmlRpcClient();
carlaXmlRpcClient.initialize(xmlRpcServerUrl);
carlaXmlRpcClient = new CarlaXmlRpcClient(xmlRpcServerUrl);
}
catch (MalformedURLException m)
{
log.error("Errors occurred with {0}", m.getMessage());
log.error("Errors occurred with {}", m.getMessage());
carlaXmlRpcClient.closeConnection();
}
// Start the CARLA simulator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.eclipse.mosaic.fed.carla.carlaconnect;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.xmlrpc.XmlRpcException;
Expand All @@ -32,11 +31,11 @@ public class CarlaXmlRpcClient{
boolean isConnected;
private String registeredFunction = "test.echo";
private XmlRpcClient client;
private XmlRpcClientConfigImpl config;
private final Logger log = LoggerFactory.getLogger(this.getClass());

public CarlaXmlRpcClient() {


public CarlaXmlRpcClient(URL xmlRpcServerUrl) {
initialize(xmlRpcServerUrl);
}

/**
Expand All @@ -56,21 +55,11 @@ public void closeConnection()
*/
public void initialize(URL xmlRpcServerUrl)
{
try{
config = new XmlRpcClientConfigImpl();
config.setServerURL(xmlRpcServerUrl);
client = new XmlRpcClient();
client.setConfig(config);
Object[] connectionTest = new Object[]{"Connection test"};
Object result = (String)client.execute(registeredFunction, connectionTest);
isConnected = true;
}
catch (XmlRpcException x)
{
log.error("Errors occurred with xmlrpc connection {0}", x.getMessage());
isConnected = false;
}

XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(xmlRpcServerUrl);
client = new XmlRpcClient();
client.setConfig(config);
isConnected = true;
}


Expand All @@ -88,7 +77,7 @@ public void requestCarlaList()
}
catch (XmlRpcException e)
{
log.error("Server is not connected! {0}", e.getMessage());
log.error("Server is not connected! {}", e.getMessage());
}
}
try{
Expand All @@ -98,7 +87,7 @@ public void requestCarlaList()
}
catch (XmlRpcException x)
{
log.error("Errors occurred with xmlrpc connection {0}", x.getMessage());
log.error("Errors occurred with xmlrpc connection {}", x.getMessage());
closeConnection();
}

Expand Down

0 comments on commit 9367abf

Please sign in to comment.