Skip to content

Java EE (JBoss/Wildfly) application that aims to find which train ride a user is probably in given a location in the Netherlands. Uses NS Public API.

License

Notifications You must be signed in to change notification settings

immortaly007/TrainFinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trainfinder

This product is currently a work in progress

This is a web service that utilizes the NS (Dutch public transport provider) public API to try to find out which train a user currently is in. The user input is a coordinate (latitude, longitude) and optionally a direction in which the user is traveling.

The service creates a model of all public trains currently active in the Netherlands and their location. Note that this model will be simplified for now (e.g. the train speed is assumed to be constant between stations).

Prerequisites

In order to run the application you need to provide two sources of information:

Configuration

This service is originally aimed created for running on a JBoss/WildFly server. It should be portable to other servers (maybe with minor changes), but I haven't tested this.

You need to provide your NS public API username and password and the location of the railway map file. Configuration is stored in the WildFly/JBoss configuration directory (the folder where you put standalone.xml):

wildfly-10.1.0.Final/standalone/configuration

In this folder, you need to create the following file:

applications/trainfinder/Configuration.xml

Which should have the following content:

<?xml version="1.0" encoding="UTF-8"?>
<TrainFinder>
	<NSApi>
		<Username>[email protected]</Username>
		<Password>NS.Provided.Password</Password>
	</NSApi>
    <OpenStreetMap>
    	<RailroadFile>/path/to/your/railway-map.osm</RailroadFile>
    </OpenStreetMap>
</TrainFinder>

Where you should replace [email protected] and NS.Provided.Password by your NS API credentials, and /path/to/your/railway-map.osm by the path to tour railway map.

Running the application

Build the repository (mvn clean package) and deploy the generated trainfinder.war (found in the target directory) to your application server (either by placing it in wildfly-10.1.0.Final/standalone/deployments or by using WildFly/JBoss CLI).

It will be accessible on whatever is the default location for war files on your application server. For wildfly it is host:port/trainfinder/. In wildfly, you can easily change the context root and virtual server using the src\main\webapp\WEB-INF\jboss-web.xml deployment descriptor with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>

    <context-root>/</context-root>
    <virtual-host>trainfinder-host</virtual-host>
    
</jboss-web>

When you start the server, it should start reading the railway map and polling stations.

How to use

You can view live train information on a map using http://host:port/trainfinder/live. The functionality is accessible through a REST interface at: http://host:port/trainfinder/rest/train. The following resources exists:

  • rest/train/stations: returns a JSON array with all known stations
  • rest/train/trains: returns a JSON array with information on all known active trains, such as the current position of the train, the previous and next stations, and the ride is in currently on.

About

Java EE (JBoss/Wildfly) application that aims to find which train ride a user is probably in given a location in the Netherlands. Uses NS Public API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published