We have discussed in previous articles how to set up the network data for pgrouting and how to develop a wrapper to search the route between two points.
Here we will discuss how to set up Geoserver to provide the result of the wrapper as a WMS or WFS layer to be used in a web page using OpenLayers 3 (next article) .Among all the Postgres / Postgis / Geoserver / OpenLayers chain, this part is, still, the simplest. We simply have to set up a Workspace, a Data Warehouse, and a layer using the wrapper SQL query developed in the previous article.
Setting up a workspace
For the entire Geoserver setting up, you must log in as administrator to the administration interface. Once logged in, click Workspaces in the Data module (left menu) and click Add New Workspace.

Fill in the two fields with a name for the workspace (here pgrouting) and the domain address (http://pgrouting.org), then click the Send button .
Setting up a data warehouse
Click Warehouses in the Data module on the left menu and click Add New Warehouse. On the list of Vector data sources, select PostGIS

The warehouse configuration page opens

In the workspaces list select the workspace that has just been created: pgrouting, and give a name to your data source (here itineraries ).
Fill in the correct connection details for your Postgres database: the database is the name of your Postgres database containing the network tables, a username and login password. Avoid using the postgres username for obvious security reasons. Create a username with rights only on the data necessary for your application.
The rest of the information can be left the same. Click the Save button . You will have the configuration page of a new layer.

Click on Configure a new SQL view

Assign a name to the display and enter the last sql query that we tested in the previous article:
SELECT ST_MakeLine (route.geom) FROM (SELECT geom FROM pgr_route_entreAetB (‘ways’,% x1%,% y1%,% x2%,% y2%) ORDER BY seq) AS route
But at this stage you do not need to enter true coordinate values: we replace them with variables. The values of these variables will be WMS or WFS parameters that will be received. In SQL View Settings, click Guess Settings From SQL .

You must enter default values. They will be used in case of request without coordinates.
Enter the following string ^ -? [\ d.] + $ in Regular Validation Expression. The user will,only, be entitled to enter numbers in the variables. In Attributes , click Refresh .

Modify the geometry type to match the geometry returned by the sql query (in this case a LineString) as well as the return SRID (here 4326).
Click Save .
It only remains to set up the rest of the parameters for the layer. In our case it is enough to make sure that the native SRIDs and data are the needed for our application. For native SRID, as explained when setting up the network tables, pgrouting works exclusively in 4326 (latitude / longitude). On the other hand, in our WEB page (which we have not discussed yet) we will use OpenStreetMap as a base map. Therefore, we need to set up the Geoserver output in EPSG: 3857 (the SRID used by OSM).

Do not forget to change CRS management into a CRR re-projecter from native to the CRS stated .
Click Emprises -> Based on Data and Calculated on native emprises to complete the layer configuration.
Click Save . Make sure you have everything set up by clicking Layer Preview and selecting OpenLayers. You must get the route between the points you entered as default points:

You have completed the Geoserver setting up.