Page 1 of 1

Adjust Server Profile via XMLSnippets Java Example

Posted: Thu Dec 22, 2016 2:09 pm
by frank.essenberger
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:

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);
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.

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>

Re: Adjust Server Profile via XMLSnippets Java Example

Posted: Fri Dec 23, 2016 9:03 am
by Bernd Welter
Hello Frank,

thanks for the examples! This is the reason why we implemented the Snippet mechanism: to enable cloud users to have access to all parameter features of a server. Useful not only for xTour but also for xDima and xRoute.

Little obstacle: if you want to use at least two independent routing profiles in the context of a a xTour request
this is not possible with a single transaction. But maybe one could create two succeeding xTour dummy transactions (each one creates a new dima via snippet, deleteAfter==false) to prepare the requirements of the later planning transaction.

Best regards Bernd