Download File

1,797 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,797
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Download File

  1. 1. PWB519 Accessing Third-Party Enterprise JavaBeans Servers from PowerBuilder 9.0 Jim O’Neil Principal Technical Support Engineer Sybase, Inc. (Concord, MA) [email_address]
  2. 2. Accessing Third-Party EJB Servers <ul><li>Agenda </li></ul><ul><li>Overview of the Enterprise JavaBeans (EJB) Model </li></ul><ul><li>PowerBuilder EJB client implementation </li></ul><ul><li>Coding a PowerBuilder EJB client application </li></ul><ul><li>Deploying PowerBuilder NVOs to EJB servers </li></ul><ul><li>Additional resources </li></ul>
  3. 3. Accessing Third-Party EJB Servers <ul><li>Agenda </li></ul><ul><li>Overview of the Enterprise JavaBeans (EJB) Model </li></ul><ul><li>PowerBuilder EJB client implementation </li></ul><ul><li>Coding a PowerBuilder EJB client application </li></ul><ul><li>Deploying PowerBuilder NVOs to EJB servers </li></ul><ul><li>Additional resources </li></ul>
  4. 4. Overview of the Enterprise JavaBeans Model <ul><li>EJB is Sun’s J2EE transactional, vendor-neutral, enterprise component architecture providing </li></ul><ul><li>Modeling of business entities and synchronous and asynchronous processes </li></ul><ul><li>Persistence via explicit code (bean-managed) or via services of the EJB server (container-managed) </li></ul><ul><li>Vendor neutrality and interoperability </li></ul><ul><li>XML driven deployment and configuration </li></ul>Core Concepts
  5. 5. Overview of the Enterprise JavaBeans Model <ul><li>EJB types </li></ul><ul><li>Session beans model processes </li></ul><ul><ul><li>Stateless EJBs are reusable and ‘single-task’ oriented </li></ul></ul><ul><ul><li>Stateful EJBs remain associated with a client and are disposed when client is through </li></ul></ul><ul><li>Entity beans model objects that persist, often in the form of records in a database </li></ul><ul><li>Message-driven beans respond to asynchronous requests from the Java Message Service (JMS) </li></ul>Core Concepts
  6. 6. Overview of the Enterprise JavaBeans Model business method create findByPrimaryKey J2EE Server Client Application home interface stub EJB Home Implementation class ancillary Java classes remote interface stub EJB Object return value lookup Initial Context Java Message Service Message-driven bean onMessage JNDI Service topic/queue  External messaging client applications messages Enterprise Information System Representative Enterprise JavaBeans Server and Client Application
  7. 7. Overview of the Enterprise JavaBeans Model <ul><li>Java Naming and Directory Interface (JNDI) </li></ul><ul><li>Provides a standardized way of accessing resources in a distributed environment </li></ul><ul><li>Protocol and naming service agnostic </li></ul><ul><ul><li>DNS </li></ul></ul><ul><ul><li>NDIS </li></ul></ul><ul><ul><li>LDAP </li></ul></ul><ul><ul><li>X.500 </li></ul></ul><ul><li>Implemented by the javax.naming package and three other packages below it </li></ul><ul><li>javax.naming.InitialContext is the entry point to the EJB Server </li></ul><ul><ul><li>bind – associates a name with an object </li></ul></ul><ul><ul><li>lookup – finds an object given the name </li></ul></ul>Interfaces and Classes
  8. 8. Overview of the Enterprise JavaBeans Model <ul><li>Home interface </li></ul><ul><li>Provides remote client-view of methods affecting the EJB lifecycle </li></ul><ul><li>Extends javax.ejb.EJBHome </li></ul><ul><li>Can include business methods that are not specific to a given EJB instance </li></ul><ul><li>Lacking for message-driven beans since they have no client-view </li></ul>Interfaces and Classes
  9. 9. Overview of the Enterprise JavaBeans Model <ul><li>Component interface </li></ul><ul><li>Provides remote client-side view of bean’s business methods </li></ul><ul><li>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 </li></ul><ul><li>Lacking for message-driven beans since they have no client-view </li></ul>Interfaces and Classes
  10. 10. Overview of the Enterprise JavaBeans Model <ul><li>Implementation class </li></ul><ul><li>Implements one of the extensions of the javax.ejb.EnterpriseBean class which provide lifecycle notification methods (e.g., ejbPassivate ) </li></ul><ul><ul><li>javax.ejb.EntityBean </li></ul></ul><ul><ul><li>javax.ejb.SessionBean </li></ul></ul><ul><ul><li>javax.ejb.MessageDrivenBean </li></ul></ul><ul><li>Class in which EJB developer codes the business methods defined in the bean’s component interface(s) </li></ul>Interfaces and Classes
  11. 11. Overview of the Enterprise JavaBeans Model <ul><li>Primary key class </li></ul><ul><li>Applicable only to entity beans </li></ul><ul><li>Uniquely differentiates one instance from the other instances sharing the same EJBHome </li></ul><ul><li>Class must be a legal value type in RMI-IIOP </li></ul><ul><ul><li>Implements java.io.Serializable </li></ul></ul><ul><ul><li>Does not implement java.rmi.remote </li></ul></ul>Interfaces and Classes
  12. 12. Overview of the Enterprise JavaBeans Model <ul><li>Exceptions </li></ul><ul><li>System exceptions are unchecked and propagate to the client as java.rmi.RemoteException </li></ul><ul><li>Application exceptions are checked and propagate to the client as a descendant of java.lang.Exception </li></ul><ul><ul><li>EJB-specific exceptions include FinderException , CreateException , RemoveException (all in javax.ejb package) </li></ul></ul><ul><ul><li>Business method exceptions are at the discretion of the EJB developer </li></ul></ul>Interfaces and Classes
  13. 13. Overview of the Enterprise JavaBeans Model <ul><li>Other interfaces and classes </li></ul><ul><li>Local interfaces used for access within server context (e.g., intercomponent calls, servlet invocation) </li></ul><ul><ul><li>javax.ejb.EJBLocalHome </li></ul></ul><ul><ul><li>javax.ejb.EJBLocalObject </li></ul></ul><ul><li>Interfaces for serializing EJB references </li></ul><ul><ul><li>HomeHandle - reference to EJBHome </li></ul></ul><ul><ul><li>Handle - reference to EJBObject </li></ul></ul><ul><li>EJBMetaData interface provides mechanism to gather information about the bean </li></ul><ul><ul><li>Reference to EJBHome object </li></ul></ul><ul><ul><li>Home, component interface and primary key classes </li></ul></ul><ul><ul><li>Functions to determine bean type </li></ul></ul>Interfaces and Classes
  14. 14. Accessing Third-Party EJB Servers <ul><li>Agenda </li></ul><ul><li>Overview of the Enterprise JavaBeans (EJB) Model </li></ul><ul><li>PowerBuilder EJB client implementation </li></ul><ul><li>Coding a PowerBuilder EJB client application </li></ul><ul><li>Deploying PowerBuilder NVOs to EJB servers </li></ul><ul><li>Additional resources </li></ul>
  15. 15. PowerBuilder EJB Client Implementation <ul><li>Feature overview </li></ul><ul><li>Uses Java Native Interface (JNI) for interoperability </li></ul><ul><li>Supports 1.0, 1.1, and 2.0 EJBs </li></ul><ul><li>Supports client-managed transactions </li></ul><ul><li>Supports system and application exception handling </li></ul><ul><li>Supplemented by EJB Proxy Generator </li></ul><ul><ul><li>PowerBuilder IDE </li></ul></ul><ul><ul><li>EJB2PB90 command line utility </li></ul></ul>Architecture Overview
  16. 16. PowerBuilder EJB Client Implementation <ul><li>Implementation overview </li></ul><ul><li>Built using the PowerBuilder Native Interface (PBNI) which allows developers to </li></ul><ul><ul><li>Extend core features of PowerBuilder via custom C++ classes, and </li></ul></ul><ul><ul><li>Access PowerBuilder objects from other languages like C++, VisualBasic, and Delphi </li></ul></ul><ul><li>Three PBNI classes are exposed in the PBEJBCLIENT90.PBD </li></ul><ul><ul><li>JavaVM </li></ul></ul><ul><ul><li>EJBConnection </li></ul></ul><ul><ul><li>EJBTransaction </li></ul></ul><ul><li>EJBLocator Java class, which wraps javax.naming.InitialContext , is contained in PBEJBCLIENT90.JAR </li></ul><ul><li>PowerBuilder proxy objects represent all other Java classes and interfaces required for a given EJB </li></ul><ul><li>JDK required for development, JRE for runtime – PowerBuilder installs Sun JDK 1.4 by default to ease configuration issues </li></ul>Architecture Overview
  17. 17. PowerBuilder EJB Client Implementation <ul><li>JavaVM object </li></ul><ul><li>Loads and initializes Java VM inside of the PowerBuilder process </li></ul><ul><li>Supported by configurable PowerBuilder ‘JVM Service’ which handles all JDK/JRE needs in PowerBuilder environment </li></ul><ul><ul><li>JDBC Connectivity </li></ul></ul><ul><ul><li>EJB Client Functionality </li></ul></ul><ul><ul><li>JSP Deployment </li></ul></ul><ul><ul><li>XSL-FO </li></ul></ul><ul><li>Be aware… </li></ul><ul><ul><li>Once Java VM is loaded, for whatever reason, by PowerBuilder, you cannot modify its environment, classpath, etc.; use return value of CreateJavaVM to determine if Java VM was actually loaded or already resident </li></ul></ul><ul><ul><li>Debug option for CreateJavaVM method is not available for JDK 1.4 </li></ul></ul><ul><ul><li>Methods exist for determining the actual class for a returned interface, downcasting classes, determining interfaces implemented by classes, etc. </li></ul></ul>Architecture Overview
  18. 18. PowerBuilder EJB Client Implementation <ul><li>PowerBuilder JVM Service configuration </li></ul><ul><li>JDK and JRE Location can be specified in System Options dialog </li></ul><ul><li>JVM properties and CLASSPATH entries are in the registry </li></ul><ul><ul><li>Design-time: KLMSybasePowerBuilder9.0JavaPBIDEConfig </li></ul></ul><ul><ul><ul><li>PBJVMConfig </li></ul></ul></ul><ul><ul><ul><li>PBJVMProps </li></ul></ul></ul><ul><ul><ul><li>PBSysClasspath </li></ul></ul></ul><ul><ul><li>Run-time: KLMSybasePowerBuilder9.0JavaPBRTConfig </li></ul></ul><ul><ul><ul><li>PBJVMConfig </li></ul></ul></ul><ul><ul><ul><li>PBJVMProps </li></ul></ul></ul>Architecture Overview
  19. 19. PowerBuilder EJB Client Implementation Architecture Overview <ul><li>EJBConnection object </li></ul><ul><li>Analog of the PowerBuilder Connection object </li></ul><ul><li>Serves as a PowerBuilder façade to the InitialContext class within the PBEJBCLIENT90.JAR file </li></ul><ul><ul><li>ConnectToServer - sets initialContext </li></ul></ul><ul><ul><li>DisconnectServer - closes initialContext </li></ul></ul><ul><ul><li>Lookup - returns EJBHome reference given JNDI name </li></ul></ul><ul><ul><li>GetEJBTransaction - returns reference enabling client-managed transactions </li></ul></ul><ul><ul><li>CreateJavaInstance – create a Java class within client Java VM </li></ul></ul><ul><li>Be aware… </li></ul><ul><ul><li>Properties array argument to ConnectToServer is the only ‘vendor-specific’ requirement; PowerBuilder doesn’t ‘know’ what EJB server you are using </li></ul></ul><ul><ul><li>CreateJavaInstance is used to create a Java class on the client – you don’t need an EJB server at all to do this! </li></ul></ul>
  20. 20. PowerBuilder EJB Client Implementation Architecture Overview <ul><li>EJBTransaction object </li></ul><ul><li>Populated by GetEJBTransaction method of the EJBConnection object </li></ul><ul><li>Wraps javax.transaction.UserTransaction and so provides methods for initiating, coordinating, and completing a transaction from a client application </li></ul><ul><ul><li>Begin  GetStatus </li></ul></ul><ul><ul><li>Commit  SetRollbackOnly </li></ul></ul><ul><ul><li>Rollback  SetTransactionTimeout </li></ul></ul><ul><li>Be aware… </li></ul><ul><ul><li>Not all EJB servers support client-managed transactions </li></ul></ul><ul><ul><li>Best practices have a session bean on the server controlling the transaction </li></ul></ul>
  21. 21. PowerBuilder EJB Client Implementation Architecture Overview <ul><li>EJBLocator Java class </li></ul><ul><li>Single Java class residing in PBEJBCLIENT90.JAR: com.sybase.powerbuilder.ejb.EJBLocator </li></ul><ul><ul><li>Four methods, all wrapped by the EJBConnection PBNI object </li></ul></ul><ul><ul><li>Required for deployed applications </li></ul></ul><ul><li>JAR is included in CLASSPATH managed by JVM Service with the assumption that it is located relative to the PBJVM90.DLL </li></ul>
  22. 22. PowerBuilder EJB Client Implementation Architecture Overview <ul><li>PowerBuilder proxy objects </li></ul><ul><li>Used to delegate requests to and from the underlying Java classes </li></ul><ul><li>Inherited from Nonvisualobject or Exception class like other PowerBuilder proxies </li></ul><ul><li>Generated using javap command in JDK </li></ul><ul><ul><li>EJB Client Proxy wizard / project in PowerBuilder development environment </li></ul></ul><ul><ul><li>EJB2PB90 stand-alone utility </li></ul></ul><ul><li>Includes </li></ul><ul><ul><li>Public methods defined on its associated Java class </li></ul></ul><ul><ul><li>Public class variables in PowerBuilder 9.0.1 and later </li></ul></ul><ul><li>To avoid conflicts with PowerBuilder reserved words, names may be decorated </li></ul><ul><ul><li>Proxy name prefix “java_”, for example, java_integer </li></ul></ul><ul><ul><li>Method name postfix ”_j”, for example, and_j </li></ul></ul><ul><li>Java methods that return arrays will return any in PowerBuilder </li></ul><ul><li>Proxies are also supported by a PowerBuilder mapping structure that correlates the PowerBuilder proxy name to the underlying Java class name </li></ul>
  23. 23. PowerBuilder EJB Client Implementation Architecture Overview Sample source for a PowerBuilder proxy object $PBExportHeader$ejbobject.srx $PBExportComments$Proxy imported from EJB via EJB Proxy generator. global type EJBObject from Remote end type type variables protected: string EJBObject_javaname= &quot;javax.ejb.EJBObject&quot; end variables forward prototypes public: function EJBHome getEJBHome() throws RemoteException alias for &quot;getEJBHome,()Ljavax/ejb/EJBHome;&quot; function any getPrimaryKey() throws RemoteException alias for &quot;getPrimaryKey,()Ljava/lang/Object;&quot; subroutine remove() throws RemoteException, RemoveException alias for &quot;remove,()V&quot; function Handle getHandle() throws RemoteException alias for &quot;getHandle,()Ljavax/ejb/Handle;” function boolean isIdentical( EJBObject EJBObject_1) throws RemoteException alias for &quot;isIdentical,(Ljavax/ejb/EJBObject;)Z&quot; end prototypes
  24. 24. Accessing Third-Party EJB Servers <ul><li>Agenda </li></ul><ul><li>Overview of the Enterprise JavaBeans (EJB) Model </li></ul><ul><li>PowerBuilder EJB client implementation </li></ul><ul><li>Coding a PowerBuilder EJB client application </li></ul><ul><li>Deploying PowerBuilder NVOs to EJB servers </li></ul><ul><li>Additional resources </li></ul>
  25. 25. Coding a PowerBuilder EJB Client Application <ul><li>Setting up your environment </li></ul><ul><ul><li>Adding the EJB client implementation to your target </li></ul></ul><ul><ul><li>Generating proxies </li></ul></ul><ul><li>Basic client coding steps </li></ul><ul><li>Advanced topics </li></ul>
  26. 26. Coding a PowerBuilder EJB Client Application <ul><li>Adding the EJB Client implementation to your target </li></ul><ul><li>Include PBEJBCLIENT90.PBD in your target’s library list </li></ul>Setting Up Your Environment
  27. 27. Coding a PowerBuilder EJB Client Application <ul><li>Generating proxies </li></ul><ul><li>Use EJB Client Proxy Wizard </li></ul>Setting Up Your Environment EJB home interface name must be same as remote interface name followed by ‘Home’
  28. 28. Coding a PowerBuilder EJB Client Application <ul><li>Generating proxies </li></ul><ul><li>Use EJB2PB90.EXE, a completely stand-alone utility, and import resulting files into PowerBuilder target </li></ul><ul><li>Syntax: ejb2pb90 [-classpath pathlist] EJBName [prefix] </li></ul><ul><li>Output includes </li></ul><ul><ul><li>Various .srx files – the proxy objects </li></ul></ul><ul><ul><li>ejbproxies.txt – listing the .srx files produced </li></ul></ul><ul><ul><li>ejbproxies.err – containing the diagnostic message in the event an error occurs while the proxies are generated </li></ul></ul><ul><ul><li>$EJBName$_ejb_pb_mapping.srs – the mapping structure </li></ul></ul>Setting Up Your Environment
  29. 29. Coding a PowerBuilder EJB Client Application <ul><li>Basic client coding steps </li></ul><ul><li>Initialize the Java VM </li></ul><ul><li>Connect to the EJB Server </li></ul><ul><li>Lookup an EJB </li></ul><ul><li>Invoke methods on the EJB </li></ul><ul><li>Disconnect from the EJB Server </li></ul>
  30. 30. Coding a PowerBuilder EJB Client Application <ul><li>Initialize the Java VM </li></ul><ul><ul><li>TRY </li></ul></ul><ul><ul><li>g_JavaVM = CREATE JavaVM </li></ul></ul><ul><ul><li>CHOOSE CASE g_JavaVM.CreateJavaVM(is_ClassPath, false) </li></ul></ul><ul><ul><li>CASE 0 </li></ul></ul><ul><ul><li>// JVM just loaded </li></ul></ul><ul><ul><li>CASE 1 </li></ul></ul><ul><ul><li>// JVM was already loaded, is_ClassPath ignored </li></ul></ul><ul><ul><li>CASE -1 </li></ul></ul><ul><ul><li>// failure, likely due to not finding JVM.DLL </li></ul></ul><ul><ul><li>CASE -2 </li></ul></ul><ul><ul><li>// failure, do to not finding EJBLocator class </li></ul></ul><ul><ul><li>END CHOOSE </li></ul></ul><ul><ul><li>CATCH (PBXRuntimeError prte) </li></ul></ul><ul><ul><li>// catch any exception raised in PBNI extension </li></ul></ul><ul><ul><li>END TRY </li></ul></ul>Basic Client Coding Steps
  31. 31. Coding a PowerBuilder EJB Client Application <ul><li>Connect to the EJB Server </li></ul><ul><ul><li>TRY </li></ul></ul><ul><ul><li>g_EJBConn = CREATE EJBConnection </li></ul></ul><ul><ul><li>// set initial context properties </li></ul></ul><ul><ul><li>ls_props[1] = &quot;javax.naming.Context.INITIAL_CONTEXT_FACTORY=&quot; + & </li></ul></ul><ul><ul><li> &quot;com.sybase.ejb.InitialContextFactory&quot; </li></ul></ul><ul><ul><li>ls_props[2] = &quot;javax.naming.Context.PROVIDER_URL=iiop://localhost:9000&quot; </li></ul></ul><ul><ul><li>ls_props[3] = &quot;javax.naming.Context.SECURITY_PRINCIPAL=jagadmin&quot; </li></ul></ul><ul><ul><li>ls_props[4] = &quot;javax.naming.Context.SECURITY_CREDENTIALS=&quot; </li></ul></ul><ul><ul><li>// connect to EJB server </li></ul></ul><ul><ul><li>g_EJBConn.connectToServer(ls_props) </li></ul></ul><ul><ul><li>CATCH (NamingException ne) </li></ul></ul><ul><ul><li>// naming exception may occur when initial context class not found </li></ul></ul><ul><ul><li>CATCH (PBXRuntimeError prte) </li></ul></ul><ul><ul><li>// catch any exception raised in PBNI extension </li></ul></ul><ul><ul><li>END TRY </li></ul></ul>Basic Client Coding Steps
  32. 32. Coding a PowerBuilder EJB Client Application <ul><li>Lookup an EJB </li></ul><ul><ul><li>TRY </li></ul></ul><ul><ul><li>g_HelloHome = g_EJBConn.lookup(&quot;HelloHome&quot;, &quot;PB9/Hello&quot;, &quot;pb9.HelloHome&quot;) </li></ul></ul><ul><ul><li>g_hello = g_helloHome.create() </li></ul></ul><ul><ul><li>CATCH (NamingException ne) </li></ul></ul><ul><ul><li>// raised if EJB not located </li></ul></ul><ul><ul><li>CATCH (CreateException ce) </li></ul></ul><ul><ul><li>// raised if problem in instantiating EJB </li></ul></ul><ul><ul><li>CATCH (RemoteException re) </li></ul></ul><ul><ul><li>// raised whenever there is a unchecked exception on server </li></ul></ul><ul><ul><li>CATCH (PBXRuntimeError prte) </li></ul></ul><ul><ul><li>// raised whenever there is an exception in the PBNI extension </li></ul></ul><ul><ul><li>END TRY </li></ul></ul>Basic Client Coding Steps
  33. 33. Coding a PowerBuilder EJB Client Application <ul><li>Invoke methods on the EJB </li></ul><ul><ul><li>TRY </li></ul></ul><ul><ul><li>MessageBox(&quot;Hello&quot;, g_hello.sayHello() </li></ul></ul><ul><ul><li>CATCH (YourCustomException yce) </li></ul></ul><ul><ul><li>// handle user-defined exception raised by EJB, for example, an exception </li></ul></ul><ul><ul><li>// indicating that an account lacks sufficient funds for withdrawal </li></ul></ul><ul><ul><li>CATCH (RemoteException re) </li></ul></ul><ul><ul><li>// raised whenever there is a unchecked exception on server </li></ul></ul><ul><ul><li>CATCH (PBXRuntimeError prte) </li></ul></ul><ul><ul><li>// raised whenever there is an exception in the PBNI extension </li></ul></ul><ul><ul><li>END TRY </li></ul></ul>Basic Client Coding Steps
  34. 34. Coding a PowerBuilder EJB Client Application <ul><li>Disconnect from the EJB server </li></ul><ul><ul><li>TRY </li></ul></ul><ul><ul><li>g_EJBConn.disconnectServer() </li></ul></ul><ul><ul><li>CATCH (NamingException ne) </li></ul></ul><ul><ul><li>// naming exception is unlikely here, but could be thrown by underlying </li></ul></ul><ul><ul><li>// Java InitialContext object </li></ul></ul><ul><ul><li>CATCH (PBXRuntimeError prte) </li></ul></ul><ul><ul><li>// raised whenever there is an exception in the PBNI extension </li></ul></ul><ul><ul><li>END TRY </li></ul></ul>Basic Client Coding Steps As in many distributed processing scenarios, disconnecting a client does NOT automatically free server resources, such as stateful EJBs that the client was using.
  35. 35. Coding a PowerBuilder EJB Client Application <ul><li>Advanced topics </li></ul><ul><li>java.lang.Object references </li></ul><ul><li>Using interfaces and casting </li></ul><ul><li>Client-managed transactions </li></ul><ul><li>Creating proxies for stand-alone Java classes </li></ul>
  36. 36. Coding a PowerBuilder EJB Client Application <ul><li>java.lang.Object references </li></ul><ul><li>Many EJB methods will return java.lang.Object references or expect them as parameters </li></ul><ul><li>PowerBuilder will treat a java.lang.Object reference as a PowerBuilder any variable within the method prototype </li></ul><ul><li>The mapping structure created when generating proxies is consulted at run-time to map the underlying Java class to an appropriate proxy </li></ul>Advanced Topics global type Hello_ejb_pb_mapping from structure string item1 = &quot;java.rmi.Remote:Remote&quot; string item2 = &quot;java.io.Serializable:Serializable&quot; string item3 = &quot;java.io.IOException:IOException&quot; string item4 = &quot;java.io.OutputStream:OutputStream&quot; string item5 = &quot;java.io.FilterOutputStream:FilterOutputStream&quot; string item6 = &quot;java.io.UnsupportedEncodingException:UnsupportedEncodingException&quot; string item7 = &quot;java.io.PrintStream:PrintStream&quot; …
  37. 37. Coding a PowerBuilder EJB Client Application <ul><li>Using interfaces and casting </li></ul><ul><li>Additional JavaVM object methods extend your capabilities </li></ul><ul><ul><li>GetActualClass – determines the actual Java class name when provided a PowerBuilder proxy object that represents a Java interface </li></ul></ul><ul><ul><li>GetSuperClass – determines the Java class that is the ancestor of the Java class or interface represented by the PowerBuilder proxy object </li></ul></ul><ul><ul><li>GetInterfaces – returns list of Java interfaces implemented by the Java class represented by the given PowerBuilder proxy object </li></ul></ul><ul><ul><li>DynamicCast – casts a PowerBuilder proxy object to another object – typically used to downcast a Java reference, use cautiously since invalid casts can cause instability </li></ul></ul>Advanced Topics
  38. 38. Coding a PowerBuilder EJB Client Application <ul><li>Using interfaces and casting – an example </li></ul><ul><ul><li>Collection px_Collection </li></ul></ul><ul><ul><li>Vector px_Vector </li></ul></ul><ul><ul><li>Stack px_Stack </li></ul></ul><ul><ul><li>TRY </li></ul></ul><ul><ul><li>px_ListMgr = px_ListMgrHome.create() </li></ul></ul><ul><ul><li>px_Collection = px_ListMgr.getList(as_listType) </li></ul></ul><ul><ul><li>CHOOSE CASE g_JavaVM. GetActualClass (px_Collection) </li></ul></ul><ul><ul><li>CASE &quot;java.util.Stack&quot; </li></ul></ul><ul><ul><li>px_Stack = g_JavaVM. DynamicCast (px_Collection, &quot;Stack&quot;) </li></ul></ul><ul><ul><li>DO WHILE TRUE </li></ul></ul><ul><ul><li>this.processItem(px_Stack.pop()) </li></ul></ul><ul><ul><li>LOOP </li></ul></ul><ul><ul><li> CASE &quot;java.util.Vector“ </li></ul></ul><ul><ul><li>px_Vector = g_JavaVM. DynamicCast (px_Collection, “Vector”) </li></ul></ul><ul><ul><li>FOR i TO px_Vector.size() </li></ul></ul><ul><ul><li>this.processItem(px_Vector.elementAt(i)) </li></ul></ul><ul><ul><li>NEXT </li></ul></ul><ul><ul><li>... </li></ul></ul>Advanced Topics
  39. 39. Coding a PowerBuilder EJB Client Application <ul><li>Client-managed transactions </li></ul><ul><li>The EJBTransaction object in the PBNI implementation has a direct correspondence to javax.transaction.UserTransaction </li></ul><ul><ul><li>Begin - starts a transaction </li></ul></ul><ul><ul><li>Commit - commits the current transaction </li></ul></ul><ul><ul><li>SetRollbackOnly - marks the current transaction as doomed </li></ul></ul><ul><ul><li>SetTransactionTimeout - sets the amount of time a transaction can be in progress before it is rolled back. </li></ul></ul><ul><ul><li>GetStatus - returns the status of the current transaction </li></ul></ul><ul><li>Not all EJB servers support this and even if they do, best practices discourage its use </li></ul>Advanced Topics
  40. 40. Coding a PowerBuilder EJB Client Application <ul><li>Client-managed transactions – an example </li></ul><ul><ul><li>EJBConnection conn </li></ul></ul><ul><ul><li>EJBTransaction trans </li></ul></ul><ul><ul><li>conn = create EJBConnection </li></ul></ul><ul><ul><li>TRY </li></ul></ul><ul><ul><li>conn.connectToServer(is_props) </li></ul></ul><ul><ul><li>trans = conn. getEJBTransaction () </li></ul></ul><ul><ul><li>trans. Begin () </li></ul></ul><ul><ul><li>// Create a component and call methods to be </li></ul></ul><ul><ul><li>// executed within the transaction </li></ul></ul><ul><ul><li>trans. Commit () </li></ul></ul><ul><ul><li>CATCH (Exception e) </li></ul></ul><ul><ul><li>trans. Rollback () </li></ul></ul><ul><ul><li>END TRY </li></ul></ul>Advanced Topics
  41. 41. Coding a PowerBuilder EJB Client Application <ul><li>Creating proxies for stand-alone Java classes </li></ul><ul><li>You can use the EJB client implementation to call Java classes on the client as well! </li></ul><ul><li>Create ‘dummy’ home and remote interface Java classes and reference the desired Java class as a method argument or return value </li></ul><ul><li>Generate proxies for this ‘pseudo’ EJB and the proxies for the referenced classes will be automatically generated </li></ul><ul><li>Now use the CreateJavaInstance method of the EJBConnection object to create instances of your Java class on the client (you can do this without issuing a ConnectToServer ) </li></ul>Advanced Topics public interface DummyHome {} Dummy Home interface Java code Dummy Home interface Java code public interface Dummy { public abstract void foo(com.your.JavaClass x); }
  42. 42. Accessing Third-Party EJB Servers <ul><li>Agenda </li></ul><ul><li>Overview of the Enterprise JavaBeans (EJB) Model </li></ul><ul><li>PowerBuilder EJB client implementation </li></ul><ul><li>Coding a PowerBuilder EJB client application </li></ul><ul><li>Deploying PowerBuilder NVOs to EJB servers </li></ul><ul><li>Additional resources </li></ul>
  43. 43. Deploying PowerBuilder NVOs to EJB Servers <ul><li>Sunlly Group’s PBridge (http://www.sunlly.com) </li></ul><ul><li>Since PowerBuilder 7, you can use PowerBuilder NVOs natively in EAServer and have them interoperate with EJB components and Java clients </li></ul><ul><li>Sunlly PBridge’s offering will allow you to deploy your PowerBuilder components into other application servers such as WebLogic and WebSphere </li></ul><ul><ul><li>Built on PBNI architecture offered by PowerBuilder 9 </li></ul></ul><ul><ul><li>Currently in beta and supporting </li></ul></ul><ul><ul><ul><li>BEA WebLogic </li></ul></ul></ul><ul><ul><ul><li>IBM WebSphere </li></ul></ul></ul><ul><ul><ul><li>Sun J2EE reference implementation </li></ul></ul></ul><ul><li>Visit them at TechWave! </li></ul>
  44. 44. Deploying PowerBuilder NVOs to EJB Servers Sunlly PBridge – Client Deployment Interface
  45. 45. Accessing Third-Party EJB Servers <ul><li>Agenda </li></ul><ul><li>Overview of the Enterprise JavaBeans (EJB) Model </li></ul><ul><li>PowerBuilder EJB client implementation </li></ul><ul><li>Coding a PowerBuilder EJB client application </li></ul><ul><li>Deploying PowerBuilder NVOs to EJB servers </li></ul><ul><li>Additional resources </li></ul>
  46. 46. Accessing Third-Party EJB Servers <ul><li>InitialContext classes and default URLs for major EJB servers </li></ul>Additional Resources jnp:// server :1099 org.jnp.interfaces.NamingContextFactory Jboss ormi:// server :23791/ application com.evermind.server. ApplicationClientInitialContextFactory Oracle9 i AS iiop:// server :9010 com.sun.jndi.cosnaming.CNCtxFactory Sun ONE iiop:// server :900 (v. 4) Iiop:// server :2809 (v. 5) com.ibm.websphere.naming. WsnInitialContextFactory IBM WebSphere Application Server t3:// server :7001 weblogic.jndi.WLInitialContextFactory BEA WebLogic Server iiop:// server : 9000 com.sybase.ejb.InitialContextFactory Sybase EAServer PROVIDER_URL (default) INITIAL_CONTEXT_FACTORY Class Server
  47. 47. Accessing Third-Party EJB Servers <ul><li>Learning more about the EJB client feature </li></ul><ul><li>PowerBuilder Extension Reference in product documentation set </li></ul><ul><li>EJB specification (http://java.sun.com/products/ejb/docs.html) </li></ul><ul><li>3rd party J2EE server web sites </li></ul><ul><ul><li>BEA Systems WebLogic Server (http://www.bea.com/framework.jsp?CNT=index.htm&FP=/content/products/platform/) </li></ul></ul><ul><ul><li>Jboss (http://www.jboss.org) </li></ul></ul><ul><ul><li>IBM WebSphere Application Server ( http://www.ibm.com /websphere) </li></ul></ul><ul><ul><li>Oracle9iAS ( http://http://www.oracle.com/ip/deploy/ias/ ) </li></ul></ul><ul><li>SAMS Publishing PowerBuilder: Internet and Distributed Application Development (http://www.pb9book.com) </li></ul><ul><li>Sybase Developer Network (http://sdn.sybase.com) </li></ul><ul><ul><li>Technical document: “Accessing 3 rd Party EJB Servers from PowerBuilder 9” (http://www.sybase.com/detail?id=1024977) </li></ul></ul><ul><ul><li>CodeXchange… </li></ul></ul>Additional Resources
  48. 48. SDN Presents CodeXchange <ul><li>New SDN feature enables community collaboration </li></ul><ul><ul><li>Download samples created by Sybase </li></ul></ul><ul><ul><li>Leverage contributions of others to exploit PBNI (i.e. PBNI CommonDialog, PBNI OLEObject utilities) </li></ul></ul><ul><ul><li>Contribute your own code or start your own collaborative project with input from other PowerBuilder experts </li></ul></ul><ul><li>Any SDN member can participate </li></ul><ul><ul><li>Log in using your MySybase account via SDN </li></ul></ul><ul><li>Join the collaboration already underway </li></ul><ul><ul><li>http://powerbuilder.codexchange.sybase.com or via SDN at www.sybase.com/developer </li></ul></ul><ul><li>SDN & CodeXchange at TechWave </li></ul><ul><ul><li>Technology Boardwalk </li></ul></ul><ul><ul><li>Sybase Booth Theater </li></ul></ul>Share PowerBuilder 9 Code and Tools
  49. 49. Accessing Third-Party EJB Servers <ul><li>Questions </li></ul>

×