consuming java web services in webdynpro abap

22
Consuming a java based web service in WebDynpro ABAP Applies to: This document applies to SAP ECC 6.0, SAP NetWeaver 2004s. For more information, visit the WebDynpro ABAP homepage . Summary This article provides a step by step guide for consuming java webservices in WebDynpro ABAP with a simple example. Author: Aisurya Kumar Puhan Company: Incture Technologies Pvt Ltd. Created on: 28 October 2011 Author Bio Aisurya Kumar Puhan is working as SAP NetWeaver Consultant in Incture Technologies Pvt Ltd .He has around 3 years of experience in SAP ABAP, including 1 year in WebDynpro ABAP development. SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com © 2011 SAP AG 1

Upload: aisurya-puhan

Post on 21-Feb-2015

125 views

Category:

Documents


11 download

TRANSCRIPT

Page 1: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Applies to:

This document applies to SAP ECC 6.0, SAP NetWeaver 2004s. For more information, visit the

WebDynpro ABAP homepage.

Summary

This article provides a step by step guide for consuming java webservices in WebDynpro ABAP with a simple example.

Author: Aisurya Kumar Puhan

Company: Incture Technologies Pvt Ltd.

Created on: 28 October 2011

Author Bio

Aisurya Kumar Puhan is working as SAP NetWeaver Consultant in Incture Technologies Pvt Ltd .He has around 3 years of experience in SAP ABAP, including 1 year in WebDynpro ABAP development.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 1

Page 2: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Table of Contents

Introduction:...................................................................................................................................................... 3

Scenario :.......................................................................................................................................................... 3

Step 1 : Create enterprise service.....................................................................................................................3

Step 2: Choose “Service consumer”.................................................................................................................3

Step 3 : Browse the WSDL file from local system.............................................................................................4

Step 4 : Enter a package , prefix ......................................................................................................................5

Step 5 : Continue and complete........................................................................................................................ 5

Step 6 : Save and activate it............................................................................................................................. 6

Step 7 : Open SOAMANAGER......................................................................................................................... 6

Step 8 : Search the Web service....................................................................................................................... 7

Step 9 : Create a logical port............................................................................................................................. 8

Step 10 : Testing of created proxy.................................................................................................................. 10

Step 11 : Create a WD ABAP component.......................................................................................................12

Step 12 : Create a service call........................................................................................................................ 12

Step 13 : Node creation in Component controller...........................................................................................15

Step 14 : Coding inside the method “EXECUTE_SI_OBS_CUSTOMER_STATUS”...................................16

Step 15 : Mapping from component controller to view...................................................................................19

Step 16 : Binding............................................................................................................................................. 19

Step 17 : Code inside the submit button.........................................................................................................20

Step 18 : Testing............................................................................................................................................. 20

Related Content.............................................................................................................................................. 21

Copyright......................................................................................................................................................... 22

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 2

Page 3: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Introduction:

This article provides a step by step guide for consuming a java based web service in WebDynpro ABAP with simple demo scenario.

Scenario :

Updating a status of customer taking input from WD ABAP screen.

Step 1 : Create enterprise service.

Create an enterprise service inside a package or local object.

Step 2: Choose “Service consumer”.

Step 3 : Browse the WSDL file from local system.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 3

Page 4: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Step 4 : Enter a package , prefix ..

Step 5 : Continue and complete.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 4

Page 5: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Step 6 : Save and activate it.

Step 7 : Open SOAMANAGER

Now open transaction “SOAMANAGER”. Enter your credentials and log in.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 5

Page 6: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Step 8 : Search the Web service.

Click on “single service configuration”.

Search by : consumer proxy

Search pattern : External key name

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 6

Page 7: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Step 9 : Create a logical port.

Highlight the search results by clicking on it and click Apply Selection. Move to Configurations and create logical port.

Enter a port name, description.

WSDL access settings : VIA FILE

And browse the file from local system and apply settings.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 7

Page 8: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Now save it.

Binding is done now.

Step 10 : Testing of created proxy.

Now execute the proxy service which is created with the logical port which we did using SOAMANAGER.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 8

Page 9: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Switch to XML editor and enter values for testing.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 9

