100% found this document useful (1 vote)
2K views5 pages

Como Publicar REST Web Service - ABAP SAP

This document provides instructions for publishing a REST web service when SAP Netweaver Gateway is not available. It describes creating a custom class with an IF_HTTP_EXTENSION interface to handle requests, reading query parameters, and returning a JSON response. It also explains setting up a service in SICF to expose the handler and test it by making requests to a URL with a query parameter.

Uploaded by

Carlos Faria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views5 pages

Como Publicar REST Web Service - ABAP SAP

This document provides instructions for publishing a REST web service when SAP Netweaver Gateway is not available. It describes creating a custom class with an IF_HTTP_EXTENSION interface to handle requests, reading query parameters, and returning a JSON response. It also explains setting up a service in SICF to expose the handler and test it by making requests to a URL with a query parameter.

Uploaded by

Carlos Faria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • Introduction: Introduces the document's purpose, showing how to publish a REST Web Service when SAP Netweaver Gateway is unavailable.
  • Exercise: Provides a hands-on exercise to demonstrate creating a REST Web Service, involving basic URL modifications for service parameter testing.
  • Create custom class: Details steps for creating a custom class using IF_HTTP_EXTENSION for handling requests and sending server parameters.
  • Create service in SICF: Explains the process of creating a service in SICF, including adding a new service in the SAP system and setting configurations.
  • Test your service: Describes the method to test the newly created service and observe responses by changing query parameters.

This tutorial will explain how to publish REST Web Service when SAP Netweaver Gateway is not available.

Exercise
Go to [Link] and the server will respond with the following content:
{"message": You have entered myVar=50 as query parameter."}

Be in mind that this content could be JSON or XML format. In this exercise, it is a basic JSON object.

Create custom class


Firstly, create a class object with IF_HTTP_EXTENSION interface.

Implement the method IF_HTTP_EXTENSION~HANDLE_REQUEST, where you will have the server
parameter. There, the query parameter will be read from the request and the response will be set in JSON
format.
method IF_HTTP_EXTENSION~HANDLE_REQUEST.

DATA: lt_fields TYPE tihttpnvp,

lv_header_query TYPE string,

lv_html TYPE string.

FIELD-SYMBOLS: <fs_field> LIKE LINE OF lt_fields.

*" get HEADER fields

server->request->get_header_fields(

CHANGING

fields = lt_fields " Header fields

).

" Read the fields table and look for name "~query_string" -- this will contain the URL query

READ TABLE lt_fields

WITH KEY name = '~query_string'

ASSIGNING <fs_field>.

IF sy-subrc EQ 0.

CONCATENATE '{"message": "You have entered'

<fs_field>-value

'as query parameter."}'

INTO lv_html SEPARATED BY space.

*" Output to HTML


server->response->set_cdata(

EXPORTING

data = lv_html " Character data

* offset = 0 " Offset into character data

* length = -1 " Length of character data

).

ENDIF.

endmethod.

Create service in SICF


We need to expose the handler as a service, so go to SICF transaction, and add a new service in
default_host.

In this service, a communication user is needed. It is recommended that the user is a service user instead
of a dialog user.
If a user is not specified, authentication dialog will request when performing the REST Web Service request.
And finally, add the custom class as handler.
Test your service
A new service with ZREST name was created in default_host, so the URL to test is the following:
 [Link]
Firstly, right click on the service and select Test service. Your default browser will be launched with your
SAP Client.

Change the query parameter and type anything. The response will be updated.

You might also like