SlideShare wird heruntergeladen. ×
0
Integrating SAP the     Java EE way      JBoss OneDayTalk 2012Carsten Erker
Remember those    days...?
Statement st = conn.createStatement();ResultSet rs = st.executeQuery( "SELECT * FROM customer" );List<Customer> customers ...
Who is still doing this?
Nowadays we dosomething like this...
@Entitypublic class Customer{  @Id @GeneratedValue  private Long id;  private String firstName;  private String lastName;  ...
List<Customer> customers = entityManager   .createQuery( "select c from Customer c" )   .getResultList();
When calling businesslogic in SAP we don‘t  want to go the old         way...
Setting the stage...       Courtesy of Special Collections, University of Houston Libraries. UH Digital Library.
The SAP JavaConnector (JCo)
How it works...
Calls function modules    in SAP backend
Function modules are apiece of code written in         ABAP
They have an interface with different types ofparameters to pass data
FUNCTION BAPI_SFLIGHT_GETLIST.*"-----------------------------------------------------*"*"Lokale Schnittstelle:*" IMPORTING...
JCo runs on top of  the SAP-proprietary     RFC interface(Remote Function Call)
JCo can be used inClient and Server mode
Example code calling a function module in        SAP...
JCoDestination destination = JCoDestinationManager.getDestination( "NSP" );JCoFunction function =   destination.getReposit...
=> Lots of glue code, tedious mapping of     parameters
But - JCo has somebenefits that make it a good fit for business        apps...
It can be used with    Transactions
It implementsConnection Pooling
SAP functions can becalled asynchronously
It is fast
The bad points...
The programming     model
Does not fit very wellinto the Java EE world:
Not trivial to use it    with CMT
The same goes for     Security
The alternative:Java EE ConnectorArchitecture (JCA)
JCA is a Java EE   standard
JCA was created forthe interaction of Java EE applications withEnterprise Information Systems, such as SAP
A Resource Adapter isan implementation of JCA for a certain EIS
A RA is deployed in an Application Server in  form of a Resource     Archive (.rar)
The RA takes care of...
TransactionManagement
ConnectionManagement
SecurityManagement
... all this in a standard             way
JCA solves a lot ofproblems, except one...
The programming     model       :-(
JCA defines the   Common Client Interface (CCI) for astandard way to access         an EIS
Because of the many   different natures ofEIS‘s, it is overly generic
It operates on Lists,Maps and/or ResultSets representing the data
Additionally, a lot ofglue code needs to be       written
In this, it is not toodifferent from SAP‘s  Java Connector...
@Resource( mappedName = "java:jboss/eis/NSP" )private ConnectionFactory connectionFactory;...Connection connection = conne...
List<Customer> customers = new ArrayList<Customer>();IndexedRecord customerTable = ( IndexedRecord ) output.get( "CUST_LIS...
SAP offers a RA that only runs on SAPApplication Servers
Any more alternatives?
For read-only andless frequent SAP calls     consider using     Web Services
A SOA platform may bewell suited for not-so-   tight integration
Introducing the cool       stuff...          Photo by Alan Levine, CC-BY 2.0, http://www.flickr.com/photos/cogdog
It implements JCA     version 1.5
It currently only  supports the outbound way
Under the hood, it uses    the SAP Java  Connector (JCo)
The next steps...
Upgrading Cuckoo to  JCA version 1.6
Adding inbound  capability
Cuckoo isOpen Source under  LGPL License
More info:https://sourceforge.net/p/cuckoo-ra/
Example application:https://github.com/cerker/     cuckoo-example
What was all the fussabout the programming        model?
We still have to solve  this problem...
Hibersap is somethinglike an O/R mapper for      SAP functions
It makes use of Java  annotations to mapSAP functions and their   parameters to Java        objects
It has an API that is   quite similar to   Hibernate/JPA
Thus it fits very wellinto the modern Java        world
Hibersap takes care ofmost of the glue code
It can be either usedwith JCo or with a JCA   Resource Adapter
Switching betweenthem is a matter of   configuration
This makes integration   testing a breeze
Finally, some code...
The business object...
@Bapi( "BAPI_FLCUST_GETLIST" )public class CustomerList{  @Import @Parameter("MAX_ROWS")  private int maxRows;  @Table @Pa...
The API...
Session session = sessionManager.openSession();CustomerList customerList = new CustomerList( 10 );session.execute( custome...
The configuration...
META-INF/hibersap.xml                                            => JCA<hibersap>  <session-manager name="NSP">     <conte...
META-INF/hibersap.xml                                            => JCo<hibersap>  <session-manager name="NSP">     <conte...
Bean Validation can be used on parameter       fields...
@Parameter( "COUNTR_ISO" )@NotNull @Size(min = 2, max = 2)private String countryKeyIso;
Converters allow fordata type or format  conversion on parameter fields...
@Parameter( "TYPE" )@Convert( converter = SeverityConverter.class )private Severity severity;
Hibersap is OpenSource and licensed   under LGPL
More info:http://hibersap.org
Putting it all together...
In a Java EE application     we should use       Cuckoo RA
Thus, we can make use   of CMT in EJBs
...and all the other   benefits of JCA
Using Hibersap, we gain    an elegant and      lightweight programming model
... especially when using   Hibersap‘s EJB tools
Thus, we get muchnicer code that is easierto understand, maintain        and test
Example application:https://github.com/cerker/cuckoo-hibersap-example
Tooling...
JBoss Forge plugin:  https://github.com/ forge/plugin-hibersap        See also:http://blog.akquinet.de/      2012/07/12/
Hibersap-Camel     Component:  https://github.com/bjoben/camel-hibersap
About me...
Carsten ErkerSoftware Architect and Consultantakquinet AG in Berlin / Germanycarsten.erker@akquinet.de
Questions?
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Nächste SlideShare
Wird geladen in ...5
×

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

3,920

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 Kommentare
4 Gefällt mir
Statistiken
Notizen
  • Hinterlassen Sie den ersten Kommentar

Keine Downloads
Views
Gesamtviews
3,920
Bei Slideshare
0
Aus Einbettungen
0
Anzahl an Einbettungen
4
Aktionen
Geteilt
0
Downloads
90
Kommentare
0
Gefällt mir
4
Einbettungen 0
No embeds

No notes for slide

Transcript of "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?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×