HTTP connection check and improved error messages (#6806)

Co-authored-by: abaplint[bot] <24845621+abaplint[bot]@users.noreply.github.com>
Co-authored-by: Lars Hvam <larshp@hotmail.com>
This commit is contained in:
Marc Bernard 2024-02-23 14:09:38 +01:00 committed by GitHub
parent c8b3cf0746
commit 0d35e9377e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 258 additions and 54 deletions

View File

@ -28,6 +28,12 @@ CLASS zcl_abapgit_http DEFINITION
VALUE(ro_client) TYPE REF TO zcl_abapgit_http_client VALUE(ro_client) TYPE REF TO zcl_abapgit_http_client
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS check_connection
IMPORTING
!iv_url TYPE string
RAISING
zcx_abapgit_exception.
PROTECTED SECTION. PROTECTED SECTION.
CLASS-METHODS check_auth_requested CLASS-METHODS check_auth_requested
@ -51,6 +57,24 @@ CLASS zcl_abapgit_http DEFINITION
VALUE(rv_scheme) TYPE string VALUE(rv_scheme) TYPE string
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS get_http_client
IMPORTING
!iv_url TYPE string
RETURNING
VALUE(ri_client) TYPE REF TO if_http_client
RAISING
zcx_abapgit_exception.
CLASS-METHODS get_connection_longtext
IMPORTING
!iv_host TYPE string
!iv_ssl_id TYPE ssfapplssl
!iv_proxy_host TYPE string
!iv_proxy_service TYPE string
RETURNING
VALUE(rv_longtext) TYPE string.
PRIVATE SECTION. PRIVATE SECTION.
ENDCLASS. ENDCLASS.
@ -123,55 +147,22 @@ CLASS zcl_abapgit_http IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD check_connection.
" Check if a connection from this system to the git host is possible
" This will validate the general HTTP/HTTPS/SSL configuration and certificates
get_http_client( iv_url ).
ENDMETHOD.
METHOD create_by_url. METHOD create_by_url.
DATA: lv_uri TYPE string, DATA: lv_uri TYPE string,
lv_scheme TYPE string, lv_scheme TYPE string,
lv_authorization TYPE string, lv_authorization TYPE string,
li_client TYPE REF TO if_http_client, li_client TYPE REF TO if_http_client,
ls_header LIKE LINE OF it_headers, ls_header LIKE LINE OF it_headers.
lo_proxy_configuration TYPE REF TO zcl_abapgit_proxy_config,
lv_text TYPE string.
li_client = get_http_client( iv_url ).
CREATE OBJECT lo_proxy_configuration.
li_client = zcl_abapgit_exit=>get_instance( )->create_http_client( iv_url ).
IF li_client IS NOT BOUND.
cl_http_client=>create_by_url(
EXPORTING
url = zcl_abapgit_url=>host( iv_url )
ssl_id = zcl_abapgit_exit=>get_instance( )->get_ssl_id( )
proxy_host = lo_proxy_configuration->get_proxy_url( iv_url )
proxy_service = lo_proxy_configuration->get_proxy_port( iv_url )
IMPORTING
client = li_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
" make sure:
" a) SSL is setup properly in STRUST
lv_text = 'HTTPS ARGUMENT_NOT_FOUND | STRUST/SSL Setup correct?'.
WHEN OTHERS.
" Make sure ANONYM PSE exists in transaction STRUST, https://github.com/abapGit/abapGit/issues/6768
lv_text = 'While creating HTTP Client'.
ENDCASE.
zcx_abapgit_exception=>raise( lv_text ).
ENDIF.
ENDIF.
IF lo_proxy_configuration->get_proxy_authentication( iv_url ) = abap_true.
zcl_abapgit_proxy_auth=>run( li_client ).
ENDIF.
CREATE OBJECT ro_client CREATE OBJECT ro_client
EXPORTING EXPORTING
@ -244,6 +235,136 @@ CLASS zcl_abapgit_http IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD get_connection_longtext.
CONSTANTS lc_docs TYPE string VALUE 'https://docs.abapgit.org/user-guide/setup/ssl-setup.html'.
DATA lv_proxy TYPE string.
IF iv_proxy_host IS NOT INITIAL.
lv_proxy = | via proxy <b>{ iv_proxy_host }:{ iv_proxy_service }</b>|.
ENDIF.
rv_longtext = |abapGit is trying to connect to <b>{ iv_host }</b> |
&& |using SSL certificates under <b>{ iv_ssl_id }</b>{ lv_proxy }. |
&& |Check system parameters (transaction |
&& zcl_abapgit_html=>create( )->a(
iv_txt = 'RZ10'
iv_act = |{ zif_abapgit_definitions=>c_action-jump_transaction }?transaction=RZ10|
iv_class = 'no-pad' )
&& |), SSL setup (transaction |
&& zcl_abapgit_html=>create( )->a(
iv_txt = 'STRUST'
iv_act = |{ zif_abapgit_definitions=>c_action-jump_transaction }?transaction=STRUST|
iv_class = 'no-pad' )
&& |), Internet connection monitor (transaction |
&& zcl_abapgit_html=>create( )->a(
iv_txt = 'SMICM'
iv_act = |{ zif_abapgit_definitions=>c_action-jump_transaction }?transaction=SMICM|
iv_class = 'no-pad' )
&& |)|.
IF lv_proxy IS NOT INITIAL.
rv_longtext = rv_longtext
&& |, and proxy configuration (|
&& zcl_abapgit_html=>create( )->a(
iv_txt = 'global settings'
iv_act = |{ zif_abapgit_definitions=>c_action-go_settings }|
iv_class = 'no-pad' )
&& |)|.
ENDIF.
rv_longtext = rv_longtext
&& |. It's recommended to get your SAP Basis and network teams involved. |
&& |For more information and troubleshooting, see the |
&& zcl_abapgit_html=>create( )->a(
iv_txt = 'abapGit documentation'
iv_act = |{ zif_abapgit_definitions=>c_action-url }?url={ lc_docs }|
iv_class = 'no-pad' )
&& |.|.
ENDMETHOD.
METHOD get_http_client.
DATA:
lv_error TYPE string,
lv_longtext TYPE string,
lv_host TYPE string,
lv_ssl_id TYPE ssfapplssl,
lv_proxy_host TYPE string,
lv_proxy_service TYPE string,
lo_proxy_configuration TYPE REF TO zcl_abapgit_proxy_config.
CREATE OBJECT lo_proxy_configuration.
ri_client = zcl_abapgit_exit=>get_instance( )->create_http_client( iv_url ).
IF ri_client IS INITIAL.
lv_host = zcl_abapgit_url=>host( iv_url ).
lv_ssl_id = zcl_abapgit_exit=>get_instance( )->get_ssl_id( ).
lv_proxy_host = lo_proxy_configuration->get_proxy_url( iv_url ).
lv_proxy_service = lo_proxy_configuration->get_proxy_port( iv_url ).
lv_longtext = get_connection_longtext(
iv_host = lv_host
iv_ssl_id = lv_ssl_id
iv_proxy_host = lv_proxy_host
iv_proxy_service = lv_proxy_service ).
cl_http_client=>create_by_url(
EXPORTING
url = lv_host
ssl_id = lv_ssl_id
proxy_host = lv_proxy_host
proxy_service = lv_proxy_service
IMPORTING
client = ri_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
pse_not_found = 4
pse_not_distrib = 5
pse_errors = 6
OTHERS = 7 ).
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
lv_error = 'ARGUMENT_NOT_FOUND'.
WHEN 2.
lv_error = 'PLUGIN_NOT_ACTIVE'.
WHEN 3.
lv_error = 'INTERNAL_ERROR'.
WHEN 4.
lv_error = 'PSE_NOT_FOUND'.
WHEN 5.
lv_error = 'PSE_NOT_DISTRIB'.
WHEN 6.
lv_error = 'PSE_ERRORS'.
WHEN OTHERS.
lv_error = |OTHER_ERROR_{ sy-subrc }|.
ENDCASE.
IF sy-subrc BETWEEN 4 AND 6.
zcx_abapgit_exception=>raise_t100( iv_longtext = lv_longtext ).
ELSE.
zcx_abapgit_exception=>raise(
iv_text = |Error { lv_error } creating HTTP connection. Check the configuration|
iv_longtext = lv_longtext ).
ENDIF.
ENDIF.
ENDIF.
IF lo_proxy_configuration->get_proxy_authentication( iv_url ) = abap_true.
zcl_abapgit_proxy_auth=>run( ri_client ).
ENDIF.
ENDMETHOD.
METHOD is_local_system. METHOD is_local_system.
DATA: lv_host TYPE string, DATA: lv_host TYPE string,

View File

@ -467,6 +467,8 @@ CLASS zcl_abapgit_gui_chunk_lib IMPLEMENTATION.
lv_longtext = |{ lv_longtext }<p>{ <lv_longtext_paragraph> }</p>{ cl_abap_char_utilities=>newline }|. lv_longtext = |{ lv_longtext }<p>{ <lv_longtext_paragraph> }</p>{ cl_abap_char_utilities=>newline }|.
ENDLOOP. ENDLOOP.
lv_longtext = |{ lv_longtext }<br>|.
ENDIF. ENDIF.
ri_html->add( |<div id="message" class="message-panel">| ). ri_html->add( |<div id="message" class="message-panel">| ).
@ -490,7 +492,7 @@ CLASS zcl_abapgit_gui_chunk_lib IMPLEMENTATION.
iv_msgno = ix_error->if_t100_message~t100key-msgno ). iv_msgno = ix_error->if_t100_message~t100key-msgno ).
IF lv_title IS NOT INITIAL. IF lv_title IS NOT INITIAL.
lv_text = |Message ({ ix_error->if_t100_message~t100key-msgid }/{ ix_error->if_t100_message~t100key-msgno })|. lv_text = |Message E{ ix_error->if_t100_message~t100key-msgno }({ ix_error->if_t100_message~t100key-msgid })|.
ri_html->add_a( ri_html->add_a(
iv_txt = lv_text iv_txt = lv_text

View File

@ -229,6 +229,8 @@ CLASS zcl_abapgit_gui_page_addonline IMPLEMENTATION.
iv_key = c_id-url iv_key = c_id-url
iv_val = lx_err->get_text( ) ). iv_val = lx_err->get_text( ) ).
ENDTRY. ENDTRY.
zcl_abapgit_http=>check_connection( lv_url ).
ENDIF. ENDIF.
IF io_form_data->get( c_id-package ) IS NOT INITIAL. IF io_form_data->get( c_id-package ) IS NOT INITIAL.

