1 / 59

E173 Invoking Enterprise Java Beans From PowerBuilder

E173 Invoking Enterprise Java Beans From PowerBuilder. Jim O’Neil Principal Technical Support Engineer Enterprise Solutions Division joneil@sybase.com. Invoking Enterprise Java Beans From PowerBuilder. Agenda Overview of the Enterprise Java Bean (EJB) Model

Albert_Lan
Télécharger la présentation

E173 Invoking Enterprise Java Beans From PowerBuilder

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. E173 Invoking Enterprise Java Beans From PowerBuilder • Jim O’Neil • Principal Technical Support Engineer • Enterprise Solutions Division • joneil@sybase.com

  2. Invoking Enterprise Java Beans From PowerBuilder Agenda • Overview of the Enterprise Java Bean (EJB) Model • Implementation of EJB client functionality • Architecture overview • Demo (with supporting slides) • Additional resources • EJB server vendor-specific requirements • Learning more about the EJB client feature

  3. Invoking Enterprise Java Beans From PowerBuilder Overview of the Enterprise Java Bean Model • Core concepts • EJB types • Interfaces and classes • Exceptions • The view from a client

  4. Overview of the Enterprise Java Bean Model Core concepts • EJB is Sun’s J2EE transactional, vendor-neutral, enterprise component architecture providing • Modeling of business entities and synchronous and asynchronous processes • Persistence via explicit code (bean-managed) or via services of the EJB server (container-managed) • Vendor neutrality and interoperability • XML driven deployment and configuration

  5. Overview of the Enterprise Java Bean Model EJB types • Session beans model processes • Stateless EJBs are reusable and ‘single-task’ oriented • Stateful EJBs remain associated with a client and are disposed when client is through • Entity beans model objects that persist, often in the form of records in a database • Message-driven beans respond to asynchronous requests from the Java Message Service (JMS)

  6. Overview of the Enterprise Java Bean Model Interfaces and classes • Home interface • Component interface • Local interfaces • Implementation class • Primary key class • Supporting interfaces

  7. Overview of the Enterprise Java Bean ModelInterfaces and Classes Home interface • Provides remote client-view of methods affecting the EJB lifecycle • Extends javax.ejb.EJBHome • With EJB 2.0, can include business methods that are not specific to a given EJB instance • Lacking for message-driven beans since they have no client-view

  8. Overview of the Enterprise Java Bean ModelInterfaces and Classes Component interface • Provides remote client-side view of bean’s business methods • Extends javax.ejb.EJBObject thus providing methods to obtain access to Home interface and Primary Key classes and to test for equality between EJB instances • Lacking for message-driven beans since they have no client-view

  9. Overview of the Enterprise Java Bean ModelInterfaces and Classes Local interfaces • Interfaces (home and component) used by ‘clients’ within the same Java Virtual Machine (VM) as the EJB • javax.ejb.EJBLocalHome • javax.ejb.EJBLocalObject • Benefits lie in faster access and the less complex programming possible due to lack of a network layer • Primary drawback is the tight-coupling of the client to the component thus eliminating location independence and reducing options for redistribution

  10. Overview of the Enterprise Java Bean ModelInterfaces and Classes Implementation class • Implements one of the extensions of the javax.ejb.EnterpriseBean class which provide lifecycle notification methods (e.g., ejbPassivate) • javax.ejb.EntityBean • javax.ejb.SessionBean • javax.ejb.MessageDrivenBean • Class in which EJB developer codes the business methods defined in the bean’s component interface(s)

  11. Overview of the Enterprise Java Bean ModelInterfaces and Classes Primary key class • Applicable only to entity beans • Uniquely differentiates one instance from the other instances sharing the same EJBHome • Class must be a legal value type in RMI-IIOP • Implements java.io.Serializable • Does not implement java.rmi.remote • Does not result in Java->IDL name collisions

  12. Overview of the Enterprise Java Bean ModelInterfaces and Classes Supporting interfaces • Interfaces for serializing EJB references • HomeHandle - reference to EJBHome • Handle - reference to EJBObject • EJBMetaData interface provides mechanism to gather information about the bean • Reference to EJBHome object • Home, component interface and primary key classes • Functions to determine bean type

  13. Overview of the Enterprise Java Bean Model Exceptions • System exceptions are unchecked and propagate to the client as java.rmi.RemoteException • Application exceptions are checked and propagate to the client as a descendant of java.lang.Exception • EJB-specific exceptions include FinderException, CreateException, RemoveException (all in javax.ejb package) • Business method exceptions are at the discretion of the EJB developer

  14. lookup Naming Service initialContext EJB home Home createfindByXXX EJB home stub EJB object Component business method bean instance EJB object stub Overview of the Enterprise Java Bean Model The view from a client Client EJB Container (Server)

  15. Invoking Enterprise Java Beans From PowerBuilder Implementation of EJB client functionality • Feature and implementation overview • Supporting PowerBuilder classes • Client coding steps (Demo) • Advanced topics • Handling exceptions • Accessing message-driven beans • Client-managed transactions

  16. DISCLAIMER PowerBuilder 9.0 is still in its beta release cycle. The information included in this presentation is current as of the beginning of Beta 3. There may be changes to the implementation as presented in these slides. The product documentation available when PowerBuilder 9.0 is released will supersede the information contained in the remainder of this presentation. Invoking Enterprise Java Beans From PowerBuilder Implementation of EJB client functionality

  17. Implementation of EJB Client Functionality Feature overview • Uses Java Native Interface (JNI) for interoperability • Supports 1.0, 1.1, and 2.0 EJBs • Supports client-managed transactions • Supports system and application exception handling • Supplemented by EJB Proxy Generator • PowerBuilder IDE • EJB2PB command line utility

  18. Implementation of EJB Client Functionality Implementation overview • Built using the new PowerBuilder Native Interface (PBNI) which allows developers to • Extend core features of PowerBuilder via custom C++ classes, and • Access PowerBuilder objects from other languages like C++, VisualBasic, and Delphi • For much more detail on PBNI see session E175 Introduction to PowerBuilder Native Interface

  19. Implementation of EJB Client Functionality Supporting PowerBuilder classes • Eight PBNI classes are exposed as custom class user objects in the PBEJBCLIENT90.PBD (and DLL) delivered with PowerBuilder 9 • JavaVM> EJBTransaction • EJBConnection> EJBMetaData • EJBHome> EJBHomeHandle • EJBObject > EJBHandle • The PBD is added to the target’s library list and the DLL placed somewhere in the system PATH

  20. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes JavaVM • Loads and initializes Java VM inside of the PowerBuilder process • Prerequisite for EJB access • Only one Java VM can be loaded for duration of process • Java VM reference variable in PowerBuilder would generally be an instance variable of a singleton NVO or a global variable, depending on the application’s partitioning

  21. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes EJBConnection • EJB client analog of the PowerBuilder connection object used for CORBA access to EAServer • ConnectToServer - sets initialContextgiven ContextFactory class, URL and user credentials • DisconnectServer - closes initialContext • Lookup - returns EJBHome reference given JNDI name • GetEJBTransaction - returns reference enabling client to manage transaction • CreateJavaInstance - creates Java class instance to support EJB methods (e.g., primary key class)

  22. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes EJBHome • Ancestor of home interface classes created by the PowerBuilder EJB Proxy wizard and the EJB2PB command line utility • Wraps methods of javax.ejb.EJBHome • GetHomeHandle • GetEJBMetaData • Remove • Proxies will also be generated for HomeHandle and EJBMetaData

  23. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes EJBObject • Ancestor of remote component interface classes created by the PowerBuilder EJB Proxy wizard and the EJB2PB command line utility • Wraps methods of javax.ejb.EJBObject • GetEJBHome > IsIdentical • GetHandle > Remove • GetPrimaryKey • Proxies will also be generated for Handle and Object

  24. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes EJBTransaction • Populated by GetEJBTransaction method of the EJBConnection object • Wraps javax.transaction.UserTransactionand so providesmethods for initiating, coordinating, and completing a transaction from client application • Begin > GetStatus • Commit > SetRollbackOnly • Rollback > SetTransactionTimeout

  25. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes EJBMetaData • Populated by EJBHome.GetEJBMetaData method • Wraps javax.ejb.EJBMetaDataproviding methods to dynamically determine the EJB implementation • GetHomeInterfaceClass • GetPrimaryKeyClass • GetRemoteInterfaceClass • GetEJBHome • IsSession • IsStatelessSession

  26. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes EJBHomeHandle • Populated by EJBHome.GetHomeHandle method • Wraps javax.ejb.HomeHandleproviding a mechanism to serialize the reference to an EJB home interface for later use • GetEJBHome method converts from HomeHandle back to a home interface reference (EJBHome)

  27. Implementation of EJB Client FunctionalityPBEJBCLIENT90.PBD Classes EJBHandle • Populated by EJBObject.GetHandle method • Wraps javax.ejb.Handleproviding a mechanism to the serialize reference to an EJB instance for later use • GetEJBObject converts from Handle back to a remote component interface reference (EJBObject)

  28. Implementation of EJB Client Functionality Client coding steps • Get EJB stubs and other required client classes from EJB server • Setup Java environment • Add EJB PBNI classes to PowerBuilder target • Generate PowerBuilder proxies for EJB • Code the client application accessing the EJB

  29. Implementation of EJB Client FunctionalityClient Coding Steps Get EJB stubs and other required client classes from EJB server • Each vendor has client classes required in the CLASSPATH (e.g., weblogic.jar for BEA WebLogic) • Since this is a JNI implementation, the Java stub classes for the EJB are also required. Instructions for generating and compiling those stubs will also be detailed by the EJB server vendor. With EAServer, for example, you would use Jaguar Manager.

  30. Implementation of EJB Client FunctionalityClient Coding Steps Setup Java environment • Set the JAVA_HOME environment variable to the directory containing the JDK • Make sure jvm.dll is in the path (the file is usually located in %JAVA_HOME%/jre/bin/classic) • Ensure correct operation of javap (which is used for generation of proxies) • javap.exe is usually in %JAVA_HOME%/bin • javax.ejb classes must be in CLASSPATH

  31. Implementation of EJB Client FunctionalityClient Coding Steps Add EJB PBNI classes to PowerBuilder target • Add PBEJBCLIENT90.PBDto your PowerScript target’s library list • Ensure that PBEJBCLIENT90.DLL is in your PATH • Ensure that PBEJBCLIENT90.JAR is in your CLASSPATH

  32. Implementation of EJB Client FunctionalityClient Coding Steps Generate proxies for EJB • PowerBuilder uses proxies that ‘wrap’ the EJB stubs as well as any intermediary Java classes that may be required • EJB Client Proxy Wizard • EJB2PB command line utility

  33. Implementation of EJB Client FunctionalityClient Coding Steps Generate proxies for EJB via IDE

  34. Implementation of EJB Client FunctionalityClient Coding Steps Generate proxies for EJB via EJB2PB • EJB2PB.EXE is a command-line program found in the Shared/PowerBuilder folder • EJB2PB [-classpath pathlist] EJBName [prefix] • pathlist - optional extension to system CLASSPATH for finding EJBName class • EJBName - remote component interface class name • prefix - optional prefix for proxies • Output is two or more .srx files which can then be imported into a PowerScript target

  35. Implementation of EJB Client FunctionalityClient Coding Steps Code the client application accessing the EJB • Create Java VM • Connect to EJB server • Look up EJB’s home interface • Access EJB’s remote component interface • Call business method(s) • Disconnect from EJB server

  36. Implementation of EJB Client FunctionalityClient Coding Steps Create the JavaVM • Define JVM reference variable as a global variableJavaVM gJVM • Declare properties array and classpath variables • string props[]- arguments to JAVA.EXE command line (analogous to Java Properties) • string classpath - additional classes to be appended to system CLASSPATH prior to starting the Java VM

  37. Implementation of EJB Client FunctionalityClient Coding Steps Create the JavaVM • Create Java VM reference long llRet llRet = gJVM.createJavaVM(classpath, props) IF (llRet <> 0) THEN MessageBox("Failed to Create JavaVM", "Return Code: " + String(llRet), StopSign!) END IF

  38. Implementation of EJB Client FunctionalityClient Coding Steps Connect to EJB server • Create an EJBConnection instance EJBConnection lcWebsphere lcWebsphere = CREATE EJBConnection • Initialize required connectivity properties string props[] props[1] = "javax.naming.Context.INITIAL_CONTEXT_FACTORY=weblogic.jndi.WLInitialContextFactory" props[2] = "javax.naming.Context.PROVIDER_URL=t3://localhost:7001"

  39. Implementation of EJB Client FunctionalityClient Coding Steps Connect to EJB server • Connect to the server TRY lcWebsphere.connectToServer(props) CATCH (Exception e1) MessageBox("Connection Exception", e1.getMessage(), StopSign!) END TRY

  40. Implementation of EJB Client FunctionalityClient Coding Steps Lookup EJB’s home interface TraderHome lejbHome // EJB Home proxy TRY lejbHome = lcWebsphere.lookup("TraderHome", "statelessSession.TraderHome", "examples.ejb11.basic.statelessSession. TraderHome") CATCH (NamingException e2) MessageBox("Lookup Failed", e2.getMessage()) CATCH (Throwable e3) MessageBox("Other Error", e3.getMessage()) END TRY

  41. Implementation of EJB Client FunctionalityClient Coding Steps Access EJB’s remote component interface Trader lejbObject // EJB proxyTRY lejbObject = lejbHome.ejbCreate() CATCH (CreateException e4) MessageBox(”EJB Creation Failed", e4.getMessage()) CATCH (Throwable e5) MessageBox(”Other Error", e5.getMessage()) END TRY

  42. Implementation of EJB Client FunctionalityClient Coding Steps Call business method(s) TradeResult lnvRet // Java class proxy TRY lnvRet = lejbObject.buy("SY", 1000) MessageBox(”Purchase Info", "Purchase of: " + String(lnvRet.getNumberTraded()) + " shares of " + lnvRet.getStockSymbol() + " was successful!") CATCH (Throwable e6) MessageBox(”Unexpected Error", e6.getMessage()) END TRY

  43. Implementation of EJB Client FunctionalityClient Coding Steps Disconnect from EJB server lcWebsphere.disconnectServer() As in most distributed processing scenarios,disconnecting from the client does not automatically free server resources and could result in orphaned instances!

  44. Implementation of EJB Client FunctionalityAdvanced Topics Handling exceptions • EJB client capability requires heavy use of the TRY-CATCH-FINALLY construct in PowerScript • Java exceptions raised from EJBs extend java.lang.Exception (with few exceptions) • Client proxies wrapping ‘system’ exceptions like java.rmi.RemoteException, etc. extend the PowerBuilder core Exception class • Application exceptions thrown by EJBs are likewise handled by PowerBuilder Exception class proxies

  45. Implementation of EJB Client FunctionalityAdvanced Topics Accessing message-driven beans • Message-driven beans have no client view • No home or component interfaces • No direct invocation mechanism from a client • Message-driven beans ‘listen’ to messages delivered by the Java Message Service (JMS)

  46. Implementation of EJB Client FunctionalityAdvanced Topics Accessing message-driven beans • A PowerBuilder client can send a JMS message to a ‘listening’ message-driven bean • Via the CORBA layer to EAServer’s Message Service • Via HTTP using PowerBuilder’s PostURL function to invoke a servlet that publishes a JMS message • Via JNI • Via 3rd party tools like JMSCourier

  47. Implementation of EJB Client FunctionalityAdvanced Topics Client-managed transactions • EJBTransaction wraps the functionality of javax.transaction.UserTransaction providing a complete implementation of the Java interface (http://java.sun.com/products/jta) • PowerBuilder can thus serve as the controller of a transaction involving bean-managed EJBs versus requiring a “coordinator” EJB on the server to which the client delegates the handling of the transaction

  48. Implementation of EJB Client FunctionalityAdvanced Topics Client-managed transactions • Obtain reference to the transaction EJBConnection conn EJBTransaction trans string properties[] conn = create EJBConnection TRY conn.connectToServer(props) trans = conn.getEJBTransaction() CATCH (Exception e) ... END TRY

  49. Implementation of EJB Client FunctionalityAdvanced Topics Client-managed transactions • Manage the transaction from the client TRY trans.Begin() // Create a component and call methods to be // executed within the transaction ... // Commit the transaction trans.Commit() CATCH (Exception e) trans.Rollback() END TRY

  50. Invoking Enterprise Java Beans From PowerBuilder EJB server vendor-specific requirements • In addition to Sybase EAServer, PowerBuilder 9.0 is tested against • BEA™Systems, Inc. WebLogic® Server • IBM® WebSphere® • There is, however, nothing in the implementation to preclude connecting to any other J2EE compliant application server

More Related