Adjust Server Profile via XMLSnippets Java Example

Proper forum for all questions related to xServer INTERNET = the Azure based cloud solution. This forum deals with the architecture topics such as load balancing, available profiles and standard server settings.
Please be aware that questions about core functionality such as routing, mapping, geocoding in general should be placed in the xServers dedicated forum ;-)
Post Reply
frank.essenberger
Posts: 12
Joined: Mon Feb 29, 2016 2:26 pm

Adjust Server Profile via XMLSnippets Java Example

Post 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>
User avatar
Bernd Welter
Site Admin
Posts: 2564
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Adjust Server Profile via XMLSnippets Java Example

Post 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
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Post Reply