Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration

Size: px
Start display at page:

Download "Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration"

Transcription

1 SAP NetWeaver How-To Guide Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Applicable Releases: SAP NetWeaver Process Integration 7.1 SAP NetWeaver Business Rules Management 7.2 Topic Area: SOA Middleware Capability: Service Bus Version 1.1 March 2010

2 Copyright 2010 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, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iseries, pseries, xseries, zseries, z/os, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/os, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. 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 Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mysap, mysap.com, xapps, xapp, SAP NetWeaver, 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 in several other countries all over the world. 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. These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. SAP NetWeaver How-to Guides are intended to simplify the product implementation. While specific product features and procedures typically are explained in a practical business context, it is not implied that those features and procedures are the only approach in solving a specific business problem using SAP NetWeaver. Should you wish to receive additional information, clarification or support, please refer to SAP Consulting. Any software coding and/or code lines / strings ( Code ) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent. Disclaimer Some components of this product are based on Java. Any code change in these components may cause unpredictable and severe malfunctions and is therefore expressively prohibited, as is any decompilation of these components. Any Java Source Code delivered with this product is only to be used by SAP s Support Services and may not be modified or altered in any way.

3 Document History Document Version Description 1.10 Revision 1.00 First official release of this guide

4 Typographic Conventions Type Style Example Text Description Words or characters quoted from the screen. These include field names, screen titles, pushbuttons labels, menu names, menu paths, and menu options. Cross-references to other documentation Icons Icon Description Caution Note or Important Example Recommendation or Tip Example text Example text Example text <Example text> EXAMPLE TEXT Emphasized words or phrases in body text, graphic titles, and table titles File and directory names and their paths, messages, names of variables and parameters, source text, and names of installation, upgrade and database tools. User entry texts. These are words or characters that you enter in the system exactly as they appear in the documentation. Variable user entry. Angle brackets indicate that you replace these words and characters with appropriate entries to make entries in the system. Keys on the keyboard, for example, F2 or ENTER.

5 Table of Contents 1. Business Scenario Background Information Prerequisites Step-by-Step Procedure Create an XSD in the ESR Create a BRM Rule in NWDS Create a BRM Project Import the XSD into the Project Add the XSD Elements to the BRM Project Create a Ruleset Create a Decision Table Create the Rule Create a Web Service from the Rule Build the Project Deploy the Project Testing the Rule using WSNavigator Use SOAMANAGER to Retrieve the WSDL of the Rule Test the Web Service in WSNavigator Configure PI to use the Rule from BRM Configure SOAP Communication Channel Develop Message Mapping in the Enterprise Services Repository Message Types Used for Mapping Create the User-Function to Call the Rule Web Service Construct the Message Mapping Test the Message Mapping Appendix Appendix A: Code example of the user-defined function calling a BRM Ruleset web service Appendix B: How to obtain the structure of the XML Message used to call the web service

6 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 1. Business Scenario SAP NetWeaver Business Rules Management (BRM) provides a powerful toolset covering all aspects of rule handling in business applications. Message processing in SAP NetWeaver Process integration (PI) can take advantage of those business rules in multiple ways. 2. Background Information SAP NetWeaver PI can make use of rules in multiple ways: Within routings, business rules may provide additional data in Extended Receiver Determinations and Enhanced Interface Determinations Within a mapping step, business rules information may enrich the original data providing lookup and value mapping functionality Within ccbpm, rules may also be used to enrich process data or to provide decision criteria for conditions steps This HowTo-Guide makes use of very simple message mapping scenario to highlight the steps that are required to take advantage of SAP NetWeaver Business Rules Management in process integration. The example provided here may also serve as role model for the usage of BRM in PI routings and PI Integration Processes (ccbpm processes). 3. Prerequisites This HowTo-Guide describes a scenario that has been implemented using a PI system version 7.1 EhP1 and a BRM system version 7.2. Knowledge Required Basic knowledge in rules modeling Familiar with Business Rule Management System Basic knowledge in PI 7.1 Familiar with Message Mapping in PI Software Required SAP NetWeaver Developer Studio 7.20, includes the Rules Composer perspective SAP CE 7.20, and with it configured in the SAP NetWeaver Developer Studio SAP PI 7.1 EhP1 March