View File

@ -43,6 +43,7 @@ CLASS zcl_abapgit_gui_page_repo_view DEFINITION
DATA mo_repo TYPE REF TO zcl_abapgit_repo . DATA mo_repo TYPE REF TO zcl_abapgit_repo .
DATA mo_repo_aggregated_state TYPE REF TO zcl_abapgit_repo_item_state. DATA mo_repo_aggregated_state TYPE REF TO zcl_abapgit_repo_item_state.
DATA mv_connection_error TYPE abap_bool.
DATA mv_cur_dir TYPE string . DATA mv_cur_dir TYPE string .
DATA mv_hide_files TYPE abap_bool . DATA mv_hide_files TYPE abap_bool .
DATA mv_max_lines TYPE i . DATA mv_max_lines TYPE i .
@ -192,6 +193,10 @@ CLASS zcl_abapgit_gui_page_repo_view DEFINITION
RAISING RAISING
zcx_abapgit_exception. zcx_abapgit_exception.
METHODS check_connection
RAISING
zcx_abapgit_exception.
ENDCLASS. ENDCLASS.
@ -576,6 +581,22 @@ CLASS zcl_abapgit_gui_page_repo_view IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD check_connection.
DATA lo_repo TYPE REF TO zif_abapgit_repo_online.
mv_connection_error = abap_true.
IF mo_repo->is_offline( ) = abap_false.
lo_repo ?= mo_repo.
zcl_abapgit_http=>check_connection( lo_repo->get_url( ) ).
ENDIF.
mv_connection_error = abap_false.
ENDMETHOD.
METHOD constructor. METHOD constructor.
DATA: lo_settings TYPE REF TO zcl_abapgit_settings, DATA: lo_settings TYPE REF TO zcl_abapgit_settings,
@ -1229,6 +1250,26 @@ CLASS zcl_abapgit_gui_page_repo_view IMPLEMENTATION.
" Reinit, for the case of type change " Reinit, for the case of type change
mo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( mo_repo->get_key( ) ). mo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( mo_repo->get_key( ) ).
IF mv_connection_error = abap_true.
" If connection doesn't work, render a minimal header
ri_html->add( |<div class="repo" id="repo{ mv_key }">| ).
ri_html->add( zcl_abapgit_gui_chunk_lib=>render_repo_top(
io_repo = mo_repo
iv_show_edit = abap_true
iv_show_branch = abap_false
iv_show_commit = abap_false
iv_interactive_branch = abap_false ) ).
ri_html->add( '</div>' ).
ri_html->add( render_head_line( ) ).
" Reset error flag to try connecting again next time
CLEAR mv_connection_error.
RETURN.
ENDIF.
check_connection( ).
check_branch( ). check_branch( ).
mv_are_changes_recorded_in_tr = zcl_abapgit_factory=>get_sap_package( mo_repo->get_package( ) mv_are_changes_recorded_in_tr = zcl_abapgit_factory=>get_sap_package( mo_repo->get_package( )
@ -1346,11 +1387,7 @@ CLASS zcl_abapgit_gui_page_repo_view IMPLEMENTATION.
" and allow troubleshooting of issue " and allow troubleshooting of issue
zcl_abapgit_persistence_user=>get_instance( )->set_repo_show( || ). zcl_abapgit_persistence_user=>get_instance( )->set_repo_show( || ).
ri_html->add( render_head_line( ) ). RAISE EXCEPTION lx_error.
ri_html->add( zcl_abapgit_gui_chunk_lib=>render_error(
iv_extra_style = 'repo_banner'
ix_error = lx_error ) ).
ENDTRY. ENDTRY.
register_deferred_script( render_scripts( ) ). register_deferred_script( render_scripts( ) ).

View File

@ -121,6 +121,7 @@ CLASS zcl_abapgit_gui_page_sett_remo DEFINITION
METHODS validate_form METHODS validate_form
IMPORTING IMPORTING
io_form_data TYPE REF TO zcl_abapgit_string_map io_form_data TYPE REF TO zcl_abapgit_string_map
iv_connection_check TYPE abap_bool DEFAULT abap_true
RETURNING RETURNING
VALUE(ro_validation_log) TYPE REF TO zcl_abapgit_string_map VALUE(ro_validation_log) TYPE REF TO zcl_abapgit_string_map
RAISING RAISING
@ -864,6 +865,10 @@ CLASS zcl_abapgit_gui_page_sett_remo IMPLEMENTATION.
iv_key = c_id-url iv_key = c_id-url
iv_val = lx_error->get_text( ) ). iv_val = lx_error->get_text( ) ).
ENDTRY. ENDTRY.
IF iv_connection_check = abap_true.
zcl_abapgit_http=>check_connection( lv_url ).
ENDIF.
ENDIF. ENDIF.
IF lv_offline = abap_false. IF lv_offline = abap_false.