Page 10: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Now switch to HTML editor and execute it.

Get the result.

Now it is ready to call the Proxy class in Webdynpro ABAP.

Step 11 : Create a WD ABAP component.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 10

Page 11: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Step 12 : Create a service call.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 11

Page 12: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Enter the proxy class , method and the Logical port name which we have created in SOAMANAGER

Change the object type of parameters to “Context (Node/Attribute)” , so that it will be visible in the context.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 12

Page 13: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 13

Page 14: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Continue and Complete .

Step 13 : Node creation in Component controller.

Now create two nodes i.e input_parameter and output_parameter.

Step 14 : Coding inside the method “EXECUTE_SI_OBS_CUSTOMER_STATUS”.

METHOD execute_si_obs_customer_status .

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 14

Page 15: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

*********************read from input parameter    DATA lo_nd_input_paramater TYPE REF TO if_wd_context_node.    DATA lo_el_input_paramater TYPE REF TO if_wd_context_element.    DATA ls_input_paramater TYPE wd_this->element_input_paramater.*   navigate from <CONTEXT> to <INPUT_PARAMATER> via lead selection    lo_nd_input_paramater = wd_context->get_child_node( name = wd_this->wdctx_input_paramater ).*   get element via lead selection    lo_el_input_paramater = lo_nd_input_paramater->get_element( ).*   @TODO handle not set lead selection    IF lo_el_input_paramater IS INITIAL.    ENDIF.*   get all declared attributes    lo_el_input_paramater->get_static_attributes(      IMPORTING        static_attributes = ls_input_paramater ).**** End of read

**********************    read and set importing values     DATA lo_nd_input TYPE REF TO if_wd_context_node.

     DATA lo_el_input TYPE REF TO if_wd_context_element.     DATA ls_input TYPE wd_this->element_input.     DATA lv_mt_customer_status_update_i TYPE wd_this->element_input-mt_customer_status_update_inpu.

*    navigate from <CONTEXT> to <INPUT> via lead selection     lo_nd_input = wd_context->path_get_node( path = `SI_OBS_CUSTOMER_STAT.IMPORTING.INPUT` ).

*    get element via lead selection     lo_el_input = lo_nd_input->get_element( ).

*    @TODO handle not set lead selection     IF lo_el_input IS INITIAL.     ENDIF.lv_mt_customer_status_update_i-CUSTOMER_ID = ls_input_paramater-CUSTOMER_ID.lv_mt_customer_status_update_i-STATUS = ls_input_paramater-STATUS.

*    set single attribute     lo_el_input->set_attribute(       name =  `MT_CUSTOMER_STATUS_UPDATE_INPU`       value = lv_mt_customer_status_update_i ).

*****************   end of read and set importing values  IF NOT wd_this->m_zkuco_si_obs_custome IS BOUND.    TRY.        CREATE OBJECT wd_this->m_zkuco_si_obs_custome          EXPORTING            logical_port_name = `ZKU2_PORT`.      CATCH cx_ai_system_fault .    ENDTRY.  ENDIF.

* declarations for context navigation  DATA lo_si_obs_customer_stat TYPE REF TO if_wd_context_node.  DATA lo_exporting TYPE REF TO if_wd_context_node.  DATA lo_output TYPE REF TO if_wd_context_node.  DATA lo_importing TYPE REF TO if_wd_context_node.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 15

Page 16: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

  DATA lo_input TYPE REF TO if_wd_context_node.  DATA lo_element TYPE REF TO if_wd_context_element.

* declarations for parameters  DATA ls_c_output TYPE if_componentcontroller=>element_output.  DATA ls_c_input TYPE if_componentcontroller=>element_input.* get all involved child nodes  lo_si_obs_customer_stat = wd_context->get_child_node( wd_this->wdctx_si_obs_customer_stat ).  lo_exporting = lo_si_obs_customer_stat->get_child_node( wd_this->wdctx_exporting ).  lo_output = lo_exporting->get_child_node( wd_this->wdctx_output ).  lo_importing = lo_si_obs_customer_stat->get_child_node( wd_this->wdctx_importing ).  lo_input = lo_importing->get_child_node( wd_this->wdctx_input ).