7 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 4. Step-by-Step Procedure In this guide we will create a rule to determine customer discounts based on their customer number and which region the order came from. Then, we will use this rule in our PI message mapping. The message mapping can be used to determine the total discounted cost of the order, which can be sent to a backend system for fulfillment. The steps of the exercise are as follow: 1. Create an XSD which can be used by BRM to create the rules. The XSD is created by designing a Message Type in PI s Enterprise Service Repository (ESR). 2. Create a BRM rule using NWDS: a. Create a BRM project. b. Import the XSD created from the Message Type. c. Create a decision table using the elements of the XSD. d. Create a rule to use the decision table. 3. Create a web service from the rule. 4. Build and deploy the project to a CE 7.2 system. 5. Test the web service. 6. In PI s Integration Directory, create a SOAP adapter to use the web service. 7. In PI s ESR, create a Message Mapping and a user-define function to use the web service. 8. Test the Message Mapping. 4.1 Create an XSD in the ESR 1. Create a Message Type with the following elements: March

8 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 2. In the XSD tab of the Message Type, we can copy or export the XSD to a local file. 4.2 Create a BRM Rule in NWDS Tip From more information on BRM, please reference Business Rules Management Tutorial Center in SDN: Create a BRM Project 1. Create a new project: March

9 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 2. Select Development Component: 3. Select the Rule Composer: March

10 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 4. Select MyComponent under LocalDevelopment: 5. Name the project: orderdiscount March

11 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Import the XSD into the Project 1. Expand src in the project and right-click on wsdl and select Import : 2. Select XSD for the import and click Next : March

12 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 3. Click Next : 4. Enter the location of the XSD file and click Finish : March

13 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 5. The following screen should result: Add the XSD Elements to the BRM Project 1. Add the XSD by double-click on Project Resources, select the Alias tab and click on Add and select XSD Element : March

14 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 2. Select the imported XSD and click Finish : 3. Select the XSD elements which will be used in the development of rule or decision table. Expand the XSD structure and check the following elements to be used: OrderDiscount_MT/CustNo OrderDiscount_MT/Region OrderDiscount_MT/Discount = {double} Note Those elements designated as = {something}, such as Discount, is used for output. Those without it are used as input. March

15 S... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Create a Ruleset 1. Create a ruleset by right-click on Rules Modeling and select New Ruleset : 2. Name the ruleset: OrderDiscountRule March

16 Create... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Create a Decision Table The decision table will help to determine the customer discount. This is a very simple table, consisting of using customer number and region as input, and providing the discount as the output. 1. Create a new decision table by right-click on Decision Table and select New Decision Table : 2. Name the decision table: OrderDiscountTable: March

17 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 3. Select CustNo and Region as the conditions of the table. These are the inputs. 4. The following will result. Click Next to continue: March

18 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 5. Select the Action, which is Discount, for the decision table. This is the output. 6. The following screens will result: March

19 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 7. Enter value for the 1 st customer by right-click on Default Value of the first column, CustNo, and select Add Condition Values : 8. Enter value for the 1 st customer number: March

20 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 9. Enter values for Region of the 1 st customer by repeating the above process in the 2 nd column: 10. Enter 3 values for Region: Americas, EMEA and APJ 11. The following table content should result: March

21 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 12. Create the rest of the customer values by right-click on the 1 st customer and select Add Condition Values : 13. Add CustNo values for the rest of the customers: Tip The reason we go through this process of creating the 1 st customer first, then creating the remaining customers is that the template of the 1 st customer will be use for all the other customers, e.g. all the regions names will all be included. March

22 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 14. The following table entries will result: 15. Enter the Discount values as below: March

23 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Create the Rule 1. Create a new Rule: 2. Name the new rule: OrderDiscountRule March

24 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 3. In the Rule development screen, click + under the If condition. Replace the left-hand side with Boolean.TRUE by clicking on Operation.isSuccessful and selecting Boolean.TRUE. Repeat the same for the right-hand side of the Equals. 4. Assign the Decision Table. Click on the + under the Then clause, and select the Decision Table OrderDiscountTable : March

25 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 5. The following should result: Create a Web Service from the Rule 1. Create the Web Service: March

26 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 2. Navigate through the following screens: Build the Project 1. Build the project by right-click on the project, select: Development Component Build March

27 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 2. Click OK to complete: March

28 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Deploy the Project 1. Deploy the project by right-click on the project, select: Development Component Deploy 2. Click OK to complete: March

29 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 4.3 Testing the Rule using WSNavigator Use SOAMANAGER to Retrieve the WSDL of the Rule 1. Go to NWA on the CE 7.20 system where the Rule has been deployed. Select: SOA Management Application and Scenario Communication Single Service Administration 2. Retrieve the WSDL, by: a. Enter: *discount* in the Find field. b. Click Go. c. Select OrderDiscountRulePortType. d. Click the tab WSDLs. e. Obtain the displayed WSDL. March