View File

@ -378,7 +378,9 @@ CLASS ltcl_validate_form IMPLEMENTATION.
METHOD when_validate_form. METHOD when_validate_form.
mo_act_validation_log = mo_cut->validate_form( mo_given_form_data ). mo_act_validation_log = mo_cut->validate_form(
io_form_data = mo_given_form_data
iv_connection_check = abap_false ).
ENDMETHOD. ENDMETHOD.

View File

@ -120,6 +120,11 @@ CLASS zcl_abapgit_gui_router DEFINITION
!iv_url TYPE csequence !iv_url TYPE csequence
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
METHODS call_transaction
IMPORTING
!iv_tcode TYPE csequence
RAISING
zcx_abapgit_exception .
METHODS get_state_settings METHODS get_state_settings
IMPORTING IMPORTING
!ii_event TYPE REF TO zif_abapgit_gui_event !ii_event TYPE REF TO zif_abapgit_gui_event
@ -157,6 +162,30 @@ CLASS zcl_abapgit_gui_router IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD call_transaction.
DATA lv_msg TYPE c LENGTH 200.
CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
DESTINATION 'NONE'
STARTING NEW TASK 'ABAPGIT'
EXPORTING
tcode = iv_tcode
EXCEPTIONS
communication_failure = 1 MESSAGE lv_msg
system_failure = 2 MESSAGE lv_msg
OTHERS = 3.
IF sy-subrc <> 0.
lv_msg = |Error starting transaction { iv_tcode }: { lv_msg }|.
MESSAGE lv_msg TYPE 'I'.
ELSE.
lv_msg = |Transaction { iv_tcode } opened in a new window|.
MESSAGE lv_msg TYPE 'S'.
ENDIF.
ENDMETHOD.
METHOD db_actions. METHOD db_actions.
DATA ls_db_key TYPE zif_abapgit_persistence=>ty_content. DATA ls_db_key TYPE zif_abapgit_persistence=>ty_content.
@ -680,6 +709,10 @@ CLASS zcl_abapgit_gui_router IMPLEMENTATION.
rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act. rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act.
WHEN zif_abapgit_definitions=>c_action-jump_transaction.
call_transaction( |{ ii_event->query( )->get( 'TRANSACTION' ) }| ).
rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act.
WHEN zif_abapgit_definitions=>c_action-jump_transport. WHEN zif_abapgit_definitions=>c_action-jump_transport.
jump_display_transport( |{ ii_event->query( )->get( 'TRANSPORT' ) }| ). jump_display_transport( |{ ii_event->query( )->get( 'TRANSPORT' ) }| ).
rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act. rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act.

