slide1 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
E173 Invoking Enterprise Java Beans From PowerBuilder PowerPoint Presentation
Download Presentation
E173 Invoking Enterprise Java Beans From PowerBuilder

Loading in 2 Seconds...

play fullscreen
1 / 59

E173 Invoking Enterprise Java Beans From PowerBuilder - PowerPoint PPT Presentation


  • 789 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'E173 Invoking Enterprise Java Beans From PowerBuilder' - Albert_Lan


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

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
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
invoking enterprise java beans from powerbuilder3
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
overview of the enterprise java bean model
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
overview of the enterprise java bean model5
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)
overview of the enterprise java bean model6
Overview of the Enterprise Java Bean Model

Interfaces and classes

  • Home interface
  • Component interface
  • Local interfaces
  • Implementation class
  • Primary key class
  • Supporting interfaces
overview of the enterprise java bean model interfaces and classes
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
overview of the enterprise java bean model interfaces and classes8
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
overview of the enterprise java bean model interfaces and classes9
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
overview of the enterprise java bean model interfaces and classes10
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)
overview of the enterprise java bean model interfaces and classes11
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
overview of the enterprise java bean model interfaces and classes12
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
overview of the enterprise java bean model13
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
overview of the enterprise java bean model14

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)

invoking enterprise java beans from powerbuilder15
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
invoking enterprise java beans from powerbuilder16

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

implementation of ejb client functionality
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
implementation of ejb client functionality18
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
implementation of ejb client functionality19
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
implementation of ejb client functionality pbejbclient90 pbd classes
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
implementation of ejb client functionality pbejbclient90 pbd classes21
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)
implementation of ejb client functionality pbejbclient90 pbd classes22
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
implementation of ejb client functionality pbejbclient90 pbd classes23
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
implementation of ejb client functionality pbejbclient90 pbd classes24
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
implementation of ejb client functionality pbejbclient90 pbd classes25
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
implementation of ejb client functionality pbejbclient90 pbd classes26
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)
implementation of ejb client functionality pbejbclient90 pbd classes27
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)
implementation of ejb client functionality28
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
implementation of ejb client functionality client coding steps
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.
implementation of ejb client functionality client coding steps30
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
implementation of ejb client functionality client coding steps31
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
implementation of ejb client functionality client coding steps32
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
implementation of ejb client functionality client coding steps33
Implementation of EJB Client FunctionalityClient Coding Steps

Generate proxies for EJB via IDE

implementation of ejb client functionality client coding steps34
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
implementation of ejb client functionality client coding steps35
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
implementation of ejb client functionality client coding steps36
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
implementation of ejb client functionality client coding steps37
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

implementation of ejb client functionality client coding steps38
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"

implementation of ejb client functionality client coding steps39
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

implementation of ejb client functionality client coding steps40
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

implementation of ejb client functionality client coding steps41
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

implementation of ejb client functionality client coding steps42
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

implementation of ejb client functionality client coding steps43
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!

implementation of ejb client functionality advanced topics
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
implementation of ejb client functionality advanced topics45
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)
implementation of ejb client functionality advanced topics46
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
implementation of ejb client functionality advanced topics47
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
implementation of ejb client functionality advanced topics48
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

implementation of ejb client functionality advanced topics49
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

invoking enterprise java beans from powerbuilder50
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
invoking enterprise java beans from powerbuilder51
Invoking Enterprise Java Beans From PowerBuilder

EJB server vendor-specific requirements

  • To use PowerBuilder 9.0’s EJB client feature, some vendor-specific information is required to make the connection to the target EJB server
    • Initial context class
    • Provider URL format
    • Supporting classes required on the client machine
  • Subsequent slides detail specifics for the major J2EE server vendors (URL format includes default values)
ejb server vendor specific requirements
EJB Server Vendor-Specific Requirements

EAServer

  • Initial context:com.sybase.ejb.InitialContextFactory
  • URL format: iiop://localhost:9000
  • Supporting classes: easclient.jareasj2ee.jar

You can access EJBs on EAServer with PowerBuilder 8 on EAServer using the standard connection object (which utilities EAServer’s ORB to connect to the server)

ejb server vendor specific requirements53
EJB Server Vendor-Specific Requirements

WebLogic® Server

  • Initial context:weblogic.jndi.WLInitialContextFactory
  • URL format: t3://localhost:7001
  • Supporting class: weblogic.jar
ejb server vendor specific requirements54
EJB Server Vendor-Specific Requirements

IBM®

  • Initial context:com.ibm.websphere.naming. WsnInitialContextFactory
  • URL format: iiop://localhost:900
  • Supporting classes include weblogic.jar and others obtained from the WebSphere Application Client CD that ships with the J2EE server
  • Note that WebSphere relies on the IBM Java VM not Sun’s
ejb server vendor specific requirements55
EJB Server Vendor-Specific Requirements

ONE Application Server (formerly Application Server)

  • Initial context:com.sun.jndi.cosnaming.CNCtxFactory
  • URL format: iiop://localhost:9010
  • Supporting classes: javax.jar iasclient.jar
  • Additional ORB configuration may also be required when invoking from remote clients
ejb server vendor specific requirements56
EJB Server Vendor-Specific Requirements
  • Initial context:org.jnp.interfaces.NamingContextFactory
  • URL format: jnp://localhost:1099
  • Supporting classes are located in the client subdirectory of the J2EE server installation and include as a minimum
    • jnp-client.jar > jboss-client.jar
    • jnet.jar > jboss-j2ee.jar
invoking enterprise java beans from powerbuilder57
Invoking Enterprise Java Beans From PowerBuilder

Learning more about the EJB client feature

  • EJB specification available at Sun’s web site
  • 3rd party J2EE server web sites
  • Participate in the PowerBuilder 9.0 Beta!
  • Sybase Developer Network (SDN)
invoking enterprise java beans from powerbuilder58
Invoking Enterprise Java Beans From PowerBuilder

Sybase Developer Network (SDN)

  • Single point of access to developer software, services, and up-to-date technical information:
    • White papers and documentation
    • Collaboration with other developers and Sybase engineers
    • Code samples and beta programs
    • Technical recordings
    • Free software
    • Join today: www.sybase.com/developer or visit SDN at TechWave’s Technology Boardwalk