30 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 3. The web service can be displayed in the browser using the WSDL URL: Important Copy the location URL value in the WSDL to a Notepad. The URL will be used in the SOAP communication channel configuration in PI. March

31 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Test the Web Service in WSNavigator 1. Start WSNavigator and enter the WSDL URL obtained from the previous step and click Next : 2. Enter CustNo and Region values as test data: March

32 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 3. The Discount value will be returned: 4.4 Configure PI to use the Rule from BRM Important This section will require the target URL you saved from Section 4.3.1, step Configure SOAP Communication Channel In order for Message Mapping to access the web service of the BRM rule, we will need to configure a SOAP receiver communication channel. In the communication channel configuration, the target URL location of the web service must be specified. This URL should have already been obtained in Section 4.3.1, step 3. The communication channel configuration should look like the following: March

33 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Tip Remember the Business Component name and Channel name. These will be used by the Message Mapping program. 4.5 Develop Message Mapping in the Enterprise Services Repository Message Types Used for Mapping 1. To demonstrate the Message Mapping, two Message Types are created, as shown below: March

34 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration cust_no and region will be used to determine the values for discount and total_cost. 2. Select tab Signature and add a parameter of category Adapter, type SOAP to the list of Parameters Create the User-Function to Call the Rule Web Service The following is user-function create to call the webservice: March

35 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 1. Input variables: 2. User-function code: The complete source code is in Appendix A. March

36 S... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Tip Appendix B shows how the XML message used for calling the rule web service can be obtained Construct the Message Mapping The message mapping pertaining to the user-function is shown below: Test the Message Mapping 1. Select the SOAP Communication Channel to use for the web service call. 2. Enter the source XML values and execute: March

37 ... Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration March

38 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration 5. Appendix 5.1 Appendix A: Code example of the user-defined function calling a BRM Ruleset web service public String calculatediscount(string cust_no, String region, Channel soapdiscount, Container container) throws StreamTransformationException{ SystemAccessor accessor = null; String discount = ""; StringBuffer sb = new StringBuffer(); try{ // 1. Get a system accessor for the channel. accessor = LookupService.getSystemAccessor(soapDiscount); // 2. Build up request InputStream reqstream; String reqstring ="<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<ns0:request-demo.sap.com-orderdiscount-orderdiscountrule- OrderDiscountRule xmlns:ns0=\" + "<ns1:orderdiscount_mt xmlns:ns1=\" + "<CustNo>"+cust_no+"</CustNo> <Region>"+region+"</Region>" + "<Discount>0</Discount> </ns1:orderdiscount_mt>" + "</ns0:request-demo.sap.com-orderdiscount-orderdiscountrule- OrderDiscountRule>"; reqstream = (InputStream) new ByteArrayInputStream(reqString.getBytes()); XmlPayload reqpayload = LookupService.getXmlPayload(reqStream); // 3. Call BRM XmlPayload respayload = (XmlPayload)accessor.call(reqPayload); // 4. Parse result byte[] b = new byte[4096]; for (int n; (n = respayload.getcontent().read(b))!= -1;) { sb.append(new String(b, 0, n)); } int i =sb.indexof("<discount>") + 10; int j =sb.indexof("</discount>"); discount = sb.substring(i, j); } catch (Exception e) { March

39 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration // TODO Auto-generated catch block e.printstacktrace(); } finally { // 5. Close the accessor in order to free resources. if (accessor!=null) accessor.close(); } return discount; 5.2 Appendix B: How to obtain the structure of the XML Message used to call the web service. One way to obtain a sample XML message used to call the web service in ESR is to import the WSDL of the web service as an external definition. Then, create a temporary mapping using the external definition. In the test mode of the mapping, we can display the XML source, which can be used in the user-defined function. Obtaining the WSDL A WSDL may import other WSDLs. When this is the case, we want to get the WSDL which defines the structure of the message. This may require us to traverse multiple imports of the WSDL, as in this case, to obtain the WSDL to use for external definition. Copy the source of the WSDL to a local file. March

40 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Create the External Definition and import the WSDL: March

41 Access SAP NetWeaver Business Rules Management from SAP NetWeaver Process Integration Create a temporary Message Mapping using the External Definition: Drag the External Definition to the source of the Message Mapping tool and select the request message. Go to the test tab to obtain the source XML: This is the XML message to be used with the web service. March

42