
Implementing Handler Classes
Use
The central task when creating a HTTP request handler is implementing the interface
IF_HTTP_EXTENSION. A prerequisite for this is implementing the method HANDLE_REQUEST () to make it possible to determine how the HTTP request handler should process an incoming HTTP request.The UML diagram in
ICF Classes and Interfaces shows the relationship between the ICF classes and interfaces and the interface IF_HTTP_EXTENSION.Procedure
In the class builder (transaction SE24), create a class that represents the HTTP request handler, and assign it to the interface
IF_HTTP_EXTENSION.You can now implement the method
HANDLE_REQUEST () (double-click on the method name).You can access the request and response data by using the reference to the interface
IF_HTTP_SERVER an argument of the method HANDLE_REQUEST (). The interface IF_HTTP_SERVER also supports the attributes FLOW_RC and LIFETIME_RC. You can assign content to these attributes using the method HANDLE_REQUEST. This allows you to specify in greater detail how an incoming request should be processed. For details of the attributes see the following sections: IF_HTTP_SERVER IF_HTTP_RESPONSE and IF_HTTP_REQUEST IF_HTTP_ENTITY

The connection to the server must be checked for an incoming request.
To do this, enter the URL
You can maintain the pingservice using Transaction SICF (see
Creating a Service). As the HTTP request handler it has class CL_HTTP_EXT_PING with the method HANDLE_REQUEST ().A data type
‘data’ of the type string is declared to interpret the body of the outgoing HTTP response:data: data type string.
As soon as the HTTP request handler is accessed, it is obvious that the connection test to the server was successful. The next task is to send a HTTP response back to the client to indicate the successful establishment of the connection. The browser should simply output the HTML line ‘connection to server successful’.
To do this, first the
Header Field content-type of the HTTP response is set to the value text/html (the method set_header_field () is called to set header fields in the response):|
server->response->set_header_field( name = 'Content-Type' value = 'text/html' ). |
Next, the HTTP string
data is filled with the string ‘connection to server successful’:|
concatenate '<html>' '<body>' 'connection to server successful'(001) '</body>' '</html into data. |
Finally, this string is transferred via a reference to the interface
IF_HTTP_SERVER of the method set_cdata, in order to fill the body of the HTTP response with this string.|
server->response->set_cdata( data = data ). |
This triggers the output of text to the browser, and the client sees that the connection test ran successfully.