Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Check whether URL exists ,also catch exception : ' Page not found' in SAP

former_member907073
Participant
0 Kudos

Hi,

I need to check whether URL exists & also catch exception : ' Page not found' in SAP programmatically via a FM or Class or any other way.

Tried with :

   CALL METHOD cl_gui_frontend_services=>execute

 

   CALL FUNCTION 'CALL_BROWSER'

Both of the above FM/class does not return any exception or error in case 'Webpage is not found'.

Please suggest a way out.

Regards,

AS

9 REPLIES 9

Former Member
0 Kudos

HTTP_CHECK_REDIRECT_URL check this FM , if its invalid  you will get the exception nraised

0 Kudos

FM suggested by you ,does not raise any of Exceptions..

Inspite of File not being there on URL ,Exception not raised .

rdiger_plantiko2
Active Contributor
0 Kudos

Hi Ramachandran,

the only way to check that the page can be requested, is to perform (redundantly) an HTTP request from within the SAP system and to check whether the HTTP statuscode of the answer is 200.

Check the following report. [ I am still waiting for the SCN features: ABAP SYNTAX HIGHLIGHTING, and FIXED FONT FOR CODE ).

Be aware, however, that there might be different network policies for the browser and for the SAP system, resulting in different HTTP status codes. This depends on the network policy of the company's intranet.

Regards,

Rüdiger

*&---------------------------------------------------------------------*
*& Report  ZZ_TEST_URL
*&---------------------------------------------------------------------*

report  zz_test_url.

parameters: p_url type c length 128 lower case
                   default 'http://www.google.com'.

start-of-selection.
   perform start.

* ---
form start.

   data: lv_status type i,
         lv_msg    type string.

   perform test_url using p_url
                    changing lv_status lv_msg.
   write: / 'Status:', lv_status.
   if lv_status >= 200 and lv_status < 400.
     write: / 'Request is OK'.
   else.
     write: / 'Request is not OK'.
     write: / lv_msg.
   endif.


endform.                    "start


* --- Check URL can be called
form test_url using    iv_url   type csequence
               changing ev_status type i
                        ev_msg    type string.

   data: lo_client  type ref to if_http_client,
         lv_url     type string.

   clear: ev_status, ev_msg.

* Convert URL into string datatype
   lv_url = iv_url.

* Create client object for performing the request
   call method cl_http_client=>create_by_url
     exporting
       url                = lv_url
     importing
       client             = lo_client
     exceptions
       argument_not_found = 1
       plugin_not_active  = 2
       internal_error     = 3
       others             = 4.
   if sy-subrc ne 0.
* HTTP error
     message id sy-msgid type sy-msgty number sy-msgno
         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
         into ev_msg.
     return.
   endif.

* Send request
   call method lo_client->send
     exceptions
       http_communication_failure = 1
       http_invalid_state         = 2
       http_processing_failed     = 3
       others                     = 4.
   if sy-subrc ne 0.
     lo_client->get_last_error( importing message = ev_msg ).
     return.
   endif.

* Wait for answer
   lo_client->receive( exceptions others = 1 ).
   if sy-subrc ne 0.
     lo_client->get_last_error( importing message = ev_msg ).
     return.
   endif.


* HTTP code. 200 = OK, 3xx = some sort of redirect = goes, too
   lo_client->response->get_status( importing code = ev_status ).


endform.                    "test_url

0 Kudos

For any URL, error message :  'ICM_HTTP_CONNECTION_FAILED' and status '0' is observed.

Any other way perhaps.

Regds,

AS

0 Kudos

I don't see another solution for your question. If you really want to check the URL from the ABAP site, before the browser gets called, you need to perform HTTP requests from the ABAP site.

This is the output of the report on my machine, when I enter "http://www.google.com"

Test Status Code URL

Status:        200

Request is OK

Check your ICF configurations: In your ABAP system you can't perform HTTP requests (should be possible).

Regards,

Rüdiger

0 Kudos

Status on my side

Test URL exist

Status:          0
Request is not OK
ICM_HTTP_CONNECTION_FAILED

Suggest a way to check ICFconfig for the same

0 Kudos

Do you have an HTTP service up and running in transaction SMICM?

If yes, what opnion do the trace files have about your request (i.e. to the requests that are issued by the program above)?

http://help.sap.com/saphelp_nw04/helpdata/en/ba/435e096b42724bbcef709fd4c32a85/frameset.htm

0 Kudos

Trace gives error;

No service for protocol HTTPS started [icxxconn_mt.  2224]

0 Kudos

Well, that's the answer.