Está en la página 1de 19

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Applies to:
SAP NetWeaver. For more information, visit the Portal and Collaboration homepage.

Summary
This article is to demonstrate how to consume a non-SAP Web Service in a Portal Component with the help of a Standalone Proxy and Portal Service. Author: Sandesh K Kumbhar
rd

Company: Larsen and Toubro InfoTech Created on: 23 March 2011

Author Bio
Sandesh Kumbhar is a SAP Certified ABAP with Netweaver 07 Associate with experience in SAP ABAP, SAP Enterprise Portal, Webdynpro Java, Webdynpro ABAP, Web Services, SOA, Java 2.0, EJB, Servlets, JSP, JDBC, XML, and SQL. Experience covers the entire spectrum of SAP Project activities ranging from designing of functional specifications by mapping the business requirements with SAP functionality, preparing the TDS documents (technical specification), developing the custom objects or enhancing the standard SAP objects, unit and integration testing, preparing turnover documents, Training, Transition support and Production Support. Currently working with Larsen and Toubro InfoTech.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 1

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Table of Contents
Creating Standalone Proxy Project .................................................................................................................... 3 Creating a Portal DC ........................................................................................................................................... 8 Creating Portal Service within the Portal DC .................................................................................................... 10 Using the Jar file from Proxy Project ................................................................................................................ 12 Creating Custom Method in Portal Service to Invoke web Service Operation ................................................. 14 List methods in Portal Service Interface ........................................................................................................... 15 Creating JSP Component ................................................................................................................................. 16 Related Content ................................................................................................................................................ 18 Disclaimer and Liability Notice .......................................................................................................................... 19

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 2

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Creating Standalone Proxy Project


1. Create Standalone Proxy Project. All the steps in point 1 need to be repeated in case the WSDL file
changes. Following steps were referred from: http://help.sap.com/saphelp_nw04/helpdata/en/77/1484b9ecb98c41af4a01131d8d46d3/frameset.ht m a. File->New->Project->Webs Services->Standalone Proxy Project

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 3

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

b. Enter Project Name and click finish.

c.

Go to web services perspective.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 4

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

d. Right click on standalone project in Client Explorer view and select New->Client Proxy Definition

e. Enter package, proxy name and select Local File System or URL option and click next.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 5

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

f.

Select the wsdl file stored on your local machine and click next.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 6

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

g.

NWDS automatically generates package names like types.p2, types.p3,etc. You can change the package name to appropriate name. For e.g. in screenshot below, I am changing types.p4 to types.SetPartnerResponse since this package would contain class SetPartnerResponse as seen in leftmost column under URI column name. Similarly change package names from types.p5 to types.PartnerDetailResponse and so on. Change all the package names. Make sure they are distinct. Click finish.

h. Project will look as below. In this way we have generated stubs from the wsdl. We will use the generated *.jar file in our portal service. It has required methods to invoke web service operations.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 7

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Creating a Portal DC
2. Create a portal DC. a. File ->New->Other->Development Component

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 8

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 9

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Creating Portal Service within the Portal DC


3. Create portal service within the portal DC created in the step above. a. File-> New->Other->Portal Application->Create a New Portal Application Object

b. In the next screen select the newly created portal DC in step 1. c. In the next screen select portal service

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 10

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

d. Enter Name, Class Name and package and click finish. It generates java files in src.api and src.core folders. For e.g.:-

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 11

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

e. Modify portalapp.xml file in dist->PORTAL-INF->portalapp.xml to as shown below:i. <?xml version="1.0" encoding="UTF-8"?> ii. <application> iii. <application-config> iv. <property name="startup" value="true"/> v. <property name="PrivateSharingReference" value="com.sap.portal.htmlb"/> vi. <property name="SharingReference" value="com.sap.portal.runtime.config,com.sap.portal.runtime.co nfig.component,usermanagement,knowledgemanagement,com.sap.port al.ivs.connectorservice"/> vii. </application-config> viii. <components/> ix. <services> x. <service name="PartnerActionsService"> xi. <service-config> xii. <property name="className" value="com.ingram.services.partneractions.PartnerActionsServic e"/> xiii. <property name="startup" value="true"/> xiv. </service-config> xv. <service-profile> xvi. <property name="Name" value="PartnerActionsService"/> xvii. </service-profile> xviii. </service> xix. </services> xx. </application>

Using the Jar file from Proxy Project


4. Next step is to use the jar file that we generated in step 1 from standalone proxy project. Below is a guide available that explains how to create external library DC, an external library deployable unit and also explains how to create a reference to these DCs from your project DCs so that you can access external jar files. http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60d99678-1a29-2d10-94b49d9a67b7199b?QuickLink=index&overridelayout=true By referring this guide you will reference an external jar file (Proxy jar in this case) in your portal service DC. For example as shown in screenshot below I have created used DCs for external library DCs.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 12

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Now go to Package Explorer view and right click select properties. Here click on Project References and make sure that external library DCs have been referred. For ex:-

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 13

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Creating Custom Method in Portal Service to Invoke web Service Operation


