Integrating SAP the Java EE Way - JBoss One Day talk 2012
Upcoming SlideShare
Loading in...5

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



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

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.



Views auf SlideShare
Views einbetten


Gefällt mir

3 Einbettungen 5 3 1 1



Details hochladen

Uploaded via as Adobe PDF


© Alle Rechte vorbehalten

Report content

Als unangemessen gemeldet Als unangemessen melden
Als unangemessen melden

Wählen Sie Ihren Grund, warum Sie diese Präsentation als unangemessen melden.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Ihre Nachricht erscheint hier
Kommentar posten
Kommentar bearbeiten

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

  • 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 = new ArrayList<Customer>();while ( ){ Customer customer = new Customer(); customer.setId( rs.getString( "ID" ) ); customer.setFirstName( rs.getString( "FIRST_NAME" ) ); customer.setLastName( rs.getString( "LAST_NAME" ) ); ... customers.add( customer );}...
  • 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
  • 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.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 );}...
  • => 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 = 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 );...
  • 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 );}
  • 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,
  • 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:
  • Example application: 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 @Parameter( "CUSTOMER_LIST" ) private List<Customer> customers; ...} public class Customer { @Parameter("CUSTOMERID") private String id; @Parameter( "CUSTNAME" ) private String firstName; ... }
  • The API...
  • Session session = sessionManager.openSession();CustomerList customerList = new CustomerList( 10 );session.execute( customerList );List<Customer> customers = customerList.getCustomers();
  • The configuration...
  • 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>
  • 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="" />" " " <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>
  • 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:
  • 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:
  • Tooling...
  • JBoss Forge plugin: forge/plugin-hibersap See also: 2012/07/12/
  • Hibersap-Camel Component:
  • About me...
  • Carsten ErkerSoftware Architect and Consultantakquinet AG in Berlin /
  • Questions?