Documentos de Académico
Documentos de Profesional
Documentos de Cultura
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
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.
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
Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service
Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service
c.
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.
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.
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.
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
Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service
Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service
b. In the next screen select the newly created portal DC in step 1. c. In the next screen select portal service
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.:-
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>
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:-
Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service
/** * 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)
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; } }
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.
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.
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>
Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service
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.
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.
Consuming a Non-SAP Web Service in a Portal Component using Standalone Proxy and Portal Service