1

Geo-server taking the wrong port number when I try to create the datastore, because of that I'm not able to create the store. The data base is sap Hana cloud .

From SAP Hana cloud I'm launching the geoserver 2.14 . In geoserver war I added gt-jdbc-hana-21.0.jar ( which is provided by the geotool ) and **ngdbc.jar **.

From the cloud, I launched the geoserver and then I created the workspace. Then I try to create the datastore. I filled all the fields which are required. But the port number I'm giving 30047( my hana cloud port number ) but it's trying to connect port number 30015 which not there. Because of that, I'm not able to create the data store, please anyone help what is the issue and how to resolve it.

Error message I'm getting

Error creating data store, check the parameters. 
Error message: Unable to obtain connection: 
Cannot create PoolableConnectionFactory (SAP DBTech JDBC: Cannot connect to jdbc:sap://vadbi1l.nwtrial.od.sap.biz// [Cannot connect to host vadbi1l.nwtrial.od.sap.biz:30015 [Connection refused (Connection refused) (local port 58788 to address 0.0.0.0, remote port 30015 to address 10.117.96.92 (vadbi1l.nwtrial.od.sap.biz))], -813.].)

enter image description here

Hana database with port number enter image description here enter image description here

enter image description here

enter image description here

Geoserver log

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
Harish CHH
  • 104
  • 11

3 Answers3

2

From a quick look at the code it seems that the Hana Datastore doesn't use the port information provided.

public String buildUrl() {
    StringBuilder sb = new StringBuilder();
    sb.append("jdbc:sap://");
    sb.append(host);
    sb.append("/?instanceNumber=");
    sb.append(Integer.toString(instance));
    if ((database != null) && !database.isEmpty()) {
        sb.append("&databaseName=");
        sb.append(database);
    }
    return sb.toString();
}

I don't know enough about Hana to say if this is a bug or not. But you could raise either a bug report or an inhancement request at the project jira.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
1

Download gt-jdbc-hana-21.0 source code from mvnrepository change code in following class

In HanaDataStoreFactory class change the getJDBCUrl method

     @SuppressWarnings({"rawtypes", "unchecked"})
        @Override
        protected String getJDBCUrl(Map params) throws IOException {
                    String host = (String) HOST.lookUp(params);
                    int instance = (Integer) INSTANCE.lookUp(params);
                    String database = (String) DATABASE.lookUp(params);
              Integer port = (Integer) PORT.lookUp(params);
                   HanaConnectionParameters cp = new HanaConnectionParameters(host, instance,
             database,port);
                 return cp.buildUrl();
    } 

In HanaConnectionParameters class

/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2018, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.data.hana;

/**
 * SAP HANA connection parameters.
 *
 * @author Stefan Uhrig, SAP SE
 */
public class HanaConnectionParameters {

    /**
     * SAP HANA connection parameters constructor.
     *
     * @param host The database host.
     * @param instance The database instance.
     * @param database The name of the tenant database. Set to null or empty string if the database
     *     is a single-container system. Set to SYSTEMDB to connect to the system database of a
     *     multi-container system.
     */
    public HanaConnectionParameters(String host, int instance, String database,int port) {
        super();
        this.host = host;
        this.instance = instance;
        this.database = database;
        this.port = port;
    }

    private String host;

    private Integer  instance;

    private String database;

    private Integer port;

    public String getHost() {
        return host;
    }

    public Integer getInstance() {
        return instance;
    }

    public String getDatabase() {
        return database;
    }

    public Integer getPort() {
        return this.port;
    }
    /**
     * Builds a JDBC connection URL.
     *
     * @return Returns the JDBC connection URL corresponding to these parameters.
     */
    public String buildUrl() {

         String url = "jdbc:sap://" + this.host + ":" + this.port;
         return url;

    }
}

after changing in the respective class , copy the pom content from gt-jdbc-hana-21.0 . build your maven and take the jar .

Harish CHH
  • 104
  • 11
0

no the port number is not mandatory with HANA as the instance number is used to derive it.

The port number is built around the instance number actually like this: 3

So, if you are connecting using the instance number, then your client will actually contact the SYSTEM DB first.

The default port suffix for the SYSTEM DB is 13.

When using HANA 1.0 where the default instance number is 00, so the port used will be 30013 to contact the SYSTEM DB. And when using HANA 2.0 the default instance number is 90, so the port used will be 39013 to contact the SYSTEM DB.

Then your client will ask the SYSTEM DB what is the port suffix for the DB you want to connect or the port of the default DB. The default DB is usually named HDB (or HXE for SAP HANA, express edition.

The default port suffix for the default DB is 15.

Then your client will connect directly to the right port.

So, this is how it goes when you don't provide the port number to make it short: - go to system db and ask for the right port then connect to it

Something really important is to check that your firewalls are not preventing the connections (you can use telnet to verify that).

So to make it work, you will need to set the port number number in the instance property.

Abdel Dadouche
  • 217
  • 1
  • 7
  • thanks for the reply , even i give right instance id, still not taking properly . you cn see in the images . – Harish CHH Mar 18 '19 at 07:14
  • There's a problem with the code.Instance number they are using as an integer. Let say your instance number 01, it will truncate the 0 then it will become 1 (because data type is integer). Then it's not a right instance number. Then they take the default port number. There's a problem with the code. – Harish CHH Mar 19 '19 at 04:40
  • Why not create a pull request to amend the code or create a GitHub issue in their repo? – Abdel Dadouche Mar 19 '19 at 09:44
  • I fixed it by changing the code . even a raise the issue in the geotool forum – Harish CHH Mar 20 '19 at 06:40