Lesson 1: Setting Up a Web Server to Receive Requests and Send Responses

The goal of this lesson is to set up an SAP Sybase IQ web server running a web service.

Prerequisites

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Create a web server and access it from a web client.

Task
  1. Create an SAP Sybase IQ database that will be used to contain web service definitions.
    iqinit -dba <user_id>,<password> echo
  2. Start a network database server using this database. This server will act as a web server.
    iqsrv16 -xs http(port=8082) -n echo echo.db

    The HTTP web server is set to listen on port 8082 for requests. Use a different port number if 8082 is disallowed on your network.

  3. Connect to the database server with Interactive SQL.
    dbisql -c "UID=<user_id>;PWD=<password>;SERVER=echo"
  4. Create a new web service to accept incoming requests.
    CREATE SERVICE EchoService
    TYPE 'RAW'
    USER DBA
    AUTHORIZATION OFF
    SECURE OFF
    AS CALL Echo();

    This statement creates a new service named EchoService that calls a stored procedure named Echo when a web client sends a request to the service. It generates an HTTP response body without any formatting (RAW) for the web client.

  5. Create the Echo procedure to handle incoming requests.
    CREATE OR REPLACE PROCEDURE Echo()
    BEGIN
        DECLARE request_body LONG VARCHAR;
        DECLARE request_mimetype LONG VARCHAR;
    
        SET request_mimetype = http_header( 'Content-Type' );
        SET request_body = isnull( http_variable('text'), http_variable('body') );
        IF request_body IS NULL THEN
            CALL sa_set_http_header('Content-Type', 'text/plain' );
            SELECT 'failed'
        ELSE
            CALL sa_set_http_header('Content-Type', request_mimetype );
            SELECT request_body;
        END IF;
    END

    This procedure formats the Content-Type header and the body of the response that is sent to the web client.

A web server is set up to receive requests and send responses.

Next

Proceed to Lesson 2: Sending requests from a web client and receiving responses.