Adjust Server Profile via XMLSnippets Java Example
Posted: Thu Dec 22, 2016 2:09 pm
In our current project, we had the requirement to include different speed profiles. If you use a local installation of xServer, you can add various profiles in the conf folder of the server and load them for your dia Matrix. However for the xServer internet, you have to stick with the profiles given on the server. This was not sufficient for our needs.
In this thread we would like to show, how you overcome such a problem. The instructions applies also to all server side profile attributes and is based on passing a XML snipped to the server. This becomes handy if he Java API is not included the attribute you want to set. If it is in the API please use the API.
Fist you jave to read your profile XML snippet. I attach a sample method, which does this:
Important is to read with UTF-8 encoding, because the server side expects this. The keyword is "ProfileXMLSnippet" in the caller context property. After you read the XML file, just add it to the client:
In the XML (germanSpeed.xml) include only the attributes, which should be changed in comparison to the server values, because the performance is influenced in a bad way by long xml files. The version number are mandatory, if you leave them you get a server side error.
In this thread we would like to show, how you overcome such a problem. The instructions applies also to all server side profile attributes and is based on passing a XML snipped to the server. This becomes handy if he Java API is not included the attribute you want to set. If it is in the API please use the API.
Fist you jave to read your profile XML snippet. I attach a sample method, which does this:
Code: Select all
InputStream is = this.getClass().getClassLoader().getResourceAsStream(file_path);
StringBuffer sb = new StringBuffer();
try (InputStreamReader fr = new InputStreamReader(is, StandardCharsets.UTF_8.name()); BufferedReader br = new BufferedReader(fr);) {
String read = br.readLine();
while (read != null) {
sb.append(read);
read = br.readLine();
}
} catch (Exception ex) {
Logger.log(MessageTexts._error, ex.getMessage());
}
String snippet = sb.toString();
CallerContextProperty p2 = new CallerContextProperty("ProfileXMLSnippet", snippet);
Important is to read with UTF-8 encoding, because the server side expects this. The keyword is "ProfileXMLSnippet" in the caller context property. After you read the XML file, just add it to the client:
Code: Select all
this.ctx = new CallerContext(new CallerContextProperty[] {...});
this.xLocateClient = (XLocateRemoteInterface) ClientFactory.createClient(...);
this.xLocateClient.setCallerContext(ctx);
Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Profile>
<Common coordinateFormat="PTV_SMARTUNITS" majorVersion="1" minorVersion="0"/>
<Routing majorVersion="2" minorVersion="0">
<Vehicle>
<Speed speedForAirLineDistance="60">
<SpeedRangeByNetworkClass minimumSpeed="80" maximumSpeed="130"/>
<SpeedRangeByNetworkClass minimumSpeed="70" maximumSpeed="100"/>
<SpeedRangeByNetworkClass minimumSpeed="60" maximumSpeed="80"/>
<SpeedRangeByNetworkClass minimumSpeed="50" maximumSpeed="70"/>
<SpeedRangeByNetworkClass minimumSpeed="25" maximumSpeed="50"/>
<SpeedRangeByNetworkClass minimumSpeed="18" maximumSpeed="40"/>
<SpeedRangeByNetworkClass minimumSpeed="9" maximumSpeed="16"/>
<SpeedRangeByNetworkClass minimumSpeed="4" maximumSpeed="6"/>
</Speed>
</Vehicle>
</Routing>
</Profile>