5. Now in the java file generated in src.core folder in portal service DC, write the method that you want to expose through this portal service by using the generated proxy classes. Sample code is below.

/** * Implement custom methods here */ public HashMap disablePartner(HashMap input,IPortalComponentRequest request, IPortalComponentResponse response){ try { PartnerActionsR1ServiceImpl ws = new PartnerActionsR1ServiceImpl(); Remote remote = ws.getLogicalPort(PartnerPortTypeR1.class); PartnerActionsEndpointBindingStub port = (PartnerActionsEndpointBindingStub) remote; BaseGeneratedStub stub = (BaseGeneratedStub) remote; //set Endpoint URL stub._setEndpoint("http://xxx.com:20000/PartnerPortType_r1"); //set request data ServiceRequest ServiceRequestPartnerDisable = new ServiceRequest(); RequestPreamble RequestPreamblePartnerDisable = new RequestPreamble(); RequestPreamblePartnerDisable.setApplicationUser("Sandesh"); Calendar cal = Calendar.getInstance(); cal.set(2011,01,25,12,22,23); RequestPreamblePartnerDisable.setTimeStamp(cal); RequestPreamblePartnerDisable.setTransactionID("1234560191919177"); ServiceRequestPartnerDisable.setRequestPreamble(RequestPreamblePartnerDisable);

String[] Partners = {"TEST"}; ServiceRequestPartnerDisable.setDisablePartnerRequest(Partners); //invoke service operation ServiceResponse resultPartnerDisable = port.disablePartnerProfile(ServiceRequestPartnerDisable); //Display response ResponsePreamble respPreamble = resultPartnerDisable.getResponsePreamble(); response.write("<BR> Return Code in Service:"+respPreamble.getReturnCode()); response.write("<BR> Message in Service:"+respPreamble.getReturnMessage()); response.write("<BR> Timestamp in Service :"+respPreamble.getTimeStamp().get(Calendar.YEAR) +":"+respPreamble.getTimeStamp().get(Calendar.MONTH)

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 14

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

+":"+respPreamble.getTimeStamp().get(Calendar.DAY_OF_MONTH) +":"+respPreamble.getTimeStamp().get(Calendar.HOUR) +":"+respPreamble.getTimeStamp().get(Calendar.MINUTE) +":"+respPreamble.getTimeStamp().get(Calendar.SECOND) ); response.write("<BR> TransID in Service:"+respPreamble.getTransactionID()); } catch (Exception e) { // TODO Auto-generated catch block response.write("<BR> Exception:- " + e.getLocalizedMessage()); } return input; } }

List methods in Portal Service Interface


6. Once you have written the method, expose this method to external world through generated interface in src.api folder.

Sample Code is as below:


package com.ingram.services.partneractions;

import java.util.HashMap; import com.sapportals.portal.prt.component.IPortalComponentRequest; import com.sapportals.portal.prt.component.IPortalComponentResponse; import com.sapportals.portal.prt.service.IService; public interface IPartnerActionsService extends IService { public static final String KEY = "PartnerActionsService"; public HashMap disablePartner(HashMap input,IPortalComponentRequest request, IPortalComponentResponse response); }

External applications will refer this service method through unique key mentioned in KEY variable above.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 15

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

7. Before this create two public parts (assembly and compilation) in portal service DC and add the interface class to these public parts.

8. Build the portal service and deploy.

Creating JSP Component


9. Now create a JSP DynPage component in some other portal DC and will have to refer the portal service DC from jspdynpage DC through used DCs as shown below. Link to compile Public Part:

10. In portalapp.xml of JSP component DC, add a sharing reference to portal service DC as below:
<application-config> <property name="startup" value="true"/> <property name="SharingReference" value="pa_service_partneractions,urlgenerator,usermanagement,knowledgemanagement,l andscape,htmlb,com.sap.portal.htmlb"/> <property name="PrivateSharingReference" value="com.sap.portal.htmlb"/> </application-config>

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 16

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

11. Refer this service by using below code in doInitialization() method.


IPartnerActionsService disableService = (IPartnerActionsService) PortalRuntime.getRuntimeResources().getService("pa_service_partneractions.PartnerA ctionsService"); HashMap inputMap = null; HashMap output = disableService.disablePartner(inputMap,request,response);

12. In this way you have accessed a portal service method from JSP Dynpage component. Portal service method invokes the web service operation and sends request from portal component to end point and receives response and sends back to portal component.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 17

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

Related Content
Creating Standalone Proxy Creating and referring external library Accessing an External Web Services in Portal SAP Community Network SOA Topic For more information, visit the Portal and Collaboration homepage.

SAP COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 18

Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service

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 COMMUNITY NETWORK 2011 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com 19

También podría gustarte