on 12-13-2013 10:34 PM
Hi All,
I am working on Odata services and want to return messages to front end application which is designed in HTML5, which provide status of update/delete or create operation. I want to return error type and description to front end.
I am using class - /iwbep/if_message_container to return message and tried with following methods:
lo_message_container = mo_context->get_message_container( ).
ls_return-type = 'S'.
ls_return-id = 'ZTEST'.
ls_return-number = '000'.
* ls_return-log_no = '111'.
ls_return-message = 'Data Available in Update Method'.
APPEND ls_return TO lt_return.
***
lo_message_container->add_messages_from_bapi(
it_bapi_messages = lt_return
iv_determine_leading_msg = /iwbep/if_message_container=>gcs_leading_msg_search_option-first
Its not showing up in response of request to front end and response body is empty . if i raise exceptions /IWBEP/CX_MGW_BUSI_EXCEPTION or /IWBEP/CX_MGW_TECH_EXCEPTION response will come with error code - 404.
Please suggest any better way to send response to front end.
Regards,
Rajesh
Hi Rajesh,
Gateway SP08 now has a standard mechanism for placing S, I, W messages in an SAP header SAP-Message: Map Message Container to Message Protocol Format - SAP NetWeaver Gateway - SAP Library.
To add a message to the header you get hold of the message container and add a message specifying that you want to add it to the response header:
lo_container = me->mo_context->get_message_container( ).
lo_container->add_message(
...
iv_add_to_response_header = abap_true
).
Regards
--Ralf
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I need to get that working as well and tried the following code in the redefinition of a "get entity set" method:
DATA lo_container TYPE REF TO /iwbep/if_message_container.
**** " add to message container object
lo_container = me->mo_context->get_message_container( ).
CALL METHOD lo_container->add_message_text_only
EXPORTING
iv_msg_type = /IWBEP/IF_MESSAGE_CONTAINER=>GCS_MESSAGE_TYPE-success
iv_msg_text = 'Success of ready entity set !'
iv_error_category = /IWBEP/IF_MESSAGE_CONTAINER=>GCS_ERROR_CATEGORY-PROCESSING
iv_is_leading_message = ABAP_TRUE
iv_add_to_response_header = ABAP_TRUE
.
this is not providing the message in the HTTP header as I expect from your description here. Perhaps you have a hint for me, thanks!
<?xml version="1.0" encoding="utf-8" ?>
</_-IWFND_-SUTIL_PROPERTY>
</_-IWFND_-SUTIL_PROPERTY>
</_-IWFND_-SUTIL_PROPERTY>
- <_-IWFND_-SUTIL_PROPERTY>
</_-IWFND_-SUTIL_PROPERTY>
</_-IWFND_-SUTIL_PROPERTY>
</_-IWFND_-SUTIL_PROPERTY>
</_-IWFND_-SUTIL_PROPERTY>
</_-IWFND_-SUTIL_PROPERTY>
</HTTP_HEADER>
Hi Ralf,
I got it working as well now on our NW 7.31 with GW SP08 with a NEW created oData service and model from scratch.
I was not able to get it working with my already existing/generated oData service by just adding the code snipped in a redefined and regenerated existing method...
Perhaps you have a hint for me what also could bring this to work to adapt existing methods.
thanks
Jörg
Hi Ralf,
I am trying to show the message on header in case of info or warning, so we dont need to raise exception and we continue to return the updated records back while post method is successful but return warning or info messages..
I am using method - add_message, As you suggested. I am appending messages using lo_container->add_message but nothing showing up in header. Do I need to raise any exception ?
I have declared variable - go_message_container is declared as type /IWBEP/IF_MESSAGE_CONTAINER
go_message_container = mo_context->get_message_container( ).
go_message_container->add_message(
EXPORTING
iv_msg_type = 'W' "ls_msg-msgty
iv_msg_id = ls_msg-arbgb
iv_msg_number = lv_num " '001'
iv_msg_text = lv_text
iv_msg_v1 = ls_msg-msgv1
iv_msg_v2 = ls_msg-msgv2
iv_msg_v3 = ls_msg-msgv3
iv_msg_v4 = ls_msg-msgv4
iv_add_to_response_header = abap_true " Flag is set to show msgs on header
).
If I try to raise exception it is returning error in response body.. How msgs will show up in header.. I may have multiple msg to show.. Please assist..
Thanks
Rajesh
Thanks Ralf for responding
I tried my adding the iv_is_leading_message to method - ADD_MESSAGE but no response on header.
I am not sure if we need to raise the exception after adding messages to container. If I do - It give error in response body with only one message with request status 400.
***
I am raising exception as follow:
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
message_container = io_message_container.
I have checked in class - /IWBEP/IF_MESSAGE_CONTAINER apart from method -
ADD_MESSAGE, Other message - ADD_MESSAGES_FROM_BAPI is also having IV_ADD_TO_RESPONSE_HEADER to show msg on header.
As I get from documents IV_ADD_TO_RESPONSE_HEADER is to show message on header,but not getting enough info to use it.
Even If I am not raising exception warnings are not coming op on header.
On our NW having SAP_GWFND/740/SP-004.
Thanks & Regards,
Rajesh
Thanks Ralf for quick response,
I am debugging to find more about where I am losing the data.. else I will go for upgrade. One more question- can we return multiple messages to request header using method ADD_MESSAGE or ADD_MESSAGES_FROM_BAPI as both have IV_ADD_TO_RESPONSE_HEADER parameter?
Thanks
Rajesh
Hi Rajesh,
you can have one leading message and an arbitrary number of detail messages. The detail messages will be in the "details" array:
sap-message: {"code":"BL/305","message":"Flight permission has not yet been granted","severity":"info","target":"FlightDate","details":[{"code":"BL/301","message":"Maximum weight exceeded","target":"","severity":"info"}]}
Regards!
--Ralf
Hi Ralf,
I tried the solution you gave and my code looks like below.
lo_message_container = me->mo_context->get_message_container( ).
lo_message_container->add_message(
EXPORTING
iv_msg_id = 'BL'
iv_msg_number = '001'
iv_msg_type = 'S'
iv_msg_text = 'STO successfully modified'
iv_is_leading_message = abap_true
iv_add_to_response_header = abap_true
).
I can see in debug that it is going through this code. But in my Fiori application, the custom message is not coming, but only standard message shows.
I try to send the message from /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_PROCESS.
We are using test system and learning Fiori. So, please let me know whether we can really send a custom success message from this method. Also not sure any configuration in Gateway system or backend ECC system we need to do.
The version of ECC is Netweaver 7.02 SP 20 (ECC 6 Ehp5 SP 17).
Really appreciate your help
thanks
Raibin
Hi All,
I am doing Update functionality and know how to send error message all discuss in this. But if I use /IWBEP/CX_MGW_BUSI_EXCEPTION to send success message from OData (as explained above), my Fiori application is thinking that as error message only.
So, can someone tell me how to send a custom success message.
All helps are really appreciated. thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajesh,
Im facing same problem as to how do i pass success, info and warning messages to UI without raising it as an exception.
If i raise it as an exception , it goes to the error call and success function call is never triggered.
Please let me know in case you have found the solution.
Thanks in advance
Regards,
Pooja
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi all,
I tried all what you guys described about this issue,but it didn't work, ,my version is NW 7.4 SP13, I'm not sure if any of you is using it, I really need to export message to front end with UI5, the problem is that i need to export message in method entityname_get_entity & *_update_entity and so on, and in this kind of method ,we have no related field for message in this entity to export,please tell to how to export message in the method I said at above....thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also tried whatever whoever said. No error and I can see the program get executed in debug. But the Fiori front-end only shows the standard message. No issue to show custom error message. But I need to show custom success message as well.
So please let me know if you able to find a way. Appreciate your response
thanks
Raibin
Hi all,
I would like to know if anyone knows how to "catch" this messages from an OData SDK. In case you may, I'll let the link to my discussion.
Thanks in advance.
Best regards,
--
Ana Velásquez
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think guys you do a hibrid teori "u" was "u" and ui5 was abp,dont mix that, i can soupouse what you do and let me tell you something gone a have seriusly trouble.. And not whit me!! Dont reply
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello All,
Lets talk about scenario when ui5 app want to call FM and of course wants to know about return status/message of FM.
Programmer wants to return this message to UI5 app.
How to do it in accordance with the best practices of odata ?
I did it with /iwbep/if_message_container and return status 400 but this solution is really far from ideal i guess.
Lucas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lucas,
If the call failed (no data retrieved), then HTTP 400 is the appropriate response, and the error messages are added to the message container which is attached to the exception that is thrown.
If the call succeeded in principle (data retrieved) but with some warnings, then HTTP 200 is the appropriate response, and the error messages should be added to the message container with parameter
iv_add_to_response_header = ABAP_TRUE
In this case no exception is thrown, and Gateway will place the messages in the response header SAP-MESSAGE.
--Ralf
Hello Lukasz,
2 ways u can implement error handling based on ur use case ->
1. Implement Create_Entity and when create operation fails raise exception as i mentioned above by returning all the error messages and u get status 400 as response.
2. U can have one more entity in the GW model and create association and navigation with the parent entity with appropriate cardinality.
In DPC/DPC_EXT class capture all the error messages coming from the logic and store in an internal table in Create_Deep_Entity method and map back this as response. Here Response would be a deep structure.
U will get 201 status always irrespective of success/failure as we are not raising any exception here. Instead we are just capturing the error/success messages as part of response.
In the UI level, object containing error response has to be checked always based on Message Type ( E or S or W or A ) and corresponding message can be displayed.
U can decide which one u want to implement.
Regards,
Ashwin
Hello Ralf,
Thanks for answer. In my case i want to return messages after create, status is 201.
As i understand you, i have to code like this:
lo_container->add_message(
exporting
iv_msg_type ='S'
iv_msg_text = 'XYZ'
..
iv_add_to_response_header = ABAP_TRUE
).
Nothing else after this ? Do i have to export lo_container some how or framework will do it?
I did it like this and i cant see message in response header.
Am i doing it ok ?
Lucas
Hi Lucasz,
For me it works if I retrieve the message container via
lo_container = me->mo_context->get_message_container( ).
lo_container->add_message(
iv_msg_type = 'S'
iv_msg_id = 'BL'
iv_msg_number = 308
iv_msg_v1 = 'Success'
iv_is_leading_message = abap_true
iv_add_to_response_header = abap_true
).
Then the message shows up in the response header.
Hope this helps!
--Ralf
Hi there, is there any possibility to tell the message container what http status code he should pass back? i only can raise exceptions with status codes but obviously i can't pass back 2xx status codes. Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mathias,
OData specifies which 2xx status code is to be used in which situation, so this is automatically handled by the framework:
Which other 2xx status codes would you have liked to used, and for which purposes?
Thanks in advance!
--Ralf
Hi Mathias,
I'm curious to learn about the scenario. There are only two standard 2xx codes not used by OData, see RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1):
So far I hadn't considered those relevant in the OData context.
Thanks!
--Ralf
Hmm, i think it is a silly request. We have an entity which can have a parameter with two possible values. internaly to different actions will take place. Ths might sound not very odata like, but at the end i think from a design point of view it was ok. By now Backend was sending back success messages, but now the fronted should take care of it(don't ask me why...) but only in case of success(again don't ask why..) so to differentiate the two paramters the frontend guys would like to have two 2xx codes to distinguish between the two actions.. fubar....
If the client sending the request decides which action to take and puts this as a parameter in the request, then it already knows which action it has requested. No need to rely on the server response.
Also with a normal 201 response the client gets back an entity representation, so even if the server chose a different action, the action code is part of the response, assuming it is a property of the request entity.
Thanks for possible option suggested.. I will try to implement both and see which one work good with process..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You need to add a parameter in the same entity for which you are using in Create operation and change the value after the successful creation and you can return the same entity to the front end.
Thanks,
Raju Bonagiri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Rajesh,
Here is a snippet for you
DATA lo_message_container TYPE REF TO /iwbep/if_message_container.
" get message container object
lo_message_container->add_message
exporting
iv_msg_type = <> "Refer to GCS_MESSAGE_TYPE
iv_msg_text = <>.
lo_message_container = me->/iwbep/if_mgw_core_srv_runtime~mo_context->get_message_container( ).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
message_container = io_message_container.
There are many other useful methods, you can have a look at the below link
SAP Library - SAP NetWeaver Gateway
Regards,
Atanu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajesh,
You are right, the exception will return error code.
In HTTP world for success you need to depend on the status code, so if status code is 200,201,204 you can consider it to be successful for READ,CREATE,UPDATE/DELETE. However you can pass some more informative text in such cases along with the HTTP response header.
Here is a snippet for you to achieve the same
data: ls_header TYPE ihttpnvp.
ls_header-name = 'my-custom-message' .
ls_header-value = '{msg_typ:S, desc: my custom message}'.
/iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).
In RESPONSE header you will get
Regards,
Atanu
Hi Atanu,
We are trying to show msg as you told on header level.. But I am finding if we raise exception header msg didnt show up. Only in case if we dont raise exception, it will show at header custom tag...
Also can you advice best use of showing msg at header level... only exception are way to show error..
Thanks..
Hi Rajesh,
When you raise an exception you can add the detail error/info/success messages directly to the exception, and they will show up in the normal OData error response body:
lo_container = /iwbep/if_mgw_conv_srv_runtime~get_message_container( ).
lo_container->add_message(
...
).
raise exception type /iwbep/cx_mgw_busi_exception
exporting
textid = /iwbep/cx_mgw_busi_exception=>business_error
message_container = lo_container.
The header should only be used in success cases, and please use the mechanism I described below, available with Gateway SP08.
Hope this helps!
--Ralf
Hello Ralf,
Is it possible to add 2 messages ?
i am trying like this, but its not works .
any idea how to add 2 messages ?
lo_container->add_message(
exporting
iv_msg_type ='I'
iv_msg_text = 'XXXXXXXXXXXXXXXXXXXX'
iv_msg_id = '1'
**iv_msg_id = '1'
iv_msg_number = '0'
).
lo_container->add_message(
exporting
iv_msg_type ='S'
iv_msg_text = 'YYYYYYYYYYYYYYYYYY'
iv_msg_id = '2'
**iv_msg_id = '1'
iv_msg_number = '0'
).
Hello Lukasz,
U can use the below code to raise an exception with table of messages.
Where LT_RETURN_MSG is a table containing all ur messages.
data: ls_return_msg TYPE BAPIRET2.
data: lt_return_msg TYPE BAPIRET2_T
data: lx_bus_ex TYPE REF TO /IWBEP/CX_MGW_BUSI_EXCEPTION.
LO_MESSAGE = MO_CONTEXT->GET_MESSAGE_CONTAINER( ).
LO_MESSAGE->ADD_MESSAGES_FROM_BAPI( IT_BAPI_MESSAGES = LT_RETURN_MSG ).
create OBJECT lx_bus_ex
exporting
message_container = LO_MESSAGE.
raise EXCEPTION lx_bus_ex.
Regards,
Ashwin
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.