* get input from context  lo_element = lo_input->get_element( ).  lo_element->get_static_attributes(    IMPORTING static_attributes = ls_c_input ).

* the invocation - errors are always fatal !!!  DATA lx_exception  TYPE REF TO cx_root.  TRY.      wd_this->m_zkuco_si_obs_custome->si_obs_customer_status_update(        EXPORTING           input =                           ls_c_input        IMPORTING           output =                          ls_c_output      ).    CATCH cx_ai_system_fault INTO lx_exception.      RAISE EXCEPTION TYPE cx_wd_no_handler        EXPORTING          previous = lx_exception.    CATCH cx_ai_application_fault INTO lx_exception.      RAISE EXCEPTION TYPE cx_wd_no_handler        EXPORTING          previous = lx_exception.  ENDTRY.

* store output to context  lo_output->bind_structure( ls_c_output ).

*********read the exporting  DATA lo_nd_output TYPE REF TO if_wd_context_node.  DATA lo_el_output TYPE REF TO if_wd_context_element.  DATA ls_output TYPE wd_this->element_output.  DATA lv_mt_customer_status_update_o TYPE wd_this->element_output-mt_customer_status_update_outp.* navigate from <CONTEXT> to <OUTPUT> via lead selection  lo_nd_output = wd_context->path_get_node( path = `SI_OBS_CUSTOMER_STAT.EXPORTING.OUTPUT` ).* get element via lead selection  lo_el_output = lo_nd_output->get_element( ).* get single attribute  lo_el_output->get_attribute(    EXPORTING      name =  `MT_CUSTOMER_STATUS_UPDATE_OUTP`

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 16

Page 17: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

    IMPORTING      value = lv_mt_customer_status_update_o ).*************end of read exporting

********************set output parameter  DATA lo_nd_output_parameter TYPE REF TO if_wd_context_node.  DATA lo_el_output_parameter TYPE REF TO if_wd_context_element.  DATA ls_output_parameter TYPE wd_this->element_output_parameter.  DATA lv_message TYPE wd_this->element_output_parameter-message.* navigate from <CONTEXT> to <OUTPUT_PARAMETER> via lead selection  lo_nd_output_parameter = wd_context->get_child_node( name = wd_this->wdctx_output_parameter ).* get element via lead selection  lo_el_output_parameter = lo_nd_output_parameter->get_element( ).  lv_message = lv_mt_customer_status_update_o-MESSAGE .* set single attribute  lo_el_output_parameter->set_attribute(    name =  `MESSAGE`    value = lv_message ).**************end of set output parameter

*generate msg* get message managerDATA lo_api_controller     TYPE REF TO if_wd_controller.DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

lo_api_controller ?= wd_this->wd_get_api( ).CALL METHOD lo_api_controller->get_message_manager  RECEIVING    message_manager = lo_message_manager    .data : output type SYMSGV.move lv_message to output .* report messageCALL METHOD lo_message_manager->report_t100_message  EXPORTING    msgid                     = 'ZWS_MSG'    msgno                     = '000'    msgty                     = 'S'    p1                        = output  .

ENDMETHOD.

Step 15 : Mapping from component controller to view.

Mapping input /output parameter from component controller to view controller.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 17

Page 18: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Step 16 : Binding

Bind the Customer id and status with input parameter.

Step 17 : Code inside the submit button.

 DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .  lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).

    lo_componentcontroller->execute_si_obs_customer_status(    ).

Now save and activate the WD component and create an Application.

Step 18 : Testing

>>>>>>>>>>>>>>>>> Testing <<<<<<<<<<<<<<<<<<<<<<<<

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 18

Page 19: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Related Content

Import/export WD ABAP component to desktop

Subscribe to button event in WD ABAP

Consuming PI web services

For more information Visit WebDynpro ABAP homepage.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 19

Page 20: Consuming Java Web Services in Webdynpro ABAP

Consuming a java based web service in WebDynpro ABAP

Copyright© Copyright 2011 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.

Java is a registered trademark of Oracle Corporation.

JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.

Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.

All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BA - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 20