cancel
Showing results for 
Search instead for 
Did you mean: 

How to Resolve the Error : HTTP_MAX_CONN_EXCEEDED in RAP Application?

AR77
Explorer
0 Kudos

Hi Experts,

I created a GSTR1 RAP application in SAP S4 HANA Public Cloud. when I am selecting all the coming data( it is around 3000+ entries ) and send all the line items to another portal I am getting this below error.

Runtime Error : HTTP_MAX_CONN_EXCEEDED. The O Data request processing has been abnormally terminated.

Error Cause:- "The maximum number of HTTP client connections has been exceeded". I found that there is multiple HTTP request are generated for a Instance and I am not able to handle this case.

Thanks for your Support.

 

 

 

junwu
Active Contributor
0 Kudos
why don't u show us the code how you send the data to external portal?
AR77
Explorer
0 Kudos

To Create Client: 

METHODS create_client IMPORTING url TYPE string RETURNING VALUE(result) TYPE REF TO if_web_http_client

RAISING cx_static_check.

METHOD create_client.

DATA(dest) = cl_http_destination_provider=>create_by_url( url ).

result = cl_web_http_client_manager=>create_by_http_destination( dest ).

ENDMETHOD.

To Get Token:

METHOD get_auth_token.

ls_config-uname = 'uname'.

DATA url TYPE string.

CONCATENATE base_url 'token-auth/' INTO url.

CONDENSE url NO-GAPS.

 

lv_token = '{"password":"password","username":"username"}'.

 

TRY.

DATA(client) = create_client( url ).

CATCH cx_static_check.

ENDTRY.

 

DATA(req) = client->get_http_request( ).

req->set_text( lv_token ).

req->set_header_field( i_name = content_type i_value = json_content ).

 

TRY.

lv_authtoken = client->execute( if_web_http_client=>post )->get_text( ).

CATCH cx_static_check.

ENDTRY.

 

ENDMETHOD.

 

In the below method i created the JSON successfully and posting my data to another portal.

Method Send_to_portal. 

TRY.
DATA lv_url TYPE string.

lv_url = 'Service URL'.
lv_res_token = get_auth_token( ).

SPLIT lv_res_token AT ':' INTO string1 string2.
CLEAR lv_res_token.
lv_res_token = string2.
REPLACE ALL OCCURRENCES OF '"' IN lv_res_token WITH ' '.
REPLACE ALL OCCURRENCES OF '}' IN lv_res_token WITH ' '.
CONDENSE lv_res_token NO-GAPS.

TRY.
DATA(client) = create_client( lv_url ).
CATCH cx_static_check.
ENDTRY.

DATA(req) = client->get_http_request( ).

req->set_header_fields( VALUE #(
( name = 'Content-Type' value = 'application/json' )
( name = 'productid' value = 'product id' )
( name = 'Authorization' value = |auth value { lv_res_token }| ) ) ).

req->append_text(
EXPORTING
data = lv_json ).

TRY.
DATA(lv_response) = client->execute(
i_method = if_web_http_client=>post ).

DATA(json_response) = lv_response->get_text( ).
DATA(stat) = lv_response->get_status( ).
CATCH: cx_web_http_client_error.
ENDTRY.
CATCH cx_static_check.
ENDTRY.

ENDMETHOD.

Accepted Solutions (0)

Answers (2)

Answers (2)

junwu
Active Contributor
0 Kudos

I think  you have to send them in batch request or bundle the data before sending

PamelaRosa1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello,

The error message "The maximum number of HTTP client connections has been exceeded" indicates that your application is trying to establish more HTTP customer connections than the server or the customer is configured to handle. Here are steps to resolve this issue:

1. Increase Maximum Connections
Server-side configuration: Increase the maximum allowed connections on the server. This varies depending on the server software you are using.
Customer-side configuration: Increase the maximum number of connections the HTTP customer library can open.

2. Implement Connection Pooling
Use or optimize connection pooling in your application to reuse existing connections instead of creating new ones for each request. Many HTTP customer libraries support connection pooling.

3. Set Connection Timeouts
Ensure that connections are properly closed after they are no longer needed. Set appropriate timeouts for your connections to prevent them from remaining open indefinitely.

4. Throttle Requests
Throttle the number of concurrent requests your application makes to the server to prevent it from exceeding the maximum connection limit.

5. Use Load Balancing
Distribute the load across multiple servers using a load balancer to ensure that no single server is overwhelmed with too many connections.

6. Monitor and Optimize
Monitor the usage of connections to identify and resolve bottlenecks. Tools like New Relic, Datadog, or custom monitoring scripts can help in identifying issues.

By following these steps, you should be able to resolve the issue of exceeding the maximum number of HTTP customer connections. Adjust the configuration values based on your application's requirements and the server's capacity.

I hope this can help you,
Best regards