Skip to Content
Author's profile photo Former Member

Consuming Your First Synchronous RESTful Service – Step-by-Step – Proxy Class and Testing

Introduction

This is the last part of a mini-series blog about how to build a basic SAP-to-REST synchronous interface scenario. The blog’s first part can be found here:  Consuming Your First Synchronous RESTful Service – Step-by-Step – Introduction. This part is to build a proxy class in the sending SAP ECC system and to test our integration scenario.


Let’s get to work


Generating a proxy class and creating a test program.

    • Generating the proxy:
      • Log on to the sender SAP ECC system. Go to either transaction SPROXY or transaction SE80. In SE80, select the “Enterprise Services Browser” object type from the left navigation pane.
    • If the software component version that we created earlier is not visible, click the “Refresh” button in order to re-read the ESR catalog.
    • Once the software component version is visible, expand the nodes of the service interface until you see the “outbound” service interface we created earlier.

https://lh5.googleusercontent.com/-4imaT0b1K1I/VWLKmEcBrmI/AAAAAAAAA6Y/bgfm3WcxhRw/w680-h652-no/18.10%2B-%2BProxy%2B1.jpg

    • Now, right-click the outbound service interface and select the “Generate Proxy” option.

https://lh5.googleusercontent.com/-dxekTzdBShk/VWLKmA9g3aI/AAAAAAAAA6o/DICI2UGXp7o/w572-h188-no/18.20%2B-%2BProxy%2B2.jpg

    • You will be presented by a wizard screen on which you can either check the “local object” flag or select an existing change request. Make sure to add a prefix in your customer name space (starts with Y or Z). Then, click “Finish.”

https://lh3.googleusercontent.com/-T5vLp1t3LLQ/VWLKmA7BzWI/AAAAAAAAA6c/zJ4KJ4qMu-o/w1394-h1106-no/18.30%2B-%2BProxy%2B3.jpg

    • After a short time, you will be presented with the details of the generated proxy. Click the “Activate” button in the top toolbar.

https://lh4.googleusercontent.com/-NX4gREdoI-w/VWLKmgmk0TI/AAAAAAAAA6Q/ydZ5fDeSBZw/w1796-h1156-no/18.40%2B-%2BProxy%2B4.jpg

    • Copy the proxy class name, and go to transaction SE24. Paste the class name there and click the “Display” button in . You can just double-click the class name in proxy details screen above.

https://lh6.googleusercontent.com/-seJQs33LrAo/VWLKmnDwkNI/AAAAAAAAA6U/cApXfXXh6ng/w882-h422-no/18.50%2B-%2BProxy%2B5.jpg

    • Find the method with the same name as the outbound service interface. Place the curser on the method name and click the “Parameters” button.

https://lh5.googleusercontent.com/-_mD7UyaqE00/VWLKmi6qTyI/AAAAAAAAA6k/_j6jIUPDYyY/w1044-h536-no/18.60%2B-%2BProxy%2B6.jpg

    • Take note of the types of the “output” and “input” parameter fields. These will be needed when creating the test program.

https://lh4.googleusercontent.com/-HfwD1k2GVYQ/VWLKm9UCzMI/AAAAAAAAA6g/NcivH_Jo_CQ/w1256-h466-no/18.70%2B-%2BProxy%2B7.jpg

    • Test program:
      • Now, go to transaction SE38 to create the test program. Type a test program name then click the “Create” button.

https://lh4.googleusercontent.com/-5kxTp89YYXo/VWLNFT5LQSI/AAAAAAAAA7k/U2-oOSGKWGI/w1040-h436-no/19.10%2B-%2BProgram%2B1.jpg

    • In the “Attributes” screen, enter a short description, select the “Executable” type, and then click the “Save” button.

https://lh5.googleusercontent.com/-uIhkzRZcog8/VWLNFYklZ5I/AAAAAAAAA7U/Or3vuDihOII/w1248-h1050-no/19.20%2B-%2BProgram%2B2.jpg

    • On the next screen, pick a package or assign the program as a local object. Then, click the “Save” button.

