Skip to content

Getting Started with SIHOT@360° using Java

Overview

In this tutorial we will be looking at the basics of the SIHOT@360° API using the Java programming language.

For the demo purpose we will:

  • create a SOAP client from the provided WSDL
  • authenticate at the server
  • retrieve all in house guests using the API

What You Will Need

  • Internet access
  • Basic knowledge of Java
  • Access to a 360° service such as public WSDL
  • JDK8 (this tutorial was created using OpenJDK8 from Zulu)

The Tutorial

This tutorial will only use minimal dependencies to demonstrate the API usage. Any server components like express outputs like html are omitted to focus on the API usage itself.

Step 1 – Loading Dependencies

Initialize the project and load dependencies.

> gradle init

Welcome to Gradle 7.3.3!

Here are the highlights of this release:
 - Easily declare new test suites in Java projects
 - Support for Java 17
 - Support for Scala 3

For more details see https://docs.gradle.org/7.3.3/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 2

Select implementation language:
  1: C++
  2: Groovy
  3: Java
  4: Kotlin
  5: Scala
  6: Swift
Enter selection (default: Java) [1..6] 3

Split functionality across multiple subprojects?:
  1: no - only one application project
  2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 1

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] n
Please enter 'yes' or 'no':

Select test framework:
  1: JUnit 4
  2: TestNG
  3: Spock
  4: JUnit Jupiter
Enter selection (default: JUnit Jupiter) [1..4] 1

Project name (default: java): getting_started

Source package (default: getting_started): GettingStarted


> Task :init
Get more help with your project: https://docs.gradle.org/7.3.3/samples/sample_building_java_applications.html

BUILD SUCCESSFUL in 1m 44s
2 actionable tasks: 2 executed

After the application is initialized let's add the soap dependencies using wsimport.

wsimport -keep -d src/main/java https://partner-api.sihot.com/PDOCS/API/CBS/SihotServices01?wsdl

Note: In our case we keep the generated sources, however this is not a requirement but may help later on when using the library.

Step 2 – Initialize the client

public App() {
    SihotServices01 service;
    try {
        URL url = new URL(System.getenv("WSDL_URL"));
        service = new SihotServices01(url);
    } catch (Exception e) {
        System.out.println("invalid URL provided,.. use default from WSDL");
        System.out.println(e);
        service = new SihotServices01();
    }

    servicePort = service.getSihotServices01Port();
}

Step 3 – Authentication / Requesting a securityID (token)

To authenticate and receiving a securityID the authenticate request is required. See also Authentication for more information.

The structure of the AuthenticateRequest can be reviewed seen Authenticate.

To separate code from the configuration we read the config from the environment. The following bat-file demonstrate the concept.

SET SIHOT_USER={PLACEYOURUSERHERE!}
SET SIHOT_PASSWORD={PLACEYOURPASWORDHERE!}
SET SIHOT_HOTEL={PLACESIHOTPROPERTYIDHERE!}
SET WSDL_URL=https://partner-api.sihot.com/PDOCS/API/CBS/SihotServices01?wsdl

Ensure that you replace the entries with "PLACEYOUR"... accordingly.

public String getSecurityID() {

    LocalDateTime now = LocalDateTime.now();

    if (securityID.length() > 0 && validUntil.getSecond() > now.getSecond()) {
        return securityID;
    }

    try {
        AuthenticateRequest req = new AuthenticateRequest();
        AuthenticationInfos auth = new AuthenticationInfos();

        auth.setUser(System.getenv("SIHOT_USER"));
        auth.setPassword(System.getenv("SIHOT_PASSWORD"));
        auth.setHotel(System.getenv("SIHOT_HOTEL"));

        req.setAuthenticationInfos(auth);
        AuthenticateResponse res = servicePort.authenticate(req);

        if (res.getResult() != null) {
            if (res.getResult().getSuccess().equalsIgnoreCase("true")) {
                securityID = res.getAuthentication().get(0).getSecurityID();
                String duration = res.getAuthentication().get(0).getDurationInSec();
                System.out.println(res.getAuthentication().get(0).getDurationInSec());

                LocalDateTime validUntil = now.plusSeconds(Integer.parseInt(duration) - 20);

                System.out.println(now.toLocalTime());
                System.out.println("securityID is valid until: " + validUntil.toLocalTime());
                return securityID;
            } else {
                System.out.println("did not get a positive result");
                System.out.println(res.getResult().getErrorMsg());
                return "null";
            }
        } else {
            System.out.println("did not get a result object");
            return "null";
        }
    } catch (Exception e) {
        System.out.println("Failed to retrieve securityID");
        System.out.println(e.getMessage());
        return "null";
    }
}

