Upload Files Using Web Service In Web Dynpro Java Application

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Upload Files Using Web Service In Web Dynpro Java Application as PDF for free.

More details

  • Words: 2,177
  • Pages: 24
Upload file using Web Service in Web Dynpro Application

Upload file using Web Service in Web Dynpro Java Application Summary In a Web Dynpro application you can upload a file to server using web services. First of all you have to develop a web service which can handle attachments (binary data). Then utilize that web service from Web Dynpro to upload file. To develop this application you have to follow the steps, described later, sequentially. The overall scenario is described in Figure 1.0 Author(s): Sudip Das Company: HCL Technologies Created on: 2 April 2007

Author Bio Sudip Das is working as a Netweaver Consultant for HCL Technologies, Kolkata.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 1

Upload file using Web Service in Web Dynpro Java Application

Table of Contents Steps are to be followed .................................................................................................................. 3 Web Service Creation and Deployment .......................................................................................... 3 Create Business Method.............................................................................................................. 3 Prerequisites............................................................................................................................. 3 Procedure ................................................................................................................................. 4 Consume Web Service in a Web Dynpro Application ................................................................... 11 Prerequisites........................................................................................................................... 11 Procedure ............................................................................................................................... 11 Build, Deploy and Run Application ................................................................................................ 22 Related Content............................................................................................................................. 23 Disclaimer and Liability Notice....................................................................................................... 24

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2

Upload file using Web Service in Web Dynpro Java Application

Steps are to be followed 1. 2. 3. 4. 5. 6.

Create Web Service (WS) which can handle (file) attachments. Bundle that web service with an EAR file and deploy into server. Create a Web Dynpro application. Create a Model in Web Dynpro application and import that web service into this model. Read the file from client side and send the file to WS using Logical Port. WS will handle that file on server side and do the specific job, like store that file in local file system of server or can store in a database in the form BLOB data.

Web Service Creation and Deployment To expose web services you have to create Enterprise JavaBean (EJB) or Java class. Here we are exposing web services from an EJB. In EJB we develop business method which can handle file as binary data.

Create Business Method Prerequisites • • •

FileHandleModule EJB project is created. FileHandleModule project is currently displayed in J2EE Explorer of J2EE Development Perspective. SAP J2EE engine and Software Deployment Manager (SDM) have been running properly in WAS (Web Application Server). Again you have checked that the J2EE server is correctly selected in the NetWeaver Developer Studio.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 3

Upload file using Web Service in Web Dynpro Java Application

Procedure • •

Double click on FileHandleBean under ejb-jar.xml file and select Methods Tab. Now select Business Methods and press Add Pushbutton. (Figure 1.1) In this wizard, give the following values of the parameters. Figure 1.2 depicts the result after providing the values. Note that you have to select the type of fileContent parameter as byte.

Name

Value

Method Name

storeFile

Return Type

Void

Parameter 1 Name

fileName

Parameter 1 Type

String

Parameter 2 Name

fileContent

Parameter 2 Type

byte

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

Comment

Select Array of size 1

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 4

Upload file using Web Service in Web Dynpro Java Application



Select Bean Tab of FileHandleBean and inside storeFile method place the custom code to handle the file as binary data for specific job purpose. Here we store the file in location file system of server. Figure 1.3 shows that custom code for file processing.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 5

Upload file using Web Service in Web Dynpro Java Application



Select Web Service from the context menu of FileHandleBean. In the appeared wizard assign FileHandleWS to Web Service Name field and leave the entire field’s value as default. Choose Next button. (Figure 1.4, Figure 1.5)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 6

Upload file using Web Service in Web Dynpro Java Application



Now select the methods of the FileHandleBean which will to be contained in the Virtual Interface (Web Service), if they are not already selected. (Figure 1.6) Choose Next button.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 7

Upload file using Web Service in Web Dynpro Java Application



Now bundle the EJB project (FileHandleModule) into an EAR project. In the appeared wizard select the EAR project (if it is currently opened in J2EE Explorer) using Browse button or you can give any name for new EAR project. Provide FileHandleEAR for the EAR project name, this EAR project will

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 8

Upload file using Web Service in Web Dynpro Java Application

be created. Leave the other field’s value default like value of Virtual Interface is FileHandleWSVi and value of Web Service Definition is FileHandleWSWsd (Figure 1.7)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 9

Upload file using Web Service in Web Dynpro Java Application

• • •



Select Build EJB Archive from the context menu of the EJB project (FileHandleModule). EJB JAR file named FileHandleModule.jar will be generated. Now select Build Application Archive from the context menu of the EAR project (FileHandleEAR). EAR file named FileHandleEAR.ear will be generated. Select Deploy to J2EE engine from the context menu of FileHandleEAR.ear file, under the EAR project FileHandleEAR. (Figure 1.8). You have made sure that the SAP J2EE Engine and Software Deployment Manager (SDM) has been running properly. Again you have checked that the J2EE server is correctly selected in the Developer Studio, if it is not configured then configure it from Window → Preferences → SAP J2EE Engine.

