Integrating SAP the Java EE Way - JBoss One Day talk 2012

5,392 views

Published on

Cuckoo is an open source Resource Adapter for SAP that is compatible to the Java Connector Architecture (JCA) version 1.5.

It enables developers of Java EE applications to call functions in a SAP backend, making use of Java EE features like Container Managed Transactions and Security.




Hibersap helps developers of Java applications to call business logic in SAP backends. It defines a set of Java annotations to map SAP function modules to Java classes as well as a small, clean API to execute these function modules and handle transaction and security aspects.

Hibersap's programming model is quite similar to those of modern O/R mappers, significantly speeding up the development of SAP interfaces and making it much more fun to write the integration code.

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,392
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
116
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Integrating SAP the Java EE Way - JBoss One Day talk 2012

  1. 1. Integrating SAP the Java EE way JBoss OneDayTalk 2012Carsten Erker
  2. 2. Remember those days...?
  3. 3. Statement st = conn.createStatement();ResultSet rs = st.executeQuery( "SELECT * FROM customer" );List<Customer> customers = new ArrayList<Customer>();while ( rs.next() ){ Customer customer = new Customer(); customer.setId( rs.getString( "ID" ) ); customer.setFirstName( rs.getString( "FIRST_NAME" ) ); customer.setLastName( rs.getString( "LAST_NAME" ) ); ... customers.add( customer );}...
  4. 4. Who is still doing this?
  5. 5. Nowadays we dosomething like this...
  6. 6. @Entitypublic class Customer{ @Id @GeneratedValue private Long id; private String firstName; private String lastName; ...}
  7. 7. List<Customer> customers = entityManager .createQuery( "select c from Customer c" ) .getResultList();
  8. 8. When calling businesslogic in SAP we don‘t want to go the old way...
  9. 9. Setting the stage... Courtesy of Special Collections, University of Houston Libraries. UH Digital Library.
  10. 10. The SAP JavaConnector (JCo)
  11. 11. How it works...
  12. 12. Calls function modules in SAP backend
  13. 13. Function modules are apiece of code written in ABAP
  14. 14. They have an interface with different types ofparameters to pass data
  15. 15. FUNCTION BAPI_SFLIGHT_GETLIST.*"-----------------------------------------------------*"*"Lokale Schnittstelle:*" IMPORTING*" VALUE(FROMCITY) LIKE BAPISFDETA-CITYFROM*" VALUE(TOCITY) LIKE BAPISFDETA-CITYTO*" VALUE(AIRLINECARRIER) LIKE BAPISFDETA-CARRID*" EXPORTING*" VALUE(RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2*" TABLES*" FLIGHTLIST STRUCTURE BAPISFLIST*"-----------------------------------------------------
  16. 16. JCo runs on top of the SAP-proprietary RFC interface(Remote Function Call)
  17. 17. JCo can be used inClient and Server mode
  18. 18. Example code calling a function module in SAP...
  19. 19. JCoDestination destination = JCoDestinationManager.getDestination( "NSP" );JCoFunction function = destination.getRepository().getFunction( "BAPI_FLCUST_GETLIST" );function.getImportParameterList().setValue( "MAX_ROWS", 10 );function.execute( destination );JCoParameterList tableParams = function.getTableParameterList();JCoTable table = tableParams.getTable( "CUSTOMER_LIST" );List<Customer> customers = new ArrayList<Customer>();for ( int i = 0; i < table.getNumRows(); i++ ){ table.setRow( i ); Customer customer = new Customer(); customer.setId( table.getLong( "CUSTOMERID" ) ); customer.setLastName( table.getString( "CUSTNAME" ) ); customers.add( customer );}...
  20. 20. => Lots of glue code, tedious mapping of parameters
  21. 21. But - JCo has somebenefits that make it a good fit for business apps...
  22. 22. It can be used with Transactions
  23. 23. It implementsConnection Pooling
  24. 24. SAP functions can becalled asynchronously
  25. 25. It is fast
  26. 26. The bad points...
  27. 27. The programming model
  28. 28. Does not fit very wellinto the Java EE world:
  29. 29. Not trivial to use it with CMT
  30. 30. The same goes for Security
  31. 31. The alternative:Java EE ConnectorArchitecture (JCA)
  32. 32. JCA is a Java EE standard
  33. 33. JCA was created forthe interaction of Java EE applications withEnterprise Information Systems, such as SAP
  34. 34. A Resource Adapter isan implementation of JCA for a certain EIS
  35. 35. A RA is deployed in an Application Server in form of a Resource Archive (.rar)
  36. 36. The RA takes care of...
  37. 37. TransactionManagement
  38. 38. ConnectionManagement
  39. 39. SecurityManagement
  40. 40. ... all this in a standard way
  41. 41. JCA solves a lot ofproblems, except one...
  42. 42. The programming model :-(
  43. 43. JCA defines the Common Client Interface (CCI) for astandard way to access an EIS
  44. 44. Because of the many different natures ofEIS‘s, it is overly generic
  45. 45. It operates on Lists,Maps and/or ResultSets representing the data
  46. 46. Additionally, a lot ofglue code needs to be written
  47. 47. In this, it is not toodifferent from SAP‘s Java Connector...
  48. 48. @Resource( mappedName = "java:jboss/eis/NSP" )private ConnectionFactory connectionFactory;...Connection connection = connectionFactory.getConnection();Interaction interaction = connection.createInteraction();RecordFactory rf = connectionFactory.getRecordFactory();MappedRecord input = rf.createMappedRecord( "BAPI_FLCUST_GETLIST" );input.put( "CUSTOMER_NAME", "Ernie" );input.put( "MAX_ROWS", 20 );MappedRecord output = ( MappedRecord ) interaction.execute( null, input );...
  49. 49. List<Customer> customers = new ArrayList<Customer>();IndexedRecord customerTable = ( IndexedRecord ) output.get( "CUST_LIST" );            for ( Object row : customerTable ){ MappedRecord record = ( MappedRecord ) row; Customer customer = new Customer(); customer.setId( ( String ) record.get( "CUSTOMERID" ) );    customer.setName( ( String ) record.get( "CUSTNAME" ) ); ...    result.addCustomer( customer );}
  50. 50. SAP offers a RA that only runs on SAPApplication Servers
  51. 51. Any more alternatives?
  52. 52. For read-only andless frequent SAP calls consider using Web Services
  53. 53. A SOA platform may bewell suited for not-so- tight integration
  54. 54. Introducing the cool stuff... Photo by Alan Levine, CC-BY 2.0, http://www.flickr.com/photos/cogdog
  55. 55. It implements JCA version 1.5
  56. 56. It currently only supports the outbound way
  57. 57. Under the hood, it uses the SAP Java Connector (JCo)
  58. 58. The next steps...
  59. 59. Upgrading Cuckoo to JCA version 1.6
  60. 60. Adding inbound capability
  61. 61. Cuckoo isOpen Source under LGPL License
  62. 62. More info:https://sourceforge.net/p/cuckoo-ra/
  63. 63. Example application:https://github.com/cerker/ cuckoo-example
  64. 64. What was all the fussabout the programming model?
  65. 65. We still have to solve this problem...
  66. 66. Hibersap is somethinglike an O/R mapper for SAP functions
  67. 67. It makes use of Java annotations to mapSAP functions and their parameters to Java objects
  68. 68. It has an API that is quite similar to Hibernate/JPA
  69. 69. Thus it fits very wellinto the modern Java world
  70. 70. Hibersap takes care ofmost of the glue code
  71. 71. It can be either usedwith JCo or with a JCA Resource Adapter
  72. 72. Switching betweenthem is a matter of configuration
  73. 73. This makes integration testing a breeze
  74. 74. Finally, some code...
  75. 75. The business object...
  76. 76. @Bapi( "BAPI_FLCUST_GETLIST" )public class CustomerList{ @Import @Parameter("MAX_ROWS") private int maxRows; @Table @Parameter( "CUSTOMER_LIST" ) private List<Customer> customers; ...} public class Customer { @Parameter("CUSTOMERID") private String id; @Parameter( "CUSTNAME" ) private String firstName; ... }
  77. 77. The API...
  78. 78. Session session = sessionManager.openSession();CustomerList customerList = new CustomerList( 10 );session.execute( customerList );List<Customer> customers = customerList.getCustomers();
  79. 79. The configuration...
  80. 80. META-INF/hibersap.xml => JCA<hibersap> <session-manager name="NSP"> <context>org.hibersap.execution.jca.JCAContext</context> <jca-connection-factory> java:jboss/eis/sap/NSP </jca-connection-factory> <annotated-classes> <annotated-class> de.akquinet.jbosscc.cuckoo.example.model.CustomerSearch </annotated-class> ... </annotated-classes> </session-manager></hibersap>
  81. 81. META-INF/hibersap.xml => JCo<hibersap> <session-manager name="NSP"> <context>org.hibersap.execution.jco.JCoContext</context> <properties>" " " <property name="jco.client.client" value="001" />" " " <property name="jco.client.user" value="sapuser" />" " " <property name="jco.client.passwd" value="password" />" " " <property name="jco.client.ashost" value="10.20.30.40" />" " " <property name="jco.client.sysnr" value="00" /> ..." " </properties> <annotated-classes> <annotated-class> de.akquinet.jbosscc.cuckoo.example.model.CustomerSearch </annotated-class> ... </annotated-classes> </session-manager></hibersap>
  82. 82. Bean Validation can be used on parameter fields...
  83. 83. @Parameter( "COUNTR_ISO" )@NotNull @Size(min = 2, max = 2)private String countryKeyIso;
  84. 84. Converters allow fordata type or format conversion on parameter fields...
  85. 85. @Parameter( "TYPE" )@Convert( converter = SeverityConverter.class )private Severity severity;
  86. 86. Hibersap is OpenSource and licensed under LGPL
  87. 87. More info:http://hibersap.org
  88. 88. Putting it all together...
  89. 89. In a Java EE application we should use Cuckoo RA
  90. 90. Thus, we can make use of CMT in EJBs
  91. 91. ...and all the other benefits of JCA
  92. 92. Using Hibersap, we gain an elegant and lightweight programming model
  93. 93. ... especially when using Hibersap‘s EJB tools
  94. 94. Thus, we get muchnicer code that is easierto understand, maintain and test
  95. 95. Example application:https://github.com/cerker/cuckoo-hibersap-example
  96. 96. Tooling...
  97. 97. JBoss Forge plugin: https://github.com/ forge/plugin-hibersap See also:http://blog.akquinet.de/ 2012/07/12/
  98. 98. Hibersap-Camel Component: https://github.com/bjoben/camel-hibersap
  99. 99. About me...
  100. 100. Carsten ErkerSoftware Architect and Consultantakquinet AG in Berlin / Germanycarsten.erker@akquinet.de
  101. 101. Questions?

×