View File

@ -74,6 +74,7 @@ span.separator {
.w40 { width: 40%; } .w40 { width: 40%; }
.float-right { float: right; } .float-right { float: right; }
.pad-right { padding-right: 6px; } .pad-right { padding-right: 6px; }
.no-pad { padding: 0px !important; }
.inline { display: inline; } .inline { display: inline; }
.hidden { visibility: hidden; } .hidden { visibility: hidden; }
.nodisplay { display: none } .nodisplay { display: none }
@ -1550,4 +1551,4 @@ table.unit_tests {
} }
.modal .radio-container label:hover { .modal .radio-container label:hover {
background-color: rgba(0, 0, 0, 0.1); background-color: rgba(0, 0, 0, 0.1);
} }

View File

@ -341,6 +341,7 @@ INTERFACE zif_abapgit_definitions
homepage TYPE string VALUE 'homepage', homepage TYPE string VALUE 'homepage',
ie_devtools TYPE string VALUE 'ie_devtools', ie_devtools TYPE string VALUE 'ie_devtools',
jump TYPE string VALUE 'jump', jump TYPE string VALUE 'jump',
jump_transaction TYPE string VALUE 'jump_transaction',
jump_transport TYPE string VALUE 'jump_transport', jump_transport TYPE string VALUE 'jump_transport',
jump_user TYPE string VALUE 'jump_user', jump_user TYPE string VALUE 'jump_user',
performance_test TYPE string VALUE 'performance_test', performance_test TYPE string VALUE 'performance_test',