2 Using the PowerBuilder Application Server Plugin Alex PrattSystems ConsultantSybase EMEA
3 PreludeEnable PowerBuilder for Distributed/Web Applications has been high on the agenda in the last 10 years.There have been many solutions or frameworks developed or supported by Sybase.Most of these solutions require Sybase EAServer.Cost, Market pressure,… made life for a PowerBuilder developer tough. ( ie. Corporate decision to use WebLogic as J2EE container).Productivity, Agility rely on the the portability and re-use of legacy/existing code.
5 Prelude There was room for a solution that allows: Deploying PowerBuilder logic in different containers (J2EE)Preserved the investment made into PB code and allowed to continue use PB in J2EE projects.Enables the use of open source infrastructure.Integrated into “SOA philosophy” ( support for webservices…)The PowerBuilder Application Server Plugin answers these requirements
6 PowerBuilder Application Server Plugin What is it?PlatformsIDE IntegrationInstallationConfigurationDevelopmentDeploymentDebuggingSecurityTroubleshootingLicensing, Pricing, Release…
7 What is it?A Deployment Tool that wraps PowerBuilder NVOs as EJB Session Beans (optionally as J2EE 1.4 Web Services) for deployment into a J2EE 1.3+ compliant application server.A Server Runtime Library that integrates the PowerBuilder Virtual Machine with the EJB container and transaction and connection managers of the application server.A Remote Debugging Component that permits debugging from the PowerBuilder IDE.A Web DataWindow Component that permits browser-based clients to utilize DataWindow functionality.(certified in v1.x)A Proxy Server that permits PB clients to call deployed PB NVOs without the use of a client side Java virtual machine. Also permits PB clients and components to call “pure” EJBs.
11 Supported PowerBuilder Versions You might find that releases before work, but they will not be officially “supported”, and they will not be QA certified.
12 PowerBuilder IDE Integration The deployment tool runs on your application server machine, and emulates the Sybase EAServer PB NVO deployment API.To create a component (in PowerBuilder IDE)New -> Target -> Application Server Component, orNew -> Project -> Application Server Component, orNew -> Project -> Application Server Component WizardTo deploy a component (in project painter)“Deploy Button”, or Design -> Deploy Project
17 InstallationThe PB Server Plugin is installed on the application server host.This does not need to be the same machine where the PowerBuilder IDE is running.The PowerBuilder VM must also be installed on the application server host. The plugin installer will take care of this.(you can also use the Runtime packager to install the PowerBuilder components necessary)
18 Installation - Continued Default installation directory (Windows)c:\Program Files\Sybase\PBServerIf you have a new or updated copy of the plugin in a JAR or ZIP archive, just extract into the selected installation directory.(Optional) Define system level environment variable PB_SERVER_HOME to refer to this directory.You can install multiple copies on a machine, each copy in a separate installation directory.
19 Configuration - General The PB server plugin is configured on the application server host.Configuration uses:Batch files (Windows)Shell scripts (Unix), with file extension “.sh”Ant XML scripts (all platforms)To customize, edit the XML scripts.Shut down your application server before running configuration tasks.Ensure that file bin\set-java-home.bat refers to the JDK used by your application server.
20 Configuration - JBoss Run the following commands (Windows) cd %PB_SERVER_HOME%bin\set-admin-passwordbin\configure pb-server-jboss –Djboss.home=jboss-home-dirTo customize the configuration XML scripts edit:config\ejb-proxy-jboss.xmlconfig\pb-server-jboss.xmlIf you edit an XML script, re-run the above ‘configure’ command. Hint: check if the scripts require editing before running ‘configure’ for the first time.
21 Demo Step 1: all the components are installed ( PASP, JBOSS, JDK) Step 2: set-java-home.bat adjustments ( we are using the jdk 1.5)Step 3: set-admin-password.bat ( only if you have not done this during the install)Step 4: check that pb-server-jboss.xml and ejb-server-jboss.xml are adapted.Step 5: runconfigure.bat pb-server-jboss « -Djboss.home=c:\jboss GA »
22 C:\PBAppServer1\bin>configure. bat pb-server-jboss "-Djboss C:\PBAppServer1\bin>configure.bat pb-server-jboss "-Djboss.home=c:\jboss GA« Buildfile: C:\PBAppServer1\bin\..\config\pb-server-jboss.xmlconfigure:configure-server-onetime:configure-server-onetime-tasks:[mkdir] Created dir: C:\PBAppServer1\genfiles\jboss[jar] Building jar: C:\jboss GA\server\default\lib\init-pb-server.jar[copy] Copying 1 file to C:\jboss GA\server\default\lib[copy] Copying 1 file to C:\jboss GA\server\default\deployconfigure-client-onetime:[copy] Copying 2 files to C:\PBAppServer1\libconfigure-proxy:configure-pb-server-test:BUILD SUCCESSFULTotal time: 12 seconds
23 Server Startup - General When starting your server, the following must be ensured.Java system property pb.server.home refers to the plugin installation directory.%PB_SERVER_HOME%\lib\pb-server-(14 or 15).jar is in the CLASSPATH or otherwise shared by all deployed applications in the JVM (most of the provided scripts take care of this)%PB_SERVER_HOME%\lib is in the system PATH or java.library.path.Your PowerBuilder directory containing pbvmXXX.dll or libpbvmXXX.* is in the system PATH (Windows), LD_LIBRARY_PATH (Solaris), etc.Environment variable JAGUAR is set to plugin install dir.Enviromnent variable JAGSSL is set to true.
24 Generated Startup Script The configuration task creates a batch / script file that can be used to start your server with the necessary options. It will start your server assuming a “standard” installation of your server.The generated batch/script file can be used as a sample that you can use to determine what needs to be done before startup for the plugin to work with your server.bin\start-jboss.*, run-jboss.*bin\start-weblogic.*bin\start-websphere.*You should probably consult your application server administrator to determine the best startup script.
25 Lets do it!!! C:\PBAppServer1\bin>start-jboss.bat start "JBoss" "C:\PBAppServer1\bin\..\bin\run-jboss.bat »If it is the first time make sure you see these lines in the console or the pb-server.log15:44:40,823 INFO [STDOUT] Compiling: BCD.idl15:44:41,120 INFO [STDOUT] Compiling: MJD.idl15:44:41,198 INFO [STDOUT] Compiling: CTS.idl15:44:41,229 INFO [STDOUT] Compiling: XDT.idl15:44:41,823 INFO [STDOUT] Compiling: CtsComponents.idl15:44:43,011 INFO [STDOUT] Compiling: CtsServices.idl15:44:43,073 INFO [STDOUT] Compiling: TabularResults.idl15:44:43,417 INFO [STDOUT] Compiling: CosNaming.idl15:44:43,526 INFO [STDOUT] Compiling: DataWindow.idl15:44:43,745 INFO [STDOUT] Compiling: SessionManager.idl
26 Deployment – JBoss Notes Ensure that automatic deployment is enabled.Make sure that the ScanEnabled attribute is not set to false.Note: automatic redeployment doesn’t always seem to work properly with JBoss, when tested by Sybase.You may need to restart JBoss after deployment, to pick up your changes.
27 Development – Components Develop components as if you were writing NVOs for deployment to Sybase EAServer.Check the PowerBuilder documentation for general instructions.The deployment tool will wrap your PB NVOs as standard EJB session beans.Target-specific deployment descriptors are generated to automate the binding of JNDI names and JDBC data source resource references.
28 Development – Data Sources PowerScript (in NVO source code):sqlca.dbms = “JDBC”sqlca.dbparm = “CacheName=’MyCache’”(I use SybaseDB)connect; // check error code// use embedded SQL or DataStoredisconnect; // check error codeWhatever “cache names” you use in your code must be mapped to application server “data source” names.
29 Development – Data Sources %PB_SERVER_HOME%\config\pb-server-XXX.xml must be edited to map PB “cache names” to app. server “data source” JNDI names. Re-run the “configure” command afterwards.Add -Dcom.sybase.jaguar.jcm=true to the java options of the application server to get more debug info on the connection cache in the pb-server.log file.Remember you need to add the jdbc-driver.jar to %jboss_home%\server\default\lib16:55:39,328ERROR[STDERR]com.sybase.powerbuilder.jdbc.PbjdbcJagCache.GetConnectionFromJaguar(PbjdbcJagCache.java:297)And add reference to it in pb-server.jboss.xml
30 Development – Native Data Sources We support Sybase, Oracle, Oracle Unicode, ODBC,. ODBC Unicode. We have a “fake” JDBC driver for each data source type. The application server doesn’t realize it is managing native connections!Check the documentation for full details.Basic steps (in addition to those on previous page) are:(PowerScript Code) Set the sqlca.dbms, e.g.sqlca.dbms = “SYJ” // Sybase Native(App. Server Config) Define your application server data source to use the appropriate “fake” JDBC driver class, e.g.com.sybase.jaguar.jcm.sybase.SybaseDriver(App. Server Config) Set the connection URL, e.g.jdbc:sybase:jcm:sybase:databaseName=MyDB;user=xx;password=yy
31 Development – Data Types PowerBuilder data types are mapped to Java data types in the generated EJB remote interface. Check docs for full details.Basic types:PB: Boolean, Char, Byte, Integer, Long, LongLong, Real, Double, DecimalJava: boolean, char, byte, short, int, long, float, double, java.math.BigDecimalOther types:PB: Blob, String, Date / Time / DateTime, ResultSetJava: byte, String, java.util.Calendar, java.sql.ResultSetPB structures map to Java serializable classes with public fields.PB variable-sized arrays map to Java arrays, don’t use PB fixed size arrays.Don’t use “by reference” parameters, all results must be by the “return” type. You may need to return PB structures.
32 Development – Null Values If you want to propagate null values, you need to use the “XDT” data types.XDT_IntValue maps to java.lang.Integer.XDT_LongValue maps to java.lang.Long.You get the idea!To generate the “XDT” data types, use the “Application Server Proxy” wizard to generate proxies for package “XDT”. It may be useful to save these generated types in a PBL for convenient reuse in multiple projects.Each “XDT” type has a ‘value’ field and an ‘isNull’ field. Set ‘isNull’ to true to propagate a null value.
33 Development – DataStore Type The PB DataStore type, in combination with the PB ResultSet return type, is particularly useful for PB NVOs running in an application server.You should use DataStore only internally within your component.For improved performance, use PB NVO instance variables and create the DS and assign the “dataobject” in your NVO constructor.But check application server memory usage!
34 PB ErrorLogging Class Writes to plugin log file. PowerScript Usage: %PB_SERVER_HOME%\logs\pb-server.logPowerScript Usage:ErrorLogging loggergetContextService(“ErrorLogging”, logger)logger.log(“My Message”)
35 PB TransactionServer Class Supported methods:CreateInstance, DisableCommit, EnableCommit, IsCallerInRole, IsTransactionAborted, SetAbort, SetComplete.CreateInstance notes (for NVO to NVO inter-component calls):Use the two argument form and specify full JNDI name of target component, e.g. (error checking code omitted for brevity)TransactionServer tsgetContextService(“TransactionServer”, ts)pbtest_MyComp comp // remember to generate and use proxiests.createInstance(comp, “pbtest/MyComp”)// call methods on compIf the target NVO is not in the same EJB-JAR as the calling NVO, you might encounter issues with your application server’s class loader (e.g. ClassCastException). Sybase will NOT support NVO inter-component calls across EJB-JAR boundaries if you encounter class loader issues. Consult your application server vendor for assistance with class loader issues across EJB-JAR boundaries.
36 Development – EJB Clients For EJB clients, use your application server’s facilities for EJB client access.If your package is named “MyPackage”, and your component is named “MyComp”:The generated EJB home interface is named MyPackage.ejb.MyCompHomeThe generated EJB remote interface is named MyPackage.ejb.MyCompThe Java package for home and remote interfaces can be overridden. See “Deployment – Java Packages”.The JNDI name is “MyPackage/MyComp”.For co-located clients (e.g. JSP, servlet, other EJBs) you can use ejb-refs or direct JNDI lookups.
37 Development – PB Clients PowerBuilder has built-in facilities for calling EJBs in third party application servers: EJB proxy ProjectCheck the PowerBuilder documentation for the EJBConnection class and your application server documentation for general instructions.Alternatively, we provide a proxy server to permit native IIOP communication (without client-side JVM) from PB clients to NVOs running in your EJB server. See next page…
38 PB Clients – Proxy Server Check the PowerBuilder documentation for usage of the Connection.CreateInstance method.The Proxy Server runs alongside your application server on your application server machine. It starts automatically when your application server starts the plugin.You can define multiple proxy servers if you have multiple application servers. Your client can use multiple connection URLs for load balancing and failover, e.g.iiop://myhost1:2000;iiop://myhost:2000To configure your proxy server(s), edit:config\ejb-proxy-XXX.xmlWe will provide a redistributable “Client Edition” of the proxy server, in case you don’t want to run it on the server host.
39 Proxies for “pure” EJBs You can also generate proxies to allow PB clients and PB components to call “pure” EJBs.Use the “deploy” command:bin\deploy –proxy myejb.jarThen use the “Application Server Proxy” features of the PB IDE to generate PowerBuilder proxies.Use Connection.CreateInstance to call from PB clients.Use TransactionServer.CreateInstance to call from PB components.There are some restrictions on data types that can be mapped, check the documentation for full details.
40 Web DataWindowSupports browser-based clients using XML, XHTML, HTML. See DataWindow Programmer's Guide for general information.Check PB Server Plugin documentation for latest details on using the Web DataWindow.This is not considered a “P1” feature for the initial release of the PB server plugin. If we run into problems, we may defer full support of this feature to a subsequent release.(This is the case in version 1.0, it might work but is not guarantied)
41 Deployment – GeneralIn the PB Project Painter, for your component project(s), specify connection information as follows:Host name: TCP host name for server machinePortLogin ID -Login password - (remember, you set it!)You can override the host name and port number that the server uses for its deployment listener by changing the deploy.host and deploy.port properties in config/pb-server-XXX.xml.Remember to re-run ‘configure’.
42 DemoStep 1: lets do a simple NVO deployement using the Application Server Component TargetStep 2: lets test the deployed component with the pb-server-test.bat(NB. We can get here a nice gage of the expected performance, compare with EAServer 6!!!)Step 3: create a connection cache for the test database.(customise sybase-ds.xml and save it into %jboss_home%\server\default\deploy)Step 4: add some more functions to the NVO to test different aspects ( time management, db connectivity…)Step 5: let’s look at a couple of sample applications and see what can go wrong!!!
43 Deployment – Test & Debug “Live Editing” is useful for quickly testing changes without a full redeploy.Check the PowerBuilder “Application Techniques” document for details.Set the ejbDeployIfUnchanged property to false when using live editing. This is in:%PB_SERVER_HOME%\config\pb-server-XXX.xmlAnd remember to re-run ‘configure’!“Remote Debugging” is very useful too!
44 Remote DebuggingUse the “Start Remote” button in the PowerBuilder debugger to start a remote debugging session, as if debugging a component in Sybase EAServer.Check the PowerBuilder documentation for detailed instructions.
45 Deployment – Web Services Not enabled by default.Enable via check-box in Project Painter Properties.Your application server must support J2EE 1.4.The ResultSet return type is not supported for web services. Use array and structure types instead.
46 Deployment – Java Packages Defaults to “xyz.ejb” for NVO package “xyz”.In the Project Painter Properties, you can specify an alternate Java package.Recommendation: use Java package naming conventions, e.g. “com.example.bank”.This is required for NVO to be exposed as Webservice.
47 Deployment – Generated Code Base directory for generated files:%PB_SERVER_HOME%\genfiles\javaSubdirectories for:applicationsclassesejbjarssrcYou can generally delete generated code after deployment, but this will slow down subsequent redeployments. If using the “Proxy Server”, don’t delete the generated files. The Proxy Server uses some of them at run time.
48 Deployment – Naming Conventions Enable “camel case” option to map PB identifiers to Java style identifiers.bin\configure camel-case-onbin\configure camel-case-off (if you don’t like it)PowerScript identifiers with underscore are mapped to Java “camel case” for parameter names and NVO methods, e.g. “my_simple_method” maps to “mySimpleMethod”.A leading capital is used for structure types e.g. “my_structure” maps to “MyStructure”. Structure field names are not changed.Component names are not changed from what you specify in the Project Painter. We recommend using the Java class naming conventions (e.g. “MyComp”).Your NVO implementation class can use any name.Note: You must enable the camel case option if you will be exposing components as web services.
49 Deployment – Repository Files Base directory for repository files:%PB_SERVER_HOME%\RepositorySubdirectories for:IDL (interface definitions)Component (component properties and PBDs)Instance (server and data source properties)Package (package properties)These are needed during deployment and at runtime.
50 Deployment – Security Roles Default to “unchecked”.In the Project Painter Properties dialog, you can specify required roles (logical role names) for each component.Use your application server’s facilities (if necessary) for mapping these logical role names onto physical roles.
51 Deployment – Cluster Notes If your application server is running in a cluster, and each server has its own copy of the PB plugin directory, you must either:Deploy all components to all servers, orCopy the contents of the “config”, “deploy”, “genfiles” and “Repository” directories to all target servers, and use your application server’s facilities for distributing the deployed EJB-JAR files across the cluster.
52 Deployment – Validation Test Using the PowerBuilder IDE, define a component with package name “pbtest” and component name “MyComp”.Add some business methods of your choice. If you are feeling brave, you might want to try some methods with database access Deploy to your application server.Run the following commands:cd %PB_SERVER_HOME%bin\pb-server-testThe test program will try to call all methods of your component with “fake” parameter values (e.g. 1, 2, “S1”, S2”, …)If you have a method named “perftest”, the test program will call it repeatedly to provide basic performance metrics.Source code for the test client program can be found in src/java/com/sybase/pb/server/PbServerTest.java.
53 Troubleshooting PB application server plugin log: %PB_SERVER_HOME%\logs\pb-server.logPB application server proxy log:%PB_SERVER_HOME%\logs\ejb-proxy.logYour application server log file(s).Your application server console window (if applicable).
57 Configuration - WebLogic Run the following commands (Windows)cd %PB_SERVER_HOME%bin\set-admin-passwordbin\configure pb-server-weblogic –Dwls.home=wls-home-dir (e.g. “–Dwls.home=c:\bea\weblogic90”)To customize the configuration XML scripts edit:config\ejb-proxy-weblogic.xmlconfig\pb-server-weblogic.xmlIf you edit an XML script, re-run the above ‘configure’ command. Hint: check if the scripts require editing before running ‘configure’ for the first time.
58 Configuration - WebSphere Run the following commands (Windows)cd %PB_SERVER_HOME%bin\set-admin-passwordbin\configure pb-server-websphere –Dwas.home=was-home-dir (e.g. “–Dwas.home=c:\Program Files\IBM\WebSphere\AppServer”)To customize the configuration XML scripts edit:config\ejb-proxy-websphere.xmlconfig\pb-server-websphere.xmlIf you edit an XML script, re-run the above ‘configure’ command. Hint: check if the scripts require editing before running ‘configure’ for the first time.
59 Once Only Tasks – WebLogic Start the server.Using the WebLogic console, define a Startup Class using class name com.sybase.pb.server.PbServerStart.Shutdown the server.
60 Once Only Tasks - WebSphere Start the server.Using the WebSphere admin console, Enable the “Startup beans service”, and then deploy the PB startup service:%PB_SERVER_HOME%\deploy\websphere\pb-startup.jarShutdown the server.
61 Deployment – WebLogic Notes Ensure that your server is running in “development” mode.To configure the deployment directory, set the “deploy.dir” property in:%PB_SERVER_HOME%\config\pb-server-weblogic.xmlAlso check the “wls.domain” property is correct for your server.(you’ll realise it very quickly).
62 Deployment - WebSphere To customize the WebSphere Ant deployment options, edit (under %PB_SERVER_HOME%):config/ws-ejb-deploy.xmlconfig/ws-install-app.xmlConsult your WebSphere documentation for further details.WebSphere EJB-JAR deployment can be a bit slowIf you get impatient, you might consider using a free server such as JBoss or EAServer Developer Edition 6.0 for initial development, and deploying to WebSphere once your application is tested.