exception handling in web services

9
Exception Handling in Web Services exposed from an R/3 System SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2007 SAP AG 1 Exception Handling in Web Services exposed from an R/3 System Applies to: SAP WAS 6.2 onwards Summary We expose an RFC enabled function module as web service in R/3. While creating the function module, we specify the exceptions that should be raised under the exceptions tab. When we execute this function module we get just the Exception Name not the Exception Text maintained against that exception. Here I will show how to change the exception name in the virtual interface of the web service as well as how to specify the complete and meaningful exception text in the web service response. Author(s): Pushkar Anand Company: Deloitte Created on: 29 May 2007 Author Bio I have been working as an SAP ABAP & XI Consultant. Having worked on end to end SAP XI implementations and the basis activities, now I am moving towards ESA and SOA. XI, ALE and ESA are my key areas

Upload: zinefine

Post on 18-Aug-2015

220 views

Category:

Documents


3 download

TRANSCRIPT

Exception Handling in Web Services exposed from an R/3 System SAP DEVELOPER NETWORK |sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY|bpx.sap.com 2007 SAP AG1Exception Handling in Web Services exposed from an R/3 System Applies to: SAP WAS 6.2 onwards Summary We expose an RFC enabled function module as web service in R/3.While creating the function module, we specify the exceptions that should be raised under the exceptions tab. When we execute this function module we get just the Exception Name not the Exception Text maintained against that exception. Here I will show how to change the exception name in the virtual interface of the web service as well as how to specify the complete and meaningful exception text in the web service response. Author(s):Pushkar AnandCompany:Deloitte Created on: 29 May 2007 Author Bio I have been working as an SAP ABAP & XI Consultant. Having worked on end to end SAP XI implementations and the basis activities, now I am moving towards ESA and SOA. XI, ALE and ESA are my key areas Exception Handling in Web Services exposed from an R/3 System SAP DEVELOPER NETWORK|sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY|bpx.sap.com 2007 SAP AG 2Table of Contents ....................................................................................................... 3Exception Handling DescriptionHow to over write the exception name............................................................................................ 5 How to add more meaningful Exception Text.................................................................................. 7 Related Content............................................................................................................................... 8 Exception Handling in Web Services exposed from an R/3 System SAP DEVELOPER NETWORK|sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY|bpx.sap.com 2007 SAP AG 3Exception Handling Description Here I have created a function module ZPL which concatenates firstname and lastname into name and returns name and date. I have exposed this function module as web service. If the firstname is Pushkar, it raises an exception EXCEPT1 as shown below. Source Code : When I use Raise Exception in the ABAP code it returns just the exception name i.e.EXCEPT1 in the fault message as shown in the payload attached below. Exception Handling in Web Services exposed from an R/3 System SAP DEVELOPER NETWORK|sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY|bpx.sap.com 2007 SAP AG 4

soap-env:ClientEXCEPT1

EXCEPT1

Exception Handling in Web Services exposed from an R/3 System SAP DEVELOPER NETWORK|sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY|bpx.sap.com 2007 SAP AG 5How to over write the exception name To overwrite the exception name with more meaningful name, we can edit the virtual interface created for this web service. Go to Transaction SE80, select the Enterprise Service and click on the Service Definitions. Click on the edit button and select Faults->EXCEPT1. Here we can overwrite the default exception name with more meaningful name to be reflected in the web service. Now we edit the Exception field in Service Interface as EXCEPTION_PUSHKAR as shown below. And now on executing this web service the exception in the fault message is EXCEPTION_PUSHKAR as shown in the payload attached below. Exception Handling in Web Services exposed from an R/3 System SAP DEVELOPER NETWORK|sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY|bpx.sap.com 2007 SAP AG 6

soap-env:ClientEXCEPTION_PUSHKAR

EXCEPTION_PUSHKAR