Now provide the password for SDM. If the deployment is successful then a successful message will be displayed in the Deploy Output View pane. (Figure 1.10)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 10

Upload file using Web Service in Web Dynpro Java Application

Consume Web Service in a Web Dynpro Application To consume a web service you have to create a Web Dynpro application. Using Model of Web Dynpro a web service can be imported to a Web Dynpro application. The whole procedure is described below. Prerequisites • •



FileHandleEAR (EAR Project) should be developed and currently deployed in to WAS. SAP J2EE engine and Software Deployment Manager (SDM) have been running properly in WAS (Web Application Server). Again you have checked that the J2EE server is correctly selected in the NetWeaver Developer Studio. Here the same WAS is used, where the FileHandleEAR file is deployed which contains the web service (FileHandleWS). A Web Dynpro Project (WSDemoWD) is developed and currently displayed in Web Dynpro Explorer of Web Dynpro Perspective.

Procedure •

Now select Create Model from the context menu of Model in the Web Dynpro Explorer. (Figure 1.11)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 11

Upload file using Web Service in Web Dynpro Java Application



Select Import Web Service Model in appeared wizard and choose Next button. (Figure 1.12)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 12

Upload file using Web Service in Web Dynpro Java Application



In next wizard, provide FileHandleMdl for Model Name and com.hcl.model.fhandle for the Model Package. Choose Local Server for the WSDL (Web Service Definition Language) source or any other suitable option where the Web Service’s WSDL file is placed. (Figure 1.13)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 13

Upload file using Web Service in Web Dynpro Java Application



Now select FileHandleWS from the list of web services are available on the server. (Figure 1.14) Choose Next button. In the appeared wizard the name of the Virtual Interface will be displayed under URI. Choose Finish button. (Figure 1.15). If the import of web service is successful then the Web Dynpro project structure will be like Figure 1.16.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 14

Upload file using Web Service in Web Dynpro Java Application

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 15

Upload file using Web Service in Web Dynpro Java Application



In the Used Models area, right-click and choose Add. Select the Web Service model imported previously (FileHandleMdl) and choose OK button. (Figure 1.17 and 1.18)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 16

Upload file using Web Service in Web Dynpro Java Application



Now don’t create any context node or attribute to map the byte[ ] type in your controller or view context, just send it externally (using Logical Port) because there's a problem in the current release.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 17

Upload file using Web Service in Web Dynpro Java Application



Place some UI components in the view, StartView to select the file from client’s file system. Here we use FileUpload UI Component for this purpose. The overall design view (and Context binding with UI elements) of StartView is presented in Figure 1.19. Create three Value Attributes in the Context of StartView, listed below.

Name

Type

msg

string

fName

string

fData

Binary

uIVisibility

com.sap.ide.webdynpro.uielementdefinitions.Visibility

Provide the id for the FileUpload and Button UI element as ChosseFile and Send respectively. Bind fData and fName context element to data and fileName field of the FileUpload (ChosseFile) UI element respectively. Bind uIVisibility context element to visible field of both ChooseFile and Send UI Elements. Now bind msg context element to the text field of UploadMessage UI Element.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 18

Upload file using Web Service in Web Dynpro Java Application



Provide Send to Name to define New Action for the Send button. Now go to the implementation of the onActionSend (in StartView) and put the following code (it also includes the necessary import statements), shown in Figure 1.20. Here we collect the file name and file data using getFName() and getFData() method. Then we create the instance of model and stub, the names of the classes you can find under src folder of com.hcl.model.fhandle.proxies package (Figure 1.21)

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 19

Upload file using Web Service in Web Dynpro Java Application

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 20

Upload file using Web Service in Web Dynpro Java Application



Now put the following code, shown in Figure 1.22 in wdDoInit (in StartView) method, necessary for the FileUpload UI element.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 21

Upload file using Web Service in Web Dynpro Java Application

Build, Deploy and Run Application •



Select Save All metadata from the context menu of WSDemoWD project (Web Dynpro Project). Select Rebuild Project from the context menu of WSDemoWD project (Web Dynpro Project). Now select Deploy New Archive and Run from the context menu of WSDemoWDApp (Web Dynpro Application). After deploying and running the application provide the file name to be uploaded using Browse button and the check the specified location (mentioned in business method of EJB) of WAS where the file to be stored.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 22

Upload file using Web Service in Web Dynpro Java Application

Related Content •

http://help.sap.com/saphelp_nw04/helpdata/en/f7/af60f2e04d0848888675a800623a81/frameset.htm



http://help.sap.com/saphelp_nw04/helpdata/en/49/12eb82e057474994765faf83995ecb/frameset.htm



http://help.sap.com/saphelp_nw04/helpdata/en/90/c1343e8c7f6329e10000000a114084/frameset.ht m

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 23

Upload file using Web Service in Web Dynpro Java Application

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.

SAP DEVELOPER NETWORK | sdn.sap.com © 2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 24

Related Documents