integrating sap the java ee way - jboss one day talk 2012

103
Integrating SAP the Java EE way JBoss OneDayTalk 2012 Carsten Erker

Upload: hwilming

Post on 05-Dec-2014

4.075 views

Category:

Documents


3 download

DESCRIPTION

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.

TRANSCRIPT

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

Integrating SAP the Java EE way

JBoss OneDayTalk 2012

Carsten Erker

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

Remember those days...?

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

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 ); } ...

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

Who is still doing this?

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

Nowadays we do something like this...

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

@Entitypublic class Customer{ @Id @GeneratedValue private Long id; private String firstName; private String lastName; ...}

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

List<Customer> customers = entityManager .createQuery( "select c from Customer c" ) .getResultList();

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

When calling business logic in SAP we don‘t want to go the old

way...

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

Setting the stage...

Courtesy of Special Collections, University of Houston Libraries. UH Digital Library.

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

The SAP Java Connector (JCo)

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

How it works...

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

Calls function modules in SAP backend

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

Function modules are a piece of code written in

ABAP

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

They have an interface with different types of

parameters to pass data

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

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*"-----------------------------------------------------

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

JCo runs on top of the SAP-proprietary

RFC interface (Remote Function Call)

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

JCo can be used in Client and Server mode

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

Example code calling a function module in

SAP...

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

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 );}...

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

=> Lots of glue code, tedious mapping of

parameters

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

But - JCo has some benefits that make it a good fit for business

apps...

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

It can be used with Transactions

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

It implements Connection Pooling

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

SAP functions can be called asynchronously

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

It is fast

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

The bad points...

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

The programming model

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

Does not fit very well into the Java EE world:

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

Not trivial to use it with CMT

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

The same goes for Security

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

The alternative: Java EE Connector Architecture (JCA)

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

JCA is a Java EE standard

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

JCA was created for the interaction of Java EE applications with

Enterprise Information Systems, such as SAP

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

A Resource Adapter is an implementation of JCA for a certain EIS

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

A RA is deployed in an Application Server in form of a Resource

Archive (.rar)

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

The RA takes care of...

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

Transaction Management

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

Connection Management

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

Security Management

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

... all this in a standard way

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

JCA solves a lot of problems, except one...

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

The programming model

:-(

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

JCA defines the Common Client

Interface (CCI) for a standard way to access

an EIS

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

Because of the many different natures of

EIS‘s, it is overly generic

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

It operates on Lists, Maps and/or ResultSets representing the data

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

Additionally, a lot of glue code needs to be

written

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

In this, it is not too different from SAP‘s

Java Connector...

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

@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 );...

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

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 );}

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

SAP offers a RA that only runs on SAP

Application Servers

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

Any more alternatives?

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

For read-only and less frequent SAP calls

consider using Web Services

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

A SOA platform may be well suited for not-so-

tight integration

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

Introducing the cool stuff...

Photo by Alan Levine, CC-BY 2.0, http://www.flickr.com/photos/cogdog

Page 55: Integrating SAP the Java EE Way - JBoss One Day talk 2012
Page 56: Integrating SAP the Java EE Way - JBoss One Day talk 2012

It implements JCA version 1.5

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

It currently only supports the

outbound way

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

Under the hood, it uses the SAP Java

Connector (JCo)

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

The next steps...

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

Upgrading Cuckoo to JCA version 1.6

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

Adding inbound capability

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

Cuckoo is Open Source under

LGPL License

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

More info:https://sourceforge.net/p/cuckoo-ra/

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

What was all the fuss about the programming

model?

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

We still have to solve this problem...

Page 67: Integrating SAP the Java EE Way - JBoss One Day talk 2012
Page 68: Integrating SAP the Java EE Way - JBoss One Day talk 2012

Hibersap is something like an O/R mapper for

SAP functions

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

It makes use of Java annotations to map

SAP functions and their parameters to Java

objects

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

It has an API that is quite similar to Hibernate/JPA

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

Thus it fits very well into the modern Java

world

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

Hibersap takes care of most of the glue code

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

It can be either used with JCo or with a JCA

Resource Adapter

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

Switching between them is a matter of

configuration

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

This makes integration testing a breeze

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

Finally, some code...

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

The business object...

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

public class Customer{ @Parameter("CUSTOMERID") private String id;

@Parameter( "CUSTNAME" ) private String firstName; ...}

@Bapi( "BAPI_FLCUST_GETLIST" )public class CustomerList{ @Import @Parameter("MAX_ROWS") private int maxRows;

@Table @Parameter( "CUSTOMER_LIST" ) private List<Customer> customers; ...}

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

The API...

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

Session session = sessionManager.openSession();

CustomerList customerList = new CustomerList( 10 );session.execute( customerList );

List<Customer> customers = customerList.getCustomers();

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

The configuration...

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

<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 => JCA

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

<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>

META-INF/hibersap.xml => JCo

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

Bean Validation can be used on parameter

fields...

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

@Parameter( "COUNTR_ISO" ) @NotNull @Size(min = 2, max = 2) private String countryKeyIso;

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

Converters allow for data type or format

conversion on parameter fields...

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

@Parameter( "TYPE" ) @Convert( converter = SeverityConverter.class ) private Severity severity;

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

Hibersap is Open Source and licensed

under LGPL

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

More info:http://hibersap.org

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

Putting it all together...

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

In a Java EE application we should use Cuckoo RA

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

Thus, we can make use of CMT in EJBs

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

...and all the other benefits of JCA

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

Using Hibersap, we gain an elegant and

lightweight programming model

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

... especially when using Hibersap‘s EJB tools

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

Thus, we get much nicer code that is easier to understand, maintain

and test

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

Tooling...

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

Hibersap-Camel Component:

https://github.com/bjoben/camel-hibersap

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

About me...

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

Carsten ErkerSoftware Architect and Consultantakquinet AG in Berlin / Germany

[email protected]

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

Questions?