In this step we will write a new function that will call the api to retrieve the in-house guests for a certain day.

public SGUESTINHOUSESEARCHV001Response getInhouseGuests(String callingDate) {
    try {
        // ensure the securityID is still valid
        String _securityID = getSecurityID();

        SGUESTINHOUSESEARCHV001Request req = new SGUESTINHOUSESEARCHV001Request();
        Authentication auth = new Authentication();
        SGUESTINHOUSESEARCHV001Request.GuestInHouseSearch search = new SGUESTINHOUSESEARCHV001Request.GuestInHouseSearch();

        auth.setSecurityID(_securityID);
        search.setDate(callingDate);
        req.setAuthentication(auth);
        req.setGuestInHouseSearch(search);

        SGUESTINHOUSESEARCHV001Response res = servicePort.sGUESTINHOUSESEARCHV001(req);
        if (res.getResult() != null) {
            if (res.getResult().getSuccess().equalsIgnoreCase("true")) {
                System.out.println("got in-house guests");
                showGuests(res);
                return res;
            } else {
                System.out.println("did not get a positive result");
                System.out.println(res.getResult().getErrorMsg());
                return null;
            }
        } else {
            System.out.println("did not get a result object");
            return null;
        }
    } catch (

    Exception e) {
        System.out.println("Failed to retrieve securityID");
        System.out.println(e.getMessage());
        return null;
    }
    /*
        * showGuests(S_GUEST_IN_HOUSE_SEARCH_V001Response)
        * return S_GUEST_IN_HOUSE_SEARCH_V001Response;
        */
}

Step 5 – Showing the result

void showGuests(SGUESTINHOUSESEARCHV001Response res) {
    if (res.getRoom() == null) {
        System.out.println("Room list was empty");
        return;
    }

    for (SGUESTINHOUSESEARCHV001Response.Room room : res.getRoom()) {
        System.out.print("Room type: " + room.getCategory() +  ": ");

        for (SGUESTINHOUSESEARCHV001Response.Room.Person person : room.getPerson() ){
            System.out.print(person.getName1() + ", " + person.getName2());
        }
        System.out.println("");
    }
}

Step 6 – Bringing all together

public static void main(String[] args) {

    App app = new App();

    System.out.println(app.getSecurityID());
    app.getInhouseGuests("2021-12-22");
}

To compile and run simply run gradlew run. The output show similar like this:

> gradlew run

> Task :app:run
12:18:23.668
securityID is valid until: 13:18:03.668
0DMYu+3offrWMhmxasX63f5ohrfTM6S3zemfEKb8RZTlsY+AMl1Appi6ix2Be7VGjgF3vrYGq1j0yhrZ8um5Z5sqXDCSh430sziMmc7t9NQ20zEH2JSH5srLK51UN/upMQ==
12:18:23.815
securityID is valid until: 13:18:03.815
got in-house guests
Room type: BD: Smith, Peter
Room type: SUIT: Miller, Michael

What is next?

Download of the Source

A complete working example can be downloaded at: - GettingStarted360_Java8.zip.

To install the project run, please ensure that you enter username, password and hotel ot the setEnvironment.bat configuration file!

run as

gradlew run