Example of Using Java SDK

This section describes how to make the Example code actually work using the Java SDK.

Admin Portal Configuration

Please login to Admin Portal.

Generate Trusted Certificate and Client Certificate

First, generate a trusted certificate and a client certificate. Please go to Settings / WAAP / Configurations / Trusted Certificates.

Then, click Generate Certificate button. In this example, set the name to test. Please don't forget Client Certificate Passphrase. API-Certificate-01

After generated, click Download Client Certificate and save it to your PC.

API-Certificate-02

Add API Endpoints

Add API Endpoints. Please go to Settings / WAAP / API Protection / API Endpoints.

Add the echo API endpoint using Postman's echo server.

  • Name: echo
  • Endpoint Address/FQDN/Hostname: postman-echo.com
  • Protocol: HTTPS
  • Other settings: using default settings (no changed)

API-Endpoint-02

Add the simple web API endpoint. You will need to prepare this API endpoint by yourself. For example, here is how to start a SIMPLE web server using docker. The following expects index.html to exist in the current directory.

sudo docker run -d --rm --name simple-web -v $(pwd):/usr/share/nginx/html -p 80:80 -it nginx:latest
  • Name: simple-web
  • Endpoint Address/FQDN/Hostname: your server's IP address
  • Protocol: HTTP (or HTTPS. It's depends on your environment)
  • Other settings: using default settings (no changed)

API-Endpoint-03

Update the default API Group

Update API Group. Please go to Settings / WAAP / API Protection / API Groups.

Here, the default API Group is used. You can also add a new API Group and use it.

Click Edit button of default API Group.

  • Trusted Certificate: test
  • API Application (Main): echo, simple-web

API-Group-02

Download the example source code

Please get the example source code from github.

git clone https://github.com/iij-safous/safous-waap-sdk-java-example.git

Update the example source code to your environment

Please change the URL according to your environment.

ExampleAccessBackendEcho.java#L30

.url("https://echo.example.waap.safous.com/get?foo1=bar1&foo2=bar2")

ExampleAccessBackendSimple.java#L30

.url("https://simple-web.example.waap.safous.com")

ExampleTerminate.java#L30

.url("https://simple-web.example.waap.safous.com")

Download the Java SDK from the Admin Portal

Please go to Settings / WAAP / API Protection / SDK. Then, click Java tab and download the latest version of Java SDK.

After downloading, move the SDK to the libs directory. The file tree is as follows.

safous-waap-sdk-java-example/
+- libs/
+- safouswaap-VERSION.jar
+- src/
  :
+- pom.xml

Build the example source code

Build the source code as follows. Build requires JDK and meven.

mvn clean install

If the build is successful, safous-waap-example.jar and libs directory will be created under the target directory. Under the target/libs directory, dependent jar files are stored.

Copy your client certificate to target directory

Copy the previously downloaded client certificate file to the target directory.

cp PATH/test.p12 target

Update safouswaap.ini

Copy the safouswaap.ini.example to target/safouswaap.ini.

cp safouswaap.ini.example target/safouswaap.ini

Modify target/safouswaap.ini according to your environment.

For more details, see Configuration for Using Java SDK.

Run the example application

The example application has the following. Package name is com.example.app.

Class name Description
ExampleRegistration This is an example of registration, using registerDevice and verifyDevice method
ExampleAccessBackendEcho This is an example of transaction, using transaction method and echo API endpoint
ExampleAccessBackendSimple This is an example of transaction, using transaction method and simple-web API endpoint
ExampleTerminate This is an example of session termination, using transaction and terminate method

Run the example application as the following. After moving to the target directory, then, run the following.

cd target
java -cp ${PATH_LIB_AND_JAR} ${PACKAGE_NAME}.${CLASSNAME}

Linux / MacOS

For example,

java -cp libs/*:safous-waap-example.jar com.example.app.ExampleRegistration

Windows

For example,

java -cp libs\*;safous-waap-example.jar com.example.app.ExampleRegistration