https://lh4.googleusercontent.com/-JTg4_e_JTS0/VWLNFSF9o5I/AAAAAAAAA7Q/FckT3q2AsKk/w914-h602-no/19.30%2B-%2BProgram%2B3.jpg

    • Write the following program. Note the structure types that we copied from the proxy class. The basic logic of this program is displaying an input zip code field. Then, it will call the proxy method which will return the results in string fields. Those two fields: status and results will be displayed in the output screen. Field “results” contains an XML message in plain-text format. In a more elaborate scenario, you will need to parse the returned XML text to read specific fields.

https://lh3.googleusercontent.com/-fmxZoJO_3i4/VWLNF2I04KI/AAAAAAAAA7c/yysNgPi6Dzk/w1170-h1100-no/19.40%2B-%2BProgram%2B4.jpg

    • After saving and activating the program, click the “Test” button. Type a zip code then click the “Execute” button.

https://lh3.googleusercontent.com/-0dD0XCz-h7w/VWLNF8J8jSI/AAAAAAAAA7Y/8iRaWPKfCXU/w886-h410-no/19.50%2B-%2BProgram%2B5.jpg

    • You can see that the status and results fields were read successfully.

https://lh6.googleusercontent.com/-lqzBOBuKyfs/VWLNGCIfxsI/AAAAAAAAA7g/lXLzXpE5AHs/w3128-h664-no/19.60%2B-%2BProgram%2B6.jpg


This concludes this short SAP-to-REST mini-series. Please do let me know if this was helpful or if I missed something.

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo David Gimeno
      David Gimeno

      Nice post!!!

      Do you know if REST adapter is available by default on PI instalations?

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      It is available in newer releases 7.31 (SP14) and 7.4 (SP9). See this document: New adapter in SAP Process Integration for consumption and provisioning of REST based services.

      Author's profile photo Pavan kumar
      Pavan kumar
      Author's profile photo Jean-Philippe Pain
      Jean-Philippe Pain

      Very useful as I was missing some information for the integration builder !

      Thank you very much.

      Author's profile photo Former Member
      Former Member

      Thank you so much for the excellent post.

      Author's profile photo Samuel Shen
      Samuel Shen

      When I ran the abap program, it dumps. When I try it in WSNAVIGATOR, it is showing any results.

      web service return error. Fault code: "(http://schemas.xmlsoap.org/soap/envelope/)client" fault string: "Server Error"

      I check all my ESR and IB objects and SPROXY, it is the same as yours. Do you know why this error?

      Author's profile photo Samuel Shen
      Samuel Shen

      the REST adapter in the channel monitor shows "not administered". No adapter registered for this channel.

      Author's profile photo Sara Schmidt
      Sara Schmidt

      Hi,
      at first thank you very much for your Engagement! nice blog!
      I'm trying to create the same Scenario in PI 7.50 by calling from SoapUI. i.e. SoapUI <--> PI <--> Google.
      But I get always error in SoapUI:  HTTP 500 Internal Server Error.
      In RWB Message Monitor there is the following error:
      Returning to application. Exception: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error encountered while executing mapping: com.sap.aii.af.service.mapping.MappingException: Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/xi/tf/_MM_rest_2_sap_; Details: com.sap.aii.mappingtool.tf7.IllegalInstanceException; Cannot create target element /ns0:MT_rest_service_content. Values missing in queue context. Target XSD requires a value for this element, but the target-field mapping does not create one. Check whether the XML instance is valid for the source XSD, and whether the target-field mapping fulfils the requirement of the target XSD

      Could anyone help me?

      Thanks a lot in advance!
      Sara

      Author's profile photo Jon Prow
      Jon Prow

      Sara,

       

      Make sure you have correct case on your objects.  I had to update  "Status" and "Results" to "status and "results".  After regenerating the sproxy I was getting the desired results.  Hope this helps.

       

      -Jon

      Author's profile photo Former Member
      Former Member

      Thanks, great information, do you have an example for POST operation?

      Author's profile photo Maxime Tchougoua-Djemen
      Maxime Tchougoua-Djemen

      Amazing work!